From 97c1d01cbbc3ea828a2edfdc3a0b221e31d89f28 Mon Sep 17 00:00:00 2001 From: Giacomo Pozzoni Date: Sat, 11 Apr 2020 12:07:57 +0000 Subject: Core/Pooling: Remove respawn times from the database when despawning a pool (#24422) * Core/Pooling: Remove respawn times from the database when despawning a pool Remove respawn times from the database when despawning a pool. This is needed when a Game Event ends but there are still some respawn times saved in the database. * Remove respawn time of active pool objects even if they are not spawned (cherry picked from commit 4f33fd3932d362466ee017111895bf14fcc79c88) --- src/server/game/Pools/PoolMgr.cpp | 55 +++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 8 deletions(-) (limited to 'src/server/game/Pools/PoolMgr.cpp') diff --git a/src/server/game/Pools/PoolMgr.cpp b/src/server/game/Pools/PoolMgr.cpp index 070323fc99d..c8f410e90e7 100644 --- a/src/server/game/Pools/PoolMgr.cpp +++ b/src/server/game/Pools/PoolMgr.cpp @@ -140,7 +140,7 @@ bool PoolGroup::CheckPool() const // If no guid is passed, the pool is just removed (event end case) // If guid is filled, cache will be used and no removal will occur, it just fill the cache template -void PoolGroup::DespawnObject(ActivePoolData& spawns, uint64 guid) +void PoolGroup::DespawnObject(ActivePoolData& spawns, uint64 guid, bool alwaysDeleteRespawnTime) { for (size_t i=0; i < EqualChanced.size(); ++i) { @@ -149,10 +149,12 @@ void PoolGroup::DespawnObject(ActivePoolData& spawns, uint64 guid) { if (!guid || EqualChanced[i].guid == guid) { - Despawn1Object(EqualChanced[i].guid); + Despawn1Object(EqualChanced[i].guid, alwaysDeleteRespawnTime); spawns.RemoveObject(EqualChanced[i].guid, poolId); } } + else if (alwaysDeleteRespawnTime) + RemoveRespawnTimeFromDB(EqualChanced[i].guid); } for (size_t i = 0; i < ExplicitlyChanced.size(); ++i) @@ -162,16 +164,18 @@ void PoolGroup::DespawnObject(ActivePoolData& spawns, uint64 guid) { if (!guid || ExplicitlyChanced[i].guid == guid) { - Despawn1Object(ExplicitlyChanced[i].guid); + Despawn1Object(ExplicitlyChanced[i].guid, alwaysDeleteRespawnTime); spawns.RemoveObject(ExplicitlyChanced[i].guid, poolId); } } + else if (alwaysDeleteRespawnTime) + RemoveRespawnTimeFromDB(ExplicitlyChanced[i].guid); } } // Method that is actualy doing the removal job on one creature template<> -void PoolGroup::Despawn1Object(uint64 guid) +void PoolGroup::Despawn1Object(uint64 guid, bool alwaysDeleteRespawnTime) { if (CreatureData const* data = sObjectMgr->GetCreatureData(guid)) { @@ -190,13 +194,16 @@ void PoolGroup::Despawn1Object(uint64 guid) creature->SaveRespawnTime(); creature->AddObjectToRemoveList(); } + + if (alwaysDeleteRespawnTime) + map->RemoveRespawnTime(SpawnObjectType::SPAWN_TYPE_CREATURE, guid, nullptr, true); } } } // Same on one gameobject template<> -void PoolGroup::Despawn1Object(uint64 guid) +void PoolGroup::Despawn1Object(uint64 guid, bool alwaysDeleteRespawnTime) { if (GameObjectData const* data = sObjectMgr->GetGameObjectData(guid)) { @@ -216,13 +223,16 @@ void PoolGroup::Despawn1Object(uint64 guid) go->SaveRespawnTime(); go->AddObjectToRemoveList(); } + + if (alwaysDeleteRespawnTime) + map->RemoveRespawnTime(SpawnObjectType::SPAWN_TYPE_GAMEOBJECT, guid, nullptr, true); } } } // Same on one pool template<> -void PoolGroup::Despawn1Object(uint64 child_pool_id) +void PoolGroup::Despawn1Object(uint64 child_pool_id, bool /*alwaysDeleteRespawnTime*/) { sPoolMgr->DespawnPool(child_pool_id); } @@ -380,6 +390,35 @@ void PoolGroup::ReSpawn1Object(PoolObject* /*obj*/) template <> void PoolGroup::ReSpawn1Object(PoolObject* /*obj*/) { } +template <> +void PoolGroup::RemoveRespawnTimeFromDB(uint64 guid) +{ + if (CreatureData const* data = sObjectMgr->GetCreatureData(guid)) + { + Map* map = sMapMgr->CreateBaseMap(data->mapId); + if (!map->Instanceable()) + { + map->RemoveRespawnTime(SPAWN_TYPE_CREATURE, guid, nullptr, true); + } + } +} + +template <> +void PoolGroup::RemoveRespawnTimeFromDB(uint64 guid) +{ + if (GameObjectData const* data = sObjectMgr->GetGameObjectData(guid)) + { + Map* map = sMapMgr->CreateBaseMap(data->mapId); + if (!map->Instanceable()) + { + map->RemoveRespawnTime(SPAWN_TYPE_GAMEOBJECT, guid, nullptr, true); + } + } +} + +template <> +void PoolGroup::RemoveRespawnTimeFromDB(uint64 /*guid*/) { } + //////////////////////////////////////////////////////////// // Methods of class PoolMgr @@ -737,12 +776,12 @@ void PoolMgr::DespawnPool(uint32 pool_id) { auto it = mPoolCreatureGroups.find(pool_id); if (it != mPoolCreatureGroups.end() && !it->second.isEmpty()) - it->second.DespawnObject(mSpawnedData); + it->second.DespawnObject(mSpawnedData, 0, true); } { auto it = mPoolGameobjectGroups.find(pool_id); if (it != mPoolGameobjectGroups.end() && !it->second.isEmpty()) - it->second.DespawnObject(mSpawnedData); + it->second.DespawnObject(mSpawnedData, 0, true); } { auto it = mPoolPoolGroups.find(pool_id); -- cgit v1.2.3