diff --git a/src/Battling/EventHooks/EventData.hpp b/src/Battling/EventHooks/EventData.hpp index 5cccb4f..4f2b529 100644 --- a/src/Battling/EventHooks/EventData.hpp +++ b/src/Battling/EventHooks/EventData.hpp @@ -102,6 +102,15 @@ namespace CreatureLib::Battling { const ArbUt::StringView& GetText() const noexcept { return _text; } }; + class MissEvent : public EventData { + ArbUt::BorrowedPtr _creature; + + public: + MissEvent(const ArbUt::BorrowedPtr& creature) noexcept : _creature(creature) {} + EventDataKind GetKind() const noexcept override { return EventDataKind ::Miss; } + const ArbUt::BorrowedPtr& GetCreature() const noexcept { return _creature; } + }; + } #endif // CREATURELIB_EVENTDATA_HPP diff --git a/src/Battling/EventHooks/EventDataKind.hpp b/src/Battling/EventHooks/EventDataKind.hpp index a1f52ec..d0e662e 100644 --- a/src/Battling/EventHooks/EventDataKind.hpp +++ b/src/Battling/EventHooks/EventDataKind.hpp @@ -3,7 +3,7 @@ #include namespace CreatureLib::Battling { - ENUM(EventDataKind, uint8_t, Damage, Heal, Faint, Switch, TurnStart, TurnEnd, ExperienceGain, DisplayText) + ENUM(EventDataKind, uint8_t, Damage, Heal, Faint, Switch, TurnStart, TurnEnd, ExperienceGain, Miss, DisplayText) } #endif // CREATURELIB_EVENTDATAKIND_HPP diff --git a/src/Battling/Flow/TurnHandler.cpp b/src/Battling/Flow/TurnHandler.cpp index 7845afe..1c4d576 100644 --- a/src/Battling/Flow/TurnHandler.cpp +++ b/src/Battling/Flow/TurnHandler.cpp @@ -122,7 +122,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo if (user->GetBattle()->HasEnded()) return; - auto targetSource = target; + const auto& targetSource = target; auto userSource = attack; bool fail = false; @@ -142,6 +142,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo auto numberOfHits = attack->GetNumberOfHits(); if (numberOfHits == 0) { HOOK(OnAttackMiss, targetSource, attack, target.GetRaw()); + user->GetBattle()->TriggerEventListener(user); return; }