fix(Core/SAI): Update SMART_ACTION_FORCE_DESPAWN to allow temporarily despawning gameobjects (#8340)

* fix(Core/SAI): Update SMART_ACTION_FORCE_DESPAWN to allow temporarily despawning gameobjects

* brackets

* Some improvements

* restore the virtual
This commit is contained in:
Skjalf
2021-10-14 08:23:59 -03:00
committed by GitHub
parent a8643f27b2
commit 3894dfc897
3 changed files with 93 additions and 13 deletions

View File

@@ -1323,10 +1323,21 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
{
if (IsCreature(*itr))
(*itr)->ToCreature()->DespawnOrUnsummon(e.action.forceDespawn.delay + 1);
else if (IsGameObject(*itr))
(*itr)->ToGameObject()->Delete();
if (Creature* creature = (*itr)->ToCreature())
{
creature->DespawnOrUnsummon(e.action.forceDespawn.delay + 1);
}
else if (GameObject* go = (*itr)->ToGameObject())
{
Milliseconds despawnDelay(e.action.forceDespawn.delay);
// Wait at least one world update tick before despawn, so it doesn't break linked actions.
if (despawnDelay <= 0ms)
{
despawnDelay = 1ms;
}
go->DespawnOrUnsummon(despawnDelay);
}
}
delete targets;