Add TurnStart, TurnEnd and ExperienceGain event triggers.
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
2020-08-07 11:02:37 +02:00
parent 3a170d8924
commit 5aa04a4b15
4 changed files with 36 additions and 5 deletions

View File

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

View File

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