From 0912483ba85ed4b658d8fef02e2de2c106b10836 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 21 Nov 2021 14:02:00 +0100 Subject: [PATCH] Adds OnDamage script hook. --- src/Battling/Models/Creature.cpp | 4 +++- src/Battling/ScriptHandling/BattleScript.hpp | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index a5b8804..266b344 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -205,7 +205,6 @@ namespace CreatureLib::Battling { } if (damage == 0) return; - // HOOK: On Damage auto newHealth = _currentHealth - damage; auto battle = this->GetBattle(); if (battle.HasValue()) { @@ -213,6 +212,9 @@ namespace CreatureLib::Battling { battle.GetValue()->RegisterHistoryElement(this, damage, source); } _currentHealth = newHealth; + if (battle.HasValue()) { + HOOK(OnDamage, this, this, source); + } if (IsFainted() && damage > 0 && battle != nullptr) { OnFaint(source); diff --git a/src/Battling/ScriptHandling/BattleScript.hpp b/src/Battling/ScriptHandling/BattleScript.hpp index becd6de..d24349f 100644 --- a/src/Battling/ScriptHandling/BattleScript.hpp +++ b/src/Battling/ScriptHandling/BattleScript.hpp @@ -114,6 +114,7 @@ namespace CreatureLib::Battling { [[maybe_unused]] bool* result){}; virtual void OnEndTurn(){}; + virtual void OnDamage(Creature*, DamageSource){}; virtual void OnFaint(Creature*, DamageSource){}; virtual void OnSwitchIn(Creature*){}; };