diff --git a/src/Battling/EventHooks/EventData.hpp b/src/Battling/EventHooks/EventData.hpp index 0c682c6..32989d5 100644 --- a/src/Battling/EventHooks/EventData.hpp +++ b/src/Battling/EventHooks/EventData.hpp @@ -2,6 +2,7 @@ #define CREATURELIB_EVENTDATA_HPP #include +#include "../Models/CreatureIndex.hpp" #include "../Models/DamageSource.hpp" #include "EventDataKind.hpp" @@ -54,6 +55,18 @@ namespace CreatureLib::Battling { const ArbUt::BorrowedPtr& GetCreature() const noexcept { return _creature; } }; + class SwitchEvent : public EventData { + CreatureIndex _index; + ArbUt::BorrowedPtr _newCreature; + + public: + SwitchEvent(const CreatureIndex& index, const ArbUt::BorrowedPtr& newCreature) + : _index(index), _newCreature(newCreature) {} + EventDataKind GetKind() const noexcept override { return EventDataKind ::Switch; } + const CreatureIndex& GetIndex() const noexcept { return _index; } + const ArbUt::BorrowedPtr& GetNewCreature() const noexcept { return _newCreature; } + }; + class DisplayTextEvent : public EventData { const ArbUt::StringView _text; diff --git a/src/Battling/EventHooks/EventDataKind.hpp b/src/Battling/EventHooks/EventDataKind.hpp index e45b1bb..cd1aae2 100644 --- a/src/Battling/EventHooks/EventDataKind.hpp +++ b/src/Battling/EventHooks/EventDataKind.hpp @@ -3,8 +3,7 @@ #include namespace CreatureLib::Battling { - ENUM(EventDataKind, uint8_t, Damage, Heal, Faint, DisplayText) - + ENUM(EventDataKind, uint8_t, Damage, Heal, Faint, Switch, DisplayText) } #endif // CREATURELIB_EVENTDATAKIND_HPP diff --git a/src/Battling/Models/BattleSide.cpp b/src/Battling/Models/BattleSide.cpp index c9e84ea..5f8e7e8 100644 --- a/src/Battling/Models/BattleSide.cpp +++ b/src/Battling/Models/BattleSide.cpp @@ -62,13 +62,14 @@ void BattleSide::SetCreature(ArbUt::BorrowedPtr creature, uint8_t inde for (auto side : _battle->GetSides()) { if (side == this) continue; - for (auto c : side->GetCreatures()) { + for (const auto& c : side->GetCreatures()) { if (c != nullptr) { c->MarkOpponentAsSeen(creature); creature->MarkOpponentAsSeen(c.GetRaw()); } } } + _battle->TriggerEventListener(CreatureIndex(this->_index, index), creature); } bool BattleSide::CreatureOnSide(const ArbUt::BorrowedPtr& creature) const {