Entities/GO: Add forceRespawnTimer support to DespawnOrUnsummon. Use it in SAI.

(cherry picked from commit 264d4e1d30)
This commit is contained in:
Treeston
2018-02-14 02:23:55 +01:00
committed by Shauren
parent 19ed9c971f
commit 168be492f5
6 changed files with 21 additions and 24 deletions

View File

@@ -1043,22 +1043,18 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
case SMART_ACTION_FORCE_DESPAWN:
{
// 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);
Milliseconds despawnDelay(e.action.forceDespawn.delay);
if (despawnDelay <= 0ms)
despawnDelay = 1ms;
Seconds forceRespawnTimer(e.action.forceDespawn.forceRespawnTimer);
for (WorldObject* target : targets)
{
if (Creature* creature = target->ToCreature())
{
if (SmartAI* smartAI = CAST_AI(SmartAI, creature->AI()))
{
smartAI->SetDespawnTime(respawnDelay);
smartAI->StartDespawn();
}
else
creature->DespawnOrUnsummon(respawnDelay);
}
creature->DespawnOrUnsummon(despawnDelay, forceRespawnTimer);
else if (GameObject* goTarget = target->ToGameObject())
goTarget->DespawnOrUnsummon(Milliseconds(respawnDelay));
goTarget->DespawnOrUnsummon(despawnDelay, forceRespawnTimer);
}
break;
}