feat(Core/Misc): implement ObjectGuid class (port from TC) (#4885)

This commit is contained in:
UltraNix
2021-04-25 22:18:03 +02:00
committed by GitHub
parent 91081f4ad8
commit f4c226423d
568 changed files with 10655 additions and 11019 deletions

View File

@@ -328,12 +328,12 @@ inline void Battleground::_ProcessResurrect(uint32 diff)
{
if (GetReviveQueueSize())
{
for (std::map<uint64, std::vector<uint64> >::iterator itr = m_ReviveQueue.begin(); itr != m_ReviveQueue.end(); ++itr)
for (std::map<ObjectGuid, GuidVector>::iterator itr = m_ReviveQueue.begin(); itr != m_ReviveQueue.end(); ++itr)
{
Creature* sh = nullptr;
for (std::vector<uint64>::const_iterator itr2 = (itr->second).begin(); itr2 != (itr->second).end(); ++itr2)
for (ObjectGuid const guid : itr->second)
{
Player* player = ObjectAccessor::FindPlayer(*itr2);
Player* player = ObjectAccessor::FindPlayer(guid);
if (!player)
continue;
@@ -348,9 +348,10 @@ inline void Battleground::_ProcessResurrect(uint32 diff)
// Resurrection visual
player->CastSpell(player, SPELL_RESURRECTION_VISUAL, true);
m_ResurrectQueue.push_back(*itr2);
m_ResurrectQueue.push_back(guid);
}
(itr->second).clear();
itr->second.clear();
}
m_ReviveQueue.clear();
@@ -362,15 +363,15 @@ inline void Battleground::_ProcessResurrect(uint32 diff)
}
else if (m_LastResurrectTime > 500) // Resurrect players only half a second later, to see spirit heal effect on NPC
{
for (std::vector<uint64>::const_iterator itr = m_ResurrectQueue.begin(); itr != m_ResurrectQueue.end(); ++itr)
for (ObjectGuid const guid : m_ResurrectQueue)
{
Player* player = ObjectAccessor::FindPlayer(*itr);
Player* player = ObjectAccessor::FindPlayer(guid);
if (!player)
continue;
player->ResurrectPlayer(1.0f);
player->CastSpell(player, 6962, true);
player->CastSpell(player, SPELL_SPIRIT_HEAL_MANA, true);
sObjectAccessor->ConvertCorpseForPlayer(*itr);
player->SpawnCorpseBones(false);
}
m_ResurrectQueue.clear();
}
@@ -557,7 +558,7 @@ inline void Battleground::_ProcessJoin(uint32 diff)
if (GetStatus() == STATUS_IN_PROGRESS)
{
for (ToBeTeleportedMap::const_iterator itr = m_ToBeTeleported.begin(); itr != m_ToBeTeleported.end(); ++itr)
if (Player* p = ObjectAccessor::GetObjectInOrOutOfWorld(itr->first, (Player*)nullptr))
if (Player* p = ObjectAccessor::FindConnectedPlayer(itr->first))
if (Player* t = ObjectAccessor::FindPlayer(itr->second))
{
if (!t->FindMap() || t->FindMap() != GetBgMap())
@@ -566,7 +567,7 @@ inline void Battleground::_ProcessJoin(uint32 diff)
p->SetSummonPoint(t->GetMapId(), t->GetPositionX(), t->GetPositionY(), t->GetPositionZ(), 15, true);
WorldPacket data(SMSG_SUMMON_REQUEST, 8 + 4 + 4);
data << uint64(t->GetGUID());
data << t->GetGUID();
data << uint32(t->GetZoneId());
data << uint32(15 * IN_MILLISECONDS);
p->GetSession()->SendPacket(&data);
@@ -1019,7 +1020,7 @@ void Battleground::EndBattleground(TeamId winnerTeamId)
BattlegroundScoreMap::const_iterator score = PlayerScores.find(player->GetGUID());
stmt->setUInt32(0, battlegroundId);
stmt->setUInt32(1, player->GetGUIDLow());
stmt->setUInt32(1, player->GetGUID().GetCounter());
stmt->setBool(2, bgTeamId == winnerTeamId);
stmt->setUInt32(3, score->second->GetKillingBlows());
stmt->setUInt32(4, score->second->GetDeaths());
@@ -1205,7 +1206,7 @@ void Battleground::AddPlayer(Player* player)
// score struct must be created in inherited class
uint64 guid = player->GetGUID();
ObjectGuid guid = player->GetGUID();
TeamId teamId = player->GetBgTeamId();
// Add to list/maps
@@ -1282,7 +1283,7 @@ void Battleground::AddOrSetPlayerToCorrectBgGroup(Player* player, TeamId teamId)
return;
}
uint64 playerGuid = player->GetGUID();
ObjectGuid playerGuid = player->GetGUID();
Group* group = GetBgRaid(teamId);
if (!group) // first player joined
{
@@ -1380,7 +1381,7 @@ void Battleground::ReadyMarkerClicked(Player* p)
{
if (!isArena() || GetStatus() >= STATUS_IN_PROGRESS || GetStartDelayTime() <= BG_START_DELAY_15S || (m_Events & BG_STARTING_EVENT_3) || p->IsSpectator())
return;
readyMarkerClickedSet.insert(p->GetGUIDLow());
readyMarkerClickedSet.insert(p->GetGUID());
uint32 count = readyMarkerClickedSet.size();
uint32 req = ArenaTeam::GetReqPlayersForType(GetArenaType());
p->GetSession()->SendNotification("You are marked as ready %u/%u", count, req);
@@ -1453,7 +1454,7 @@ void Battleground::UpdatePlayerScore(Player* player, uint32 type, uint32 value,
}
}
void Battleground::AddPlayerToResurrectQueue(uint64 npc_guid, uint64 player_guid)
void Battleground::AddPlayerToResurrectQueue(ObjectGuid npc_guid, ObjectGuid player_guid)
{
m_ReviveQueue[npc_guid].push_back(player_guid);
@@ -1466,26 +1467,26 @@ void Battleground::AddPlayerToResurrectQueue(uint64 npc_guid, uint64 player_guid
void Battleground::RemovePlayerFromResurrectQueue(Player* player)
{
for (std::map<uint64, std::vector<uint64> >::iterator itr = m_ReviveQueue.begin(); itr != m_ReviveQueue.end(); ++itr)
for (std::vector<uint64>::iterator itr2 = (itr->second).begin(); itr2 != (itr->second).end(); ++itr2)
for (std::map<ObjectGuid, GuidVector>::iterator itr = m_ReviveQueue.begin(); itr != m_ReviveQueue.end(); ++itr)
for (GuidVector::iterator itr2 = itr->second.begin(); itr2 != itr->second.end(); ++itr2)
if (*itr2 == player->GetGUID())
{
(itr->second).erase(itr2);
itr->second.erase(itr2);
player->RemoveAurasDueToSpell(SPELL_WAITING_FOR_RESURRECT);
return;
}
}
void Battleground::RelocateDeadPlayers(uint64 queueIndex)
void Battleground::RelocateDeadPlayers(ObjectGuid queueIndex)
{
// Those who are waiting to resurrect at this node are taken to the closest own node's graveyard
std::vector<uint64>& ghostList = m_ReviveQueue[queueIndex];
GuidVector& ghostList = m_ReviveQueue[queueIndex];
if (!ghostList.empty())
{
GraveyardStruct const* closestGrave = nullptr;
for (std::vector<uint64>::const_iterator itr = ghostList.begin(); itr != ghostList.end(); ++itr)
for (ObjectGuid const guid : ghostList)
{
Player* player = ObjectAccessor::FindPlayer(*itr);
Player* player = ObjectAccessor::FindPlayer(guid);
if (!player)
continue;
@@ -1495,6 +1496,7 @@ void Battleground::RelocateDeadPlayers(uint64 queueIndex)
if (closestGrave)
player->TeleportTo(GetMapId(), closestGrave->x, closestGrave->y, closestGrave->z, player->GetOrientation());
}
ghostList.clear();
}
}
@@ -1511,7 +1513,7 @@ bool Battleground::AddObject(uint32 type, uint32 entry, float x, float y, float
// and when loading it (in go::LoadFromDB()), a new guid would be assigned to the object, and a new object would be created
// So we must create it specific for this instance
GameObject* go = sObjectMgr->IsGameObjectStaticTransport(entry) ? new StaticTransport() : new GameObject();
if (!go->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT), entry, GetBgMap(),
if (!go->Create(map->GenerateLowGuid<HighGuid::GameObject>(), entry, GetBgMap(),
PHASEMASK_NORMAL, x, y, z, o, G3D::Quat(rotation0, rotation1, rotation2, rotation3), 100, goState))
{
LOG_ERROR("sql.sql", "Battleground::AddObject: cannot create gameobject (entry: %u) for BG (map: %u, instance id: %u)!",
@@ -1522,11 +1524,11 @@ bool Battleground::AddObject(uint32 type, uint32 entry, float x, float y, float
return false;
}
/*
uint32 guid = go->GetGUIDLow();
ObjectGuid::LowType spawnId = go->GetSpawnId();
// without this, UseButtonOrDoor caused the crash, since it tried to get go info from godata
// iirc that was changed, so adding to go data map is no longer required if that was the only function using godata from GameObject without checking if it existed
GameObjectData& data = sObjectMgr->NewGOData(guid);
GameObjectData& data = sObjectMgr->NewGOData(spawnId);
data.id = entry;
data.mapid = GetMapId();
@@ -1567,8 +1569,8 @@ void Battleground::DoorClose(uint32 type)
}
}
else
LOG_ERROR("server", "Battleground::DoorClose: door gameobject (type: %u, GUID: %u) not found for BG (map: %u, instance id: %u)!",
type, GUID_LOPART(BgObjects[type]), m_MapId, m_InstanceID);
LOG_ERROR("server", "Battleground::DoorClose: door gameobject (type: %u, %s) not found for BG (map: %u, instance id: %u)!",
type, BgObjects[type].ToString().c_str(), m_MapId, m_InstanceID);
}
void Battleground::DoorOpen(uint32 type)
@@ -1579,16 +1581,16 @@ void Battleground::DoorOpen(uint32 type)
obj->SetGoState(GO_STATE_ACTIVE);
}
else
LOG_ERROR("server", "Battleground::DoorOpen: door gameobject (type: %u, GUID: %u) not found for BG (map: %u, instance id: %u)!",
type, GUID_LOPART(BgObjects[type]), m_MapId, m_InstanceID);
LOG_ERROR("server", "Battleground::DoorOpen: door gameobject (type: %u, %s) not found for BG (map: %u, instance id: %u)!",
type, BgObjects[type].ToString().c_str(), m_MapId, m_InstanceID);
}
GameObject* Battleground::GetBGObject(uint32 type)
{
GameObject* obj = GetBgMap()->GetGameObject(BgObjects[type]);
if (!obj)
LOG_ERROR("server", "Battleground::GetBGObject: gameobject (type: %u, GUID: %u) not found for BG (map: %u, instance id: %u)!",
type, GUID_LOPART(BgObjects[type]), m_MapId, m_InstanceID);
LOG_ERROR("server", "Battleground::GetBGObject: gameobject (type: %u, %s) not found for BG (map: %u, instance id: %u)!",
type, BgObjects[type].ToString().c_str(), m_MapId, m_InstanceID);
return obj;
}
@@ -1596,8 +1598,8 @@ Creature* Battleground::GetBGCreature(uint32 type)
{
Creature* creature = GetBgMap()->GetCreature(BgCreatures[type]);
if (!creature)
LOG_ERROR("server", "Battleground::GetBGCreature: creature (type: %u, GUID: %u) not found for BG (map: %u, instance id: %u)!",
type, GUID_LOPART(BgCreatures[type]), m_MapId, m_InstanceID);
LOG_ERROR("server", "Battleground::GetBGCreature: creature (type: %u, %s) not found for BG (map: %u, instance id: %u)!",
type, BgCreatures[type].ToString().c_str(), m_MapId, m_InstanceID);
return creature;
}
@@ -1639,7 +1641,7 @@ Creature* Battleground::AddCreature(uint32 entry, uint32 type, float x, float y,
}
Creature* creature = new Creature();
if (!creature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, PHASEMASK_NORMAL, entry, 0, x, y, z, o))
if (!creature->Create(map->GenerateLowGuid<HighGuid::Unit>(), map, PHASEMASK_NORMAL, entry, 0, x, y, z, o))
{
LOG_ERROR("server", "Battleground::AddCreature: cannot create creature (entry: %u) for BG (map: %u, instance id: %u)!",
entry, m_MapId, m_InstanceID);
@@ -1687,13 +1689,14 @@ bool Battleground::DelCreature(uint32 type)
if (Creature* creature = GetBgMap()->GetCreature(BgCreatures[type]))
{
creature->AddObjectToRemoveList();
BgCreatures[type] = 0;
BgCreatures[type].Clear();
return true;
}
LOG_ERROR("server", "Battleground::DelCreature: creature (type: %u, GUID: %u) not found for BG (map: %u, instance id: %u)!",
type, GUID_LOPART(BgCreatures[type]), m_MapId, m_InstanceID);
BgCreatures[type] = 0;
LOG_ERROR("server", "Battleground::DelCreature: creature (type: %u, %s) not found for BG (map: %u, instance id: %u)!",
type, BgCreatures[type].ToString().c_str(), m_MapId, m_InstanceID);
BgCreatures[type].Clear();
return false;
}
@@ -1706,12 +1709,14 @@ bool Battleground::DelObject(uint32 type)
{
obj->SetRespawnTime(0); // not save respawn time
obj->Delete();
BgObjects[type] = 0;
BgObjects[type].Clear();
return true;
}
LOG_ERROR("server", "Battleground::DelObject: gameobject (type: %u, GUID: %u) not found for BG (map: %u, instance id: %u)!",
type, GUID_LOPART(BgObjects[type]), m_MapId, m_InstanceID);
BgObjects[type] = 0;
LOG_ERROR("server", "Battleground::DelObject: gameobject (type: %u, %s) not found for BG (map: %u, instance id: %u)!",
type, BgObjects[type].ToString().c_str(), m_MapId, m_InstanceID);
BgObjects[type].Clear();
return false;
}
@@ -1722,7 +1727,7 @@ bool Battleground::AddSpiritGuide(uint32 type, float x, float y, float z, float
if (Creature* creature = AddCreature(entry, type, x, y, z, o))
{
creature->setDeathState(DEAD);
creature->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT, creature->GetGUID());
creature->SetGuidValue(UNIT_FIELD_CHANNEL_OBJECT, creature->GetGUID());
// aura
// TODO: Fix display here
// creature->SetVisibleAura(0, SPELL_SPIRIT_HEAL_CHANNEL);
@@ -1878,7 +1883,7 @@ TeamId Battleground::GetOtherTeamId(TeamId teamId)
return teamId != TEAM_NEUTRAL ? (teamId == TEAM_ALLIANCE ? TEAM_HORDE : TEAM_ALLIANCE) : TEAM_NEUTRAL;
}
bool Battleground::IsPlayerInBattleground(uint64 guid) const
bool Battleground::IsPlayerInBattleground(ObjectGuid guid) const
{
BattlegroundPlayerMap::const_iterator itr = m_Players.find(guid);
if (itr != m_Players.end())
@@ -1916,13 +1921,15 @@ void Battleground::SetHoliday(bool is_holiday)
m_HonorMode = is_holiday ? BG_HOLIDAY : BG_NORMAL;
}
int32 Battleground::GetObjectType(uint64 guid)
int32 Battleground::GetObjectType(ObjectGuid guid)
{
for (uint32 i = 0; i < BgObjects.size(); ++i)
if (BgObjects[i] == guid)
return i;
LOG_ERROR("server", "Battleground::GetObjectType: player used gameobject (GUID: %u) which is not in internal data for BG (map: %u, instance id: %u), cheating?",
GUID_LOPART(guid), m_MapId, m_InstanceID);
LOG_ERROR("server", "Battleground::GetObjectType: player used gameobject (%s) which is not in internal data for BG (map: %u, instance id: %u), cheating?",
guid.ToString().c_str(), m_MapId, m_InstanceID);
return -1;
}