From 72018b983c5bb9de28dab6e0c1ec997d217d9be1 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Fri, 8 Oct 2021 10:33:53 -0400 Subject: [PATCH] Core/AI: Add a new LeavingWorld AI hook Port From (https://github.com/TrinityCore/TrinityCore/commit/2642fb1a489e4b79a17bbb63127c8b3ce2823e1e) --- Source/Game/AI/CoreAI/UnitAI.cs | 4 ++++ Source/Game/Entities/Unit/Unit.cs | 3 +++ 2 files changed, 7 insertions(+) diff --git a/Source/Game/AI/CoreAI/UnitAI.cs b/Source/Game/AI/CoreAI/UnitAI.cs index 92467d657..11e0e1a8b 100644 --- a/Source/Game/AI/CoreAI/UnitAI.cs +++ b/Source/Game/AI/CoreAI/UnitAI.cs @@ -480,6 +480,10 @@ namespace Game.AI // Called when the unit leaves combat public virtual void JustExitedCombat() { } + // Called when the unit is about to be removed from the world (despawn, grid unload, corpse disappearing, player logging out etc.) + public virtual void LeavingWorld() { } + + // Called at any Damage to any victim (before damage apply) public virtual void DamageDealt(Unit victim, ref uint damage, DamageEffectType damageType) { } public virtual void DamageTaken(Unit attacker, ref uint damage) { } public virtual void HealReceived(Unit by, uint addhealth) { } diff --git a/Source/Game/Entities/Unit/Unit.cs b/Source/Game/Entities/Unit/Unit.cs index cda7db4e3..fec3e7e50 100644 --- a/Source/Game/Entities/Unit/Unit.cs +++ b/Source/Game/Entities/Unit/Unit.cs @@ -435,6 +435,9 @@ namespace Game.Entities if (IsInWorld) { m_duringRemoveFromWorld = true; + if (IsAIEnabled) + GetAI().LeavingWorld(); + if (IsVehicle()) RemoveVehicleKit(true);