Adds creature Switch event.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
9d56aaa52a
commit
3a170d8924
|
@ -2,6 +2,7 @@
|
|||
#define CREATURELIB_EVENTDATA_HPP
|
||||
|
||||
#include <Arbutils/Memory/BorrowedPtr.hpp>
|
||||
#include "../Models/CreatureIndex.hpp"
|
||||
#include "../Models/DamageSource.hpp"
|
||||
#include "EventDataKind.hpp"
|
||||
|
||||
|
@ -54,6 +55,18 @@ namespace CreatureLib::Battling {
|
|||
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
|
||||
};
|
||||
|
||||
class SwitchEvent : public EventData {
|
||||
CreatureIndex _index;
|
||||
ArbUt::BorrowedPtr<Creature> _newCreature;
|
||||
|
||||
public:
|
||||
SwitchEvent(const CreatureIndex& index, const ArbUt::BorrowedPtr<Creature>& newCreature)
|
||||
: _index(index), _newCreature(newCreature) {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::Switch; }
|
||||
const CreatureIndex& GetIndex() const noexcept { return _index; }
|
||||
const ArbUt::BorrowedPtr<Creature>& GetNewCreature() const noexcept { return _newCreature; }
|
||||
};
|
||||
|
||||
class DisplayTextEvent : public EventData {
|
||||
const ArbUt::StringView _text;
|
||||
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
#include <Arbutils/Enum.hpp>
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
ENUM(EventDataKind, uint8_t, Damage, Heal, Faint, DisplayText)
|
||||
|
||||
ENUM(EventDataKind, uint8_t, Damage, Heal, Faint, Switch, DisplayText)
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_EVENTDATAKIND_HPP
|
||||
|
|
|
@ -62,13 +62,14 @@ void BattleSide::SetCreature(ArbUt::BorrowedPtr<Creature> 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<SwitchEvent>(CreatureIndex(this->_index, index), creature);
|
||||
}
|
||||
|
||||
bool BattleSide::CreatureOnSide(const ArbUt::BorrowedPtr<Creature>& creature) const {
|
||||
|
|
Loading…
Reference in New Issue