Cleaned up Events, added events on species and variant changes.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
parent
c484c376c3
commit
64b08d4ff0
|
@ -1,4 +1,4 @@
|
|||
#include "../../src/Battling/EventHooks/EventData.hpp"
|
||||
#include "../../src/Battling/EventHooks/EventDataClasses.hpp"
|
||||
#include "../Core.hpp"
|
||||
using namespace CreatureLib::Battling;
|
||||
|
||||
|
|
|
@ -1,116 +0,0 @@
|
|||
#ifndef CREATURELIB_EVENTDATA_HPP
|
||||
#define CREATURELIB_EVENTDATA_HPP
|
||||
|
||||
#include <Arbutils/Memory/BorrowedPtr.hpp>
|
||||
#include "../Models/CreatureIndex.hpp"
|
||||
#include "../Models/DamageSource.hpp"
|
||||
#include "EventDataKind.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
// Predeclare some classes.
|
||||
class Creature;
|
||||
|
||||
class EventData {
|
||||
public:
|
||||
virtual ~EventData() = default;
|
||||
virtual EventDataKind GetKind() const noexcept = 0;
|
||||
};
|
||||
|
||||
class DamageEvent : public EventData {
|
||||
ArbUt::BorrowedPtr<Creature> _creature;
|
||||
DamageSource _damageSource;
|
||||
uint32_t _originalHealth;
|
||||
uint32_t _newHealth;
|
||||
|
||||
public:
|
||||
DamageEvent(Creature* c, DamageSource s, uint32_t oHealth, uint32_t newHealth) noexcept
|
||||
: _creature(c), _damageSource(s), _originalHealth(oHealth), _newHealth(newHealth) {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::Damage; }
|
||||
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
|
||||
DamageSource GetDamageSource() const noexcept { return _damageSource; }
|
||||
uint32_t GetOriginalHealth() const noexcept { return _originalHealth; }
|
||||
uint32_t GetNewHealth() const noexcept { return _newHealth; }
|
||||
};
|
||||
|
||||
class HealEvent : public EventData {
|
||||
ArbUt::BorrowedPtr<Creature> _creature;
|
||||
uint32_t _originalHealth;
|
||||
uint32_t _newHealth;
|
||||
|
||||
public:
|
||||
HealEvent(ArbUt::BorrowedPtr<Creature> c, uint32_t oHealth, uint32_t newHealth) noexcept
|
||||
: _creature(c), _originalHealth(oHealth), _newHealth(newHealth) {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::Heal; }
|
||||
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
|
||||
uint32_t GetOriginalHealth() const noexcept { return _originalHealth; }
|
||||
uint32_t GetNewHealth() const noexcept { return _newHealth; }
|
||||
};
|
||||
|
||||
class FaintEvent : public EventData {
|
||||
ArbUt::BorrowedPtr<Creature> _creature;
|
||||
|
||||
public:
|
||||
FaintEvent(ArbUt::BorrowedPtr<Creature> c) noexcept : _creature(c) {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::Faint; }
|
||||
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 TurnStartEvent : public EventData {
|
||||
public:
|
||||
TurnStartEvent() {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::TurnStart; }
|
||||
};
|
||||
|
||||
class TurnEndEvent : public EventData {
|
||||
public:
|
||||
TurnEndEvent() {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::TurnEnd; }
|
||||
};
|
||||
|
||||
class ExperienceGainEvent : public EventData {
|
||||
ArbUt::BorrowedPtr<Creature> _creature;
|
||||
uint32_t _previousExperience;
|
||||
uint32_t _newExperience;
|
||||
|
||||
public:
|
||||
ExperienceGainEvent(const ArbUt::BorrowedPtr<Creature>& creature, uint32_t previousExp, uint32_t newExp)
|
||||
: _creature(creature), _previousExperience(previousExp), _newExperience(newExp) {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::ExperienceGain; }
|
||||
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
|
||||
uint32_t GetPreviousExperience() const noexcept { return _previousExperience; }
|
||||
uint32_t GetNewExperience() const noexcept { return _newExperience; }
|
||||
};
|
||||
|
||||
class DisplayTextEvent : public EventData {
|
||||
const ArbUt::StringView _text;
|
||||
|
||||
public:
|
||||
DisplayTextEvent(const ArbUt::StringView& text) noexcept : _text(text) {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::DisplayText; }
|
||||
const ArbUt::StringView& GetText() const noexcept { return _text; }
|
||||
};
|
||||
|
||||
class MissEvent : public EventData {
|
||||
ArbUt::BorrowedPtr<Creature> _creature;
|
||||
|
||||
public:
|
||||
MissEvent(const ArbUt::BorrowedPtr<Creature>& creature) noexcept : _creature(creature) {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::Miss; }
|
||||
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_EVENTDATA_HPP
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef CREATURELIB_EVENTDATACLASSES_HPP
|
||||
#define CREATURELIB_EVENTDATACLASSES_HPP
|
||||
|
||||
#include "Events/ChangeSpeciesEvent.hpp"
|
||||
#include "Events/ChangeVariantEvent.hpp"
|
||||
#include "Events/DamageEvent.hpp"
|
||||
#include "Events/DisplayTextEvent.hpp"
|
||||
#include "Events/EventData.hpp"
|
||||
#include "Events/ExperienceGainEvent.hpp"
|
||||
#include "Events/FaintEvent.hpp"
|
||||
#include "Events/HealEvent.hpp"
|
||||
#include "Events/MissEvent.hpp"
|
||||
#include "Events/SwitchEvent.hpp"
|
||||
#include "Events/TurnEvents.hpp"
|
||||
|
||||
#endif // CREATURELIB_EVENTDATACLASSES_HPP
|
|
@ -3,7 +3,8 @@
|
|||
#include <Arbutils/Enum.hpp>
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
ENUM(EventDataKind, uint8_t, Damage, Heal, Faint, Switch, TurnStart, TurnEnd, ExperienceGain, Miss, DisplayText)
|
||||
ENUM(EventDataKind, uint8_t, Damage, Heal, Faint, Switch, TurnStart, TurnEnd, ExperienceGain, Miss, DisplayText,
|
||||
ChangeSpecies, ChangeVariant)
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_EVENTDATAKIND_HPP
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <thread>
|
||||
#include <vector>
|
||||
#include "../../Library/Exceptions/CreatureException.hpp"
|
||||
#include "EventData.hpp"
|
||||
#include "Events/EventData.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
/// The Event Hook class allows users to write consumers for the battle events, for example to write User Interfaces
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef CREATURELIB_CHANGESPECIESEVENT_HPP
|
||||
#define CREATURELIB_CHANGESPECIESEVENT_HPP
|
||||
#include "EventData.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class ChangeSpeciesEvent : public EventData {
|
||||
const ArbUt::BorrowedPtr<Creature> _creature;
|
||||
const ArbUt::BorrowedPtr<const CreatureLib::Library::CreatureSpecies> _newSpecies;
|
||||
|
||||
public:
|
||||
ChangeSpeciesEvent(const ArbUt::BorrowedPtr<Creature>& creature,
|
||||
const ArbUt::BorrowedPtr<const CreatureLib::Library::CreatureSpecies>& species) noexcept
|
||||
: _creature(creature), _newSpecies(species) {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::ChangeSpecies; }
|
||||
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
|
||||
const ArbUt::BorrowedPtr<const CreatureLib::Library::CreatureSpecies>& GetNewSpecies() const noexcept {
|
||||
return _newSpecies;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_CHANGESPECIESEVENT_HPP
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef CREATURELIB_CHANGEVARIANTEVENT_HPP
|
||||
#define CREATURELIB_CHANGEVARIANTEVENT_HPP
|
||||
#include "EventData.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class ChangeVariantEvent : public EventData {
|
||||
const ArbUt::BorrowedPtr<Creature> _creature;
|
||||
const ArbUt::BorrowedPtr<const CreatureLib::Library::SpeciesVariant> _newVariant;
|
||||
|
||||
public:
|
||||
ChangeVariantEvent(const ArbUt::BorrowedPtr<Creature>& creature,
|
||||
const ArbUt::BorrowedPtr<const CreatureLib::Library::SpeciesVariant>& variant) noexcept
|
||||
: _creature(creature), _newVariant(variant) {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::ChangeVariant; }
|
||||
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
|
||||
const ArbUt::BorrowedPtr<const CreatureLib::Library::SpeciesVariant>& GetNewVariant() const noexcept {
|
||||
return _newVariant;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_CHANGEVARIANTEVENT_HPP
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef CREATURELIB_DAMAGEEVENT_HPP
|
||||
#define CREATURELIB_DAMAGEEVENT_HPP
|
||||
#include "EventData.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class DamageEvent : public EventData {
|
||||
ArbUt::BorrowedPtr<Creature> _creature;
|
||||
DamageSource _damageSource;
|
||||
uint32_t _originalHealth;
|
||||
uint32_t _newHealth;
|
||||
|
||||
public:
|
||||
DamageEvent(Creature* c, DamageSource s, uint32_t oHealth, uint32_t newHealth) noexcept
|
||||
: _creature(c), _damageSource(s), _originalHealth(oHealth), _newHealth(newHealth) {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::Damage; }
|
||||
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
|
||||
DamageSource GetDamageSource() const noexcept { return _damageSource; }
|
||||
uint32_t GetOriginalHealth() const noexcept { return _originalHealth; }
|
||||
uint32_t GetNewHealth() const noexcept { return _newHealth; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_DAMAGEEVENT_HPP
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef CREATURELIB_DISPLAYTEXTEVENT_HPP
|
||||
#define CREATURELIB_DISPLAYTEXTEVENT_HPP
|
||||
#include "EventData.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class DisplayTextEvent : public EventData {
|
||||
const ArbUt::StringView _text;
|
||||
|
||||
public:
|
||||
DisplayTextEvent(const ArbUt::StringView& text) noexcept : _text(text) {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::DisplayText; }
|
||||
const ArbUt::StringView& GetText() const noexcept { return _text; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_DISPLAYTEXTEVENT_HPP
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef CREATURELIB_EVENTDATA_HPP
|
||||
#define CREATURELIB_EVENTDATA_HPP
|
||||
|
||||
#include <Arbutils/Memory/BorrowedPtr.hpp>
|
||||
#include "../../Models/CreatureIndex.hpp"
|
||||
#include "../../Models/DamageSource.hpp"
|
||||
#include "../EventDataKind.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
// Predeclare some classes.
|
||||
class Creature;
|
||||
|
||||
class EventData {
|
||||
public:
|
||||
virtual ~EventData() = default;
|
||||
virtual EventDataKind GetKind() const noexcept = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_EVENTDATA_HPP
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef CREATURELIB_EXPERIENCEGAINEVENT_HPP
|
||||
#define CREATURELIB_EXPERIENCEGAINEVENT_HPP
|
||||
#include "EventData.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class ExperienceGainEvent : public EventData {
|
||||
ArbUt::BorrowedPtr<Creature> _creature;
|
||||
uint32_t _previousExperience;
|
||||
uint32_t _newExperience;
|
||||
|
||||
public:
|
||||
ExperienceGainEvent(const ArbUt::BorrowedPtr<Creature>& creature, uint32_t previousExp, uint32_t newExp)
|
||||
: _creature(creature), _previousExperience(previousExp), _newExperience(newExp) {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::ExperienceGain; }
|
||||
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
|
||||
uint32_t GetPreviousExperience() const noexcept { return _previousExperience; }
|
||||
uint32_t GetNewExperience() const noexcept { return _newExperience; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_EXPERIENCEGAINEVENT_HPP
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef CREATURELIB_FAINTEVENT_HPP
|
||||
#define CREATURELIB_FAINTEVENT_HPP
|
||||
#include "EventData.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class FaintEvent : public EventData {
|
||||
ArbUt::BorrowedPtr<Creature> _creature;
|
||||
|
||||
public:
|
||||
FaintEvent(ArbUt::BorrowedPtr<Creature> c) noexcept : _creature(c) {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::Faint; }
|
||||
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_FAINTEVENT_HPP
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef CREATURELIB_HEALEVENT_HPP
|
||||
#define CREATURELIB_HEALEVENT_HPP
|
||||
#include "EventData.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class HealEvent : public EventData {
|
||||
ArbUt::BorrowedPtr<Creature> _creature;
|
||||
uint32_t _originalHealth;
|
||||
uint32_t _newHealth;
|
||||
|
||||
public:
|
||||
HealEvent(ArbUt::BorrowedPtr<Creature> c, uint32_t oHealth, uint32_t newHealth) noexcept
|
||||
: _creature(c), _originalHealth(oHealth), _newHealth(newHealth) {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::Heal; }
|
||||
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
|
||||
uint32_t GetOriginalHealth() const noexcept { return _originalHealth; }
|
||||
uint32_t GetNewHealth() const noexcept { return _newHealth; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_HEALEVENT_HPP
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef CREATURELIB_MISSEVENT_HPP
|
||||
#define CREATURELIB_MISSEVENT_HPP
|
||||
#include "EventData.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class MissEvent : public EventData {
|
||||
ArbUt::BorrowedPtr<Creature> _creature;
|
||||
|
||||
public:
|
||||
explicit MissEvent(const ArbUt::BorrowedPtr<Creature>& creature) noexcept : _creature(creature) {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::Miss; }
|
||||
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
|
||||
};
|
||||
}
|
||||
#endif // CREATURELIB_MISSEVENT_HPP
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef CREATURELIB_SWITCHEVENT_HPP
|
||||
#define CREATURELIB_SWITCHEVENT_HPP
|
||||
#include "EventData.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
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; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_SWITCHEVENT_HPP
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef CREATURELIB_TURNEVENTS_HPP
|
||||
#define CREATURELIB_TURNEVENTS_HPP
|
||||
#include "EventData.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class TurnStartEvent : public EventData {
|
||||
public:
|
||||
TurnStartEvent() {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::TurnStart; }
|
||||
};
|
||||
|
||||
class TurnEndEvent : public EventData {
|
||||
public:
|
||||
TurnEndEvent() {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::TurnEnd; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_TURNEVENTS_HPP
|
|
@ -2,6 +2,7 @@
|
|||
#include <Arbutils/Assert.hpp>
|
||||
#include <unordered_set>
|
||||
#include "../../Library/Exceptions/NotImplementedException.hpp"
|
||||
#include "../EventHooks/EventDataClasses.hpp"
|
||||
#include "../ScriptHandling/ScriptMacros.hpp"
|
||||
#include "ResolveTarget.hpp"
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "Battle.hpp"
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include <memory>
|
||||
#include "../EventHooks/EventDataClasses.hpp"
|
||||
#include "../Flow/TurnHandler.hpp"
|
||||
#include "../Flow/TurnOrdering.hpp"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "BattleSide.hpp"
|
||||
#include <algorithm>
|
||||
#include "../../Library/Exceptions/CreatureException.hpp"
|
||||
#include "../EventHooks/EventDataClasses.hpp"
|
||||
#include "Battle.hpp"
|
||||
|
||||
using namespace CreatureLib::Battling;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "Creature.hpp"
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include "../EventHooks/EventDataClasses.hpp"
|
||||
#include "../Models/Battle.hpp"
|
||||
#include "../ScriptHandling/ScriptMacros.hpp"
|
||||
|
||||
|
@ -36,7 +37,6 @@ namespace CreatureLib::Battling {
|
|||
AssertNotNull(species);
|
||||
AssertNotNull(variant);
|
||||
_species = species;
|
||||
ChangeVariant(variant);
|
||||
|
||||
// If the creature is genderless, but it's new species is not, we want to set its gender
|
||||
if (_gender != CreatureLib::Library::Gender::Genderless && _species->GetGenderRate() != -1) {
|
||||
|
@ -53,6 +53,10 @@ namespace CreatureLib::Battling {
|
|||
else if (_species->GetGenderRate() == -1 && _gender != CreatureLib::Library::Gender::Genderless) {
|
||||
_gender = CreatureLib::Library::Gender::Genderless;
|
||||
}
|
||||
if (_battle != nullptr) {
|
||||
_battle->TriggerEventListener<ChangeSpeciesEvent>(this, _species);
|
||||
}
|
||||
ChangeVariant(variant);
|
||||
}
|
||||
|
||||
void Creature::ChangeVariant(const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant) {
|
||||
|
@ -79,6 +83,10 @@ namespace CreatureLib::Battling {
|
|||
}
|
||||
|
||||
// TODO: consider variant specific attacks?
|
||||
|
||||
if (_battle != nullptr) {
|
||||
_battle->TriggerEventListener<ChangeVariantEvent>(this, _variant);
|
||||
}
|
||||
}
|
||||
|
||||
void Creature::ChangeLevelBy(int8_t amount) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#ifdef TESTS_BUILD
|
||||
#include "../../extern/catch.hpp"
|
||||
#include "../../src/Battling/EventHooks/EventDataClasses.hpp"
|
||||
#include "../../src/Battling/EventHooks/EventHook.hpp"
|
||||
#include "../../src/Battling/Models/CreateCreature.hpp"
|
||||
#include "../TestLibrary/TestLibrary.hpp"
|
||||
|
|
Loading…
Reference in New Issue