From aa7ef797d6c362710a38c12e31db4b8f3b2963e4 Mon Sep 17 00:00:00 2001 From: ariel- Date: Mon, 6 Feb 2017 19:28:44 -0300 Subject: Core/SmartAI: Delay SMART_ACTION_FORCE_DESPAWN by at least one world tick - Restore old despawn behavior of SmartAI despawning (without reintroducing the run time logs caused by IsSmart) - Some SAIs relied on this to function (for example #1249) Partial reverts commit 4fc4c81e8989febd7e650d749af358548e264e2c --- src/server/game/AI/SmartScripts/SmartScript.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index 8acbc9bea45..a6f84695876 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -1066,11 +1066,24 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u if (!targets) break; - for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr) - if (Creature* target = (*itr)->ToCreature()) - target->DespawnOrUnsummon(e.action.forceDespawn.delay); - else if (GameObject* goTarget = (*itr)->ToGameObject()) - goTarget->SetRespawnTime(e.action.forceDespawn.delay + 1); + // there should be at least a world update tick before despawn, to avoid breaking linked actions + int32 const respawnDelay = std::max(e.action.forceDespawn.delay, 1); + + for (WorldObject* target : *targets) + { + if (Creature* creatureTarget = target->ToCreature()) + { + if (SmartAI* smartAI = CAST_AI(SmartAI, creatureTarget->AI())) + { + smartAI->SetDespawnTime(respawnDelay); + smartAI->StartDespawn(); + } + else + creatureTarget->DespawnOrUnsummon(respawnDelay); + } + else if (GameObject* goTarget = target->ToGameObject()) + goTarget->SetRespawnTime(respawnDelay); + } delete targets; break; -- cgit v1.2.3