From 23bd0da64664b842fdd331f0e0d5af7fd386f32b Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 28 Mar 2021 11:58:26 +0200 Subject: [PATCH] Adds swap event when two creatures swap positions. Signed-off-by: Deukhoofd --- src/Battling/EventHooks/EventDataClasses.hpp | 1 + src/Battling/EventHooks/EventDataKind.hpp | 2 +- src/Battling/EventHooks/Events/FailEvent.hpp | 2 +- src/Battling/EventHooks/Events/SwapEvent.hpp | 21 ++++++++++++++++++++ src/Battling/Models/BattleSide.cpp | 1 + 5 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/Battling/EventHooks/Events/SwapEvent.hpp diff --git a/src/Battling/EventHooks/EventDataClasses.hpp b/src/Battling/EventHooks/EventDataClasses.hpp index 47fc15a..8d9eeba 100644 --- a/src/Battling/EventHooks/EventDataClasses.hpp +++ b/src/Battling/EventHooks/EventDataClasses.hpp @@ -13,6 +13,7 @@ #include "Events/FaintEvent.hpp" #include "Events/HealEvent.hpp" #include "Events/MissEvent.hpp" +#include "Events/SwapEvent.hpp" #include "Events/SwitchEvent.hpp" #include "Events/TurnEvents.hpp" diff --git a/src/Battling/EventHooks/EventDataKind.hpp b/src/Battling/EventHooks/EventDataKind.hpp index 74e2c83..eb08e14 100644 --- a/src/Battling/EventHooks/EventDataKind.hpp +++ b/src/Battling/EventHooks/EventDataKind.hpp @@ -3,7 +3,7 @@ namespace CreatureLib::Battling { ENUM(EventDataKind, uint8_t, Damage, Heal, Faint, Switch, TurnStart, TurnEnd, ExperienceGain, Miss, DisplayText, - ChangeSpecies, ChangeVariant, AttackUse, ChangeStatBoost) + ChangeSpecies, ChangeVariant, AttackUse, ChangeStatBoost, Fail, Swap) } #endif // CREATURELIB_EVENTDATAKIND_HPP diff --git a/src/Battling/EventHooks/Events/FailEvent.hpp b/src/Battling/EventHooks/Events/FailEvent.hpp index 449c204..9d3e4dc 100644 --- a/src/Battling/EventHooks/Events/FailEvent.hpp +++ b/src/Battling/EventHooks/Events/FailEvent.hpp @@ -8,7 +8,7 @@ namespace CreatureLib::Battling { public: FailEvent(ArbUt::BorrowedPtr c) noexcept : _creature(c) {} - EventDataKind GetKind() const noexcept override { return EventDataKind ::Faint; } + EventDataKind GetKind() const noexcept override { return EventDataKind ::Fail; } const ArbUt::BorrowedPtr& GetCreature() const noexcept { return _creature; } }; } diff --git a/src/Battling/EventHooks/Events/SwapEvent.hpp b/src/Battling/EventHooks/Events/SwapEvent.hpp new file mode 100644 index 0000000..f6d9412 --- /dev/null +++ b/src/Battling/EventHooks/Events/SwapEvent.hpp @@ -0,0 +1,21 @@ +#ifndef SWAPEVENT_HPP +#define SWAPEVENT_HPP + +namespace CreatureLib::Battling { + class SwapEvent final : public EventData { + u8 _sideIndex; + u8 _positionA; + u8 _positionB; + + public: + SwapEvent(u8 sideIndex, u8 positionA, u8 positionB) noexcept + : _sideIndex(sideIndex), _positionA(positionA), _positionB(positionB) {} + EventDataKind GetKind() const noexcept override { return EventDataKind ::Swap; } + + inline u8 GetSideIndex() const noexcept { return _sideIndex; } + inline u8 GetPositionA() const noexcept { return _positionA; } + inline u8 GetPositionB() const noexcept { return _positionB; } + }; +} + +#endif // SWAPEVENT_HPP diff --git a/src/Battling/Models/BattleSide.cpp b/src/Battling/Models/BattleSide.cpp index 92b4c1b..42b120d 100644 --- a/src/Battling/Models/BattleSide.cpp +++ b/src/Battling/Models/BattleSide.cpp @@ -120,5 +120,6 @@ bool BattleSide::SwapPositions(u8 a, u8 b) { auto creatureA = _creatures[a]; _creatures[a] = _creatures[b]; _creatures[b] = creatureA; + _battle->TriggerEventListener(_index, a, b); return true; }