From 62a34581918a612135e17353008abd91ccd09848 Mon Sep 17 00:00:00 2001 From: killerwife Date: Thu, 28 Sep 2023 13:10:05 +0200 Subject: [PATCH] GameObject: Despawn/Refill chests 5 min after first opening even if not looted --- src/game/Entities/GameObject.cpp | 13 ++++++++----- src/game/Entities/GameObject.h | 3 ++- src/game/Loot/LootMgr.cpp | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/game/Entities/GameObject.cpp b/src/game/Entities/GameObject.cpp index b8dc2e9ae9..f376dc58e0 100644 --- a/src/game/Entities/GameObject.cpp +++ b/src/game/Entities/GameObject.cpp @@ -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; @@ -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(); @@ -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) { @@ -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) diff --git a/src/game/Entities/GameObject.h b/src/game/Entities/GameObject.h index b5415b11f1..a83bc9e7b8 100644 --- a/src/game/Entities/GameObject.h +++ b/src/game/Entities/GameObject.h @@ -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(); @@ -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(); diff --git a/src/game/Loot/LootMgr.cpp b/src/game/Loot/LootMgr.cpp index 3316d44d97..3bdae864fc 100644 --- a/src/game/Loot/LootMgr.cpp +++ b/src/game/Loot/LootMgr.cpp @@ -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; }