aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiacomo Pozzoni <giacomopoz@gmail.com>2020-04-11 12:07:57 +0000
committerGitHub <noreply@github.com>2020-04-11 14:07:57 +0200
commit4f33fd3932d362466ee017111895bf14fcc79c88 (patch)
treea446a043eaa8d5b6c84ce0389be85c9e09e85d88
parenteb31ae9b1839ff26246d68584937825bd7ce7932 (diff)
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
-rw-r--r--src/server/game/Maps/Map.cpp15
-rw-r--r--src/server/game/Maps/Map.h6
-rw-r--r--src/server/game/Pools/PoolMgr.cpp55
-rw-r--r--src/server/game/Pools/PoolMgr.h5
4 files changed, 65 insertions, 16 deletions
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp
index 710fe526874..105898a6d1d 100644
--- a/src/server/game/Maps/Map.cpp
+++ b/src/server/game/Maps/Map.cpp
@@ -3136,15 +3136,20 @@ void Map::DeleteRespawnInfo(RespawnInfo* info, CharacterDatabaseTransaction dbTr
_respawnTimes.erase(info->handle);
// database
+ DeleteRespawnInfoFromDB(info->type, info->spawnId, dbTrans);
+
+ // then cleanup the object
+ delete info;
+}
+
+void Map::DeleteRespawnInfoFromDB(SpawnObjectType type, ObjectGuid::LowType spawnId, CharacterDatabaseTransaction dbTrans)
+{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_RESPAWN);
- stmt->setUInt16(0, info->type);
- stmt->setUInt32(1, info->spawnId);
+ stmt->setUInt16(0, type);
+ stmt->setUInt32(1, spawnId);
stmt->setUInt16(2, GetId());
stmt->setUInt32(3, GetInstanceId());
CharacterDatabase.ExecuteOrAppend(dbTrans, stmt);
-
- // then cleanup the object
- delete info;
}
void Map::DoRespawn(SpawnObjectType type, ObjectGuid::LowType spawnId, uint32 gridId)
diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h
index 7b8812d6304..fca66292cb4 100644
--- a/src/server/game/Maps/Map.h
+++ b/src/server/game/Maps/Map.h
@@ -771,6 +771,7 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
bool AddRespawnInfo(RespawnInfo const& info);
void UnloadAllRespawnInfos();
void DeleteRespawnInfo(RespawnInfo* info, CharacterDatabaseTransaction dbTrans = nullptr);
+ void DeleteRespawnInfoFromDB(SpawnObjectType type, ObjectGuid::LowType spawnId, CharacterDatabaseTransaction dbTrans = nullptr);
public:
void GetRespawnInfo(std::vector<RespawnInfo*>& respawnData, SpawnObjectTypeMask types) const;
@@ -781,10 +782,13 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
Respawn(info, dbTrans);
}
void Respawn(RespawnInfo* info, CharacterDatabaseTransaction dbTrans = nullptr);
- void RemoveRespawnTime(SpawnObjectType type, ObjectGuid::LowType spawnId, CharacterDatabaseTransaction dbTrans = nullptr)
+ void RemoveRespawnTime(SpawnObjectType type, ObjectGuid::LowType spawnId, CharacterDatabaseTransaction dbTrans = nullptr, bool alwaysDeleteFromDB = false)
{
if (RespawnInfo* info = GetRespawnInfo(type, spawnId))
DeleteRespawnInfo(info, dbTrans);
+ // Some callers might need to make sure the database doesn't contain any respawn time
+ else if (alwaysDeleteFromDB)
+ DeleteRespawnInfoFromDB(type, spawnId, dbTrans);
}
size_t DespawnAll(SpawnObjectType type, ObjectGuid::LowType spawnId);
diff --git a/src/server/game/Pools/PoolMgr.cpp b/src/server/game/Pools/PoolMgr.cpp
index 45407c4c5aa..d01977151d7 100644
--- a/src/server/game/Pools/PoolMgr.cpp
+++ b/src/server/game/Pools/PoolMgr.cpp
@@ -133,7 +133,7 @@ bool PoolGroup<T>::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<class T>
-void PoolGroup<T>::DespawnObject(ActivePoolData& spawns, ObjectGuid::LowType guid)
+void PoolGroup<T>::DespawnObject(ActivePoolData& spawns, ObjectGuid::LowType guid, bool alwaysDeleteRespawnTime)
{
for (size_t i=0; i < EqualChanced.size(); ++i)
{
@@ -142,10 +142,12 @@ void PoolGroup<T>::DespawnObject(ActivePoolData& spawns, ObjectGuid::LowType gui
{
if (!guid || EqualChanced[i].guid == guid)
{
- Despawn1Object(EqualChanced[i].guid);
+ Despawn1Object(EqualChanced[i].guid, alwaysDeleteRespawnTime);
spawns.RemoveObject<T>(EqualChanced[i].guid, poolId);
}
}
+ else if (alwaysDeleteRespawnTime)
+ RemoveRespawnTimeFromDB(EqualChanced[i].guid);
}
for (size_t i = 0; i < ExplicitlyChanced.size(); ++i)
@@ -155,16 +157,18 @@ void PoolGroup<T>::DespawnObject(ActivePoolData& spawns, ObjectGuid::LowType gui
{
if (!guid || ExplicitlyChanced[i].guid == guid)
{
- Despawn1Object(ExplicitlyChanced[i].guid);
+ Despawn1Object(ExplicitlyChanced[i].guid, alwaysDeleteRespawnTime);
spawns.RemoveObject<T>(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<Creature>::Despawn1Object(ObjectGuid::LowType guid)
+void PoolGroup<Creature>::Despawn1Object(ObjectGuid::LowType guid, bool alwaysDeleteRespawnTime)
{
if (CreatureData const* data = sObjectMgr->GetCreatureData(guid))
{
@@ -183,13 +187,16 @@ void PoolGroup<Creature>::Despawn1Object(ObjectGuid::LowType guid)
creature->SaveRespawnTime();
creature->AddObjectToRemoveList();
}
+
+ if (alwaysDeleteRespawnTime)
+ map->RemoveRespawnTime(SpawnObjectType::SPAWN_TYPE_CREATURE, guid, nullptr, true);
}
}
}
// Same on one gameobject
template<>
-void PoolGroup<GameObject>::Despawn1Object(ObjectGuid::LowType guid)
+void PoolGroup<GameObject>::Despawn1Object(ObjectGuid::LowType guid, bool alwaysDeleteRespawnTime)
{
if (GameObjectData const* data = sObjectMgr->GetGameObjectData(guid))
{
@@ -209,13 +216,16 @@ void PoolGroup<GameObject>::Despawn1Object(ObjectGuid::LowType guid)
go->SaveRespawnTime();
go->AddObjectToRemoveList();
}
+
+ if (alwaysDeleteRespawnTime)
+ map->RemoveRespawnTime(SpawnObjectType::SPAWN_TYPE_GAMEOBJECT, guid, nullptr, true);
}
}
}
// Same on one pool
template<>
-void PoolGroup<Pool>::Despawn1Object(uint32 child_pool_id)
+void PoolGroup<Pool>::Despawn1Object(uint32 child_pool_id, bool /*alwaysDeleteRespawnTime*/)
{
sPoolMgr->DespawnPool(child_pool_id);
}
@@ -385,6 +395,35 @@ void PoolGroup<GameObject>::ReSpawn1Object(PoolObject* /*obj*/)
template <>
void PoolGroup<Pool>::ReSpawn1Object(PoolObject* /*obj*/) { }
+template <>
+void PoolGroup<Creature>::RemoveRespawnTimeFromDB(ObjectGuid::LowType 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<GameObject>::RemoveRespawnTimeFromDB(ObjectGuid::LowType 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<Pool>::RemoveRespawnTimeFromDB(ObjectGuid::LowType /*guid*/) { }
+
////////////////////////////////////////////////////////////
// Methods of class PoolMgr
@@ -741,12 +780,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);
diff --git a/src/server/game/Pools/PoolMgr.h b/src/server/game/Pools/PoolMgr.h
index 758725117e6..6e870e6eb03 100644
--- a/src/server/game/Pools/PoolMgr.h
+++ b/src/server/game/Pools/PoolMgr.h
@@ -72,9 +72,10 @@ class TC_GAME_API PoolGroup
bool isEmpty() const { return ExplicitlyChanced.empty() && EqualChanced.empty(); }
void AddEntry(PoolObject& poolitem, uint32 maxentries);
bool CheckPool() const;
- void DespawnObject(ActivePoolData& spawns, ObjectGuid::LowType guid=0);
- void Despawn1Object(ObjectGuid::LowType guid);
+ void DespawnObject(ActivePoolData& spawns, ObjectGuid::LowType guid=0, bool alwaysDeleteRespawnTime = false);
+ void Despawn1Object(ObjectGuid::LowType guid, bool alwaysDeleteRespawnTime = false);
void SpawnObject(ActivePoolData& spawns, uint32 limit, uint32 triggerFrom);
+ void RemoveRespawnTimeFromDB(ObjectGuid::LowType guid);
void Spawn1Object(PoolObject* obj);
void ReSpawn1Object(PoolObject* obj);