Allow techs to affect unit counters stats.

Reviewed by: @wraitii
Differential Revision: https://code.wildfiregames.com/D1782
This was SVN commit r22346.
This commit is contained in:
Stan 2019-06-06 20:44:30 +00:00
parent c219ee54b2
commit 08bfcf144b
4 changed files with 19 additions and 14 deletions

View File

@ -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
});

View File

@ -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({

View File

@ -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

View File

@ -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;