Adds OnDamage script hook.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2021-11-21 14:02:00 +01:00
parent 40d6e8a389
commit 0912483ba8
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 4 additions and 1 deletions

View File

@ -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<DamageHistory>(this, damage, source);
}
_currentHealth = newHealth;
if (battle.HasValue()) {
HOOK(OnDamage, this, this, source);
}
if (IsFainted() && damage > 0 && battle != nullptr) {
OnFaint(source);

View File

@ -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*){};
};