Core/SmartAI: Delay SMART_ACTION_FORCE_DESPAWN by at least one world tick

Port From (https://github.com/TrinityCore/TrinityCore/commit/a29a157e34e603aed5dd813702f16bb3e0ccd3a5)
This commit is contained in:
hondacrx
2019-08-15 11:55:27 -04:00
parent bab0bbdf3c
commit 146f0639e2
+16 -7
View File
@@ -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);
}
}