aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Globals/ObjectMgr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/game/Globals/ObjectMgr.cpp')
-rw-r--r--src/server/game/Globals/ObjectMgr.cpp87
1 files changed, 57 insertions, 30 deletions
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp
index ec2bf4b499b..e665fc71aeb 100644
--- a/src/server/game/Globals/ObjectMgr.cpp
+++ b/src/server/game/Globals/ObjectMgr.cpp
@@ -2300,33 +2300,70 @@ void ObjectMgr::LoadCreatures()
// Add to grid if not managed by the game event or pool system
if (gameEvent == 0 && PoolId == 0)
- AddCreatureToGrid(guid, &data);
+ AddCreatureToGrid(&data);
}
while (result->NextRow());
TC_LOG_INFO("server.loading", ">> Loaded " SZFMTD " creatures in %u ms", _creatureDataStore.size(), GetMSTimeDiffToNow(oldMSTime));
}
-void ObjectMgr::AddCreatureToGrid(ObjectGuid::LowType guid, CreatureData const* data)
+bool ObjectMgr::HasPersonalSpawns(uint32 mapid, Difficulty spawnMode, uint32 phaseId) const
{
- for (Difficulty difficulty : data->spawnDifficulties)
+ return Trinity::Containers::MapGetValuePtr(_mapPersonalObjectGuidsStore, { mapid, spawnMode, phaseId }) != nullptr;
+}
+
+CellObjectGuids const* ObjectMgr::GetCellPersonalObjectGuids(uint32 mapid, Difficulty spawnMode, uint32 phaseId, uint32 cell_id) const
+{
+ if (CellObjectGuidsMap const* guids = Trinity::Containers::MapGetValuePtr(_mapPersonalObjectGuidsStore, { mapid, spawnMode, phaseId }))
+ return Trinity::Containers::MapGetValuePtr(*guids, cell_id);
+
+ return nullptr;
+}
+
+template<CellGuidSet CellObjectGuids::*guids>
+void ObjectMgr::AddSpawnDataToGrid(SpawnData const* data)
+{
+ uint32 cellId = Trinity::ComputeCellCoord(data->spawnPoint.GetPositionX(), data->spawnPoint.GetPositionY()).GetId();
+ bool isPersonalPhase = PhasingHandler::IsPersonalPhase(data->phaseId);
+ if (!isPersonalPhase)
+ {
+ for (Difficulty difficulty : data->spawnDifficulties)
+ (_mapObjectGuidsStore[{ data->mapId, difficulty }][cellId].*guids).insert(data->spawnId);
+ }
+ else
{
- CellCoord cellCoord = Trinity::ComputeCellCoord(data->spawnPoint.GetPositionX(), data->spawnPoint.GetPositionY());
- CellObjectGuids& cell_guids = _mapObjectGuidsStore[{ data->mapId, difficulty }][cellCoord.GetId()];
- cell_guids.creatures.insert(guid);
+ for (Difficulty difficulty : data->spawnDifficulties)
+ (_mapPersonalObjectGuidsStore[{ data->mapId, difficulty, data->phaseId }][cellId].*guids).insert(data->spawnId);
}
}
-void ObjectMgr::RemoveCreatureFromGrid(ObjectGuid::LowType guid, CreatureData const* data)
+template<CellGuidSet CellObjectGuids::*guids>
+void ObjectMgr::RemoveSpawnDataFromGrid(SpawnData const* data)
{
- for (Difficulty difficulty : data->spawnDifficulties)
+ uint32 cellId = Trinity::ComputeCellCoord(data->spawnPoint.GetPositionX(), data->spawnPoint.GetPositionY()).GetId();
+ bool isPersonalPhase = PhasingHandler::IsPersonalPhase(data->phaseId);
+ if (!isPersonalPhase)
+ {
+ for (Difficulty difficulty : data->spawnDifficulties)
+ (_mapObjectGuidsStore[{ data->mapId, difficulty }][cellId].*guids).erase(data->spawnId);
+ }
+ else
{
- CellCoord cellCoord = Trinity::ComputeCellCoord(data->spawnPoint.GetPositionX(), data->spawnPoint.GetPositionY());
- CellObjectGuids& cell_guids = _mapObjectGuidsStore[{ data->mapId, difficulty }][cellCoord.GetId()];
- cell_guids.creatures.erase(guid);
+ for (Difficulty difficulty : data->spawnDifficulties)
+ (_mapPersonalObjectGuidsStore[{ data->mapId, difficulty, data->phaseId }][cellId].*guids).erase(data->spawnId);
}
}
+void ObjectMgr::AddCreatureToGrid(CreatureData const* data)
+{
+ AddSpawnDataToGrid<&CellObjectGuids::creatures>(data);
+}
+
+void ObjectMgr::RemoveCreatureFromGrid(CreatureData const* data)
+{
+ RemoveSpawnDataFromGrid<&CellObjectGuids::creatures>(data);
+}
+
ObjectGuid::LowType ObjectMgr::AddGameObjectData(uint32 entry, uint32 mapId, Position const& pos, QuaternionData const& rot, uint32 spawntimedelay /*= 0*/)
{
GameObjectTemplate const* goinfo = GetGameObjectTemplate(entry);
@@ -2352,7 +2389,7 @@ ObjectGuid::LowType ObjectMgr::AddGameObjectData(uint32 entry, uint32 mapId, Pos
data.dbData = false;
data.spawnGroupData = GetLegacySpawnGroup();
- AddGameobjectToGrid(spawnId, &data);
+ AddGameobjectToGrid(&data);
// Spawn if necessary (loaded grids only)
// We use spawn coords to spawn
@@ -2407,7 +2444,7 @@ ObjectGuid::LowType ObjectMgr::AddCreatureData(uint32 entry, uint32 mapId, Posit
data.dynamicflags = cInfo->dynamicflags;
data.spawnGroupData = GetLegacySpawnGroup();
- AddCreatureToGrid(spawnId, &data);
+ AddCreatureToGrid(&data);
// We use spawn coords to spawn
if (!map->Instanceable() && !map->IsRemovalGrid(data.spawnPoint))
@@ -2663,7 +2700,7 @@ void ObjectMgr::LoadGameObjects()
}
if (gameEvent == 0 && PoolId == 0) // if not this is to be managed by GameEvent System or Pool system
- AddGameobjectToGrid(guid, &data);
+ AddGameobjectToGrid(&data);
}
while (result->NextRow());
@@ -2885,24 +2922,14 @@ void ObjectMgr::OnDeleteSpawnData(SpawnData const* data)
ASSERT(false, "Spawn data (%u," UI64FMTD ") being removed is member of spawn group %u, but not actually listed in the lookup table for that group!", uint32(data->type), data->spawnId, data->spawnGroupData->groupId);
}
-void ObjectMgr::AddGameobjectToGrid(ObjectGuid::LowType guid, GameObjectData const* data)
+void ObjectMgr::AddGameobjectToGrid(GameObjectData const* data)
{
- for (Difficulty difficulty : data->spawnDifficulties)
- {
- CellCoord cellCoord = Trinity::ComputeCellCoord(data->spawnPoint.GetPositionX(), data->spawnPoint.GetPositionY());
- CellObjectGuids& cell_guids = _mapObjectGuidsStore[{ data->mapId, difficulty }][cellCoord.GetId()];
- cell_guids.gameobjects.insert(guid);
- }
+ AddSpawnDataToGrid<&CellObjectGuids::gameobjects>(data);
}
-void ObjectMgr::RemoveGameobjectFromGrid(ObjectGuid::LowType guid, GameObjectData const* data)
+void ObjectMgr::RemoveGameobjectFromGrid(GameObjectData const* data)
{
- for (Difficulty difficulty : data->spawnDifficulties)
- {
- CellCoord cellCoord = Trinity::ComputeCellCoord(data->spawnPoint.GetPositionX(), data->spawnPoint.GetPositionY());
- CellObjectGuids& cell_guids = _mapObjectGuidsStore[{ data->mapId, difficulty }][cellCoord.GetId()];
- cell_guids.gameobjects.erase(guid);
- }
+ RemoveSpawnDataFromGrid<&CellObjectGuids::gameobjects>(data);
}
uint32 FillMaxDurability(uint32 itemClass, uint32 itemSubClass, uint32 inventoryType, uint32 quality, uint32 itemLevel)
@@ -8431,7 +8458,7 @@ void ObjectMgr::DeleteCreatureData(ObjectGuid::LowType guid)
CreatureData const* data = GetCreatureData(guid);
if (data)
{
- RemoveCreatureFromGrid(guid, data);
+ RemoveCreatureFromGrid(data);
OnDeleteSpawnData(data);
}
@@ -8444,7 +8471,7 @@ void ObjectMgr::DeleteGameObjectData(ObjectGuid::LowType guid)
GameObjectData const* data = GetGameObjectData(guid);
if (data)
{
- RemoveGameobjectFromGrid(guid, data);
+ RemoveGameobjectFromGrid(data);
OnDeleteSpawnData(data);
}