1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Extract revenge calculation to separate method

This commit is contained in:
M 2024-01-10 22:56:26 +01:00
parent 815fa26fb3
commit 7bf273e01c
2 changed files with 19 additions and 13 deletions

View File

@ -281,6 +281,20 @@ double DamageCalculator::getAttackHateFactor() const
return allHateEffects->valOfBonuses(Selector::subtype()(BonusSubtypeID(info.defender->creatureId()))) / 100.0; return allHateEffects->valOfBonuses(Selector::subtype()(BonusSubtypeID(info.defender->creatureId()))) / 100.0;
} }
double DamageCalculator::getAttackRevengeFactor() const
{
if(info.attacker->hasBonusOfType(BonusType::REVENGE)) //HotA Haspid ability
{
int totalStackCount = info.attacker->unitBaseAmount();
int currentStackHealth = info.attacker->getAvailableHealth();
int creatureHealth = info.attacker->getMaxHealth();
return sqrt(static_cast<double>((totalStackCount + 1) * creatureHealth) / (currentStackHealth + creatureHealth) - 1);
}
return 0.0;
}
double DamageCalculator::getDefenseSkillFactor() const double DamageCalculator::getDefenseSkillFactor() const
{ {
int defenseAdvantage = getTargetDefenseEffective() - getActorAttackEffective(); int defenseAdvantage = getTargetDefenseEffective() - getActorAttackEffective();
@ -523,19 +537,10 @@ DamageEstimation DamageCalculator::calculateDmgRange() const
double resultingFactor = std::min(8.0, attackFactorTotal) * std::max( 0.01, defenseFactorTotal); double resultingFactor = std::min(8.0, attackFactorTotal) * std::max( 0.01, defenseFactorTotal);
double revengeAdditionalMinDamage = 0.0; //calculated separately since it bypasses cap on bonus damage
double revengeAdditionalMaxDamage = 0.0; double revengeFactor = getAttackRevengeFactor();
if(info.attacker->hasBonusOfType(BonusType::REVENGE)) //HotA Haspid ability double revengeAdditionalMinDamage = std::round(damageBase.min * revengeFactor);
{ double revengeAdditionalMaxDamage = std::round(damageBase.max * revengeFactor);
int totalStackCount = info.attacker->unitBaseAmount();
int currentStackHealth = info.attacker->getAvailableHealth();
int creatureHealth = info.attacker->getMaxHealth();
double revengeFactor = sqrt(static_cast<double>((totalStackCount + 1) * creatureHealth) / (currentStackHealth + creatureHealth) - 1);
revengeAdditionalMinDamage = std::round(damageBase.min * revengeFactor);
revengeAdditionalMaxDamage = std::round(damageBase.max * revengeFactor);
}
DamageRange damageDealt { DamageRange damageDealt {
std::max<int64_t>( 1.0, std::floor(damageBase.min * resultingFactor + revengeAdditionalMinDamage)), std::max<int64_t>( 1.0, std::floor(damageBase.min * resultingFactor + revengeAdditionalMinDamage)),

View File

@ -51,6 +51,7 @@ class DLL_LINKAGE DamageCalculator
double getAttackDeathBlowFactor() const; double getAttackDeathBlowFactor() const;
double getAttackDoubleDamageFactor() const; double getAttackDoubleDamageFactor() const;
double getAttackHateFactor() const; double getAttackHateFactor() const;
double getAttackRevengeFactor() const;
double getDefenseSkillFactor() const; double getDefenseSkillFactor() const;
double getDefenseArmorerFactor() const; double getDefenseArmorerFactor() const;