Core/DB: Unify creature_respawn and gameobject_respawn into a single respawn table
Port From (https://github.com/TrinityCore/TrinityCore/commit/be05590a12607cbf6c7f8e5436cfac0fb3625128)
This commit is contained in:
@@ -427,17 +427,11 @@ namespace Framework.Database
|
||||
PrepareStatement(CharStatements.DEL_CORPSE_CUSTOMIZATIONS, "DELETE FROM corpse_customizations WHERE ownerGuid = ?");
|
||||
PrepareStatement(CharStatements.SEL_CORPSE_LOCATION, "SELECT mapId, posX, posY, posZ, orientation FROM corpse WHERE guid = ?");
|
||||
|
||||
// Creature respawn
|
||||
PrepareStatement(CharStatements.SEL_CREATURE_RESPAWNS, "SELECT guid, respawnTime FROM creature_respawn WHERE mapId = ? AND instanceId = ?");
|
||||
PrepareStatement(CharStatements.REP_CREATURE_RESPAWN, "REPLACE INTO creature_respawn (guid, respawnTime, mapId, instanceId) VALUES (?, ?, ?, ?)");
|
||||
PrepareStatement(CharStatements.DEL_CREATURE_RESPAWN, "DELETE FROM creature_respawn WHERE guid = ? AND mapId = ? AND instanceId = ?");
|
||||
PrepareStatement(CharStatements.DEL_CREATURE_RESPAWN_BY_INSTANCE, "DELETE FROM creature_respawn WHERE mapId = ? AND instanceId = ?");
|
||||
|
||||
// Gameobject respawn
|
||||
PrepareStatement(CharStatements.SEL_GO_RESPAWNS, "SELECT guid, respawnTime FROM gameobject_respawn WHERE mapId = ? AND instanceId = ?");
|
||||
PrepareStatement(CharStatements.REP_GO_RESPAWN, "REPLACE INTO gameobject_respawn (guid, respawnTime, mapId, instanceId) VALUES (?, ?, ?, ?)");
|
||||
PrepareStatement(CharStatements.DEL_GO_RESPAWN, "DELETE FROM gameobject_respawn WHERE guid = ? AND mapId = ? AND instanceId = ?");
|
||||
PrepareStatement(CharStatements.DEL_GO_RESPAWN_BY_INSTANCE, "DELETE FROM gameobject_respawn WHERE mapId = ? AND instanceId = ?");
|
||||
// Respawns
|
||||
PrepareStatement(CharStatements.SEL_RESPAWNS, "SELECT type, spawnId, respawnTime FROM respawn WHERE mapId = ? AND instanceId = ?");
|
||||
PrepareStatement(CharStatements.REP_RESPAWN, "REPLACE INTO respawn (type, spawnId, respawnTime, mapId, instanceId) VALUES (?, ?, ?, ?, ?)");
|
||||
PrepareStatement(CharStatements.DEL_RESPAWN, "DELETE FROM respawn WHERE type = ? AND spawnId = ? AND mapId = ? AND instanceId = ?");
|
||||
PrepareStatement(CharStatements.DEL_ALL_RESPAWNS, "DELETE FROM respawn WHERE mapId = ? AND instanceId = ?");
|
||||
|
||||
// GM Bug
|
||||
PrepareStatement(CharStatements.SEL_GM_BUGS, "SELECT id, playerGuid, note, createTime, mapId, posX, posY, posZ, facing, closedBy, assignedTo, comment FROM gm_bug");
|
||||
@@ -1111,15 +1105,10 @@ namespace Framework.Database
|
||||
DEL_CORPSE_CUSTOMIZATIONS,
|
||||
SEL_CORPSE_LOCATION,
|
||||
|
||||
SEL_CREATURE_RESPAWNS,
|
||||
REP_CREATURE_RESPAWN,
|
||||
DEL_CREATURE_RESPAWN,
|
||||
DEL_CREATURE_RESPAWN_BY_INSTANCE,
|
||||
|
||||
SEL_GO_RESPAWNS,
|
||||
REP_GO_RESPAWN,
|
||||
DEL_GO_RESPAWN,
|
||||
DEL_GO_RESPAWN_BY_INSTANCE,
|
||||
SEL_RESPAWNS,
|
||||
REP_RESPAWN,
|
||||
DEL_RESPAWN,
|
||||
DEL_ALL_RESPAWNS,
|
||||
|
||||
SEL_GM_BUGS,
|
||||
REP_GM_BUG,
|
||||
|
||||
@@ -159,8 +159,7 @@ namespace Game.Maps
|
||||
DB.Characters.DirectExecute("DELETE i.* FROM instance AS i LEFT JOIN character_instance AS ci ON i.id = ci.instance LEFT JOIN group_instance AS gi ON i.id = gi.instance WHERE ci.guid IS NULL AND gi.guid IS NULL");
|
||||
|
||||
// Delete invalid references to instance
|
||||
DB.Characters.DirectExecute("DELETE FROM creature_respawn WHERE instanceId > 0 AND instanceId NOT IN (SELECT id FROM instance)");
|
||||
DB.Characters.DirectExecute("DELETE FROM gameobject_respawn WHERE instanceId > 0 AND instanceId NOT IN (SELECT id FROM instance)");
|
||||
DB.Characters.DirectExecute("DELETE FROM respawn WHERE instanceId > 0 AND instanceId NOT IN (SELECT id FROM instance)");
|
||||
DB.Characters.DirectExecute("DELETE tmp.* FROM character_instance AS tmp LEFT JOIN instance ON tmp.instance = instance.id WHERE tmp.instance > 0 AND instance.id IS NULL");
|
||||
DB.Characters.DirectExecute("DELETE tmp.* FROM group_instance AS tmp LEFT JOIN instance ON tmp.instance = instance.id WHERE tmp.instance > 0 AND instance.id IS NULL");
|
||||
|
||||
|
||||
+18
-48
@@ -812,6 +812,7 @@ namespace Game.Maps
|
||||
i_scriptLock = false;
|
||||
}
|
||||
|
||||
_weatherUpdateTimer.Update(diff);
|
||||
if (_weatherUpdateTimer.Passed())
|
||||
{
|
||||
foreach (var zoneInfo in _zoneDynamicInfo)
|
||||
@@ -2547,23 +2548,11 @@ namespace Game.Maps
|
||||
|
||||
public void RemoveRespawnTime(RespawnInfo info, bool doRespawn = false, SQLTransaction dbTrans = null)
|
||||
{
|
||||
PreparedStatement stmt;
|
||||
switch (info.type)
|
||||
{
|
||||
case SpawnObjectType.Creature:
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CREATURE_RESPAWN);
|
||||
break;
|
||||
case SpawnObjectType.GameObject:
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_GO_RESPAWN);
|
||||
break;
|
||||
default:
|
||||
Cypher.Assert(false, $"Invalid respawninfo type {info.type} for spawnid {info.spawnId} map {GetId()}");
|
||||
return;
|
||||
}
|
||||
|
||||
stmt.AddValue(0, info.spawnId);
|
||||
stmt.AddValue(1, GetId());
|
||||
stmt.AddValue(2, GetInstanceId());
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_RESPAWN);
|
||||
stmt.AddValue(0, (ushort)info.type);
|
||||
stmt.AddValue(1, info.spawnId);
|
||||
stmt.AddValue(2, GetId());
|
||||
stmt.AddValue(3, GetInstanceId());
|
||||
DB.Characters.ExecuteOrAppend(dbTrans, stmt);
|
||||
|
||||
if (doRespawn)
|
||||
@@ -3097,7 +3086,8 @@ namespace Game.Maps
|
||||
public void SaveRespawnTimeDB(SpawnObjectType type, ulong spawnId, long respawnTime, SQLTransaction dbTrans = null)
|
||||
{
|
||||
// Just here for support of compatibility mode
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement((type == SpawnObjectType.GameObject) ? CharStatements.REP_GO_RESPAWN : CharStatements.REP_CREATURE_RESPAWN);
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.REP_RESPAWN);
|
||||
stmt.AddValue(0, (ushort)type);
|
||||
stmt.AddValue(0, spawnId);
|
||||
stmt.AddValue(1, respawnTime);
|
||||
stmt.AddValue(2, GetId());
|
||||
@@ -3107,7 +3097,7 @@ namespace Game.Maps
|
||||
|
||||
public void LoadRespawnTimes()
|
||||
{
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CREATURE_RESPAWNS);
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_RESPAWNS);
|
||||
stmt.AddValue(0, GetId());
|
||||
stmt.AddValue(1, GetInstanceId());
|
||||
SQLResult result = DB.Characters.Query(stmt);
|
||||
@@ -3115,30 +3105,15 @@ namespace Game.Maps
|
||||
{
|
||||
do
|
||||
{
|
||||
var loguid = result.Read<ulong>(0);
|
||||
var respawnTime = result.Read<long>(1);
|
||||
SpawnObjectType type = (SpawnObjectType)result.Read<ushort>(0);
|
||||
var spawnId = result.Read<ulong>(1);
|
||||
var respawnTime = result.Read<long>(2);
|
||||
|
||||
CreatureData cdata = Global.ObjectMgr.GetCreatureData(loguid);
|
||||
if (cdata != null)
|
||||
SaveRespawnTime(SpawnObjectType.Creature, loguid, cdata.Id, respawnTime, GetZoneId(PhasingHandler.EmptyPhaseShift, cdata.spawnPoint), GridDefines.ComputeGridCoord(cdata.spawnPoint.GetPositionX(), cdata.spawnPoint.GetPositionY()).GetId(), false);
|
||||
|
||||
} while (result.NextRow());
|
||||
}
|
||||
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_GO_RESPAWNS);
|
||||
stmt.AddValue(0, GetId());
|
||||
stmt.AddValue(1, GetInstanceId());
|
||||
result = DB.Characters.Query(stmt);
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
do
|
||||
{
|
||||
var loguid = result.Read<uint>(0);
|
||||
var respawnTime = result.Read<long>(1);
|
||||
|
||||
GameObjectData godata = Global.ObjectMgr.GetGameObjectData(loguid);
|
||||
if (godata != null)
|
||||
SaveRespawnTime(SpawnObjectType.GameObject, loguid, godata.Id, respawnTime, GetZoneId(PhasingHandler.EmptyPhaseShift, godata.spawnPoint), GridDefines.ComputeGridCoord(godata.spawnPoint.GetPositionX(), godata.spawnPoint.GetPositionY()).GetId(), false);
|
||||
SpawnData data = Global.ObjectMgr.GetSpawnData(type, spawnId);
|
||||
if (data != null)
|
||||
SaveRespawnTime(type, spawnId, data.Id, respawnTime, GetZoneId(PhasingHandler.EmptyPhaseShift, data.spawnPoint), GridDefines.ComputeGridCoord(data.spawnPoint.GetPositionX(), data.spawnPoint.GetPositionY()).GetId(), false);
|
||||
else
|
||||
Log.outError(LogFilter.Maps, $"Loading saved respawn time of {respawnTime} for spawnid ({type},{spawnId}) - spawn does not exist, ignoring");
|
||||
|
||||
} while (result.NextRow());
|
||||
}
|
||||
@@ -3154,12 +3129,7 @@ namespace Game.Maps
|
||||
|
||||
public static void DeleteRespawnTimesInDB(uint mapId, uint instanceId)
|
||||
{
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CREATURE_RESPAWN_BY_INSTANCE);
|
||||
stmt.AddValue(0, mapId);
|
||||
stmt.AddValue(1, instanceId);
|
||||
DB.Characters.Execute(stmt);
|
||||
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_GO_RESPAWN_BY_INSTANCE);
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_ALL_RESPAWNS);
|
||||
stmt.AddValue(0, mapId);
|
||||
stmt.AddValue(1, instanceId);
|
||||
DB.Characters.Execute(stmt);
|
||||
|
||||
@@ -486,7 +486,7 @@ namespace Game
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loading Instance Template...");
|
||||
Global.ObjectMgr.LoadInstanceTemplate();
|
||||
|
||||
// Must be called before `creature_respawn`/`gameobject_respawn` tables
|
||||
// Must be called before `respawn` data
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loading instances...");
|
||||
Global.InstanceSaveMgr.LoadInstances();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user