diff --git a/CInterface/Battling/DamageLibrary.cpp b/CInterface/Battling/DamageLibrary.cpp index 4f78380..8f516bc 100644 --- a/CInterface/Battling/DamageLibrary.cpp +++ b/CInterface/Battling/DamageLibrary.cpp @@ -7,19 +7,23 @@ export const DamageLibrary* CreatureLib_DamageLibrary_Construct() { return new D export void CreatureLib_DamageLibrary_Destruct(const DamageLibrary* p) { delete p; } export uint8_t CreatureLib_DamageLibrary_GetDamage(uint32_t& out, const DamageLibrary* p, ExecutingAttack* attack, - Creature* target, uint8_t hitIndex) { - Try(out = p->GetDamage(attack, target, hitIndex);) + Creature* target, uint8_t hitIndex, + ExecutingAttack::HitData* hitData) { + Try(out = p->GetDamage(attack, target, hitIndex, *hitData);) } export uint8_t CreatureLib_DamageLibrary_GetBasePower(uint8_t& out, const DamageLibrary* p, ExecutingAttack* attack, - Creature* target, uint8_t hitIndex) { - Try(out = p->GetBasePower(attack, target, hitIndex);) + Creature* target, uint8_t hitIndex, + ExecutingAttack::HitData* hitData) { + Try(out = p->GetBasePower(attack, target, hitIndex, *hitData);) } export float CreatureLib_DamageLibrary_GetStatModifier(float& out, const DamageLibrary* p, ExecutingAttack* attack, - Creature* target, uint8_t hitIndex) { - Try(out = p->GetStatModifier(attack, target, hitIndex);) + Creature* target, uint8_t hitIndex, + ExecutingAttack::HitData* hitData) { + Try(out = p->GetStatModifier(attack, target, hitIndex, *hitData);) } export float CreatureLib_DamageLibrary_GetDamageModifier(float& out, const DamageLibrary* p, ExecutingAttack* attack, - Creature* target, uint8_t hitIndex) { - Try(out = p->GetDamageModifier(attack, target, hitIndex);) + Creature* target, uint8_t hitIndex, + ExecutingAttack::HitData* hitData) { + Try(out = p->GetDamageModifier(attack, target, hitIndex, *hitData);) } diff --git a/src/Battling/Flow/TurnHandler.cpp b/src/Battling/Flow/TurnHandler.cpp index b1e69b8..13faceb 100644 --- a/src/Battling/Flow/TurnHandler.cpp +++ b/src/Battling/Flow/TurnHandler.cpp @@ -147,8 +147,8 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe HOOK(ChangeEffectiveness, attack, attack, target, hitIndex, &effectiveness) hit.SetEffectiveness(effectiveness); hit.SetCritical(library->GetMiscLibrary()->IsCritical(attack, target, hitIndex)); - hit.SetBasePower(dmgLibrary->GetBasePower(attack, target, hitIndex)); - hit.SetDamage(dmgLibrary->GetDamage(attack, target, hitIndex)); + hit.SetBasePower(dmgLibrary->GetBasePower(attack, target, hitIndex, hit)); + hit.SetDamage(dmgLibrary->GetDamage(attack, target, hitIndex, hit)); if (attackData->GetCategory() == Library::AttackCategory::Status) { if (attackData->HasSecondaryEffect()) { diff --git a/src/Battling/Library/DamageLibrary.cpp b/src/Battling/Library/DamageLibrary.cpp index 0dfe4b0..78e4927 100644 --- a/src/Battling/Library/DamageLibrary.cpp +++ b/src/Battling/Library/DamageLibrary.cpp @@ -3,21 +3,22 @@ #include "../ScriptHandling/ScriptMacros.hpp" using namespace CreatureLib::Battling; -uint32_t DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const { +uint32_t DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex, + const ExecutingAttack::HitData& hitData) const { AssertNotNull(attack) AssertNotNull(target) auto levelMod = static_cast(2 * attack->GetUser()->GetLevel()) / 5 + 2; - auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex); - auto bp = hit.GetBasePower(); - auto statMod = GetStatModifier(attack, target, hitIndex); + auto bp = hitData.GetBasePower(); + auto statMod = GetStatModifier(attack, target, hitIndex, hitData); HOOK(ModifyStatModifier, attack, attack, target, hitIndex, &statMod); uint32_t damage = static_cast((((levelMod * static_cast(bp) * statMod) / 50) + 2) * - GetDamageModifier(attack, target, hitIndex)); + GetDamageModifier(attack, target, hitIndex, hitData)); HOOK(OverrideDamage, attack, attack, target, hitIndex, &damage); return damage; } -uint8_t DamageLibrary::GetBasePower(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const { +uint8_t DamageLibrary::GetBasePower(ExecutingAttack* attack, Creature* target, uint8_t hitIndex, + const ExecutingAttack::HitData& hitData) const { AssertNotNull(attack) AssertNotNull(target) auto bp = attack->GetAttack()->GetAttack()->GetBasePower(); @@ -25,13 +26,13 @@ uint8_t DamageLibrary::GetBasePower(ExecutingAttack* attack, Creature* target, u return bp; } -float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const { +float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex, + const ExecutingAttack::HitData& hitData) const { AssertNotNull(attack) AssertNotNull(target) auto user = attack->GetUser(); AssertNotNull(user) HOOK(ChangeDamageStatsUser, attack, attack, target, hitIndex, &user); - auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex); Library::Statistic offensiveStat; Library::Statistic defensiveStat; if (attack->GetAttack()->GetAttack()->GetCategory() == Library::AttackCategory::Physical) { @@ -42,9 +43,9 @@ float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target, defensiveStat = Library::Statistic::MagicalDefense; } - auto bypassDefensive = hit.IsCritical() && target->GetStatBoost(defensiveStat) > 0; + auto bypassDefensive = hitData.IsCritical() && target->GetStatBoost(defensiveStat) > 0; HOOK(BypassDefensiveStat, attack, attack, target, hitIndex, &bypassDefensive); - auto bypassOffensive = hit.IsCritical() && user->GetStatBoost(offensiveStat) < 0; + auto bypassOffensive = hitData.IsCritical() && user->GetStatBoost(offensiveStat) < 0; HOOK(BypassOffensiveStat, attack, attack, target, hitIndex, &bypassOffensive); float offensiveValue; @@ -64,12 +65,12 @@ float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target, return offensiveValue / defensiveValue; } -float DamageLibrary::GetDamageModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const { +float DamageLibrary::GetDamageModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex, + const ExecutingAttack::HitData& hitData) const { AssertNotNull(attack) AssertNotNull(target) float mod = 1; - auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex); - mod *= hit.GetEffectiveness(); + mod *= hitData.GetEffectiveness(); HOOK(ModifyDamageModifier, attack, attack, target, hitIndex, &mod); return mod; } diff --git a/src/Battling/Library/DamageLibrary.hpp b/src/Battling/Library/DamageLibrary.hpp index 6ca7a54..a1045bf 100644 --- a/src/Battling/Library/DamageLibrary.hpp +++ b/src/Battling/Library/DamageLibrary.hpp @@ -8,11 +8,15 @@ namespace CreatureLib::Battling { class DamageLibrary { public: virtual ~DamageLibrary() = default; - virtual uint32_t GetDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const; + virtual uint32_t GetDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex, + const ExecutingAttack::HitData& hitData) const; - virtual uint8_t GetBasePower(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const; - virtual float GetStatModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const; - virtual float GetDamageModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const; + virtual uint8_t GetBasePower(ExecutingAttack* attack, Creature* target, uint8_t hitIndex, + const ExecutingAttack::HitData& hitData) const; + virtual float GetStatModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex, + const ExecutingAttack::HitData& hitData) const; + virtual float GetDamageModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex, + const ExecutingAttack::HitData& hitData) const; }; }