From c6d814e886de1d9cbf9d6e5b7f2c91477d5e796e Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 19 Nov 2021 12:15:38 +0100 Subject: [PATCH] Adds DamageSource to OnFaint script hook. --- src/Battling/Models/Creature.cpp | 7 ++++--- src/Battling/Models/Creature.hpp | 2 +- src/Battling/ScriptHandling/BattleScript.hpp | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index 6163604..4b5ebce 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -4,6 +4,7 @@ #include "../History/HistoryElements/DamageHistory.hpp" #include "../Models/Battle.hpp" #include "../ScriptHandling/ScriptMacros.hpp" +#include "DamageSource.hpp" using namespace CreatureLib; @@ -171,12 +172,12 @@ namespace CreatureLib::Battling { bool Creature::IsFainted() const noexcept { return this->_currentHealth == 0; } - void Creature::OnFaint() { + void Creature::OnFaint(DamageSource damageSource) { EnsureNotNull(_battleData.Battle) EnsureNotNull(_battleData.Side) if (_battleData.Battle.HasValue()) { _battleData.Battle.GetValue()->TriggerEventListener(this); - HOOK(OnFaint, this, this); + HOOK(OnFaint, this, this, damageSource); } _library->GetExperienceLibrary()->HandleExperienceGain(this, _battleData.SeenOpponents); if (_battleData.Battle.HasValue() && _battleData.Side.HasValue()) { @@ -205,7 +206,7 @@ namespace CreatureLib::Battling { _currentHealth = newHealth; if (IsFainted() && damage > 0 && battle != nullptr) { - OnFaint(); + OnFaint(nullptr); } } diff --git a/src/Battling/Models/Creature.hpp b/src/Battling/Models/Creature.hpp index 99b16ed..d21c7d2 100644 --- a/src/Battling/Models/Creature.hpp +++ b/src/Battling/Models/Creature.hpp @@ -67,7 +67,7 @@ namespace CreatureLib::Battling { std::vector _types = {}; private: - void OnFaint(); + void OnFaint(DamageSource damageSource); public: Creature(const ArbUt::BorrowedPtr& library, diff --git a/src/Battling/ScriptHandling/BattleScript.hpp b/src/Battling/ScriptHandling/BattleScript.hpp index 59471a3..7e3ff80 100644 --- a/src/Battling/ScriptHandling/BattleScript.hpp +++ b/src/Battling/ScriptHandling/BattleScript.hpp @@ -5,6 +5,7 @@ #include #include #include "../../Library/EffectParameter.hpp" +#include "../Models/DamageSource.hpp" namespace CreatureLib::Battling { class BaseTurnChoice; @@ -99,7 +100,7 @@ namespace CreatureLib::Battling { [[maybe_unused]] bool* result){}; virtual void OnEndTurn(){}; - virtual void OnFaint([[maybe_unused]] Creature* creature){}; + virtual void OnFaint(Creature*, DamageSource){}; }; }