diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 84b7c0bdb5..1a89ffd54f 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -2393,7 +2393,7 @@ void Creature::SaveRespawnTime(uint32 forceDelay, bool savetodb) } time_t thisRespawnTime = forceDelay ? GameTime::GetGameTime() + forceDelay : m_respawnTime; - GetMap()->SaveRespawnTime(SPAWN_TYPE_CREATURE, m_spawnId, GetEntry(), thisRespawnTime, GetMap()->GetZoneId(GetPhaseShift(), GetHomePosition()), Trinity::ComputeGridCoord(GetHomePosition().GetPositionX(), GetHomePosition().GetPositionY()).GetId(), savetodb && m_creatureData && m_creatureData->dbData); + GetMap()->SaveRespawnTime(SPAWN_TYPE_CREATURE, m_spawnId, GetEntry(), thisRespawnTime, Trinity::ComputeGridCoord(GetHomePosition().GetPositionX(), GetHomePosition().GetPositionY()).GetId(), savetodb && m_creatureData && m_creatureData->dbData); } // this should not be called by petAI or diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index a2a6500d79..427b5c40b4 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -1078,7 +1078,7 @@ void GameObject::SaveRespawnTime(uint32 forceDelay, bool savetodb) } uint32 thisRespawnTime = forceDelay ? time(nullptr) + forceDelay : m_respawnTime; - GetMap()->SaveRespawnTime(SPAWN_TYPE_GAMEOBJECT, m_spawnId, GetEntry(), thisRespawnTime, GetZoneId(), Trinity::ComputeGridCoord(GetPositionX(), GetPositionY()).GetId(), m_goData->dbData ? savetodb : false); + GetMap()->SaveRespawnTime(SPAWN_TYPE_GAMEOBJECT, m_spawnId, GetEntry(), thisRespawnTime, Trinity::ComputeGridCoord(GetPositionX(), GetPositionY()).GetId(), m_goData->dbData ? savetodb : false); } } diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 1f4f894dd4..dc12e2317f 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -3178,7 +3178,7 @@ void Map::Respawn(RespawnInfo* info, bool force, SQLTransaction dbTrans) if (!force && !CheckRespawn(info)) { if (info->respawnTime) - SaveRespawnTime(info->type, info->spawnId, info->entry, info->respawnTime, info->zoneId, info->gridId, true, true, dbTrans); + SaveRespawnTime(info->type, info->spawnId, info->entry, info->respawnTime, info->gridId, true, true, dbTrans); else RemoveRespawnTime(info); return; @@ -3228,18 +3228,19 @@ void Map::AddRespawnInfo(RespawnInfo& info, bool replace) ASSERT(success, "Insertion of respawn info with id (%u,%u) into spawn id map failed - state desync.", uint32(ri->type), ri->spawnId); } -static void PushRespawnInfoFrom(std::vector& data, RespawnInfoMap const& map, uint32 zoneId) +static void PushRespawnInfoFrom(std::vector& data, RespawnInfoMap const& map) { + data.reserve(data.size() + map.size()); for (auto const& pair : map) - if (!zoneId || pair.second->zoneId == zoneId) - data.push_back(pair.second); + data.push_back(pair.second); } -void Map::GetRespawnInfo(std::vector& respawnData, SpawnObjectTypeMask types, uint32 zoneId) const + +void Map::GetRespawnInfo(std::vector& respawnData, SpawnObjectTypeMask types) const { if (types & SPAWN_TYPEMASK_CREATURE) - PushRespawnInfoFrom(respawnData, _creatureRespawnTimesBySpawnId, zoneId); + PushRespawnInfoFrom(respawnData, _creatureRespawnTimesBySpawnId); if (types & SPAWN_TYPEMASK_GAMEOBJECT) - PushRespawnInfoFrom(respawnData, _gameObjectRespawnTimesBySpawnId, zoneId); + PushRespawnInfoFrom(respawnData, _gameObjectRespawnTimesBySpawnId); } RespawnInfo* Map::GetRespawnInfo(SpawnObjectType type, ObjectGuid::LowType spawnId) const @@ -3313,7 +3314,7 @@ void Map::RemoveRespawnTime(std::vector& respawnData, bool doRespa void Map::ProcessRespawns() { - time_t now = time(NULL); + time_t now = time(nullptr); while (!_respawnTimes.empty()) { RespawnInfo* next = _respawnTimes.top(); @@ -4435,7 +4436,7 @@ void Map::UpdateIteratorBack(Player* player) m_mapRefIter = m_mapRefIter->nocheck_prev(); } -void Map::SaveRespawnTime(SpawnObjectType type, ObjectGuid::LowType spawnId, uint32 entry, time_t respawnTime, uint32 zoneId, uint32 gridId, bool writeDB, bool replace, SQLTransaction dbTrans) +void Map::SaveRespawnTime(SpawnObjectType type, ObjectGuid::LowType spawnId, uint32 entry, time_t respawnTime, uint32 gridId, bool writeDB, bool replace, SQLTransaction dbTrans) { if (!respawnTime) { @@ -4450,7 +4451,6 @@ void Map::SaveRespawnTime(SpawnObjectType type, ObjectGuid::LowType spawnId, uin ri.entry = entry; ri.respawnTime = respawnTime; ri.gridId = gridId; - ri.zoneId = zoneId; AddRespawnInfo(ri, replace); if (writeDB) @@ -4482,7 +4482,7 @@ void Map::LoadRespawnTimes() uint64 respawnTime = fields[1].GetUInt64(); if (CreatureData const* cdata = sObjectMgr->GetCreatureData(loguid)) - SaveRespawnTime(SPAWN_TYPE_CREATURE, loguid, cdata->id, time_t(respawnTime), GetZoneId(PhasingHandler::GetEmptyPhaseShift(), cdata->spawnPoint), Trinity::ComputeGridCoord(cdata->spawnPoint.GetPositionX(), cdata->spawnPoint.GetPositionY()).GetId(), false); + SaveRespawnTime(SPAWN_TYPE_CREATURE, loguid, cdata->id, time_t(respawnTime), Trinity::ComputeGridCoord(cdata->spawnPoint.GetPositionX(), cdata->spawnPoint.GetPositionY()).GetId(), false); } while (result->NextRow()); } diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index 48be4fa157..d6f06bc91d 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -301,7 +301,6 @@ struct RespawnInfo uint32 entry; time_t respawnTime; uint32 gridId; - uint32 zoneId; RespawnListHandle handle; }; inline bool CompareRespawnInfo::operator()(RespawnInfo const* a, RespawnInfo const* b) const @@ -607,7 +606,7 @@ class TC_GAME_API Map : public GridRefManager void UpdatePlayerZoneStats(uint32 oldZone, uint32 newZone); - void SaveRespawnTime(SpawnObjectType type, ObjectGuid::LowType spawnId, uint32 entry, time_t respawnTime, uint32 zoneId, uint32 gridId = 0, bool writeDB = true, bool replace = false, SQLTransaction dbTrans = nullptr); + void SaveRespawnTime(SpawnObjectType type, ObjectGuid::LowType spawnId, uint32 entry, time_t respawnTime, uint32 gridId = 0, bool writeDB = true, bool replace = false, SQLTransaction dbTrans = nullptr); void SaveRespawnTimeDB(SpawnObjectType type, ObjectGuid::LowType spawnId, time_t respawnTime, SQLTransaction dbTrans = nullptr); void LoadRespawnTimes(); void DeleteRespawnTimes() { DeleteRespawnInfo(); DeleteRespawnTimesInDB(GetId(), GetInstanceId()); } @@ -800,10 +799,10 @@ class TC_GAME_API Map : public GridRefManager DeleteRespawnInfo(info); toDelete.clear(); } - void DeleteRespawnInfo(SpawnObjectTypeMask types, uint32 zoneId = 0) + void DeleteRespawnInfo(SpawnObjectTypeMask types) { std::vector v; - GetRespawnInfo(v, types, zoneId); + GetRespawnInfo(v, types); if (!v.empty()) DeleteRespawnInfo(v); } @@ -814,7 +813,7 @@ class TC_GAME_API Map : public GridRefManager } public: - void GetRespawnInfo(std::vector& respawnData, SpawnObjectTypeMask types, uint32 zoneId = 0) const; + void GetRespawnInfo(std::vector& respawnData, SpawnObjectTypeMask types) const; RespawnInfo* GetRespawnInfo(SpawnObjectType type, ObjectGuid::LowType spawnId) const; void ForceRespawn(SpawnObjectType type, ObjectGuid::LowType spawnId) { @@ -823,10 +822,10 @@ class TC_GAME_API Map : public GridRefManager } void RemoveRespawnTime(RespawnInfo* info, bool doRespawn = false, SQLTransaction dbTrans = nullptr); void RemoveRespawnTime(std::vector& respawnData, bool doRespawn = false, SQLTransaction dbTrans = nullptr); - void RemoveRespawnTime(SpawnObjectTypeMask types = SPAWN_TYPEMASK_ALL, uint32 zoneId = 0, bool doRespawn = false, SQLTransaction dbTrans = nullptr) + void RemoveRespawnTime(SpawnObjectTypeMask types = SPAWN_TYPEMASK_ALL, bool doRespawn = false, SQLTransaction dbTrans = nullptr) { std::vector v; - GetRespawnInfo(v, types, zoneId); + GetRespawnInfo(v, types); if (!v.empty()) RemoveRespawnTime(v, doRespawn, dbTrans); } diff --git a/src/server/scripts/Commands/cs_list.cpp b/src/server/scripts/Commands/cs_list.cpp index b71bc99be5..37939bd49e 100644 --- a/src/server/scripts/Commands/cs_list.cpp +++ b/src/server/scripts/Commands/cs_list.cpp @@ -33,6 +33,7 @@ EndScriptData */ #include "MapManager.h" #include "ObjectAccessor.h" #include "ObjectMgr.h" +#include "PhasingHandler.h" #include "Player.h" #include "RBAC.h" #include "SpellAuraEffects.h" @@ -699,24 +700,37 @@ public: char const* stringGameobject = sObjectMgr->GetTrinityString(LANG_LIST_RESPAWNS_GAMEOBJECTS, locale); uint32 zoneId = player->GetZoneId(); + char const* zoneName = GetZoneName(zoneId, locale); if (range) handler->PSendSysMessage(LANG_LIST_RESPAWNS_RANGE, stringCreature, range); else - handler->PSendSysMessage(LANG_LIST_RESPAWNS_ZONE, stringCreature, GetZoneName(zoneId, handler->GetSessionDbcLocale()), zoneId); + handler->PSendSysMessage(LANG_LIST_RESPAWNS_ZONE, stringCreature, zoneName, zoneId); handler->PSendSysMessage(LANG_LIST_RESPAWNS_LISTHEADER); - map->GetRespawnInfo(respawns, SPAWN_TYPEMASK_CREATURE, range ? 0 : zoneId); - for (RespawnInfo* ri : respawns) + map->GetRespawnInfo(respawns, SPAWN_TYPEMASK_CREATURE); + + for (RespawnInfo const* ri : respawns) { CreatureData const* data = sObjectMgr->GetCreatureData(ri->spawnId); if (!data) continue; - if (range && !player->IsInDist(data->spawnPoint, range)) - continue; + + uint32 respawnZoneId = map->GetZoneId(PhasingHandler::GetEmptyPhaseShift(), data->spawnPoint); + if (range) + { + if (!player->IsInDist(data->spawnPoint, range)) + continue; + } + else + { + if (zoneId != respawnZoneId) + continue; + } + uint32 gridY = ri->gridId / MAX_NUMBER_OF_GRIDS; uint32 gridX = ri->gridId % MAX_NUMBER_OF_GRIDS; std::string respawnTime = ri->respawnTime > time(nullptr) ? secsToTimeString(uint64(ri->respawnTime - time(nullptr)), true) : stringOverdue; - handler->PSendSysMessage("%u | %u | [%02u,%02u] | %s (%u) | %s", ri->spawnId, ri->entry, gridX, gridY, GetZoneName(ri->zoneId, handler->GetSessionDbcLocale()), ri->zoneId, map->IsSpawnGroupActive(data->spawnGroupData->groupId) ? respawnTime.c_str() : "inactive"); + handler->PSendSysMessage("%u | %u | [%02u,%02u] | %s (%u) | %s", ri->spawnId, ri->entry, gridX, gridY, GetZoneName(respawnZoneId, locale), respawnZoneId, map->IsSpawnGroupActive(data->spawnGroupData->groupId) ? respawnTime.c_str() : "inactive"); } respawns.clear(); @@ -725,19 +739,30 @@ public: else handler->PSendSysMessage(LANG_LIST_RESPAWNS_ZONE, stringGameobject, GetZoneName(zoneId, handler->GetSessionDbcLocale()), zoneId); handler->PSendSysMessage(LANG_LIST_RESPAWNS_LISTHEADER); - map->GetRespawnInfo(respawns, SPAWN_TYPEMASK_GAMEOBJECT, range ? 0 : zoneId); - for (RespawnInfo* ri : respawns) + map->GetRespawnInfo(respawns, SPAWN_TYPEMASK_GAMEOBJECT); + for (RespawnInfo const* ri : respawns) { GameObjectData const* data = sObjectMgr->GetGameObjectData(ri->spawnId); if (!data) continue; - if (range && !player->IsInDist(data->spawnPoint, range)) - continue; + + uint32 respawnZoneId = map->GetZoneId(PhasingHandler::GetEmptyPhaseShift(), data->spawnPoint); + if (range) + { + if (!player->IsInDist(data->spawnPoint, range)) + continue; + } + else + { + if (zoneId != respawnZoneId) + continue; + } + uint32 gridY = ri->gridId / MAX_NUMBER_OF_GRIDS; uint32 gridX = ri->gridId % MAX_NUMBER_OF_GRIDS; std::string respawnTime = ri->respawnTime > time(nullptr) ? secsToTimeString(uint64(ri->respawnTime - time(nullptr)), true) : stringOverdue; - handler->PSendSysMessage("%u | %u | [% 02u, % 02u] | %s (%u) | %s", ri->spawnId, ri->entry, gridX, gridY, GetZoneName(ri->zoneId, handler->GetSessionDbcLocale()), ri->zoneId, map->IsSpawnGroupActive(data->spawnGroupData->groupId) ? respawnTime.c_str() : "inactive"); + handler->PSendSysMessage("%u | %u | [% 02u, % 02u] | %s (%u) | %s", ri->spawnId, ri->entry, gridX, gridY, GetZoneName(respawnZoneId, locale), respawnZoneId, map->IsSpawnGroupActive(data->spawnGroupData->groupId) ? respawnTime.c_str() : "inactive"); } return true; } diff --git a/src/server/scripts/Commands/cs_misc.cpp b/src/server/scripts/Commands/cs_misc.cpp index e10cf98820..119ec46962 100644 --- a/src/server/scripts/Commands/cs_misc.cpp +++ b/src/server/scripts/Commands/cs_misc.cpp @@ -1912,7 +1912,7 @@ public: // Now handle any that had despawned, but had respawn time logged. std::vector data; - player->GetMap()->GetRespawnInfo(data, SPAWN_TYPEMASK_ALL, 0); + player->GetMap()->GetRespawnInfo(data, SPAWN_TYPEMASK_ALL); if (!data.empty()) { uint32 const gridId = Trinity::ComputeGridCoord(player->GetPositionX(), player->GetPositionY()).GetId();