Skip to content

Commit

Permalink
GameObject: Despawn/Refill chests 5 min after first opening even if n…
Browse files Browse the repository at this point in the history
…ot looted
  • Loading branch information
killerwife committed Sep 28, 2023
1 parent 9f2a11d commit 62a3458
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/game/Entities/GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ GameObject::GameObject() : WorldObject(),
m_isInUse = false;
m_reStockTimer = 0;
m_rearmTimer = 0;
m_despawnTimer = 0;
m_despawnTimer = TimePoint::max();

m_delayedActionTimer = 0;

Expand Down Expand Up @@ -532,9 +532,7 @@ void GameObject::Update(const uint32 diff)
case GAMEOBJECT_TYPE_CHEST:
if (m_loot)
{
if (m_loot->IsChanged())
m_despawnTimer = time(nullptr) + 5 * MINUTE; // TODO:: need to add a define?
else if (m_despawnTimer != 0 && m_despawnTimer <= time(nullptr))
if (m_despawnTimer <= GetMap()->GetCurrentClockTime())
m_lootState = GO_JUST_DEACTIVATED;

m_loot->Update();
Expand Down Expand Up @@ -631,7 +629,7 @@ void GameObject::Update(const uint32 diff)
SetLootState(GO_READY);
return; // SetLootState and return because go is treated as "burning flag" due to GetGoAnimProgress() being 100 and would be removed on the client
case GAMEOBJECT_TYPE_CHEST:
m_despawnTimer = 0;
m_despawnTimer = TimePoint::max();
// consumable confirmed to override chest restock
if (!m_goInfo->chest.consumable && m_goInfo->chest.chestRestockTime)
{
Expand Down Expand Up @@ -752,6 +750,11 @@ void GameObject::Heartbeat()
AI()->OnHeartbeat();
}

void GameObject::SetChestDespawn()
{
m_despawnTimer = GetMap()->GetCurrentClockTime() + std::chrono::minutes(5);
}

void GameObject::Refresh()
{
// not refresh despawned not casted GO (despawned casted GO destroyed in all cases anyway)
Expand Down
3 changes: 2 additions & 1 deletion src/game/Entities/GameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ class GameObject : public WorldObject
uint32 GetRespawnDelay() const { return m_respawnDelay; }
void SetRespawnDelay(uint32 delay, bool once = false) { m_respawnDelay = delay; m_respawnOverriden = true; m_respawnOverrideOnce = once; }
void SetForcedDespawn() { m_forcedDespawn = true; };
void SetChestDespawn();
void Refresh();
void Delete();

Expand Down Expand Up @@ -968,7 +969,7 @@ class GameObject : public WorldObject
// Used for chest type
bool m_isInUse; // only one player at time are allowed to open chest
time_t m_reStockTimer; // timer to refill the chest
time_t m_despawnTimer; // timer to despawn the chest if something changed in it
TimePoint m_despawnTimer; // timer to despawn the chest if something changed in it

void TriggerSummoningRitual();
void TriggerDelayedAction();
Expand Down
2 changes: 1 addition & 1 deletion src/game/Loot/LootMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ void Loot::Release(Player* player)
{
if (!IsLootedForAll())
{
updateClients = true;
go->SetChestDespawn(); // chests despawn after 5 min even if nothing looted
break;
}

Expand Down

0 comments on commit 62a3458

Please sign in to comment.