Trigger event when stat boost changes.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
26
src/Battling/EventHooks/Events/ChangeStatEvent.hpp
Normal file
26
src/Battling/EventHooks/Events/ChangeStatEvent.hpp
Normal 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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user