diff --git a/src/Battling/Flow/TurnHandler.cpp b/src/Battling/Flow/TurnHandler.cpp index d8a0535..dbf3f57 100644 --- a/src/Battling/Flow/TurnHandler.cpp +++ b/src/Battling/Flow/TurnHandler.cpp @@ -85,7 +85,7 @@ void TurnHandler::ExecuteAttackChoice(AttackTurnChoice* choice) { HOOK(OnBeforeAttack, attack, attack); for (auto& kv : attack->GetTargets()) { - HandleAttackForTarget(attack, kv.first, kv.second); + HandleAttackForTarget(attack, kv.first, &kv.second); } // TODO: We currently delete this, but we probably want to store this in a log, so scripts can look it up. @@ -93,7 +93,7 @@ void TurnHandler::ExecuteAttackChoice(AttackTurnChoice* choice) { } void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* target, - const ExecutingAttack::TargetData& targetData) { + ExecutingAttack::TargetData* targetData) { auto user = attack->GetUser(); ScriptSource* targetSource = target; @@ -113,12 +113,12 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe return; } - if (!targetData.IsHit()) { + if (!targetData->IsHit()) { HOOK(OnAttackMiss, targetSource, attack, target); return; } - auto numHits = targetData.GetNumberOfHits(); + auto numHits = targetData->GetNumberOfHits(); if (numHits == 0) return; auto attackData = attack->GetAttack()->GetAttack(); @@ -132,22 +132,22 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe // STOP, STOP! HE'S ALREADY DEAD ;_; break; } - auto hit = targetData.GetHit(hitIndex); + auto hit = targetData->GetHit(hitIndex); - auto hitType = hit.GetType(); + auto hitType = hit->GetType(); HOOK(ChangeAttackType, targetSource, attack, target, hitIndex, hitType); - hit.SetEffectiveness(library->GetTypeLibrary()->GetEffectiveness(hitType, target->GetTypes())); - hit.SetCritical(library->GetCriticalLibrary()->IsCritical(attack, target, hitIndex)); - hit.SetBasePower(dmgLibrary->GetBasePower(attack, target, hitIndex)); - hit.SetDamage(dmgLibrary->GetDamage(attack, target, hitIndex)); + hit->SetEffectiveness(library->GetTypeLibrary()->GetEffectiveness(hitType, target->GetTypes())); + hit->SetCritical(library->GetCriticalLibrary()->IsCritical(attack, target, hitIndex)); + hit->SetBasePower(dmgLibrary->GetBasePower(attack, target, hitIndex)); + hit->SetDamage(dmgLibrary->GetDamage(attack, target, hitIndex)); if (attackData->GetCategory() == Library::AttackCategory::Status) { HOOK(OnStatusMove, userSource, attack, target, hitIndex); } else { - auto damage = hit.GetDamage(); + auto damage = hit->GetDamage(); if (damage > target->GetCurrentHealth()) { damage = target->GetCurrentHealth(); - hit.SetDamage(damage); + hit->SetDamage(damage); } if (damage > 0) { target->Damage(damage, DamageSource::AttackDamage); diff --git a/src/Battling/Flow/TurnHandler.hpp b/src/Battling/Flow/TurnHandler.hpp index 0e1be29..0115930 100644 --- a/src/Battling/Flow/TurnHandler.hpp +++ b/src/Battling/Flow/TurnHandler.hpp @@ -13,7 +13,7 @@ namespace CreatureLib::Battling { static void ExecuteAttackChoice(AttackTurnChoice* choice); static void HandleAttackForTarget(ExecutingAttack* attack, Creature* target, - const ExecutingAttack::TargetData& targetData); + ExecutingAttack::TargetData* targetData); public: static void RunTurn(Battle* battle, ChoiceQueue* queue); diff --git a/src/Battling/Library/DamageLibrary.cpp b/src/Battling/Library/DamageLibrary.cpp index 6e50fbc..d27de3d 100644 --- a/src/Battling/Library/DamageLibrary.cpp +++ b/src/Battling/Library/DamageLibrary.cpp @@ -4,7 +4,7 @@ using namespace CreatureLib::Battling; int DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const { auto levelMod = static_cast(2 * attack->GetUser()->GetLevel()); auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex); - auto bp = hit.GetBasePower(); + auto bp = hit->GetBasePower(); auto statMod = GetStatModifier(attack, target, hitIndex); // HOOK: Modify stat modifier int damage = static_cast((((levelMod * static_cast(bp) * statMod) / 50) + 2) * @@ -33,9 +33,9 @@ float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target, defensiveStat = Core::Statistic::MagicalDefense; } - auto bypassDefensive = hit.IsCritical() && target->GetStatBoost(defensiveStat) > 0; + auto bypassDefensive = hit->IsCritical() && target->GetStatBoost(defensiveStat) > 0; // HOOK: allow bypassing defensive stat modifiers. - auto bypassOffensive = hit.IsCritical() && user->GetStatBoost(offensiveStat) < 0; + auto bypassOffensive = hit->IsCritical() && user->GetStatBoost(offensiveStat) < 0; // HOOK: Allow bypassing offensive stat modifiers. float offensiveValue; @@ -58,7 +58,7 @@ float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target, float DamageLibrary::GetDamageModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const { float mod = 1; auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex); - mod *= hit.GetEffectiveness(); + mod *= hit->GetEffectiveness(); // HOOK: Modify damage modifier. return mod; } diff --git a/src/Battling/Models/ExecutingAttack.hpp b/src/Battling/Models/ExecutingAttack.hpp index d69d172..6007077 100644 --- a/src/Battling/Models/ExecutingAttack.hpp +++ b/src/Battling/Models/ExecutingAttack.hpp @@ -44,7 +44,7 @@ namespace CreatureLib::Battling { } TargetData() = default; - const HitData& GetHit(uint8_t index) const { return _hits[index]; } + HitData* GetHit(uint8_t index) { return &_hits[index]; } HitData* GetHitPtr(uint8_t index) { return &_hits[index]; } @@ -75,7 +75,7 @@ namespace CreatureLib::Battling { bool IsCreatureTarget(Creature* creature) { return _targets.find(creature) != _targets.end(); } - const std::unordered_map& GetTargets() { return _targets; } + std::unordered_map& GetTargets() { return _targets; } Creature* GetUser() { return _user; } diff --git a/tests/TestLibrary/TestLibrary.cpp b/tests/TestLibrary/TestLibrary.cpp index 9e57f55..9217541 100644 --- a/tests/TestLibrary/TestLibrary.cpp +++ b/tests/TestLibrary/TestLibrary.cpp @@ -31,13 +31,13 @@ SpeciesLibrary *TestLibrary::BuildSpeciesLibrary() { AttackLibrary *TestLibrary::BuildAttackLibrary() { auto l = new AttackLibrary(); - l->LoadAttack("standard", new AttackData("standard", "normal", AttackCategory::Physical, 50, 100, 30, + l->LoadAttack("standard", new AttackData("standard", "normal", AttackCategory::Physical, 20, 100, 30, AttackTarget::AdjacentOpponent, 0, {})); - l->LoadAttack("highPriority", new AttackData("highPriority", "normal", AttackCategory::Physical, 50, 100, 30, + l->LoadAttack("highPriority", new AttackData("highPriority", "normal", AttackCategory::Physical, 20, 100, 30, AttackTarget::AdjacentOpponent, 1, {})); - l->LoadAttack("higherPriority", new AttackData("higherPriority", "normal", AttackCategory::Physical, 50, 100, 30, + l->LoadAttack("higherPriority", new AttackData("higherPriority", "normal", AttackCategory::Physical, 20, 100, 30, AttackTarget::AdjacentOpponent, 2, {})); - l->LoadAttack("lowPriority", new AttackData("lowPriority", "normal", AttackCategory::Physical, 50, 100, 30, + l->LoadAttack("lowPriority", new AttackData("lowPriority", "normal", AttackCategory::Physical, 20, 100, 30, AttackTarget::AdjacentOpponent, -1, {})); return l; }