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 5d96e04 commit 1967efb
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 @@ -98,7 +98,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 @@ -548,9 +548,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 @@ -655,7 +653,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 @@ -774,6 +772,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 @@ -820,6 +820,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 @@ -1006,7 +1007,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 @@ -1327,7 +1327,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 1967efb

Please sign in to comment.