Pass ExecutingAttack values by reference instead of pointer.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-04-25 16:04:17 +02:00
parent 734d056449
commit 0e874346bb
5 changed files with 25 additions and 27 deletions

View File

@@ -91,7 +91,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.
@@ -99,7 +99,7 @@ void TurnHandler::ExecuteAttackChoice(AttackTurnChoice* choice) {
}
void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* target,
ExecutingAttack::TargetData* targetData) {
ExecutingAttack::TargetData& targetData) {
auto user = attack->GetUser();
AssertNotNull(user)
AssertNotNull(target)
@@ -121,12 +121,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();
@@ -140,17 +140,15 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
if (target->IsFainted()) {
break;
}
auto hit = targetData->GetHit(hitIndex);
AssertNotNull(hit)
auto hitType = hit->GetType();
auto& hit = targetData.GetHit(hitIndex);
auto hitType = hit.GetType();
HOOK(ChangeAttackType, targetSource, attack, target, hitIndex, &hitType);
auto effectiveness = library->GetTypeLibrary()->GetEffectiveness(hitType, target->GetTypes());
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.SetEffectiveness(effectiveness);
hit.SetCritical(library->GetMiscLibrary()->IsCritical(attack, target, hitIndex));
hit.SetBasePower(dmgLibrary->GetBasePower(attack, target, hitIndex));
hit.SetDamage(dmgLibrary->GetDamage(attack, target, hitIndex));
if (attackData->GetCategory() == Library::AttackCategory::Status) {
if (attackData->HasSecondaryEffect()) {
@@ -167,10 +165,10 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
}
}
} 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);

View File

@@ -15,7 +15,7 @@ namespace CreatureLib::Battling {
static void ExecuteAttackChoice(AttackTurnChoice* choice);
static void HandleAttackForTarget(ExecutingAttack* attack, Creature* target,
ExecutingAttack::TargetData* targetData);
ExecutingAttack::TargetData& targetData);
static void ExecuteSwitchChoice(SwitchTurnChoice* choice);
static void ExecuteFleeChoice(FleeTurnChoice* choice);