Initial support for Event Hooks.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#define CREATURELIB_BATTLE_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "../EventHooks/EventHook.hpp"
|
||||
#include "../Flow/ChoiceQueue.hpp"
|
||||
#include "../Library/BattleLibrary.hpp"
|
||||
#include "../TurnChoices/BaseTurnChoice.hpp"
|
||||
@@ -22,6 +23,7 @@ namespace CreatureLib::Battling {
|
||||
ChoiceQueue* _currentTurnQueue = nullptr;
|
||||
bool _hasEnded = false;
|
||||
BattleResult _battleResult = BattleResult::Empty();
|
||||
EventHook* _eventHook = new EventHook();
|
||||
|
||||
ScriptSet _volatile;
|
||||
|
||||
@@ -71,6 +73,9 @@ namespace CreatureLib::Battling {
|
||||
inline const BattleResult& GetResult() const { return _battleResult; }
|
||||
|
||||
const std::vector<BattleSide*>& GetSides() const { return _sides; }
|
||||
|
||||
void RegisterEventListener(EVENT_HOOK_FUNC(listener)) { this->_eventHook->RegisterListener(listener); }
|
||||
void TriggerEventListener(EventData* data) { this->_eventHook->TriggerEvent(data); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,9 @@ void Battling::Creature::Damage(uint32_t damage, Battling::DamageSource source)
|
||||
damage = __CurrentHealth;
|
||||
}
|
||||
// HOOK: On Damage
|
||||
__CurrentHealth -= damage;
|
||||
auto newHealth = __CurrentHealth - damage;
|
||||
this->GetBattle()->TriggerEventListener(new DamageEvent(this, source, __CurrentHealth, newHealth));
|
||||
__CurrentHealth = newHealth;
|
||||
|
||||
if (IsFainted() && damage > 0) {
|
||||
OnFaint();
|
||||
|
||||
Reference in New Issue
Block a user