From e5f7beecf5fabefa13fbe2645cc7d7ca707e46e8 Mon Sep 17 00:00:00 2001 From: Discover- Date: Wed, 18 Dec 2013 10:06:19 +0100 Subject: Core/SAI: Using SMART_ACTION_FORCE_DESPAWN now despawns the given target_type instead of always the creature itself. --- src/server/game/AI/SmartScripts/SmartScript.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index 9b97124de64..a36621f87d5 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -1040,18 +1040,24 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u } case SMART_ACTION_FORCE_DESPAWN: { - if (!IsSmart()) + ObjectList* targets = GetTargets(e, unit); + + if (!targets) break; - // The AI is only updated if the creature is alive - if (me->IsAlive()) + for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr) { - CAST_AI(SmartAI, me->AI())->SetDespawnTime(e.action.forceDespawn.delay + 1); // Next tick - CAST_AI(SmartAI, me->AI())->StartDespawn(); + if (!IsCreature(*itr)) + continue; + + if ((*itr)->ToUnit()->IsAlive() && IsSmart((*itr)->ToCreature())) + { + CAST_AI(SmartAI, (*itr)->ToCreature()->AI())->SetDespawnTime(e.action.forceDespawn.delay + 1); // Next tick + CAST_AI(SmartAI, (*itr)->ToCreature()->AI())->StartDespawn(); + } + else + (*itr)->ToCreature()->DespawnOrUnsummon(e.action.forceDespawn.delay); } - // Otherwise we call the despawn directly - else - me->DespawnOrUnsummon(e.action.forceDespawn.delay); break; } -- cgit v1.2.3