aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server/game/AI/SmartScripts/SmartScript.cpp23
1 files changed, 18 insertions, 5 deletions
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<int32>(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;