Add TurnStart, TurnEnd and ExperienceGain event triggers.
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
3a170d8924
commit
5aa04a4b15
|
@ -67,6 +67,32 @@ namespace CreatureLib::Battling {
|
|||
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;
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <Arbutils/Enum.hpp>
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
ENUM(EventDataKind, uint8_t, Damage, Heal, Faint, Switch, DisplayText)
|
||||
ENUM(EventDataKind, uint8_t, Damage, Heal, Faint, Switch, TurnStart, TurnEnd, ExperienceGain, DisplayText)
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_EVENTDATAKIND_HPP
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "Battle.hpp"
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include "../../Library/Exceptions/NotImplementedException.hpp"
|
||||
#include <memory>
|
||||
#include "../Flow/TurnHandler.hpp"
|
||||
#include "../Flow/TurnOrdering.hpp"
|
||||
|
||||
|
@ -19,7 +19,7 @@ bool Battle::CanUse(const ArbUt::BorrowedPtr<BaseTurnChoice>& choice) {
|
|||
}
|
||||
|
||||
bool Battle::TrySetChoice(BaseTurnChoice* choice) {
|
||||
AssertNotNull(choice);
|
||||
AssertNotNull(choice)
|
||||
if (!CanUse(choice))
|
||||
return false;
|
||||
choice->GetUser()->GetBattleSide()->SetChoice(choice);
|
||||
|
@ -42,7 +42,7 @@ void Battle::CheckChoicesSetAndRun() {
|
|||
} catch (const CreatureException& e) {
|
||||
throw e;
|
||||
} catch (const std::exception& e) {
|
||||
THROW_CREATURE("Exception during choices set validation: '" << e.what() << "'.");
|
||||
THROW_CREATURE("Exception during choices set validation: '" << e.what() << "'.")
|
||||
}
|
||||
|
||||
auto choices = std::vector<std::shared_ptr<BaseTurnChoice>>(_numberOfSides * _creaturesPerSide);
|
||||
|
@ -76,7 +76,8 @@ void Battle::CheckChoicesSetAndRun() {
|
|||
} catch (const std::exception& e) {
|
||||
THROW_CREATURE("Exception during turn ordering: '" << e.what() << "'.")
|
||||
}
|
||||
this->_currentTurnQueue.reset(new ChoiceQueue(choices));
|
||||
this->_currentTurnQueue = std::make_unique<ChoiceQueue>(choices);
|
||||
TriggerEventListener<TurnStartEvent>();
|
||||
try {
|
||||
TurnHandler::RunTurn(this->_currentTurnQueue);
|
||||
} catch (const CreatureException& e) {
|
||||
|
@ -87,6 +88,7 @@ void Battle::CheckChoicesSetAndRun() {
|
|||
if (this->_currentTurnQueue->HasCompletedQueue) {
|
||||
this->_currentTurnQueue = nullptr;
|
||||
}
|
||||
TriggerEventListener<TurnEndEvent>();
|
||||
}
|
||||
|
||||
ArbUt::BorrowedPtr<ChoiceQueue> Battle::GetCurrentTurnQueue() const noexcept { return _currentTurnQueue; }
|
||||
|
|
|
@ -213,6 +213,9 @@ void Battling::Creature::AddExperience(uint32_t amount) {
|
|||
if (level >= maxLevel) {
|
||||
exp = _library->GetGrowthRateLibrary()->CalculateExperience(this->GetSpecies()->GetGrowthRate(), maxLevel);
|
||||
}
|
||||
if (_battle != nullptr) {
|
||||
_battle->TriggerEventListener<ExperienceGainEvent>(this, _experience, exp);
|
||||
}
|
||||
_experience = exp;
|
||||
_level = level;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue