diff options
-rw-r--r-- | src/server/game/AI/CreatureAI.h | 3 | ||||
-rw-r--r-- | src/server/game/Entities/Unit/Unit.cpp | 10 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/server/game/AI/CreatureAI.h b/src/server/game/AI/CreatureAI.h index d4e5c895e26..61fe33d567e 100644 --- a/src/server/game/AI/CreatureAI.h +++ b/src/server/game/AI/CreatureAI.h @@ -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*/) { } diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 163881b34a5..8f5cb9990fd 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -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()) { |