Changeset View
Standalone View
binaries/data/mods/public/simulation/components/DelayedDamage.js
Show All 33 Lines | |||||||||||||
* @param {string} data.splash.shape - The shape of the splash range. | * @param {string} data.splash.shape - The shape of the splash range. | ||||||||||||
* @param {Object} data.splash.attackData - same as attackData, for splash. | * @param {Object} data.splash.attackData - same as attackData, for splash. | ||||||||||||
*/ | */ | ||||||||||||
DelayedDamage.prototype.MissileHit = function(data, lateness) | DelayedDamage.prototype.MissileHit = function(data, lateness) | ||||||||||||
{ | { | ||||||||||||
if (!data.position) | if (!data.position) | ||||||||||||
return; | return; | ||||||||||||
let cmpSoundManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager); | |||||||||||||
if (cmpSoundManager && data.attackImpactSound) | |||||||||||||
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.splash) | if (data.splash) | ||||||||||||
Attacking.CauseDamageOverArea({ | Attacking.CauseDamageOverArea({ | ||||||||||||
"type": data.type, | "type": data.type, | ||||||||||||
"attackData": data.splash.attackData, | "attackData": data.splash.attackData, | ||||||||||||
"attacker": data.attacker, | "attacker": data.attacker, | ||||||||||||
"attackerOwner": data.attackerOwner, | "attackerOwner": data.attackerOwner, | ||||||||||||
"origin": Vector2D.from3D(data.position), | "origin": Vector2D.from3D(data.position), | ||||||||||||
"radius": data.splash.radius, | "radius": data.splash.radius, | ||||||||||||
"shape": data.splash.shape, | "shape": data.splash.shape, | ||||||||||||
"direction": data.direction, | "direction": data.direction, | ||||||||||||
"friendlyFire": data.splash.friendlyFire | "friendlyFire": data.splash.friendlyFire | ||||||||||||
}); | }); | ||||||||||||
let cmpProjectileManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ProjectileManager); | let cmpProjectileManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ProjectileManager); | ||||||||||||
let target = data.target; | let target = data.target; | ||||||||||||
// Since we can't damage mirages, replace a miraged target by the real target. | // Since we can't damage mirages, replace a miraged target by the real target. | ||||||||||||
let cmpMirage = Engine.QueryInterface(data.target, IID_Mirage); | let cmpMirage = Engine.QueryInterface(data.target, IID_Mirage); | ||||||||||||
if (cmpMirage) | if (cmpMirage) | ||||||||||||
target = cmpMirage.GetParent(); | target = cmpMirage.GetParent(); | ||||||||||||
var hitTarget = PositionHelper.TestCollision(target, data.position, lateness) && | |||||||||||||
Silier: let | |||||||||||||
Done Inline ActionsYou don't need the variable anymore :) Freagarach: You don't need the variable anymore :) | |||||||||||||
Attacking.HandleAttackEffects(target, data.type, data.attackData, data.attacker, data.attackerOwner); | |||||||||||||
let cmpSoundManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager); | |||||||||||||
if (cmpSoundManager) | |||||||||||||
cmpSoundManager.PlaySoundGroupAtPosition(GetImpactSoundGroup(data.type, target, data.attacker, !hitTarget), data.position); | |||||||||||||
// Deal direct damage if we hit the main target | // Deal direct damage if we hit the main target | ||||||||||||
// and we could handle the attack. | // and we could handle the attack. | ||||||||||||
Done Inline Actionsspace Silier: space | |||||||||||||
if (PositionHelper.TestCollision(target, data.position, lateness) && | if (hitTarget) | ||||||||||||
Not Done Inline ActionsIf an entity is invulnerable, they will return false here, but not after playing the blocked sound. Freagarach: If an entity is invulnerable, they will return false here, but not after playing the blocked… | |||||||||||||
Attacking.HandleAttackEffects(target, data.type, data.attackData, data.attacker, data.attackerOwner)) | |||||||||||||
{ | { | ||||||||||||
Done Inline ActionsSo, if we didn't hit the main target, but _did_ hit a secondary one, we'd still play a miss sound? Freagarach: So, if we didn't hit the main target, but _did_ hit a secondary one, we'd still play a miss… | |||||||||||||
cmpProjectileManager.RemoveProjectile(data.projectileId); | cmpProjectileManager.RemoveProjectile(data.projectileId); | ||||||||||||
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 ents = PositionHelper.EntitiesNearPoint(Vector2D.from3D(data.position), this.MISSILE_HIT_RADIUS, | let ents = PositionHelper.EntitiesNearPoint(Vector2D.from3D(data.position), this.MISSILE_HIT_RADIUS, | ||||||||||||
Attacking.GetPlayersToDamage(data.attackerOwner, data.friendlyFire)); | Attacking.GetPlayersToDamage(data.attackerOwner, data.friendlyFire)); | ||||||||||||
for (let ent of ents) | for (let ent of ents) | ||||||||||||
{ | { | ||||||||||||
if (!PositionHelper.TestCollision(ent, data.position, lateness) || | if (!PositionHelper.TestCollision(ent, data.position, lateness) || | ||||||||||||
!Attacking.HandleAttackEffects(ent, data.type, data.attackData, data.attacker, data.attackerOwner)) | !Attacking.HandleAttackEffects(ent, data.type, data.attackData, data.attacker, data.attackerOwner)) | ||||||||||||
Not Done Inline ActionsThen a second entity is tried to be hit here. (If it is invulnerable (or doesn't have cmpResistance, e.g. trees), it will play the blocked sound again.) If it receives any effect, the impact sound is played. Freagarach: Then a second entity is tried to be hit here. (If it is invulnerable (or doesn't have… | |||||||||||||
continue; | continue; | ||||||||||||
cmpProjectileManager.RemoveProjectile(data.projectileId); | cmpProjectileManager.RemoveProjectile(data.projectileId); | ||||||||||||
break; | break; | ||||||||||||
Done Inline Actions
Freagarach: | |||||||||||||
} | } | ||||||||||||
Done Inline ActionsCheck whether we hit something here and play the "missed" variant else. Freagarach: Check whether we hit something here and play the "missed" variant else. | |||||||||||||
}; | }; | ||||||||||||
Done Inline Actions
Freagarach: | |||||||||||||
Engine.RegisterSystemComponentType(IID_DelayedDamage, "DelayedDamage", DelayedDamage); | Engine.RegisterSystemComponentType(IID_DelayedDamage, "DelayedDamage", DelayedDamage); | ||||||||||||
Done Inline ActionsAccording to the code below, this should be missed? Freagarach: According to the code below, this should be `missed`? | |||||||||||||
Done Inline ActionsWell then I need to invert the boolean somewhere. Stan: Well then I need to invert the boolean somewhere. | |||||||||||||
Done Inline Actionsif (hitTarget): attack_impact_" + type + "_missed"? (I would even find it nicer to have a seperate function for the two, but that is probably not desireable from a performance POV.) Freagarach: `if (hitTarget): attack_impact_" + type + "_missed"`?
So I suggest using `missed` and having it… |
let