fix(Core/Grids): Fix corpse loading after a server restart (#22594)
This commit is contained in:
@@ -84,20 +84,14 @@ void GridObjectLoader::LoadAllCellsInGrid()
|
|||||||
LoadGameObjects(cell_guids.gameobjects, _map);
|
LoadGameObjects(cell_guids.gameobjects, _map);
|
||||||
LoadCreatures(cell_guids.creatures, _map);
|
LoadCreatures(cell_guids.creatures, _map);
|
||||||
|
|
||||||
if (std::unordered_set<Corpse*> const* corpses = _map->GetCorpsesInCell(_grid.GetId()))
|
if (std::unordered_set<Corpse*> const* corpses = _map->GetCorpsesInGrid(_grid.GetId()))
|
||||||
{
|
{
|
||||||
for (Corpse* corpse : *corpses)
|
for (Corpse* corpse : *corpses)
|
||||||
{
|
{
|
||||||
if (corpse->IsInGrid())
|
if (corpse->IsInGrid())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CellCoord cellCoord = Acore::ComputeCellCoord(corpse->GetPositionX(), corpse->GetPositionY());
|
AddObjectHelper<Corpse>(_map, corpse);
|
||||||
Cell cell(cellCoord);
|
|
||||||
|
|
||||||
if (corpse->IsWorldObject())
|
|
||||||
_grid.AddWorldObject(cell.CellX(), cell.CellY(), corpse);
|
|
||||||
else
|
|
||||||
_grid.AddGridObject(cell.CellX(), cell.CellY(), corpse);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1033,7 +1033,7 @@ void Map::UnloadAll()
|
|||||||
|
|
||||||
_transports.clear();
|
_transports.clear();
|
||||||
|
|
||||||
for (auto& cellCorpsePair : _corpsesByCell)
|
for (auto& cellCorpsePair : _corpsesByGrid)
|
||||||
{
|
{
|
||||||
for (Corpse* corpse : cellCorpsePair.second)
|
for (Corpse* corpse : cellCorpsePair.second)
|
||||||
{
|
{
|
||||||
@@ -1043,7 +1043,7 @@ void Map::UnloadAll()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_corpsesByCell.clear();
|
_corpsesByGrid.clear();
|
||||||
_corpsesByPlayer.clear();
|
_corpsesByPlayer.clear();
|
||||||
_corpseBones.clear();
|
_corpseBones.clear();
|
||||||
}
|
}
|
||||||
@@ -1848,6 +1848,12 @@ void Map::AddToActive(GameObject* d)
|
|||||||
AddToActiveHelper(d);
|
AddToActiveHelper(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
void Map::AddToActive(Corpse* /*c*/)
|
||||||
|
{
|
||||||
|
// do nothing for corpses
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void Map::RemoveFromActive(T* obj)
|
void Map::RemoveFromActive(T* obj)
|
||||||
{
|
{
|
||||||
@@ -2667,7 +2673,8 @@ void Map::AddCorpse(Corpse* corpse)
|
|||||||
{
|
{
|
||||||
corpse->SetMap(this);
|
corpse->SetMap(this);
|
||||||
|
|
||||||
_corpsesByCell[corpse->GetCellCoord().GetId()].insert(corpse);
|
GridCoord const gridCoord = Acore::ComputeGridCoord(corpse->GetPositionX(), corpse->GetPositionY());
|
||||||
|
_corpsesByGrid[gridCoord.GetId()].insert(corpse);
|
||||||
if (corpse->GetType() != CORPSE_BONES)
|
if (corpse->GetType() != CORPSE_BONES)
|
||||||
_corpsesByPlayer[corpse->GetOwnerGUID()] = corpse;
|
_corpsesByPlayer[corpse->GetOwnerGUID()] = corpse;
|
||||||
else
|
else
|
||||||
@@ -2677,6 +2684,7 @@ void Map::AddCorpse(Corpse* corpse)
|
|||||||
void Map::RemoveCorpse(Corpse* corpse)
|
void Map::RemoveCorpse(Corpse* corpse)
|
||||||
{
|
{
|
||||||
ASSERT(corpse);
|
ASSERT(corpse);
|
||||||
|
GridCoord const gridCoord = Acore::ComputeGridCoord(corpse->GetPositionX(), corpse->GetPositionY());
|
||||||
|
|
||||||
corpse->DestroyForNearbyPlayers();
|
corpse->DestroyForNearbyPlayers();
|
||||||
if (corpse->IsInGrid())
|
if (corpse->IsInGrid())
|
||||||
@@ -2687,7 +2695,7 @@ void Map::RemoveCorpse(Corpse* corpse)
|
|||||||
corpse->ResetMap();
|
corpse->ResetMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
_corpsesByCell[corpse->GetCellCoord().GetId()].erase(corpse);
|
_corpsesByGrid[gridCoord.GetId()].erase(corpse);
|
||||||
if (corpse->GetType() != CORPSE_BONES)
|
if (corpse->GetType() != CORPSE_BONES)
|
||||||
_corpsesByPlayer.erase(corpse->GetOwnerGUID());
|
_corpsesByPlayer.erase(corpse->GetOwnerGUID());
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -359,10 +359,10 @@ public:
|
|||||||
typedef std::unordered_multimap<ObjectGuid::LowType, GameObject*> GameObjectBySpawnIdContainer;
|
typedef std::unordered_multimap<ObjectGuid::LowType, GameObject*> GameObjectBySpawnIdContainer;
|
||||||
GameObjectBySpawnIdContainer& GetGameObjectBySpawnIdStore() { return _gameobjectBySpawnIdStore; }
|
GameObjectBySpawnIdContainer& GetGameObjectBySpawnIdStore() { return _gameobjectBySpawnIdStore; }
|
||||||
|
|
||||||
[[nodiscard]] std::unordered_set<Corpse*> const* GetCorpsesInCell(uint32 cellId) const
|
[[nodiscard]] std::unordered_set<Corpse*> const* GetCorpsesInGrid(uint32 gridId) const
|
||||||
{
|
{
|
||||||
auto itr = _corpsesByCell.find(cellId);
|
auto itr = _corpsesByGrid.find(gridId);
|
||||||
if (itr != _corpsesByCell.end())
|
if (itr != _corpsesByGrid.end())
|
||||||
return &itr->second;
|
return &itr->second;
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -631,7 +631,7 @@ private:
|
|||||||
MapStoredObjectTypesContainer _objectsStore;
|
MapStoredObjectTypesContainer _objectsStore;
|
||||||
CreatureBySpawnIdContainer _creatureBySpawnIdStore;
|
CreatureBySpawnIdContainer _creatureBySpawnIdStore;
|
||||||
GameObjectBySpawnIdContainer _gameobjectBySpawnIdStore;
|
GameObjectBySpawnIdContainer _gameobjectBySpawnIdStore;
|
||||||
std::unordered_map<uint32/*cellId*/, std::unordered_set<Corpse*>> _corpsesByCell;
|
std::unordered_map<uint32/*gridId*/, std::unordered_set<Corpse*>> _corpsesByGrid;
|
||||||
std::unordered_map<ObjectGuid, Corpse*> _corpsesByPlayer;
|
std::unordered_map<ObjectGuid, Corpse*> _corpsesByPlayer;
|
||||||
std::unordered_set<Corpse*> _corpseBones;
|
std::unordered_set<Corpse*> _corpseBones;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user