Implements Attack Use event.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
parent
64b08d4ff0
commit
5536a6b83d
|
@ -1,6 +1,7 @@
|
|||
#ifndef CREATURELIB_EVENTDATACLASSES_HPP
|
||||
#define CREATURELIB_EVENTDATACLASSES_HPP
|
||||
|
||||
#include "Events/AttackUseEvent.hpp"
|
||||
#include "Events/ChangeSpeciesEvent.hpp"
|
||||
#include "Events/ChangeVariantEvent.hpp"
|
||||
#include "Events/DamageEvent.hpp"
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace CreatureLib::Battling {
|
||||
ENUM(EventDataKind, uint8_t, Damage, Heal, Faint, Switch, TurnStart, TurnEnd, ExperienceGain, Miss, DisplayText,
|
||||
ChangeSpecies, ChangeVariant)
|
||||
ChangeSpecies, ChangeVariant, AttackUse)
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_EVENTDATAKIND_HPP
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef CREATURELIB_ATTACKUSEEVENT_HPP
|
||||
#define CREATURELIB_ATTACKUSEEVENT_HPP
|
||||
#include "EventData.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class AttackUseEvent : public EventData {
|
||||
ArbUt::BorrowedPtr<ExecutingAttack> _attack;
|
||||
|
||||
public:
|
||||
AttackUseEvent(const ArbUt::BorrowedPtr<ExecutingAttack>& attack) noexcept : _attack(attack) {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::AttackUse; }
|
||||
const ArbUt::BorrowedPtr<ExecutingAttack>& GetAttack() const noexcept { return _attack; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_ATTACKUSEEVENT_HPP
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue