Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Damage.js
Show First 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | |||||
* @param {number} data.attackerOwner - the player id of the owner of the attacker. | * @param {number} data.attackerOwner - the player id of the owner of the attacker. | ||||
* @param {boolean} data.isSplash - a flag indicating if it's splash damage. | * @param {boolean} data.isSplash - a flag indicating if it's splash damage. | ||||
* @param {Vector3D} data.position - the expected position of the target. | * @param {Vector3D} data.position - the expected position of the target. | ||||
* @param {number} data.projectileId - the id of the projectile. | * @param {number} data.projectileId - the id of the projectile. | ||||
* @param {Vector3D} data.direction - the unit vector defining the direction. | * @param {Vector3D} data.direction - the unit vector defining the direction. | ||||
* @param {Object} data.bonus - the attack bonus template from the attacker. | * @param {Object} data.bonus - the attack bonus template from the attacker. | ||||
* @param {string} data.attackImpactSound - the name of the sound emited on impact. | * @param {string} data.attackImpactSound - the name of the sound emited on impact. | ||||
* @param {Object} data.statusEffects - status effects eg. poisoning, burning etc. | * @param {Object} data.statusEffects - status effects eg. poisoning, burning etc. | ||||
* ***When splash damage*** | |||||
* @param {boolean} data.friendlyFire - a flag indicating if allied entities are also damaged. | * @param {boolean} data.friendlyFire - a flag indicating if allied entities are also damaged. | ||||
* @param {number} data.radius - the radius of the splash damage. | * ***When splash damage*** | ||||
* @param {string} data.shape - the shape of the splash range. | * @param {boolean} data.splash.friendlyFire - a flag indicating if allied entities are also damaged. | ||||
* @param {Object} data.splashBonus - the attack bonus template from the attacker. | * @param {number} data.splash.radius - the radius of the splash damage. | ||||
* @param {Object} data.splashStrengths - data of the form { 'hack': number, 'pierce': number, 'crush': number }. | * @param {string} data.splash.shape - the shape of the splash range. | ||||
* @param {Object} data.splash.bonus - the attack bonus template from the attacker. | |||||
* @param {Object} data.splash.strengths - data of the form { 'hack': number, 'pierce': number, 'crush': number }. | |||||
*/ | */ | ||||
Damage.prototype.MissileHit = function(data, lateness) | Damage.prototype.MissileHit = function(data, lateness) | ||||
{ | { | ||||
if (!data.position) | if (!data.position) | ||||
return; | return; | ||||
let cmpSoundManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager); | let cmpSoundManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager); | ||||
if (cmpSoundManager && data.attackImpactSound) | if (cmpSoundManager && data.attackImpactSound) | ||||
cmpSoundManager.PlaySoundGroupAtPosition(data.attackImpactSound, data.position); | cmpSoundManager.PlaySoundGroupAtPosition(data.attackImpactSound, data.position); | ||||
// Do this first in case the direct hit kills the target | // Do this first in case the direct hit kills the target | ||||
if (data.isSplash) | if (data.splash) | ||||
wraitii: I believe our convention is to check for data.splash | |||||
Done Inline ActionsDepends whether we need to check for the key or the value, doesn't it ? In this case we are definitely checking for the value. Maybe we shouldn't do splash if radius is 0 ? Stan: Depends whether we need to check for the key or the value, doesn't it ?
In this case we are… | |||||
Done Inline ActionsI think it would be strange to have data.splash but without a radius. Do you have a use-case? Freagarach: I think it would be strange to have `data.splash` but without a radius. Do you have a use-case? | |||||
Done Inline ActionsI guess with techs / auras it might sorta happen? And then possibly we want to disable splash? wraitii: I guess with techs / auras it might sorta happen? And then possibly we want to disable splash? | |||||
Done Inline ActionsYeah, was thinking about that as well. radius > 0? Freagarach: Yeah, was thinking about that as well. `radius > 0`? | |||||
{ | |||||
this.CauseSplashDamage({ | this.CauseSplashDamage({ | ||||
"attacker": data.attacker, | "attacker": data.attacker, | ||||
"origin": Vector2D.from3D(data.position), | "origin": Vector2D.from3D(data.position), | ||||
"radius": data.radius, | "radius": data.splash.radius, | ||||
"shape": data.shape, | "shape": data.splash.shape, | ||||
"strengths": data.splashStrengths, | "strengths": data.splash.strengths, | ||||
"splashBonus": data.splashBonus, | "splashBonus": data.splash.bonus, | ||||
"direction": data.direction, | "direction": data.direction, | ||||
"playersToDamage": this.GetPlayersToDamage(data.attackerOwner, data.friendlyFire), | "playersToDamage": this.GetPlayersToDamage(data.attackerOwner, data.splash.friendlyFire), | ||||
"type": data.type, | "type": data.type, | ||||
"attackerOwner": data.attackerOwner | "attackerOwner": data.attackerOwner | ||||
}); | }); | ||||
} | |||||
let cmpProjectileManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ProjectileManager); | let cmpProjectileManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ProjectileManager); | ||||
// Deal direct damage if we hit the main target | // Deal direct damage if we hit the main target | ||||
// and if the target has DamageReceiver (not the case for a mirage for example) | // and if the target has DamageReceiver (not the case for a mirage for example) | ||||
let cmpDamageReceiver = Engine.QueryInterface(data.target, IID_DamageReceiver); | let cmpDamageReceiver = Engine.QueryInterface(data.target, IID_DamageReceiver); | ||||
if (cmpDamageReceiver && this.TestCollision(data.target, data.position, lateness)) | if (cmpDamageReceiver && this.TestCollision(data.target, data.position, lateness)) | ||||
{ | { | ||||
data.multiplier = GetDamageBonus(data.attacker, data.target, data.type, data.bonus); | data.multiplier = GetDamageBonus(data.attacker, data.target, data.type, data.bonus); | ||||
this.CauseDamage(data); | this.CauseDamage(data); | ||||
cmpProjectileManager.RemoveProjectile(data.projectileId); | cmpProjectileManager.RemoveProjectile(data.projectileId); | ||||
let cmpStatusReceiver = Engine.QueryInterface(data.target, IID_StatusEffectsReceiver); | let cmpStatusReceiver = Engine.QueryInterface(data.target, IID_StatusEffectsReceiver); | ||||
if (cmpStatusReceiver && data.statusEffects) | if (cmpStatusReceiver && data.statusEffects) | ||||
cmpStatusReceiver.InflictEffects(data.statusEffects); | cmpStatusReceiver.InflictEffects(data.statusEffects); | ||||
return; | return; | ||||
} | } | ||||
let targetPosition = this.InterpolatedLocation(data.target, lateness); | let targetPosition = this.InterpolatedLocation(data.target, lateness); | ||||
if (!targetPosition) | if (!targetPosition) | ||||
return; | return; | ||||
// If we didn't hit the main target look for nearby units | // If we didn't hit the main target look for nearby units | ||||
let cmpPlayer = QueryPlayerIDInterface(data.attackerOwner); | let playersToDamage = this.GetPlayersToDamage(data.attackerOwner, data.friendlyFire); | ||||
let ents = this.EntitiesNearPoint(Vector2D.from3D(data.position), targetPosition.horizDistanceTo(data.position) * 2, cmpPlayer.GetEnemies()); | let ents = this.EntitiesNearPoint(Vector2D.from3D(data.position), targetPosition.horizDistanceTo(data.position) * 2, playersToDamage); | ||||
Done Inline ActionsToo long a line. wraitii: Too long a line. | |||||
for (let ent of ents) | for (let ent of ents) | ||||
{ | { | ||||
if (!this.TestCollision(ent, data.position, lateness)) | if (!this.TestCollision(ent, data.position, lateness)) | ||||
continue; | continue; | ||||
this.CauseDamage({ | this.CauseDamage({ | ||||
"strengths": data.strengths, | "strengths": data.strengths, | ||||
"target": ent, | "target": ent, | ||||
▲ Show 20 Lines • Show All 150 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
I believe our convention is to check for data.splash