Adds swap event when two creatures swap positions.
continuous-integration/drone/push Build is passing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2021-03-28 11:58:26 +02:00
parent acacd02ef9
commit 23bd0da646
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
5 changed files with 25 additions and 2 deletions

View File

@ -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"

View File

@ -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

View File

@ -8,7 +8,7 @@ namespace CreatureLib::Battling {
public:
FailEvent(ArbUt::BorrowedPtr<Creature> c) noexcept : _creature(c) {}
EventDataKind GetKind() const noexcept override { return EventDataKind ::Faint; }
EventDataKind GetKind() const noexcept override { return EventDataKind ::Fail; }
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
};
}

View File

@ -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

View File

@ -120,5 +120,6 @@ bool BattleSide::SwapPositions(u8 a, u8 b) {
auto creatureA = _creatures[a];
_creatures[a] = _creatures[b];
_creatures[b] = creatureA;
_battle->TriggerEventListener<SwapEvent>(_index, a, b);
return true;
}