From 08bfcf144b1e58111bc40215d91cf35ca68008a8 Mon Sep 17 00:00:00 2001 From: Stan Date: Thu, 6 Jun 2019 20:44:30 +0000 Subject: [PATCH] Allow techs to affect unit counters stats. Reviewed by: @wraitii Differential Revision: https://code.wildfiregames.com/D1782 This was SVN commit r22346. --- .../data/mods/public/simulation/components/Attack.js | 4 ++-- .../data/mods/public/simulation/components/Damage.js | 6 +++--- .../simulation/components/tests/test_Attack.js | 12 ++++++------ .../mods/public/simulation/helpers/DamageBonus.js | 11 ++++++++--- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/Attack.js b/binaries/data/mods/public/simulation/components/Attack.js index 0deda9e2c5..77468b43a6 100644 --- a/binaries/data/mods/public/simulation/components/Attack.js +++ b/binaries/data/mods/public/simulation/components/Attack.js @@ -613,7 +613,7 @@ Attack.prototype.PerformAttack = function(type, target) if (attackerOwner == INVALID_PLAYER) return; - let multiplier = GetDamageBonus(target, this.GetBonusTemplate(type)); + let multiplier = GetDamageBonus(this.entity, target, type, this.GetBonusTemplate(type)); let cmpHealth = Engine.QueryInterface(target, IID_Health); if (!cmpHealth || cmpHealth.GetHitpoints() == 0) return; @@ -640,7 +640,7 @@ Attack.prototype.PerformAttack = function(type, target) "strengths": this.GetAttackStrengths(type), "target": target, "attacker": this.entity, - "multiplier": GetDamageBonus(target, this.GetBonusTemplate(type)), + "multiplier": GetDamageBonus(this.entity, target, type, this.GetBonusTemplate(type)), "type": type, "attackerOwner": attackerOwner }); diff --git a/binaries/data/mods/public/simulation/components/Damage.js b/binaries/data/mods/public/simulation/components/Damage.js index d6cc25fab6..fd7e1003a6 100644 --- a/binaries/data/mods/public/simulation/components/Damage.js +++ b/binaries/data/mods/public/simulation/components/Damage.js @@ -134,7 +134,7 @@ Damage.prototype.MissileHit = function(data, lateness) let cmpDamageReceiver = Engine.QueryInterface(data.target, IID_DamageReceiver); if (cmpDamageReceiver && this.TestCollision(data.target, data.position, lateness)) { - data.multiplier = GetDamageBonus(data.target, data.bonus); + data.multiplier = GetDamageBonus(data.attacker, data.target, data.type, data.bonus); this.CauseDamage(data); cmpProjectileManager.RemoveProjectile(data.projectileId); @@ -161,7 +161,7 @@ Damage.prototype.MissileHit = function(data, lateness) "strengths": data.strengths, "target": ent, "attacker": data.attacker, - "multiplier": GetDamageBonus(ent, data.bonus), + "multiplier": GetDamageBonus(data.attacker, ent, data.type, data.bonus), "type": data.type, "attackerOwner": data.attackerOwner }); @@ -223,7 +223,7 @@ Damage.prototype.CauseSplashDamage = function(data) } if (data.splashBonus) - damageMultiplier *= GetDamageBonus(ent, data.splashBonus); + damageMultiplier *= GetDamageBonus(data.attacker, ent, data.type, data.splashBonus); // Call CauseDamage which reduces the hitpoints, posts network command, plays sounds.... this.CauseDamage({ diff --git a/binaries/data/mods/public/simulation/components/tests/test_Attack.js b/binaries/data/mods/public/simulation/components/tests/test_Attack.js index d4867e947b..affa894e22 100644 --- a/binaries/data/mods/public/simulation/components/tests/test_Attack.js +++ b/binaries/data/mods/public/simulation/components/tests/test_Attack.js @@ -184,12 +184,12 @@ for (let className of ["Infantry", "Cavalry"]) TS_ASSERT(cmpAttack.GetBonusTemplate("Capture") === null); - let getAttackBonus = (t, e) => GetDamageBonus(e, cmpAttack.GetBonusTemplate(t)); - TS_ASSERT_UNEVAL_EQUALS(getAttackBonus("Melee", defender), className == "Cavalry" ? 2 : 1); - TS_ASSERT_UNEVAL_EQUALS(getAttackBonus("Ranged", defender), 1); - TS_ASSERT_UNEVAL_EQUALS(getAttackBonus("Ranged.Splash", defender), className == "Cavalry" ? 3 : 1); - TS_ASSERT_UNEVAL_EQUALS(getAttackBonus("Capture", defender), 1); - TS_ASSERT_UNEVAL_EQUALS(getAttackBonus("Slaughter", defender), 1); + let getAttackBonus = (s, t, e) => GetDamageBonus(s, e, t, cmpAttack.GetBonusTemplate(t)); + TS_ASSERT_UNEVAL_EQUALS(getAttackBonus(attacker, "Melee", defender), className == "Cavalry" ? 2 : 1); + TS_ASSERT_UNEVAL_EQUALS(getAttackBonus(attacker, "Ranged", defender), 1); + TS_ASSERT_UNEVAL_EQUALS(getAttackBonus(attacker, "Ranged.Splash", defender), className == "Cavalry" ? 3 : 1); + TS_ASSERT_UNEVAL_EQUALS(getAttackBonus(attacker, "Capture", defender), 1); + TS_ASSERT_UNEVAL_EQUALS(getAttackBonus(attacker, "Slaughter", defender), 1); }); // CanAttack rejects elephant attack due to RestrictedClasses diff --git a/binaries/data/mods/public/simulation/helpers/DamageBonus.js b/binaries/data/mods/public/simulation/helpers/DamageBonus.js index c6bb702772..e3c88bc0ae 100644 --- a/binaries/data/mods/public/simulation/helpers/DamageBonus.js +++ b/binaries/data/mods/public/simulation/helpers/DamageBonus.js @@ -1,7 +1,12 @@ /** - * Calculate the attack damage multiplier against a target. + * Calculates the attack damage multiplier against a target. + * @param {entity_id_t} source - The source entity's id. + * @param {entity_id_t} target - The target entity's id. + * @param {string} type - The type of attack. + * @param {Object} template - The bonus' template. + * @return {number} - The source entity's attack bonus against the specified target. */ -function GetDamageBonus(target, template) +function GetDamageBonus(source, target, type, template) { let attackBonus = 1; @@ -17,7 +22,7 @@ function GetDamageBonus(target, template) continue; if (bonus.Classes && bonus.Classes.split(/\s+/).some(cls => !cmpIdentity.HasClass(cls))) continue; - attackBonus *= bonus.Multiplier; + attackBonus *= ApplyValueModificationsToEntity("Attack/" + type + "/Bonuses/" + key + "/Multiplier", +bonus.Multiplier, source); } return attackBonus;