aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Maps/Map.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/game/Maps/Map.cpp')
-rw-r--r--src/server/game/Maps/Map.cpp42
1 files changed, 33 insertions, 9 deletions
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp
index 85cc87eaa6e..30925fbe139 100644
--- a/src/server/game/Maps/Map.cpp
+++ b/src/server/game/Maps/Map.cpp
@@ -1612,6 +1612,13 @@ void Map::UnloadAll()
RemoveFromMap<Transport>(transport, true);
}
+
+ for (auto& cellCorpsePair : _corpsesByCell)
+ for (Corpse* corpse : cellCorpsePair.second)
+ delete corpse;
+
+ _corpsesByCell.clear();
+ _corpsesByPlayer.clear();
}
// *****************************
@@ -3659,14 +3666,16 @@ void Map::AddCorpse(Corpse* corpse)
{
corpse->SetMap(this);
- CellCoord cellCoord = Trinity::ComputeCellCoord(corpse->GetPositionX(), corpse->GetPositionY());
- _corpsesByCell[cellCoord.GetId()].insert(corpse);
- _corpsesByPlayer[corpse->GetOwnerGUID()] = corpse;
+ _corpsesByCell[corpse->GetCellCoord().GetId()].insert(corpse);
+ if (corpse->GetType() != CORPSE_BONES)
+ _corpsesByPlayer[corpse->GetOwnerGUID()] = corpse;
+ else
+ _corpseBones.insert(corpse);
}
void Map::RemoveCorpse(Corpse* corpse)
{
- ASSERT(corpse && corpse->GetType() != CORPSE_BONES);
+ ASSERT(corpse);
corpse->DestroyForNearbyPlayers();
if (corpse->IsInGrid())
@@ -3677,9 +3686,11 @@ void Map::RemoveCorpse(Corpse* corpse)
corpse->ResetMap();
}
- CellCoord cellCoord = Trinity::ComputeCellCoord(corpse->GetPositionX(), corpse->GetPositionY());
- _corpsesByCell[cellCoord.GetId()].erase(corpse);
- _corpsesByPlayer.erase(corpse->GetOwnerGUID());
+ _corpsesByCell[corpse->GetCellCoord().GetId()].erase(corpse);
+ if (corpse->GetType() != CORPSE_BONES)
+ _corpsesByPlayer.erase(corpse->GetOwnerGUID());
+ else
+ _corpseBones.erase(corpse);
}
Corpse* Map::ConvertCorpseToBones(ObjectGuid const& ownerGuid, bool insignia /*= false*/)
@@ -3710,12 +3721,12 @@ Corpse* Map::ConvertCorpseToBones(ObjectGuid const& ownerGuid, bool insignia /*=
for (uint8 i = OBJECT_FIELD_GUID + 4; i < CORPSE_END; ++i) // don't overwrite guid
bones->SetUInt32Value(i, corpse->GetUInt32Value(i));
- bones->SetGridCoord(corpse->GetGridCoord());
+ bones->SetCellCoord(corpse->GetCellCoord());
bones->Relocate(corpse->GetPositionX(), corpse->GetPositionY(), corpse->GetPositionZ(), corpse->GetOrientation());
bones->SetUInt32Value(CORPSE_FIELD_FLAGS, CORPSE_FLAG_UNK2 | CORPSE_FLAG_BONES);
bones->SetGuidValue(CORPSE_FIELD_OWNER, ObjectGuid::Empty);
- bones->SetGuidValue(OBJECT_FIELD_DATA, corpse->GetGuidValue(OBJECT_FIELD_DATA));
+ bones->SetGuidValue(OBJECT_FIELD_DATA, ObjectGuid::Empty);
for (uint8 i = 0; i < EQUIPMENT_SLOT_END; ++i)
if (corpse->GetUInt32Value(CORPSE_FIELD_ITEM + i))
@@ -3723,6 +3734,8 @@ Corpse* Map::ConvertCorpseToBones(ObjectGuid const& ownerGuid, bool insignia /*=
bones->CopyPhaseFrom(corpse);
+ AddCorpse(bones);
+
// add bones in grid store if grid loaded where corpse placed
AddToMap(bones);
}
@@ -3746,6 +3759,17 @@ void Map::RemoveOldCorpses()
for (ObjectGuid const& ownerGuid : corpses)
ConvertCorpseToBones(ownerGuid);
+
+ std::vector<Corpse*> expiredBones;
+ for (Corpse* bones : _corpseBones)
+ if (bones->IsExpired(now))
+ expiredBones.push_back(bones);
+
+ for (Corpse* bones : expiredBones)
+ {
+ RemoveCorpse(bones);
+ delete bones;
+ }
}
void Map::SendZoneDynamicInfo(Player* player)