importing the basics of the projectile/damage system from the Sounours Play-Live branch (51200); only modified how damage numbers and modifiers are interacted with and how a projectile's characteristics is accessed from the Tool that emits it; GlobalDefinitions could be imported over almost entirely, fortunately

This commit is contained in:
FateJH 2018-06-12 21:51:53 -04:00
parent 8eb2d9cf80
commit 1bceb35226
9 changed files with 2444 additions and 6 deletions

View file

@ -1,8 +1,8 @@
// Copyright (c) 2017 PSForever
package net.psforever.objects
import net.psforever.objects.definition.{AmmoBoxDefinition, ToolDefinition}
import net.psforever.objects.equipment.{Ammo, Equipment, FireModeDefinition, FireModeSwitch}
import net.psforever.objects.definition.{AmmoBoxDefinition, ProjectileDefinition, ToolDefinition}
import net.psforever.objects.equipment._
import scala.annotation.tailrec
@ -59,6 +59,20 @@ class Tool(private val toolDef : ToolDefinition) extends Equipment with FireMode
AmmoType
}
def Projectile : ProjectileDefinition = {
toolDef.ProjectileTypes({
val projIndices = FireMode.ProjectileTypeIndices
if(projIndices.isEmpty) {
AmmoTypeIndex //e.g., bullet_9mm -> bullet_9mm_projectile, bullet_9mm_AP -> bullet_9mm_AP_projectile
}
else {
projIndices(AmmoSlot.AmmoTypeIndex) //e.g., pulsar: f.mode1 -> pulsar_projectile, f.mode2 = pulsar_ap_projectile
}
})
}
def ProjectileType : Projectiles.Value = Projectile.ProjectileType
def Magazine : Int = AmmoSlot.Magazine
def Magazine_=(mag : Int) : Int = {

View file

@ -0,0 +1,161 @@
// Copyright (c) 2017 PSForever
package net.psforever.objects.definition
import net.psforever.objects.equipment.{DamageProfile, DamageType, Projectiles}
class ProjectileDefinition(objectId : Int) extends ObjectDefinition(objectId) with DamageProfile {
private val projectileType : Projectiles.Value = Projectiles(objectId) //let throw NoSuchElementException
private var damage0 : Int = 0
private var damage1 : Option[Int] = None
private var damage2 : Option[Int] = None
private var damage3 : Option[Int] = None
private var damage4 : Option[Int] = None
private var acceleration : Int = 0
private var accelerationUntil : Float = 0f
private var damageType : DamageType.Value = DamageType.None
private var damageTypeSecondary : DamageType.Value = DamageType.None
private var degradeDelay : Float = 1f
private var degradeMultiplier : Float = 1f
private var initialVelocity : Int = 1
private var lifespan : Float = 1f
private var damageAtEdge : Float = 1f
private var damageRadius : Float = 1f
private var useDamage1Subtract : Boolean = false
Name = "projectile"
def ProjectileType : Projectiles.Value = projectileType
def UseDamage1Subtract : Boolean = useDamage1Subtract
def UseDamage1Subtract_=(useDamage1Subtract : Boolean) : Boolean = {
this.useDamage1Subtract = useDamage1Subtract
UseDamage1Subtract
}
def Damage0 : Int = damage0
def Damage0_=(damage : Int) : Int = {
damage0 = damage
damage0
}
def Damage0_=(damage : Option[Int]) : Int = {
damage0 = damage match {
case Some(value) => value
case None => 0 //can not be set to None
}
Damage0
}
def Damage1 : Int = damage1.getOrElse(Damage0)
def Damage1_=(damage : Int) : Int = Damage1_=(Some(damage))
def Damage1_=(damage : Option[Int]) : Int = {
this.damage1 = damage
Damage1
}
def Damage2 : Int = damage2.getOrElse(Damage1)
def Damage2_=(damage : Int) : Int = Damage2_=(Some(damage))
def Damage2_=(damage : Option[Int]) : Int = {
this.damage2 = damage
Damage2
}
def Damage3 : Int = damage3.getOrElse(Damage2)
def Damage3_=(damage : Int) : Int = Damage3_=(Some(damage))
def Damage3_=(damage : Option[Int]) : Int = {
this.damage3 = damage
Damage3
}
def Damage4 : Int = damage4.getOrElse(Damage3)
def Damage4_=(damage : Int) : Int = Damage4_=(Some(damage))
def Damage4_=(damage : Option[Int]) : Int = {
this.damage4 = damage
Damage4
}
def Acceleration : Int = acceleration
def Acceleration_=(accel : Int) : Int = {
acceleration = accel
Acceleration
}
def AccelerationUntil : Float = accelerationUntil
def AccelerationUntil_=(accelUntil : Float) : Float = {
accelerationUntil = accelUntil
AccelerationUntil
}
def ProjectileDamageType : DamageType.Value = damageType
def ProjectileDamageType_=(damageType1 : DamageType.Value) : DamageType.Value = {
damageType = damageType1
ProjectileDamageType
}
def ProjectileDamageTypeSecondary : DamageType.Value = damageTypeSecondary
def ProjectileDamageTypeSecondary_=(damageTypeSecondary1 : DamageType.Value) : DamageType.Value = {
damageTypeSecondary = damageTypeSecondary1
ProjectileDamageTypeSecondary
}
def DegradeDelay : Float = degradeDelay
def DegradeDelay_=(degradeDelay : Float) : Float = {
this.degradeDelay = degradeDelay
DegradeDelay
}
def DegradeMultiplier : Float = degradeMultiplier
def DegradeMultiplier_=(degradeMultiplier : Float) : Float = {
this.degradeMultiplier = degradeMultiplier
DegradeMultiplier
}
def InitialVelocity : Int = initialVelocity
def InitialVelocity_=(initialVelocity : Int) : Int = {
this.initialVelocity = initialVelocity
InitialVelocity
}
def Lifespan : Float = lifespan
def Lifespan_=(lifespan : Float) : Float = {
this.lifespan = lifespan
Lifespan
}
def DamageAtEdge : Float = damageAtEdge
def DamageAtEdge_=(damageAtEdge : Float) : Float = {
this.damageAtEdge = damageAtEdge
DamageAtEdge
}
def DamageRadius : Float = damageRadius
def DamageRadius_=(damageRadius : Float) : Float = {
this.damageRadius = damageRadius
DamageRadius
}
}
object ProjectileDefinition {
def apply(projectileType : Projectiles.Value) : ProjectileDefinition = {
new ProjectileDefinition(projectileType.id)
}
}

View file

@ -8,12 +8,15 @@ import scala.collection.mutable
class ToolDefinition(objectId : Int) extends EquipmentDefinition(objectId) {
private val ammoTypes : mutable.ListBuffer[AmmoBoxDefinition] = new mutable.ListBuffer[AmmoBoxDefinition]
private val projectileTypes : mutable.ListBuffer[ProjectileDefinition] = new mutable.ListBuffer[ProjectileDefinition]
private val fireModes : mutable.ListBuffer[FireModeDefinition] = new mutable.ListBuffer[FireModeDefinition]
Name = "tool"
Packet = ToolDefinition.converter
def AmmoTypes : mutable.ListBuffer[AmmoBoxDefinition] = ammoTypes
def ProjectileTypes : mutable.ListBuffer[ProjectileDefinition] = projectileTypes
def FireModes : mutable.ListBuffer[FireModeDefinition] = fireModes
def NextFireModeIndex(index : Int) : Int = index + 1

View file

@ -0,0 +1,24 @@
// Copyright (c) 2017 PSForever
package net.psforever.objects.equipment
trait DamageProfile {
def Damage0 : Int
def Damage0_=(damage : Int) : Int
def Damage1 : Int
def Damage1_=(damage : Int) : Int
def Damage2 : Int
def Damage2_=(damage : Int) : Int
def Damage3 : Int
def Damage3_=(damage : Int) : Int
def Damage4 : Int
def Damage4_=(damage : Int) : Int
}

View file

@ -0,0 +1,17 @@
// Copyright (c) 2017 PSForever
package net.psforever.objects.equipment
/**
* An `Enumeration` of the damage type.
*/
object DamageType extends Enumeration(1) {
type Type = Value
final val Direct,
Splash,
Radiation,
Aggravated,
Plasma,
Comet,
None = Value
}

View file

@ -6,20 +6,25 @@ import net.psforever.objects.Tool
import scala.collection.mutable
class FireModeDefinition {
/** indices pointing to all ammo types used */
/** indices pointing to all ammo types used, in (an) order
* the ammo types list will be available from the `ToolDefinition` */
private val ammoTypeIndices : mutable.ListBuffer[Int] = mutable.ListBuffer[Int]()
/** custom indices pointing to the projectile type used for this mode's ammo types
* for most weapon fire modes, this list will be empty and the projectile will align with the `ammoTypeIndex`
* if at least one ammo type has a redirected projectile type, all projectiles must be defined for this mode */
private val projectileTypeIndices : mutable.ListBuffer[Int] = mutable.ListBuffer[Int]()
/** ammunition slot number this fire mode utilizes */
private var ammoSlotIndex : Int = 0
/** how many rounds are replenished each reload cycle */
private var magazine : Int = 1
/** how much is subtracted from the magazine each fire cycle;
* most weapons will only fire 1 round per fire cycle; the flamethrower, fire mode 1, fires 50 */
* most weapons will only fire 1 round per fire cycle; the flamethrower in fire mode 1 fires 50 */
private var rounds : Int = 1
/** how many sub-rounds are queued per round fired;
* the flechette fires 8 pellets per shell and generates 8 fire reports before the ammo count goes down */
private var chamber : Int = 1
//damage modifiers will follow here ... ?
/** modifiers for each damage type */
private val modifiers : DamageModifiers = new DamageModifiers
def AmmoSlotIndex : Int = ammoSlotIndex
@ -34,6 +39,12 @@ class FireModeDefinition {
ammoTypeIndices += index
}
def ProjectileTypeIndices : mutable.ListBuffer[Int] = projectileTypeIndices
def ProjectileTypeIndices_=(index : Int) : mutable.ListBuffer[Int] = {
projectileTypeIndices += index
}
def Magazine : Int = magazine
def Magazine_=(inMagazine : Int) : Int = {
@ -55,6 +66,8 @@ class FireModeDefinition {
Chamber
}
def Modifiers : DamageModifiers = modifiers
/**
* Shoot a weapon, remove an anticipated amount of ammunition.
* @param weapon the weapon
@ -105,3 +118,46 @@ class InfiniteFireModeDefinition extends FireModeDefinition {
*/
override def Discharge(weapon : Tool) : Int = 1
}
class DamageModifiers extends DamageProfile {
private var damage0 : Int = 0
private var damage1 : Int = 0
private var damage2 : Int = 0
private var damage3 : Int = 0
private var damage4 : Int = 0
def Damage0 : Int = damage0
def Damage0_=(damage : Int) : Int = {
damage0 = damage
Damage0
}
def Damage1 : Int = damage1
def Damage1_=(damage : Int) : Int = {
damage1 = damage
Damage1
}
def Damage2 : Int = damage2
def Damage2_=(damage : Int) : Int = {
damage2 = damage
Damage2
}
def Damage3 : Int = damage3
def Damage3_=(damage : Int) : Int = {
damage3 = damage
Damage3
}
def Damage4 : Int = damage4
def Damage4_=(damage : Int) : Int = {
damage4 = damage
Damage4
}
}

View file

@ -0,0 +1,146 @@
// Copyright (c) 2017 PSForever
package net.psforever.objects.equipment
/**
* An `Enumeration` of all the projectile types in the game, paired with their object id as the `Value`.
*/
object Projectiles extends Enumeration {
final val bullet_105mm_projectile = Value(1)
final val bullet_12mm_projectile = Value(4)
final val bullet_12mm_projectileb = Value(5)
final val bullet_150mm_projectile = Value(7)
final val bullet_15mm_apc_projectile = Value(10)
final val bullet_15mm_projectile = Value(11)
final val bullet_20mm_apc_projectile = Value(17)
final val bullet_20mm_projectile = Value(18)
final val bullet_25mm_projectile = Value(20)
final val bullet_35mm_projectile = Value(22)
final val bullet_75mm_apc_projectile = Value(26)
final val bullet_75mm_projectile = Value(27)
final val bullet_9mm_AP_projectile = Value(30)
final val bullet_9mm_projectile = Value(31)
final val anniversary_projectilea = Value(58)
final val anniversary_projectileb = Value(59)
final val aphelion_immolation_cannon_projectile = Value(87)
final val aphelion_laser_projectile = Value(91)
final val aphelion_plasma_rocket_projectile = Value(99)
final val aphelion_ppa_projectile = Value(103)
final val aphelion_starfire_projectile = Value(108)
final val bolt_projectile = Value(147)
final val burster_projectile = Value(155)
final val chainblade_projectile = Value(176)
final val colossus_100mm_projectile = Value(181)
final val colossus_burster_projectile = Value(188)
final val colossus_chaingun_projectile = Value(193)
final val colossus_cluster_bomb_projectile = Value(197)
final val colossus_tank_cannon_projectile = Value(207)
final val comet_projectile = Value(210)
final val dualcycler_projectile = Value(266)
final val dynomite_projectile = Value(268)
final val energy_cell_projectile = Value(273)
final val energy_gun_nc_projectile = Value(277)
final val energy_gun_tr_projectile = Value(279)
final val energy_gun_vs_projectile = Value(281)
final val enhanced_energy_cell_projectile = Value(282)
final val enhanced_quasar_projectile = Value(283)
final val falcon_projectile = Value(286)
final val firebird_missile_projectile = Value(288)
final val flail_projectile = Value(296)
final val flamethrower_fireball = Value(302)
final val flamethrower_projectile = Value(303)
final val flux_cannon_apc_projectile = Value(305)
final val flux_cannon_thresher_projectile = Value(308)
final val fluxpod_projectile = Value(311)
final val forceblade_projectile = Value(325)
final val frag_cartridge_projectile = Value(328)
final val frag_cartridge_projectile_b = Value(329)
final val frag_grenade_projectile = Value(332)
final val frag_grenade_projectile_enh = Value(333)
final val galaxy_gunship_gun_projectile = Value(341)
final val gauss_cannon_projectile = Value(348)
final val grenade_projectile = Value(372)
final val heavy_grenade_projectile = Value(392)
final val heavy_rail_beam_projectile = Value(395)
final val heavy_sniper_projectile = Value(397)
final val hellfire_projectile = Value(400)
final val hunter_seeker_missile_dumbfire = Value(404)
final val hunter_seeker_missile_projectile = Value(405)
final val jammer_cartridge_projectile = Value(414)
final val jammer_cartridge_projectile_b = Value(415)
final val jammer_grenade_projectile = Value(418)
final val jammer_grenade_projectile_enh = Value(419)
final val katana_projectile = Value(422)
final val katana_projectileb = Value(423)
final val lancer_projectile = Value(427)
final val lasher_projectile = Value(430)
final val lasher_projectile_ap = Value(431)
final val liberator_bomb_cluster_bomblet_projectile = Value(436)
final val liberator_bomb_cluster_projectile = Value(437)
final val liberator_bomb_projectile = Value(438)
final val maelstrom_grenade_projectile = Value(465)
final val maelstrom_grenade_projectile_contact = Value(466)
final val maelstrom_stream_projectile = Value(467)
final val magcutter_projectile = Value(469)
final val melee_ammo_projectile = Value(541)
final val meteor_common = Value(543)
final val meteor_projectile_b_large = Value(544)
final val meteor_projectile_b_medium = Value(545)
final val meteor_projectile_b_small = Value(546)
final val meteor_projectile_large = Value(547)
final val meteor_projectile_medium = Value(548)
final val meteor_projectile_small = Value(549)
final val mine_projectile = Value(551)
final val mine_sweeper_projectile = Value(554)
final val mine_sweeper_projectile_enh = Value(555)
final val oicw_projectile = Value(602)
final val pellet_gun_projectile = Value(631)
final val peregrine_dual_machine_gun_projectile = Value(639)
final val peregrine_mechhammer_projectile = Value(647)
final val peregrine_particle_cannon_projectile = Value(654)
final val peregrine_rocket_pod_projectile = Value(657)
final val peregrine_sparrow_projectile = Value(661)
final val phalanx_av_projectile = Value(665)
final val phalanx_flak_projectile = Value(667)
final val phalanx_projectile = Value(669)
final val phoenix_missile_guided_projectile = Value(675)
final val phoenix_missile_projectile = Value(676)
final val plasma_cartridge_projectile = Value(678)
final val plasma_cartridge_projectile_b = Value(679)
final val plasma_grenade_projectile = Value(682)
final val plasma_grenade_projectile_B = Value(683)
final val pounder_projectile = Value(694)
final val pounder_projectile_enh = Value(695)
final val ppa_projectile = Value(696)
final val pulsar_ap_projectile = Value(702)
final val pulsar_projectile = Value(703)
final val quasar_projectile = Value(713)
final val radiator_grenade_projectile = Value(718)
final val radiator_sticky_projectile = Value(719)
final val reaver_rocket_projectile = Value(723)
final val rocket_projectile = Value(735)
final val rocklet_flak_projectile = Value(738)
final val rocklet_jammer_projectile = Value(739)
final val scattercannon_projectile = Value(746)
final val scythe_projectile = Value(748)
final val scythe_projectile_slave = Value(749)
final val shotgun_shell_AP_projectile = Value(757)
final val shotgun_shell_projectile = Value(758)
final val six_shooter_projectile = Value(763)
final val skyguard_flak_cannon_projectile = Value(787)
final val sparrow_projectile = Value(792)
final val sparrow_secondary_projectile = Value(793)
final val spiker_projectile = Value(818)
final val spitfire_aa_ammo_projectile = Value(821)
final val spitfire_ammo_projectile = Value(824)
final val starfire_projectile = Value(831)
final val striker_missile_projectile = Value(840)
final val striker_missile_targeting_projectile = Value(841)
final val trek_projectile = Value(878)
final val vanu_sentry_turret_projectile = Value(944)
final val vulture_bomb_projectile = Value(988)
final val vulture_nose_bullet_projectile = Value(989)
final val vulture_tail_bullet_projectile = Value(991)
final val wasp_gun_projectile = Value(999)
final val wasp_rocket_projectile = Value(1001)
final val winchester_projectile = Value(1005)
}

View file

@ -236,6 +236,50 @@ class EquipmentTest extends Specification {
obj.AmmoType mustEqual Ammo.rocket
}
"projectile types and ammo types" in {
val suppressor_wep = Tool(suppressor)
suppressor_wep.ProjectileType mustEqual bullet_9mm_projectile.ProjectileType
suppressor_wep.NextAmmoType
suppressor_wep.ProjectileType mustEqual bullet_9mm_AP_projectile.ProjectileType
suppressor_wep.NextAmmoType
suppressor_wep.ProjectileType mustEqual bullet_9mm_projectile.ProjectileType
}
"projectile types and fire modes" in {
val pulsar_wep = Tool(pulsar)
pulsar_wep.ProjectileType mustEqual pulsar_projectile.ProjectileType
pulsar_wep.NextFireMode
pulsar_wep.ProjectileType mustEqual pulsar_ap_projectile.ProjectileType
pulsar_wep.NextFireMode
pulsar_wep.ProjectileType mustEqual pulsar_projectile.ProjectileType
}
"projectile types and fire modes / ammo types" in {
val punisher_wep = Tool(punisher)
punisher_wep.ProjectileType mustEqual bullet_9mm_projectile.ProjectileType
punisher_wep.NextAmmoType
punisher_wep.ProjectileType mustEqual bullet_9mm_AP_projectile.ProjectileType
punisher_wep.NextFireMode
punisher_wep.ProjectileType mustEqual rocket_projectile.ProjectileType
punisher_wep.NextAmmoType
punisher_wep.ProjectileType mustEqual frag_cartridge_projectile.ProjectileType
punisher_wep.NextAmmoType
punisher_wep.ProjectileType mustEqual jammer_cartridge_projectile.ProjectileType
punisher_wep.NextFireMode
punisher_wep.ProjectileType mustEqual bullet_9mm_AP_projectile.ProjectileType
punisher_wep.NextAmmoType
punisher_wep.ProjectileType mustEqual bullet_9mm_projectile.ProjectileType
punisher_wep.NextFireMode
punisher_wep.ProjectileType mustEqual jammer_cartridge_projectile.ProjectileType
punisher_wep.NextAmmoType
punisher_wep.ProjectileType mustEqual plasma_cartridge_projectile.ProjectileType
punisher_wep.NextAmmoType
punisher_wep.ProjectileType mustEqual rocket_projectile.ProjectileType
}
"discharge (1)" in {
val obj = Tool(GlobalDefinitions.punisher)
obj.Magazine mustEqual 30