mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Entities/GO: GameObjects now support (delayed) despawning in a reasonable manner. Closes #21406.
(cherry picked from commit f071fa9e93)
This commit is contained in:
@@ -1058,7 +1058,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
|
||||
creature->DespawnOrUnsummon(respawnDelay);
|
||||
}
|
||||
else if (GameObject* goTarget = target->ToGameObject())
|
||||
goTarget->SetRespawnTime(respawnDelay);
|
||||
goTarget->DespawnOrUnsummon(Milliseconds(respawnDelay));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -117,6 +117,7 @@ GameObject::GameObject() : WorldObject(false), MapObject(),
|
||||
|
||||
m_respawnTime = 0;
|
||||
m_respawnDelayTime = 300;
|
||||
m_despawnDelay = 0;
|
||||
m_lootState = GO_NOT_READY;
|
||||
m_spawnedByDefault = true;
|
||||
m_usetimes = 0;
|
||||
@@ -518,6 +519,14 @@ void GameObject::Update(uint32 diff)
|
||||
else if (!AIM_Initialize())
|
||||
TC_LOG_ERROR("misc", "Could not initialize GameObjectAI");
|
||||
|
||||
if (m_despawnDelay)
|
||||
{
|
||||
if (m_despawnDelay > diff)
|
||||
m_despawnDelay -= diff;
|
||||
else
|
||||
DespawnOrUnsummon();
|
||||
}
|
||||
|
||||
switch (m_lootState)
|
||||
{
|
||||
case GO_NOT_READY:
|
||||
@@ -945,6 +954,21 @@ void GameObject::AddUniqueUse(Player* player)
|
||||
m_unique_users.insert(player->GetGUID());
|
||||
}
|
||||
|
||||
void GameObject::DespawnOrUnsummon(Milliseconds const& delay)
|
||||
{
|
||||
if (delay > Milliseconds::zero())
|
||||
{
|
||||
if (!m_despawnDelay || m_despawnDelay > delay.count())
|
||||
m_despawnDelay = delay.count();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_goData && m_respawnDelayTime)
|
||||
SaveRespawnTime(m_respawnDelayTime);
|
||||
Delete();
|
||||
}
|
||||
}
|
||||
|
||||
void GameObject::Delete()
|
||||
{
|
||||
SetLootState(GO_NOT_READY);
|
||||
@@ -1266,7 +1290,7 @@ Unit* GameObject::GetOwner() const
|
||||
|
||||
void GameObject::SaveRespawnTime(uint32 forceDelay, bool savetodb)
|
||||
{
|
||||
if (m_goData && m_respawnTime > GameTime::GetGameTime() && m_spawnedByDefault)
|
||||
if (m_goData && (forceDelay || m_respawnTime > GameTime::GetGameTime()) && m_spawnedByDefault)
|
||||
{
|
||||
if (m_respawnCompatibilityMode)
|
||||
{
|
||||
|
||||
@@ -164,6 +164,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 Delete();
|
||||
void SendGameObjectDespawn();
|
||||
void getFishLoot(Loot* loot, Player* loot_owner);
|
||||
@@ -316,6 +317,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject>
|
||||
uint32 m_spellId;
|
||||
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;
|
||||
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