Implements Attack Use event.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
@@ -82,9 +82,9 @@ void TurnHandler::ExecuteAttackChoice(ArbUt::BorrowedPtr<AttackTurnChoice> choic
|
||||
TargetResolver::ResolveTargets(choice->GetTarget(), targetType, choice->GetUser()->GetBattle());
|
||||
, "Exception during target determination");
|
||||
|
||||
auto attack = ExecutingAttack(targets, 1, choice->GetUser(), choice->GetAttack(), choice->GetAttackScript());
|
||||
auto attack = new ExecutingAttack(targets, 1, choice->GetUser(), choice->GetAttack(), choice->GetAttackScript());
|
||||
bool prevented = false;
|
||||
HOOK_LOCAL(PreventAttack, attack, &attack, &prevented);
|
||||
HOOK(PreventAttack, attack, attack, &prevented);
|
||||
if (prevented) {
|
||||
return;
|
||||
}
|
||||
@@ -95,25 +95,29 @@ void TurnHandler::ExecuteAttackChoice(ArbUt::BorrowedPtr<AttackTurnChoice> choic
|
||||
return;
|
||||
}
|
||||
|
||||
attack->GetUser()->GetBattle()->TriggerEventListener<AttackUseEvent>(attack);
|
||||
|
||||
// HOOK: check if attack fails
|
||||
bool fail = false;
|
||||
HOOK_LOCAL(FailAttack, attack, &attack, &fail);
|
||||
HOOK(FailAttack, attack, attack, &fail);
|
||||
if (fail) {
|
||||
// TODO: Fail handling.
|
||||
return;
|
||||
}
|
||||
|
||||
bool stopBeforeAttack = false;
|
||||
HOOK_LOCAL(StopBeforeAttack, attack, &attack, &stopBeforeAttack);
|
||||
HOOK(StopBeforeAttack, attack, attack, &stopBeforeAttack);
|
||||
if (stopBeforeAttack) {
|
||||
return;
|
||||
}
|
||||
HOOK_LOCAL(OnBeforeAttack, attack, &attack);
|
||||
HOOK(OnBeforeAttack, attack, attack);
|
||||
|
||||
for (uint8_t i = 0; i < attack.GetTargetCount(); i++) {
|
||||
auto target = attack.GetTargets()[i];
|
||||
try_creature(HandleAttackForTarget(&attack, target), "Exception occurred during handling attack for target");
|
||||
for (uint8_t i = 0; i < attack->GetTargetCount(); i++) {
|
||||
auto target = attack->GetTargets()[i];
|
||||
try_creature(HandleAttackForTarget(attack, target), "Exception occurred during handling attack for target");
|
||||
}
|
||||
|
||||
delete attack;
|
||||
}
|
||||
|
||||
void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::BorrowedPtr<Creature>& target) {
|
||||
|
||||
Reference in New Issue
Block a user