From 146f0639e2d4b07ee3f9afe981a3c1a5e6238b04 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Thu, 15 Aug 2019 11:55:27 -0400 Subject: [PATCH] Core/SmartAI: Delay SMART_ACTION_FORCE_DESPAWN by at least one world tick Port From (https://github.com/TrinityCore/TrinityCore/commit/a29a157e34e603aed5dd813702f16bb3e0ccd3a5) --- Source/Game/AI/SmartScripts/SmartScript.cs | 23 +++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Source/Game/AI/SmartScripts/SmartScript.cs b/Source/Game/AI/SmartScripts/SmartScript.cs index 2f74dbd21..e0ec1af9d 100644 --- a/Source/Game/AI/SmartScripts/SmartScript.cs +++ b/Source/Game/AI/SmartScripts/SmartScript.cs @@ -1064,19 +1064,28 @@ namespace Game.AI if (targets == null) break; + // there should be at least a world update tick before despawn, to avoid breaking linked actions + uint respawnDelay = Math.Max(e.Action.forceDespawn.delay, 1u); + foreach (var obj in targets) { - if (obj.IsTypeId(TypeId.Unit)) + Creature creatureTarget = obj.ToCreature(); + if (creatureTarget != null) { - Creature target = obj.ToCreature(); - if (target) - target.DespawnOrUnsummon(e.Action.forceDespawn.delay, TimeSpan.FromSeconds(e.Action.forceDespawn.respawn)); + SmartAI smartAI = (SmartAI)creatureTarget.GetAI(); + if (smartAI != null) + { + smartAI.SetDespawnTime(respawnDelay); + smartAI.StartDespawn(); + } + else + creatureTarget.DespawnOrUnsummon(respawnDelay); } - else if (obj.IsTypeId(TypeId.GameObject)) + else { GameObject goTarget = obj.ToGameObject(); - if (goTarget) - goTarget.SetRespawnTime((int)e.Action.forceDespawn.delay + 1); + if (goTarget != null) + goTarget.SetRespawnTime((int)respawnDelay); } }