Trigger event when stat boost changes.
continuous-integration/drone/push Build is passing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2021-01-16 21:16:47 +01:00
parent 987f60ee85
commit abccc23851
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
6 changed files with 40 additions and 2 deletions

View File

@ -50,3 +50,10 @@ DESTRUCTOR(AttackUseEvent);
export const char* CreatureLib_DisplayTextEvent_GetText(const DisplayTextEvent* p) { return p->GetText().c_str(); }
export void CreatureLib_DisplayTextEvent_Destruct(const DisplayTextEvent* p) { delete p; }
BORROWED_GET_FUNC(ChangeStatBoostEvent, GetCreature, const Creature*);
SIMPLE_GET_FUNC(ChangeStatBoostEvent, GetStatistic, CreatureLib::Library::Statistic);
SIMPLE_GET_FUNC(ChangeStatBoostEvent, GetOldValue, int8_t);
SIMPLE_GET_FUNC(ChangeStatBoostEvent, GetNewValue, int8_t);
DESTRUCTOR(ChangeStatBoostEvent);

View File

@ -9,7 +9,6 @@
#define export extern "C" [[maybe_unused]]
#define CreatureLibException 2;
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
class ExceptionHandler {
static std::string _creatureLibLastException;

View File

@ -3,6 +3,7 @@
#include "Events/AttackUseEvent.hpp"
#include "Events/ChangeSpeciesEvent.hpp"
#include "Events/ChangeStatEvent.hpp"
#include "Events/ChangeVariantEvent.hpp"
#include "Events/DamageEvent.hpp"
#include "Events/DisplayTextEvent.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)
ChangeSpecies, ChangeVariant, AttackUse, ChangeStatBoost)
}
#endif // CREATURELIB_EVENTDATAKIND_HPP

View File

@ -0,0 +1,26 @@
#ifndef CHANGESTATEVENT_HPP
#define CHANGESTATEVENT_HPP
#include "EventData.hpp"
namespace CreatureLib::Battling {
class ChangeStatBoostEvent final : public EventData {
const ArbUt::BorrowedPtr<Creature> _creature;
const CreatureLib::Library::Statistic _statistic;
const int8_t _oldValue;
const int8_t _newValue;
public:
ChangeStatBoostEvent(const ArbUt::BorrowedPtr<Creature>& creature, CreatureLib::Library::Statistic statistic,
int8_t oldValue, int8_t newValue) noexcept
: _creature(creature), _statistic(statistic), _oldValue(oldValue), _newValue(newValue) {}
EventDataKind GetKind() const noexcept override { return EventDataKind ::ChangeStatBoost; }
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
CreatureLib::Library::Statistic GetStatistic() const noexcept { return _statistic; }
int8_t GetOldValue() const noexcept { return _oldValue; }
int8_t GetNewValue() const noexcept { return _newValue; }
};
}
#endif // CHANGESTATEVENT_HPP

View File

@ -109,10 +109,15 @@ namespace CreatureLib::Battling {
bool Creature::ChangeStatBoost(Library::Statistic stat, int8_t diffAmount) {
bool changed = false;
auto oldValue = this->_statBoost.GetStat(stat);
if (diffAmount > 0)
changed = this->_statBoost.IncreaseStatBy(stat, diffAmount);
else
changed = this->_statBoost.DecreaseStatBy(stat, -diffAmount);
if (this->GetBattle().HasValue()) {
auto newValue = this->_statBoost.GetStat(stat);
this->GetBattle().GetValue()->TriggerEventListener<ChangeStatBoostEvent>(this, stat, oldValue, newValue);
}
this->RecalculateBoostedStat(stat);
return changed;
}