Core/AI: Implemented OnHealthDepleted hook (#29134)

This commit is contained in:
Traesh
2023-07-24 14:31:03 +02:00
committed by GitHub
parent 2e7e49b749
commit ea134c0eae
2 changed files with 13 additions and 0 deletions

View File

@@ -98,6 +98,9 @@ class TC_GAME_API CreatureAI : public UnitAI
// Called for reaction when initially engaged - this will always happen _after_ JustEnteredCombat
virtual void JustEngagedWith(Unit* /*who*/) { }
// Called when the creature reaches 0 health (or 1 if unkillable).
virtual void OnHealthDepleted(Unit* /*attacker*/, bool /*isKill*/) { }
// Called when the creature is killed
virtual void JustDied(Unit* /*killer*/) { }

View File

@@ -864,6 +864,13 @@ bool Unit::HasBreakableByDamageCrowdControlAura(Unit* excludeCasterChannel) cons
else if (victim->IsCreature() && damageTaken >= health && victim->ToCreature()->HasFlag(CREATURE_STATIC_FLAG_UNKILLABLE))
{
damageTaken = health - 1;
// If we had damage (aka health was not 1 already) trigger OnHealthDepleted
if (damageTaken > 0)
{
if (CreatureAI* victimAI = victim->ToCreature()->AI())
victimAI->OnHealthDepleted(attacker, false);
}
}
else if (victim->IsVehicle() && damageTaken >= (health-1) && victim->GetCharmer() && victim->GetCharmer()->GetTypeId() == TYPEID_PLAYER)
{
@@ -10916,7 +10923,10 @@ void Unit::SetMeleeAnimKitId(uint16 animKitId)
// Call creature just died function
if (CreatureAI* ai = creature->AI())
{
ai->OnHealthDepleted(attacker, true);
ai->JustDied(attacker);
}
if (TempSummon * summon = creature->ToTempSummon())
{