From 7bf273e01ca45ac5c2afcf6a59fb9730472a73c9 Mon Sep 17 00:00:00 2001 From: M Date: Wed, 10 Jan 2024 22:56:26 +0100 Subject: [PATCH] Extract revenge calculation to separate method --- lib/battle/DamageCalculator.cpp | 31 ++++++++++++++++++------------- lib/battle/DamageCalculator.h | 1 + 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/battle/DamageCalculator.cpp b/lib/battle/DamageCalculator.cpp index 2f5e65426..31fe70d5c 100644 --- a/lib/battle/DamageCalculator.cpp +++ b/lib/battle/DamageCalculator.cpp @@ -281,6 +281,20 @@ double DamageCalculator::getAttackHateFactor() const 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((totalStackCount + 1) * creatureHealth) / (currentStackHealth + creatureHealth) - 1); + } + + return 0.0; +} + double DamageCalculator::getDefenseSkillFactor() const { 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 revengeAdditionalMinDamage = 0.0; - double revengeAdditionalMaxDamage = 0.0; - if(info.attacker->hasBonusOfType(BonusType::REVENGE)) //HotA Haspid ability - { - int totalStackCount = info.attacker->unitBaseAmount(); - int currentStackHealth = info.attacker->getAvailableHealth(); - int creatureHealth = info.attacker->getMaxHealth(); - - double revengeFactor = sqrt(static_cast((totalStackCount + 1) * creatureHealth) / (currentStackHealth + creatureHealth) - 1); - - revengeAdditionalMinDamage = std::round(damageBase.min * revengeFactor); - revengeAdditionalMaxDamage = std::round(damageBase.max * revengeFactor); - } + //calculated separately since it bypasses cap on bonus damage + double revengeFactor = getAttackRevengeFactor(); + double revengeAdditionalMinDamage = std::round(damageBase.min * revengeFactor); + double revengeAdditionalMaxDamage = std::round(damageBase.max * revengeFactor); DamageRange damageDealt { std::max( 1.0, std::floor(damageBase.min * resultingFactor + revengeAdditionalMinDamage)), diff --git a/lib/battle/DamageCalculator.h b/lib/battle/DamageCalculator.h index a91c006fd..d7f91e0b5 100644 --- a/lib/battle/DamageCalculator.h +++ b/lib/battle/DamageCalculator.h @@ -51,6 +51,7 @@ class DLL_LINKAGE DamageCalculator double getAttackDeathBlowFactor() const; double getAttackDoubleDamageFactor() const; double getAttackHateFactor() const; + double getAttackRevengeFactor() const; double getDefenseSkillFactor() const; double getDefenseArmorerFactor() const;