aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Maps/Map.cpp
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2019-07-14 18:49:38 +0200
committerGitHub <noreply@github.com>2019-07-14 18:49:38 +0200
commit374597c8e96c886f1e3647d405bf3160c8b98bf8 (patch)
tree172694412e864ddf875a37202a80c61726be8874 /src/server/game/Maps/Map.cpp
parent6826b8cb2cafd3f64c40357c53e10b8ceaea6b8a (diff)
Core/DB: Unify `creature_respawn` and `gameobject_respawn` into a single `respawn` table
Diffstat (limited to 'src/server/game/Maps/Map.cpp')
-rw-r--r--src/server/game/Maps/Map.cpp71
1 files changed, 21 insertions, 50 deletions
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp
index 47005d0a2a6..0fc84d4b446 100644
--- a/src/server/game/Maps/Map.cpp
+++ b/src/server/game/Maps/Map.cpp
@@ -3162,22 +3162,11 @@ void Map::DeleteRespawnInfo(RespawnInfo* info)
void Map::RemoveRespawnTime(RespawnInfo* info, bool doRespawn, SQLTransaction dbTrans)
{
- PreparedStatement* stmt;
- switch (info->type)
- {
- case SPAWN_TYPE_CREATURE:
- stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CREATURE_RESPAWN);
- break;
- case SPAWN_TYPE_GAMEOBJECT:
- stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GO_RESPAWN);
- break;
- default:
- ASSERT(false, "Invalid respawninfo type %u for spawnid %u map %u", uint32(info->type), info->spawnId, GetId());
- return;
- }
- stmt->setUInt32(0, info->spawnId);
- stmt->setUInt16(1, GetId());
- stmt->setUInt32(2, GetInstanceId());
+ PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_RESPAWN);
+ stmt->setUInt16(0, info->type);
+ stmt->setUInt32(1, info->spawnId);
+ stmt->setUInt16(2, GetId());
+ stmt->setUInt32(3, GetInstanceId());
CharacterDatabase.ExecuteOrAppend(dbTrans, stmt);
if (doRespawn)
@@ -4344,17 +4333,18 @@ void Map::SaveRespawnTime(SpawnObjectType type, ObjectGuid::LowType spawnId, uin
void Map::SaveRespawnTimeDB(SpawnObjectType type, ObjectGuid::LowType spawnId, time_t respawnTime, SQLTransaction dbTrans)
{
// Just here for support of compatibility mode
- PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement((type == SPAWN_TYPE_GAMEOBJECT) ? CHAR_REP_GO_RESPAWN : CHAR_REP_CREATURE_RESPAWN);
- stmt->setUInt32(0, spawnId);
- stmt->setUInt64(1, uint64(respawnTime));
- stmt->setUInt16(2, GetId());
- stmt->setUInt32(3, GetInstanceId());
+ PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_RESPAWN);
+ stmt->setUInt16(0, type);
+ stmt->setUInt32(1, spawnId);
+ stmt->setUInt64(2, uint64(respawnTime));
+ stmt->setUInt16(3, GetId());
+ stmt->setUInt32(4, GetInstanceId());
CharacterDatabase.ExecuteOrAppend(dbTrans, stmt);
}
void Map::LoadRespawnTimes()
{
- PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CREATURE_RESPAWNS);
+ PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_RESPAWNS);
stmt->setUInt16(0, GetId());
stmt->setUInt32(1, GetInstanceId());
if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
@@ -4362,41 +4352,22 @@ void Map::LoadRespawnTimes()
do
{
Field* fields = result->Fetch();
- ObjectGuid::LowType loguid = fields[0].GetUInt32();
- uint64 respawnTime = fields[1].GetUInt64();
+ SpawnObjectType type = SpawnObjectType(fields[0].GetUInt16());
+ ObjectGuid::LowType spawnId = fields[1].GetUInt32();
+ uint64 respawnTime = fields[2].GetUInt64();
- if (CreatureData const* cdata = sObjectMgr->GetCreatureData(loguid))
- SaveRespawnTime(SPAWN_TYPE_CREATURE, loguid, cdata->id, time_t(respawnTime), GetZoneId(cdata->spawnPoint), Trinity::ComputeGridCoord(cdata->spawnPoint.GetPositionX(), cdata->spawnPoint.GetPositionY()).GetId(), false);
-
- } while (result->NextRow());
- }
-
- stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GO_RESPAWNS);
- stmt->setUInt16(0, GetId());
- stmt->setUInt32(1, GetInstanceId());
- if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
- {
- do
- {
- Field* fields = result->Fetch();
- ObjectGuid::LowType loguid = fields[0].GetUInt32();
- uint64 respawnTime = fields[1].GetUInt64();
-
- if (GameObjectData const* godata = sObjectMgr->GetGameObjectData(loguid))
- SaveRespawnTime(SPAWN_TYPE_GAMEOBJECT, loguid, godata->id, time_t(respawnTime), GetZoneId(godata->spawnPoint), Trinity::ComputeGridCoord(godata->spawnPoint.GetPositionX(), godata->spawnPoint.GetPositionY()).GetId(), false);
+ if (SpawnData const* data = sObjectMgr->GetSpawnData(type, spawnId))
+ SaveRespawnTime(type, spawnId, data->id, time_t(respawnTime), GetZoneId(data->spawnPoint), Trinity::ComputeGridCoord(data->spawnPoint.GetPositionX(), data->spawnPoint.GetPositionY()).GetId(), false);
+ else
+ TC_LOG_ERROR("maps", "Loading saved respawn time of %" PRIu64 " for spawnid (%u,%u) - spawn does not exist, ignoring", respawnTime, uint32(type), spawnId);
} while (result->NextRow());
}
}
-void Map::DeleteRespawnTimesInDB(uint16 mapId, uint32 instanceId)
+/*static*/ void Map::DeleteRespawnTimesInDB(uint16 mapId, uint32 instanceId)
{
- PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CREATURE_RESPAWN_BY_INSTANCE);
- stmt->setUInt16(0, mapId);
- stmt->setUInt32(1, instanceId);
- CharacterDatabase.Execute(stmt);
-
- stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GO_RESPAWN_BY_INSTANCE);
+ PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ALL_RESPAWNS);
stmt->setUInt16(0, mapId);
stmt->setUInt32(1, instanceId);
CharacterDatabase.Execute(stmt);