Cleanup of ExecutingAttack, removing TargetData, and reducing the number of allocations needed.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -90,16 +90,15 @@ void TurnHandler::ExecuteAttackChoice(AttackTurnChoice* choice) {
|
||||
}
|
||||
HOOK(OnBeforeAttack, attack, attack);
|
||||
|
||||
for (auto& kv : attack->GetTargets()) {
|
||||
HandleAttackForTarget(attack, kv.first, kv.second);
|
||||
for (auto& t : attack->GetTargets()) {
|
||||
HandleAttackForTarget(attack, t);
|
||||
}
|
||||
|
||||
// TODO: We currently delete this, but we probably want to store this in a log, so scripts can look it up.
|
||||
delete attack;
|
||||
}
|
||||
|
||||
void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* target,
|
||||
ExecutingAttack::TargetData& targetData) {
|
||||
void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* target) {
|
||||
auto user = attack->GetUser();
|
||||
AssertNotNull(user)
|
||||
AssertNotNull(target)
|
||||
@@ -121,26 +120,24 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
|
||||
return;
|
||||
}
|
||||
|
||||
if (!targetData.IsHit()) {
|
||||
auto numberOfHits = attack->GetNumberOfHits();
|
||||
if (numberOfHits == 0) {
|
||||
HOOK(OnAttackMiss, targetSource, attack, target);
|
||||
return;
|
||||
}
|
||||
|
||||
auto numHits = targetData.GetNumberOfHits();
|
||||
if (numHits == 0)
|
||||
return;
|
||||
auto attackData = attack->GetAttack()->GetAttack();
|
||||
auto library = user->GetBattle()->GetLibrary();
|
||||
AssertNotNull(library)
|
||||
auto dmgLibrary = library->GetDamageLibrary();
|
||||
for (uint8_t hitIndex = 0; hitIndex < numHits; hitIndex++) {
|
||||
for (uint8_t hitIndex = 0; hitIndex < numberOfHits; hitIndex++) {
|
||||
if (user->IsFainted()) {
|
||||
break;
|
||||
}
|
||||
if (target->IsFainted()) {
|
||||
break;
|
||||
}
|
||||
auto& hit = targetData.GetHit(hitIndex);
|
||||
auto& hit = attack->GetHitData(target, hitIndex);
|
||||
auto hitType = hit.GetType();
|
||||
HOOK(ChangeAttackType, targetSource, attack, target, hitIndex, &hitType);
|
||||
auto effectiveness = library->GetTypeLibrary()->GetEffectiveness(hitType, target->GetTypes());
|
||||
|
||||
@@ -14,8 +14,7 @@ namespace CreatureLib::Battling {
|
||||
static void ExecuteChoice(BaseTurnChoice* choice);
|
||||
|
||||
static void ExecuteAttackChoice(AttackTurnChoice* choice);
|
||||
static void HandleAttackForTarget(ExecutingAttack* attack, Creature* target,
|
||||
ExecutingAttack::TargetData& targetData);
|
||||
static void HandleAttackForTarget(ExecutingAttack* attack, Creature* target);
|
||||
|
||||
static void ExecuteSwitchChoice(SwitchTurnChoice* choice);
|
||||
static void ExecuteFleeChoice(FleeTurnChoice* choice);
|
||||
|
||||
Reference in New Issue
Block a user