Index: ps/trunk/binaries/data/mods/public/simulation/components/DelayedDamage.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/DelayedDamage.js +++ ps/trunk/binaries/data/mods/public/simulation/components/DelayedDamage.js @@ -59,19 +59,21 @@ let cmpProjectileManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ProjectileManager); + let target = data.target; + // Since we can't damage mirages, replace a miraged target by the real target. + let cmpMirage = Engine.QueryInterface(data.target, IID_Mirage); + if (cmpMirage) + target = cmpMirage.GetParent(); + // Deal direct damage if we hit the main target // and we could handle the attack. - if (Attacking.TestCollision(data.target, data.position, lateness) && - Attacking.HandleAttackEffects(data.target, data.type, data.attackData, data.attacker, data.attackerOwner)) + if (Attacking.TestCollision(target, data.position, lateness) && + Attacking.HandleAttackEffects(target, data.type, data.attackData, data.attacker, data.attackerOwner)) { cmpProjectileManager.RemoveProjectile(data.projectileId); return; } - let targetPosition = Attacking.InterpolatedLocation(data.target, lateness); - if (!targetPosition) - return; - // If we didn't hit the main target look for nearby units. let ents = Attacking.EntitiesNearPoint(Vector2D.from3D(data.position), this.MISSILE_HIT_RADIUS, Attacking.GetPlayersToDamage(data.attackerOwner, data.friendlyFire)); Index: ps/trunk/binaries/data/mods/public/simulation/components/Mirage.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/Mirage.js +++ ps/trunk/binaries/data/mods/public/simulation/components/Mirage.js @@ -47,9 +47,9 @@ this.parent = ent; }; -Mirage.prototype.GetPlayer = function() +Mirage.prototype.GetParent = function() { - return this.player; + return this.parent; }; Mirage.prototype.SetPlayer = function(player) @@ -57,6 +57,11 @@ this.player = player; }; +Mirage.prototype.GetPlayer = function() +{ + return this.player; +}; + Mirage.prototype.Mirages = function(iid) { return this.miragedIids.has(iid); Index: ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Damage.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Damage.js +++ ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Damage.js @@ -432,31 +432,16 @@ TS_ASSERT(hitEnts.has(60)); hitEnts.clear(); - // The main target is not hit but another one is hit. - - AddMock(60, IID_Position, { - "GetPosition": () => new Vector3D(900, 10, 0), - "GetPreviousPosition": () => new Vector3D(900, 10, 0), - "GetPosition2D": () => new Vector2D(900, 0), - "IsInWorld": () => true, - }); - - AddMock(60, IID_Health, { - "TakeDamage": (amount, __, ___) => { - TS_ASSERT_EQUALS(false); - return { "healthChange": -amount }; - } - }); - - AddMock(SYSTEM_ENTITY, IID_RangeManager, { - "ExecuteQueryAroundPos": () => [61] + // Target is a mirage: hit the parent. + AddMock(60, IID_Mirage, { + "GetParent": () => 61 }); AddMock(61, IID_Position, { "GetPosition": () => targetPos, "GetPreviousPosition": () => targetPos, "GetPosition2D": () => Vector2D.from3D(targetPos), - "IsInWorld": () => true, + "IsInWorld": () => true }); AddMock(61, IID_Health, { @@ -468,7 +453,36 @@ }); AddMock(61, IID_Footprint, { - "GetShape": () => ({ "type": "circle", "radius": 20 }), + "GetShape": () => ({ "type": "circle", "radius": 20 }) + }); + + cmpDelayedDamage.MissileHit(data, 0); + TS_ASSERT(hitEnts.has(61)); + hitEnts.clear(); + + // Make sure we don't corrupt other tests. + DeleteMock(60, IID_Mirage); + cmpDelayedDamage.MissileHit(data, 0); + TS_ASSERT(hitEnts.has(60)); + hitEnts.clear(); + + // The main target is not hit but another one is hit. + AddMock(60, IID_Position, { + "GetPosition": () => new Vector3D(900, 10, 0), + "GetPreviousPosition": () => new Vector3D(900, 10, 0), + "GetPosition2D": () => new Vector2D(900, 0), + "IsInWorld": () => true + }); + + AddMock(60, IID_Health, { + "TakeDamage": (amount, __, ___) => { + TS_ASSERT_EQUALS(false); + return { "healthChange": -amount }; + } + }); + + AddMock(SYSTEM_ENTITY, IID_RangeManager, { + "ExecuteQueryAroundPos": () => [61] }); cmpDelayedDamage.MissileHit(data, 0);