Core/Pooling: Remove respawn times from the database when despawning a pool

Port From (https://github.com/TrinityCore/TrinityCore/commit/97c1d01cbbc3ea828a2edfdc3a0b221e31d89f28)
This commit is contained in:
hondacrx
2022-02-17 17:15:59 -05:00
parent 9d4096991c
commit 717ed6e36a
2 changed files with 62 additions and 11 deletions
+11 -3
View File
@@ -2447,11 +2447,14 @@ namespace Game.Maps
SaveRespawnInfoDB(info, dbTrans);
}
public void RemoveRespawnTime(SpawnObjectType type, ulong spawnId, SQLTransaction dbTrans = null)
public void RemoveRespawnTime(SpawnObjectType type, ulong spawnId, SQLTransaction dbTrans = null, bool alwaysDeleteFromDB = false)
{
RespawnInfo info = GetRespawnInfo(type, spawnId);
if (info != null)
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);
}
int DespawnAll(SpawnObjectType type, ulong spawnId)
@@ -2579,9 +2582,14 @@ namespace Game.Maps
_respawnTimes.Remove(info);
// database
DeleteRespawnInfoFromDB(info.type, info.spawnId, dbTrans);
}
void DeleteRespawnInfoFromDB(SpawnObjectType type, ulong spawnId, SQLTransaction dbTrans = null)
{
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_RESPAWN);
stmt.AddValue(0, (ushort)info.type);
stmt.AddValue(1, info.spawnId);
stmt.AddValue(0, (ushort)type);
stmt.AddValue(1, spawnId);
stmt.AddValue(2, GetId());
stmt.AddValue(3, GetInstanceId());
DB.Characters.ExecuteOrAppend(dbTrans, stmt);
+51 -8
View File
@@ -328,10 +328,10 @@ namespace Game
public void DespawnPool(uint pool_id)
{
if (mPoolCreatureGroups.ContainsKey(pool_id) && !mPoolCreatureGroups[pool_id].IsEmpty())
mPoolCreatureGroups[pool_id].DespawnObject(mSpawnedData);
mPoolCreatureGroups[pool_id].DespawnObject(mSpawnedData, 0, true);
if (mPoolGameobjectGroups.ContainsKey(pool_id) && !mPoolGameobjectGroups[pool_id].IsEmpty())
mPoolGameobjectGroups[pool_id].DespawnObject(mSpawnedData);
mPoolGameobjectGroups[pool_id].DespawnObject(mSpawnedData, 0, true);
if (mPoolPoolGroups.ContainsKey(pool_id) && !mPoolPoolGroups[pool_id].IsEmpty())
mPoolPoolGroups[pool_id].DespawnObject(mSpawnedData);
@@ -444,7 +444,7 @@ namespace Game
return true;
}
public void DespawnObject(ActivePoolData spawns, ulong guid = 0)
public void DespawnObject(ActivePoolData spawns, ulong guid = 0, bool alwaysDeleteRespawnTime = false)
{
for (int i = 0; i < EqualChanced.Count; ++i)
{
@@ -453,10 +453,12 @@ namespace Game
{
if (guid == 0 || 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 (int i = 0; i < ExplicitlyChanced.Count; ++i)
@@ -466,14 +468,16 @@ namespace Game
{
if (guid == 0 || 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);
}
}
void Despawn1Object(ulong guid)
void Despawn1Object(ulong guid, bool alwaysDeleteRespawnTime = false)
{
switch (typeof(T).Name)
{
@@ -495,7 +499,10 @@ namespace Game
creature.AddObjectToRemoveList();
}
}
if (alwaysDeleteRespawnTime)
map.RemoveRespawnTime(SpawnObjectType.Creature, guid, null, true);
}
}
break;
}
@@ -517,7 +524,10 @@ namespace Game
go.AddObjectToRemoveList();
}
}
if (alwaysDeleteRespawnTime)
map.RemoveRespawnTime(SpawnObjectType.GameObject, guid, null, true);
}
}
break;
}
@@ -662,6 +672,39 @@ namespace Game
// GameObject/Creature is still on map, nothing to do
}
void RemoveRespawnTimeFromDB(ulong guid)
{
switch (typeof(T).Name)
{
case "Creature":
{
CreatureData data = Global.ObjectMgr.GetCreatureData(guid);
if (data != null)
{
Map map = Global.MapMgr.CreateBaseMap(data.MapId);
if (!map.Instanceable())
{
map.RemoveRespawnTime(SpawnObjectType.Creature, guid, null, true);
}
}
}
break;
case "GameObject":
{
GameObjectData data = Global.ObjectMgr.GetGameObjectData(guid);
if (data != null)
{
Map map = Global.MapMgr.CreateBaseMap(data.MapId);
if (!map.Instanceable())
{
map.RemoveRespawnTime(SpawnObjectType.GameObject, guid, null, true);
}
}
break;
}
}
}
public void SetPoolId(uint pool_id) { poolId = pool_id; }
public bool IsEmpty() { return ExplicitlyChanced.Empty() && EqualChanced.Empty(); }