mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Entities/GO: Add forceRespawnTimer support to DespawnOrUnsummon. Use it in SAI.
This commit is contained in:
@@ -1032,22 +1032,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;
|
||||
}
|
||||
|
||||
@@ -776,6 +776,7 @@ struct SmartAction
|
||||
struct
|
||||
{
|
||||
uint32 delay;
|
||||
uint32 forceRespawnTimer;
|
||||
} forceDespawn;
|
||||
|
||||
struct
|
||||
|
||||
@@ -411,7 +411,7 @@ void GameObject::Update(uint32 diff)
|
||||
if (m_despawnDelay > diff)
|
||||
m_despawnDelay -= diff;
|
||||
else
|
||||
DespawnOrUnsummon();
|
||||
DespawnOrUnsummon(0ms, m_despawnRespawnTime);
|
||||
}
|
||||
|
||||
switch (m_lootState)
|
||||
@@ -826,17 +826,21 @@ void GameObject::AddUniqueUse(Player* player)
|
||||
m_unique_users.insert(player->GetGUID());
|
||||
}
|
||||
|
||||
void GameObject::DespawnOrUnsummon(Milliseconds const& delay)
|
||||
void GameObject::DespawnOrUnsummon(Milliseconds const& delay, Seconds const& forceRespawnTime)
|
||||
{
|
||||
if (delay > Milliseconds::zero())
|
||||
if (delay > 0ms)
|
||||
{
|
||||
if (!m_despawnDelay || m_despawnDelay > delay.count())
|
||||
{
|
||||
m_despawnDelay = delay.count();
|
||||
m_despawnRespawnTime = forceRespawnTime;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_goData && m_respawnDelayTime)
|
||||
SaveRespawnTime(m_respawnDelayTime);
|
||||
uint32 const respawnDelay = (forceRespawnTime > 0s) ? forceRespawnTime.count() : m_respawnDelayTime;
|
||||
if (m_goData && respawnDelay)
|
||||
SaveRespawnTime(respawnDelay);
|
||||
Delete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject>
|
||||
void SetSpawnedByDefault(bool b) { m_spawnedByDefault = b; }
|
||||
uint32 GetRespawnDelay() const { return m_respawnDelayTime; }
|
||||
void Refresh();
|
||||
void DespawnOrUnsummon(Milliseconds const& delay = 0ms);
|
||||
void DespawnOrUnsummon(Milliseconds const& delay = 0ms, Seconds const& forceRespawnTime = 0s);
|
||||
void Delete();
|
||||
void getFishLoot(Loot* loot, Player* loot_owner);
|
||||
void getFishLootJunk(Loot* loot, Player* loot_owner);
|
||||
@@ -293,6 +293,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject>
|
||||
time_t m_respawnTime; // (secs) time of next respawn (or despawn if GO have owner()),
|
||||
uint32 m_respawnDelayTime; // (secs) if 0 then current GO state no dependent from timer
|
||||
uint32 m_despawnDelay;
|
||||
Seconds m_despawnRespawnTime; // override respawn time after delayed despawn
|
||||
LootState m_lootState;
|
||||
ObjectGuid m_lootStateUnitGUID; // GUID of the unit passed with SetLootState(LootState, Unit*)
|
||||
bool m_spawnedByDefault;
|
||||
|
||||
Reference in New Issue
Block a user