From 0a28bd434a00e827753ae4502b41548cc6d646cf Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 5 Sep 2022 21:57:54 -0400 Subject: [PATCH] Core/SAI: Rename LeavingWorld to OnDespawn & use it in SAI Port From (https://github.com/TrinityCore/TrinityCore/commit/b0164fb2b9cc35663e337d48660d5bca1e973d99) --- Source/Framework/Constants/SmartAIConst.cs | 3 ++- Source/Game/AI/CoreAI/UnitAI.cs | 2 +- Source/Game/AI/SmartScripts/SmartAI.cs | 5 +++++ Source/Game/AI/SmartScripts/SmartAIManager.cs | 5 ++++- Source/Game/AI/SmartScripts/SmartScript.cs | 1 + Source/Game/Entities/Unit/Unit.cs | 2 +- Source/Scripts/Pets/Generic.cs | 4 ++-- 7 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Source/Framework/Constants/SmartAIConst.cs b/Source/Framework/Constants/SmartAIConst.cs index d0d847098..664cf46cd 100644 --- a/Source/Framework/Constants/SmartAIConst.cs +++ b/Source/Framework/Constants/SmartAIConst.cs @@ -240,8 +240,9 @@ namespace Framework.Constants OnSpellCast = 83, // SpellID, CooldownMin, CooldownMax OnSpellFailed = 84, // SpellID, CooldownMin, CooldownMax OnSpellStart = 85, // SpellID, CooldownMin, CooldownMax + OnDespawn = 86, // NONE - End = 86 + End } public enum SmartActions diff --git a/Source/Game/AI/CoreAI/UnitAI.cs b/Source/Game/AI/CoreAI/UnitAI.cs index dbbcc43ef..997e3febd 100644 --- a/Source/Game/AI/CoreAI/UnitAI.cs +++ b/Source/Game/AI/CoreAI/UnitAI.cs @@ -518,7 +518,7 @@ namespace Game.AI 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() { } + public virtual void OnDespawn() { } // Called at any Damage to any victim (before damage apply) public virtual void DamageDealt(Unit victim, ref uint damage, DamageEffectType damageType) { } diff --git a/Source/Game/AI/SmartScripts/SmartAI.cs b/Source/Game/AI/SmartScripts/SmartAI.cs index f8bb41dc9..dd408724d 100644 --- a/Source/Game/AI/SmartScripts/SmartAI.cs +++ b/Source/Game/AI/SmartScripts/SmartAI.cs @@ -726,6 +726,11 @@ namespace Game.AI GetScript().ProcessEventsFor(SmartEvents.CorpseRemoved, null, (uint)respawnDelay); } + public override void OnDespawn() + { + GetScript().ProcessEventsFor(SmartEvents.OnDespawn); + } + public override void PassengerBoarded(Unit passenger, sbyte seatId, bool apply) { GetScript().ProcessEventsFor(apply ? SmartEvents.PassengerBoarded : SmartEvents.PassengerRemoved, passenger, (uint)seatId, 0, apply); diff --git a/Source/Game/AI/SmartScripts/SmartAIManager.cs b/Source/Game/AI/SmartScripts/SmartAIManager.cs index 180a2451e..c92146407 100644 --- a/Source/Game/AI/SmartScripts/SmartAIManager.cs +++ b/Source/Game/AI/SmartScripts/SmartAIManager.cs @@ -634,7 +634,8 @@ namespace Game.AI SmartEvents.OnSpellCast => Marshal.SizeOf(typeof(SmartEvent.SpellCast)), SmartEvents.OnSpellFailed => Marshal.SizeOf(typeof(SmartEvent.SpellCast)), SmartEvents.OnSpellStart => Marshal.SizeOf(typeof(SmartEvent.SpellCast)), - _ => Marshal.SizeOf(typeof(SmartEvent.Raw)), + SmartEvents.OnDespawn => 0, + _ => Marshal.SizeOf(typeof(SmartEvent.Raw)), }; int rawCount = Marshal.SizeOf(typeof(SmartEvent.Raw)) / sizeof(uint); @@ -1296,6 +1297,7 @@ namespace Game.AI case SmartEvents.JustCreated: case SmartEvents.FollowCompleted: case SmartEvents.OnSpellclick: + case SmartEvents.OnDespawn: case SmartEvents.SceneStart: case SmartEvents.SceneCancel: case SmartEvents.SceneComplete: @@ -2425,6 +2427,7 @@ namespace Game.AI SmartEvents.OnSpellCast => SmartScriptTypeMaskId.Creature, SmartEvents.OnSpellFailed => SmartScriptTypeMaskId.Creature, SmartEvents.OnSpellStart => SmartScriptTypeMaskId.Creature, + SmartEvents.OnDespawn => SmartScriptTypeMaskId.Creature, _ => 0, }; diff --git a/Source/Game/AI/SmartScripts/SmartScript.cs b/Source/Game/AI/SmartScripts/SmartScript.cs index 8010cfb26..48a489c26 100644 --- a/Source/Game/AI/SmartScripts/SmartScript.cs +++ b/Source/Game/AI/SmartScripts/SmartScript.cs @@ -3211,6 +3211,7 @@ namespace Game.AI case SmartEvents.JustCreated: case SmartEvents.FollowCompleted: case SmartEvents.OnSpellclick: + case SmartEvents.OnDespawn: ProcessAction(e, unit, var0, var1, bvar, spell, gob); break; case SmartEvents.GossipHello: diff --git a/Source/Game/Entities/Unit/Unit.cs b/Source/Game/Entities/Unit/Unit.cs index a9c5aab09..0f8199481 100644 --- a/Source/Game/Entities/Unit/Unit.cs +++ b/Source/Game/Entities/Unit/Unit.cs @@ -481,7 +481,7 @@ namespace Game.Entities m_duringRemoveFromWorld = true; UnitAI ai = GetAI(); if (ai != null) - ai.LeavingWorld(); + ai.OnDespawn(); if (IsVehicle()) RemoveVehicleKit(true); diff --git a/Source/Scripts/Pets/Generic.cs b/Source/Scripts/Pets/Generic.cs index dfb760316..4a1bf507c 100644 --- a/Source/Scripts/Pets/Generic.cs +++ b/Source/Scripts/Pets/Generic.cs @@ -53,7 +53,7 @@ namespace Scripts.Pets { public npc_pet_gen_soul_trader(Creature creature) : base(creature) { } - public override void LeavingWorld() + public override void OnDespawn() { Unit owner = me.GetOwner(); if (owner != null) @@ -77,7 +77,7 @@ namespace Scripts.Pets { public npc_pet_lich(Creature creature) : base(creature) { } - public override void LeavingWorld() + public override void OnDespawn() { Unit owner = me.GetOwner(); if (owner != null)