diff --git a/binaries/data/mods/public/simulation/components/Armour.js b/binaries/data/mods/public/simulation/components/Armour.js index 2aca73555a..1e984ff55f 100644 --- a/binaries/data/mods/public/simulation/components/Armour.js +++ b/binaries/data/mods/public/simulation/components/Armour.js @@ -44,22 +44,23 @@ Armour.prototype.SetInvulnerability = function(invulnerability) /** * Take damage according to the entity's armor. - * Returns object of the form { "killed": false, "change": -12 } + * @param {Object} strengths - { "hack": number, "pierce": number, "crush": number } or something like that. + * @param {number} multiplier - the damage multiplier. + * Returns object of the form { "killed": false, "change": -12 }. */ -Armour.prototype.TakeDamage = function(hack, pierce, crush) +Armour.prototype.TakeDamage = function(strengths, multiplier = 1) { if (this.invulnerable) return { "killed": false, "change": 0 }; // Adjust damage values based on armour; exponential armour: damage = attack * 0.9^armour var armourStrengths = this.GetArmourStrengths(); - var adjHack = hack * Math.pow(0.9, armourStrengths.hack); - var adjPierce = pierce * Math.pow(0.9, armourStrengths.pierce); - var adjCrush = crush * Math.pow(0.9, armourStrengths.crush); // Total is sum of individual damages // Don't bother rounding, since HP is no longer integral. - var total = adjHack + adjPierce + adjCrush; + var total = 0; + for (let type in strengths) + total += strengths[type] * multiplier * Math.pow(0.9, armourStrengths[type] || 0); // Reduce health var cmpHealth = Engine.QueryInterface(this.entity, IID_Health); diff --git a/binaries/data/mods/public/simulation/components/Damage.js b/binaries/data/mods/public/simulation/components/Damage.js index ff8e954cd3..fba93ab0e5 100644 --- a/binaries/data/mods/public/simulation/components/Damage.js +++ b/binaries/data/mods/public/simulation/components/Damage.js @@ -239,7 +239,7 @@ Damage.prototype.CauseSplashDamage = function(data) * @param {Object} data.strengths - data in the form of { 'hack': number, 'pierce': number, 'crush': number }. * @param {number} data.target - the entity id of the target. * @param {number} data.attacker - the entity id og the attacker. - * @param {number} data.multiplier - the damage multiplier (between 0 and 1). + * @param {number} data.multiplier - the damage multiplier. * @param {string} data.type - the type of damage. * @param {number} data.attackerOwner - the player id of the attacker. */ @@ -249,7 +249,7 @@ Damage.prototype.CauseDamage = function(data) if (!cmpDamageReceiver) return; - let targetState = cmpDamageReceiver.TakeDamage(data.strengths.hack * data.multiplier, data.strengths.pierce * data.multiplier, data.strengths.crush * data.multiplier); + let targetState = cmpDamageReceiver.TakeDamage(data.strengths, data.multiplier); let cmpPromotion = Engine.QueryInterface(data.attacker, IID_Promotion); let cmpLoot = Engine.QueryInterface(data.target, IID_Loot); diff --git a/binaries/data/mods/public/simulation/components/tests/test_Damage.js b/binaries/data/mods/public/simulation/components/tests/test_Damage.js index e9ca5c8ce1..610c582af9 100644 --- a/binaries/data/mods/public/simulation/components/tests/test_Damage.js +++ b/binaries/data/mods/public/simulation/components/tests/test_Damage.js @@ -76,7 +76,7 @@ function Test_Generic() AddMock(target, IID_Health, {}); AddMock(target, IID_DamageReceiver, { - "TakeDamage": (hack, pierce, crush) => { damageTaken = true; return { "killed": false, "change": -crush }; }, + "TakeDamage": (strengths, multiplier) => { damageTaken = true; return { "killed": false, "change": -multiplier * strengths.crush }; }, }); Engine.PostMessage = function(ent, iid, message) @@ -175,26 +175,26 @@ function TestLinearSplashDamage() }); AddMock(60, IID_DamageReceiver, { - "TakeDamage": (hack, pierce, crush) => { + "TakeDamage": (strengths, multiplier) => { hitEnts.add(60); - TS_ASSERT_EQUALS(hack + pierce + crush, 100 * fallOff(2.2, -0.4)); - return { "killed": false, "change": -(hack + pierce + crush) }; + TS_ASSERT_EQUALS(multiplier * (strengths.hack + strengths.pierce + strengths.crush), 100 * fallOff(2.2, -0.4)); + return { "killed": false, "change": -multiplier * (strengths.hack + strengths.pierce + strengths.crush) }; } }); AddMock(61, IID_DamageReceiver, { - TakeDamage: (hack, pierce, crush) => { + "TakeDamage": (strengths, multiplier) => { hitEnts.add(61); - TS_ASSERT_EQUALS(hack + pierce + crush, 100 * fallOff(0, 0)); - return { "killed": false, "change": -(hack + pierce + crush) }; + TS_ASSERT_EQUALS(multiplier * (strengths.hack + strengths.pierce + strengths.crush), 100 * fallOff(0, 0)); + return { "killed": false, "change": -multiplier * (strengths.hack + strengths.pierce + strengths.crush) }; } }); AddMock(62, IID_DamageReceiver, { - "TakeDamage": (hack, pierce, crush) => { + "TakeDamage": (strengths, multiplier) => { hitEnts.add(62); - TS_ASSERT_EQUALS(hack + pierce + crush, 0); - return { "killed": false, "change": -(hack + pierce + crush) }; + TS_ASSERT_EQUALS(multiplier * (strengths.hack + strengths.pierce + strengths.crush), 0); + return { "killed": false, "change": -multiplier * (strengths.hack + strengths.pierce + strengths.crush) }; } }); @@ -207,10 +207,10 @@ function TestLinearSplashDamage() data.direction = new Vector3D(0.6, 747, 0.8); AddMock(60, IID_DamageReceiver, { - "TakeDamage": (hack, pierce, crush) => { + "TakeDamage": (strengths, multiplier) => { hitEnts.add(60); - TS_ASSERT_EQUALS(hack + pierce + crush, 100 * fallOff(1, 2)); - return { "killed": false, "change": -(hack + pierce + crush) }; + TS_ASSERT_EQUALS(multiplier * (strengths.hack + strengths.pierce + strengths.crush), 100 * fallOff(1, 2)); + return { "killed": false, "change": -multiplier * (strengths.hack + strengths.pierce + strengths.crush) }; } }); @@ -263,36 +263,36 @@ function TestCircularSplashDamage() }); AddMock(60, IID_DamageReceiver, { - "TakeDamage": (hack, pierce, crush) => { - TS_ASSERT_EQUALS(hack + pierce + crush, 100 * fallOff(0)); - return { "killed": false, "change": -(hack + pierce + crush) }; + "TakeDamage": (strengths, multiplier) => { + TS_ASSERT_EQUALS(multiplier * (strengths.hack + strengths.pierce + strengths.crush), 100 * fallOff(0)); + return { "killed": false, "change": -multiplier * (strengths.hack + strengths.pierce + strengths.crush) }; } }); AddMock(61, IID_DamageReceiver, { - "TakeDamage": (hack, pierce, crush) => { - TS_ASSERT_EQUALS(hack + pierce + crush, 100 * fallOff(5)); - return { "killed": false, "change": -(hack + pierce + crush) }; + "TakeDamage": (strengths, multiplier) => { + TS_ASSERT_EQUALS(multiplier * (strengths.hack + strengths.pierce + strengths.crush), 100 * fallOff(5)); + return { "killed": false, "change": -multiplier * (strengths.hack + strengths.pierce + strengths.crush) }; } }); AddMock(62, IID_DamageReceiver, { - "TakeDamage": (hack, pierce, crush) => { - TS_ASSERT_EQUALS(hack + pierce + crush, 100 * fallOff(1)); - return { "killed": false, "change": -(hack + pierce + crush) }; + "TakeDamage": (strengths, multiplier) => { + TS_ASSERT_EQUALS(multiplier * (strengths.hack + strengths.pierce + strengths.crush), 100 * fallOff(1)); + return { "killed": false, "change": -multiplier * (strengths.hack + strengths.pierce + strengths.crush) }; } }); AddMock(63, IID_DamageReceiver, { - "TakeDamage": (hack, pierce, crush) => { + "TakeDamage": (strengths, multiplier) => { TS_ASSERT(false); } }); AddMock(64, IID_DamageReceiver, { - "TakeDamage": (hack, pierce, crush) => { - TS_ASSERT_EQUALS(hack + pierce + crush, 0); - return { "killed": false, "change": -(hack + pierce + crush) }; + "TakeDamage": (strengths, multiplier) => { + TS_ASSERT_EQUALS(multiplier * (strengths.hack + strengths.pierce + strengths.crush), 0); + return { "killed": false, "change": -multiplier * (strengths.hack + strengths.pierce + strengths.crush) }; } }); @@ -361,10 +361,10 @@ function Test_MissileHit() AddMock(60, IID_Health, {}); AddMock(60, IID_DamageReceiver, { - "TakeDamage": (hack, pierce, crush) => { - TS_ASSERT_EQUALS(hack + pierce + crush, 100); + "TakeDamage": (strengths, multiplier) => { hitEnts.add(60); - return { "killed": false, "change": -(hack + pierce + crush) }; + TS_ASSERT_EQUALS(multiplier * (strengths.hack + strengths.pierce + strengths.crush), 100); + return { "killed": false, "change": -multiplier * (strengths.hack + strengths.pierce + strengths.crush) }; } }); @@ -400,9 +400,9 @@ function Test_MissileHit() }); AddMock(60, IID_DamageReceiver, { - "TakeDamage": (hack, pierce, crush) => { + "TakeDamage": (strengths, multiplier) => { TS_ASSERT_EQUALS(false); - return { "killed": false, "change": -(hack + pierce + crush) }; + return { "killed": false, "change": -multiplier * (strengths.hack + strengths.pierce + strengths.crush) }; } }); @@ -420,10 +420,10 @@ function Test_MissileHit() AddMock(61, IID_Health, {}); AddMock(61, IID_DamageReceiver, { - "TakeDamage": (hack, pierce, crush) => { - TS_ASSERT_EQUALS(hack + pierce + crush, 100); + "TakeDamage": (strengths, multiplier) => { + TS_ASSERT_EQUALS(multiplier * (strengths.hack + strengths.pierce + strengths.crush), 100); hitEnts.add(61); - return { "killed": false, "change": -(hack + pierce + crush) }; + return { "killed": false, "change": -multiplier * (strengths.hack + strengths.pierce + strengths.crush) }; } }); @@ -449,10 +449,10 @@ function Test_MissileHit() let dealtDamage = 0; AddMock(61, IID_DamageReceiver, { - "TakeDamage": (hack, pierce, crush) => { - dealtDamage += hack + pierce + crush; + "TakeDamage": (strengths, multiplier) => { + dealtDamage += multiplier * (strengths.hack + strengths.pierce + strengths.crush); hitEnts.add(61); - return { "killed": false, "change": -(hack + pierce + crush) }; + return { "killed": false, "change": -multiplier * (strengths.hack + strengths.pierce + strengths.crush) }; } }); @@ -466,10 +466,10 @@ function Test_MissileHit() AddMock(62, IID_Health, {}); AddMock(62, IID_DamageReceiver, { - "TakeDamage": (hack, pierce, crush) => { - TS_ASSERT_EQUALS(hack + pierce + crush, 200 * 0.75); + "TakeDamage": (strengths, multiplier) => { + TS_ASSERT_EQUALS(multiplier * (strengths.hack + strengths.pierce + strengths.crush), 200 * 0.75); hitEnts.add(62); - return { "killed": false, "change": -(hack + pierce + crush) }; + return { "killed": false, "change": -multiplier * (strengths.hack + strengths.pierce + strengths.crush) }; } });