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

(cherry picked from commit 264d4e1d30debcf6feacee3d29982875672a7bbe)
This commit is contained in:
Treeston
2021-06-20 22:10:08 +02:00
committed by Shauren
parent 19ed9c971f
commit 168be492f5
6 changed files with 21 additions and 24 deletions
@@ -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;
}