fix(Core/Grids): Fix corpse loading after a server restart (#22594)
This commit is contained in:
parent
4e8d0f565f
commit
cd87350a17
3 changed files with 18 additions and 16 deletions
|
|
@ -84,20 +84,14 @@ void GridObjectLoader::LoadAllCellsInGrid()
|
|||
LoadGameObjects(cell_guids.gameobjects, _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)
|
||||
{
|
||||
if (corpse->IsInGrid())
|
||||
continue;
|
||||
|
||||
CellCoord cellCoord = Acore::ComputeCellCoord(corpse->GetPositionX(), corpse->GetPositionY());
|
||||
Cell cell(cellCoord);
|
||||
|
||||
if (corpse->IsWorldObject())
|
||||
_grid.AddWorldObject(cell.CellX(), cell.CellY(), corpse);
|
||||
else
|
||||
_grid.AddGridObject(cell.CellX(), cell.CellY(), corpse);
|
||||
AddObjectHelper<Corpse>(_map, corpse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1033,7 +1033,7 @@ void Map::UnloadAll()
|
|||
|
||||
_transports.clear();
|
||||
|
||||
for (auto& cellCorpsePair : _corpsesByCell)
|
||||
for (auto& cellCorpsePair : _corpsesByGrid)
|
||||
{
|
||||
for (Corpse* corpse : cellCorpsePair.second)
|
||||
{
|
||||
|
|
@ -1043,7 +1043,7 @@ void Map::UnloadAll()
|
|||
}
|
||||
}
|
||||
|
||||
_corpsesByCell.clear();
|
||||
_corpsesByGrid.clear();
|
||||
_corpsesByPlayer.clear();
|
||||
_corpseBones.clear();
|
||||
}
|
||||
|
|
@ -1848,6 +1848,12 @@ void Map::AddToActive(GameObject* d)
|
|||
AddToActiveHelper(d);
|
||||
}
|
||||
|
||||
template<>
|
||||
void Map::AddToActive(Corpse* /*c*/)
|
||||
{
|
||||
// do nothing for corpses
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Map::RemoveFromActive(T* obj)
|
||||
{
|
||||
|
|
@ -2667,7 +2673,8 @@ void Map::AddCorpse(Corpse* corpse)
|
|||
{
|
||||
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)
|
||||
_corpsesByPlayer[corpse->GetOwnerGUID()] = corpse;
|
||||
else
|
||||
|
|
@ -2677,6 +2684,7 @@ void Map::AddCorpse(Corpse* corpse)
|
|||
void Map::RemoveCorpse(Corpse* corpse)
|
||||
{
|
||||
ASSERT(corpse);
|
||||
GridCoord const gridCoord = Acore::ComputeGridCoord(corpse->GetPositionX(), corpse->GetPositionY());
|
||||
|
||||
corpse->DestroyForNearbyPlayers();
|
||||
if (corpse->IsInGrid())
|
||||
|
|
@ -2687,7 +2695,7 @@ void Map::RemoveCorpse(Corpse* corpse)
|
|||
corpse->ResetMap();
|
||||
}
|
||||
|
||||
_corpsesByCell[corpse->GetCellCoord().GetId()].erase(corpse);
|
||||
_corpsesByGrid[gridCoord.GetId()].erase(corpse);
|
||||
if (corpse->GetType() != CORPSE_BONES)
|
||||
_corpsesByPlayer.erase(corpse->GetOwnerGUID());
|
||||
else
|
||||
|
|
|
|||
|
|
@ -359,10 +359,10 @@ public:
|
|||
typedef std::unordered_multimap<ObjectGuid::LowType, GameObject*> GameObjectBySpawnIdContainer;
|
||||
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);
|
||||
if (itr != _corpsesByCell.end())
|
||||
auto itr = _corpsesByGrid.find(gridId);
|
||||
if (itr != _corpsesByGrid.end())
|
||||
return &itr->second;
|
||||
|
||||
return nullptr;
|
||||
|
|
@ -631,7 +631,7 @@ private:
|
|||
MapStoredObjectTypesContainer _objectsStore;
|
||||
CreatureBySpawnIdContainer _creatureBySpawnIdStore;
|
||||
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_set<Corpse*> _corpseBones;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue