Skip to content
This repository has been archived by the owner on Jul 27, 2020. It is now read-only.

Commit

Permalink
Core/ObjectMgr: Remove GetPlayer function & the double use of singlet…
Browse files Browse the repository at this point in the history
…ons.

original patch by: Spp-

Signed-off-by: bootz <bootz@projectskyfire.org>
  • Loading branch information
Bootz committed Oct 3, 2012
1 parent b0d2d08 commit 0971a03
Show file tree
Hide file tree
Showing 35 changed files with 182 additions and 185 deletions.
8 changes: 4 additions & 4 deletions src/server/game/AuctionHouse/AuctionHouseMgr.cpp
Expand Up @@ -116,7 +116,7 @@ void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry *auction)
uint32 bidder_accId = 0;
uint32 bidder_security = 0;
uint64 bidder_guid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER);
Player *bidder = sObjectMgr->GetPlayer(bidder_guid);
Player *bidder = ObjectAccessor::FindPlayer(bidder_guid);
// data for gm.log
if (sWorld->getConfig(CONFIG_GM_LOG_TRADE))
{
Expand Down Expand Up @@ -182,7 +182,7 @@ void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry *auction)
void AuctionHouseMgr::SendAuctionSalePendingMail(AuctionEntry * auction)
{
uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER);
Player *owner = sObjectMgr->GetPlayer(owner_guid);
Player *owner = ObjectAccessor::FindPlayer(owner_guid);
uint32 owner_accId = sObjectMgr->GetPlayerAccountIdByGUID(owner_guid);
// owner exist (online or offline)
if (owner || owner_accId)
Expand Down Expand Up @@ -214,7 +214,7 @@ void AuctionHouseMgr::SendAuctionSalePendingMail(AuctionEntry * auction)
void AuctionHouseMgr::SendAuctionSuccessfulMail(AuctionEntry * auction)
{
uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER);
Player *owner = sObjectMgr->GetPlayer(owner_guid);
Player *owner = ObjectAccessor::FindPlayer(owner_guid);
uint32 owner_accId = sObjectMgr->GetPlayerAccountIdByGUID(owner_guid);
// owner exist
if (owner || owner_accId)
Expand Down Expand Up @@ -256,7 +256,7 @@ void AuctionHouseMgr::SendAuctionExpiredMail(AuctionEntry * auction)
return;

uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER);
Player *owner = sObjectMgr->GetPlayer(owner_guid);
Player *owner = ObjectAccessor::FindPlayer(owner_guid);
uint32 owner_accId = sObjectMgr->GetPlayerAccountIdByGUID(owner_guid);
// owner exist
if (owner || owner_accId)
Expand Down
18 changes: 9 additions & 9 deletions src/server/game/Battlegrounds/ArenaTeam.cpp
Expand Up @@ -57,7 +57,7 @@ ArenaTeam::~ArenaTeam()

bool ArenaTeam::Create(uint64 captainGuid, uint32 type, std::string arenaTeamName)
{
if (!sObjectMgr->GetPlayer(captainGuid)) // player not exist
if (!ObjectAccessor::FindPlayer(captainGuid)) // player not exist
return false;
if (sObjectMgr->GetArenaTeamByName(arenaTeamName)) // arena team with this name already exist
return false;
Expand Down Expand Up @@ -98,7 +98,7 @@ bool ArenaTeam::AddMember(const uint64& playerGuid)
if (GetMembersSize() >= GetType() * 2)
return false;

Player *pl = sObjectMgr->GetPlayer(playerGuid);
Player *pl = ObjectAccessor::FindPlayer(playerGuid);
if (pl)
{
if (pl->GetArenaTeamId(GetSlot()))
Expand Down Expand Up @@ -249,7 +249,7 @@ bool ArenaTeam::LoadMembersFromDB(QueryResult_AutoPtr arenaTeamMembersResult)
void ArenaTeam::SetCaptain(const uint64& guid)
{
// disable remove/promote buttons
Player *oldcaptain = sObjectMgr->GetPlayer(GetCaptain());
Player *oldcaptain = ObjectAccessor::FindPlayer(GetCaptain());
if (oldcaptain)
oldcaptain->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_MEMBER, 1);

Expand All @@ -260,7 +260,7 @@ void ArenaTeam::SetCaptain(const uint64& guid)
CharacterDatabase.PExecute("UPDATE arena_team SET captainguid = '%u' WHERE arenateamid = '%u'", GUID_LOPART(guid), GetId());

// enable remove/promote buttons
if (Player *newcaptain = sObjectMgr->GetPlayer(guid))
if (Player *newcaptain = ObjectAccessor::FindPlayer(guid))
{
newcaptain->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_MEMBER, 0);
sLog->outArena("Player: %s [GUID: %u] promoted player: %s [GUID: %u] to leader of arena team [Id: %u] [Type: %u].", oldcaptain->GetName(), oldcaptain->GetGUIDLow(), newcaptain->GetName(), newcaptain->GetGUIDLow(), GetId(), GetType());
Expand All @@ -276,7 +276,7 @@ void ArenaTeam::DelMember(uint64 guid)
break;
}

if (Player* player = sObjectMgr->GetPlayer(guid))
if (Player* player = ObjectAccessor::FindPlayer(guid))
{
player->SetInArenaTeam(0, GetSlot());
player->GetSession()->SendArenaTeamCommandResult(ERR_ARENA_TEAM_QUIT_S, GetName(), "", 0);
Expand Down Expand Up @@ -322,7 +322,7 @@ void ArenaTeam::Roster(WorldSession *session)

for (MemberList::const_iterator itr = m_members.begin(); itr != m_members.end(); ++itr)
{
pl = sObjectMgr->GetPlayer(itr->guid);
pl = ObjectAccessor::FindPlayer(itr->guid);

data << uint64(itr->guid); // guid
data << uint8((pl ? 1 : 0)); // online flag
Expand Down Expand Up @@ -375,7 +375,7 @@ void ArenaTeam::NotifyStatsChanged()
// updates arena team stats for every member of the team (not only the ones who participated!)
for (MemberList::const_iterator itr = m_members.begin(); itr != m_members.end(); ++itr)
{
Player * plr = sObjectMgr->GetPlayer(itr->guid);
Player * plr = ObjectAccessor::FindPlayer(itr->guid);
if (plr)
Stats(plr->GetSession());
}
Expand Down Expand Up @@ -448,7 +448,7 @@ void ArenaTeam::BroadcastPacket(WorldPacket *packet)
{
for (MemberList::const_iterator itr = m_members.begin(); itr != m_members.end(); ++itr)
{
Player* player = sObjectMgr->GetPlayer(itr->guid);
Player* player = ObjectAccessor::FindPlayer(itr->guid);
if (player)
player->GetSession()->SendPacket(packet);
}
Expand Down Expand Up @@ -708,7 +708,7 @@ void ArenaTeam::FinishWeek()
bool ArenaTeam::IsFighting() const
{
for (MemberList::const_iterator itr = m_members.begin(); itr != m_members.end(); ++itr)
if (Player *p = sObjectMgr->GetPlayer(itr->guid))
if (Player *p = ObjectAccessor::FindPlayer(itr->guid))
if (p->GetMap()->IsBattleArena())
return true;
return false;
Expand Down
46 changes: 23 additions & 23 deletions src/server/game/Battlegrounds/Battleground.cpp
Expand Up @@ -247,7 +247,7 @@ void Battleground::Update(time_t diff)
{
for (std::map<uint64, uint8>::iterator itr = m_RemovedPlayers.begin(); itr != m_RemovedPlayers.end(); ++itr)
{
Player *plr = sObjectMgr->GetPlayer(itr->first);
Player *plr = ObjectAccessor::FindPlayer(itr->first);
switch (itr->second)
{
//following code is handled by event:
Expand Down Expand Up @@ -281,7 +281,7 @@ void Battleground::Update(time_t diff)
{
for (std::map<uint64, BattlegroundPlayer>::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
{
Player *plr = sObjectMgr->GetPlayer(itr->first);
Player *plr = ObjectAccessor::FindPlayer(itr->first);
itr->second.LastOnlineTime += diff;

if (plr)
Expand Down Expand Up @@ -311,7 +311,7 @@ void Battleground::Update(time_t diff)
Creature *sh = NULL;
for (std::vector<uint64>::iterator itr2 = (itr->second).begin(); itr2 != (itr->second).end(); ++itr2)
{
Player *plr = sObjectMgr->GetPlayer(*itr2);
Player *plr = ObjectAccessor::FindPlayer(*itr2);
if (!plr)
continue;

Expand Down Expand Up @@ -340,7 +340,7 @@ void Battleground::Update(time_t diff)
{
for (std::vector<uint64>::iterator itr = m_ResurrectQueue.begin(); itr != m_ResurrectQueue.end(); ++itr)
{
Player *plr = sObjectMgr->GetPlayer(*itr);
Player *plr = ObjectAccessor::FindPlayer(*itr);
if (!plr)
continue;
plr->ResurrectPlayer(1.0f);
Expand Down Expand Up @@ -447,7 +447,7 @@ void Battleground::Update(time_t diff)
if (isArena())
{
for (BattlegroundPlayerMap::const_iterator itr = GetPlayers().begin(); itr != GetPlayers().end(); ++itr)
if (Player *plr = sObjectMgr->GetPlayer(itr->first))
if (Player *plr = ObjectAccessor::FindPlayer(itr->first))
plr->RemoveAurasDueToSpell(SPELL_ARENA_PREPARATION);

CheckArenaWinConditions();
Expand All @@ -457,7 +457,7 @@ void Battleground::Update(time_t diff)
PlaySoundToAll(SOUND_BG_START);

for (BattlegroundPlayerMap::const_iterator itr = GetPlayers().begin(); itr != GetPlayers().end(); ++itr)
if (Player* plr = sObjectMgr->GetPlayer(itr->first))
if (Player* plr = ObjectAccessor::FindPlayer(itr->first))
plr->RemoveAurasDueToSpell(SPELL_PREPARATION);

//Announce BG starting
Expand All @@ -474,7 +474,7 @@ void Battleground::Update(time_t diff)
{
for (std::map<uint64, BattlegroundPlayer>::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
{
if (Player* plr = sObjectMgr->GetPlayer(itr->first))
if (Player* plr = ObjectAccessor::FindPlayer(itr->first))
{
float x, y, z, o;
uint32 team = plr->GetBGTeam();
Expand Down Expand Up @@ -528,7 +528,7 @@ void Battleground::SendPacketToAll(WorldPacket *packet)
if (itr->second.LastOnlineTime)
continue;

Player *plr = sObjectMgr->GetPlayer(itr->first);
Player *plr = ObjectAccessor::FindPlayer(itr->first);
if (plr)
plr->GetSession()->SendPacket(packet);
else
Expand All @@ -543,7 +543,7 @@ void Battleground::SendPacketToTeam(uint32 TeamID, WorldPacket *packet, Player *
if (itr->second.LastOnlineTime)
continue;

Player *plr = sObjectMgr->GetPlayer(itr->first);
Player *plr = ObjectAccessor::FindPlayer(itr->first);

if (!plr)
{
Expand Down Expand Up @@ -578,7 +578,7 @@ void Battleground::PlaySoundToTeam(uint32 SoundID, uint32 TeamID)
if (itr->second.LastOnlineTime)
continue;

Player *plr = sObjectMgr->GetPlayer(itr->first);
Player *plr = ObjectAccessor::FindPlayer(itr->first);

if (!plr)
{
Expand All @@ -604,7 +604,7 @@ void Battleground::CastSpellOnTeam(uint32 SpellID, uint32 TeamID)
if (itr->second.LastOnlineTime)
continue;

Player *plr = sObjectMgr->GetPlayer(itr->first);
Player *plr = ObjectAccessor::FindPlayer(itr->first);

if (!plr)
{
Expand All @@ -628,7 +628,7 @@ void Battleground::YellToAll(Creature* creature, const char* text, uint32 langua
continue;

WorldPacket data(SMSG_MESSAGECHAT, 200);
Player *plr = sObjectMgr->GetPlayer(itr->first);
Player *plr = ObjectAccessor::FindPlayer(itr->first);
if (!plr)
{
sLog->outError("Battleground: Player (GUID: %u) not found!", GUID_LOPART(itr->first));
Expand All @@ -646,7 +646,7 @@ void Battleground::RewardHonorToTeam(uint32 Honor, uint32 TeamID)
if (itr->second.LastOnlineTime)
continue;

Player *plr = sObjectMgr->GetPlayer(itr->first);
Player *plr = ObjectAccessor::FindPlayer(itr->first);

if (!plr)
{
Expand Down Expand Up @@ -674,7 +674,7 @@ void Battleground::RewardReputationToTeam(uint32 faction_id, uint32 Reputation,
if (itr->second.LastOnlineTime)
continue;

Player *plr = sObjectMgr->GetPlayer(itr->first);
Player *plr = ObjectAccessor::FindPlayer(itr->first);

if (!plr)
{
Expand Down Expand Up @@ -772,7 +772,7 @@ void Battleground::EndBattleground(uint32 winner)
sLog->outArena("Arena match Type: %u for Team1Id: %u - Team2Id: %u ended. WinnerTeamId: %u. Winner rating: %u, Loser rating: %u. RatingChange: %i.", m_ArenaType, m_ArenaTeamIds[BG_TEAM_ALLIANCE], m_ArenaTeamIds[BG_TEAM_HORDE], winner_arena_team->GetId(), winner_rating, loser_rating, winner_change);
if (sWorld->getConfig(CONFIG_ARENA_LOG_EXTENDED_INFO))
for (Battleground::BattlegroundScoreMap::const_iterator itr = GetPlayerScoresBegin();itr !=GetPlayerScoresEnd(); ++itr)
if (Player* player = sObjectMgr->GetPlayer(itr->first))
if (Player* player = ObjectAccessor::FindPlayer(itr->first))
sLog->outArena("Statistics for %s (GUID: " UI64FMTD ", Team: %d, IP: %s): %u damage, %u healing, %u killing blows", player->GetName(), itr->first, player->GetArenaTeamId(m_ArenaType == 5 ? 2 : m_ArenaType == 3), player->GetSession()->GetRemoteAddress().c_str(), itr->second->DamageDone, itr->second->HealingDone, itr->second->KillingBlows);
}
else
Expand All @@ -791,7 +791,7 @@ void Battleground::EndBattleground(uint32 winner)

for (std::map<uint64, BattlegroundPlayer>::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
{
Player *plr = sObjectMgr->GetPlayer(itr->first);
Player *plr = ObjectAccessor::FindPlayer(itr->first);
uint32 team = itr->second.Team;

if (!plr)
Expand Down Expand Up @@ -1041,7 +1041,7 @@ void Battleground::RemovePlayerAtLeave(uint64 guid, bool Transport, bool SendPac

RemovePlayerFromResurrectQueue(guid);

Player *plr = sObjectMgr->GetPlayer(guid);
Player *plr = ObjectAccessor::FindPlayer(guid);

// should remove spirit of redemption
if (plr && plr->HasAuraType(SPELL_AURA_SPIRIT_OF_REDEMPTION))
Expand Down Expand Up @@ -1424,7 +1424,7 @@ void Battleground::AddPlayerToResurrectQueue(uint64 npc_guid, uint64 player_guid
{
m_ReviveQueue[npc_guid].push_back(player_guid);

Player *plr = sObjectMgr->GetPlayer(player_guid);
Player *plr = ObjectAccessor::FindPlayer(player_guid);
if (!plr)
return;

Expand All @@ -1447,7 +1447,7 @@ void Battleground::RemovePlayerFromResurrectQueue(uint64 player_guid)
{
(itr->second).erase(itr2);

Player *plr = sObjectMgr->GetPlayer(player_guid);
Player *plr = ObjectAccessor::FindPlayer(player_guid);
if (!plr)
return;

Expand Down Expand Up @@ -1805,7 +1805,7 @@ void Battleground::HandleKillPlayer(Player* player, Player* killer)

for (std::map<uint64, BattlegroundPlayer>::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
{
Player *plr = sObjectMgr->GetPlayer(itr->first);
Player *plr = ObjectAccessor::FindPlayer(itr->first);

if (!plr || plr == killer)
continue;
Expand Down Expand Up @@ -1848,7 +1848,7 @@ void Battleground::PlayerRelogin(uint64 guid)
if (GetStatus() != STATUS_WAIT_LEAVE)
return;

Player *plr = sObjectMgr->GetPlayer(guid);
Player *plr = ObjectAccessor::FindPlayer(guid);
if (!plr)
{
sLog->outError("Battleground: Player (GUID: %u) not found!", GUID_LOPART(guid));
Expand All @@ -1874,7 +1874,7 @@ uint32 Battleground::GetAlivePlayersCountByTeam(uint32 Team) const
{
if (itr->second.Team == Team)
{
Player * pl = sObjectMgr->GetPlayer(itr->first);
Player * pl = ObjectAccessor::FindPlayer(itr->first);
if (pl && pl->isAlive() && !pl->HasByteFlag(UNIT_FIELD_BYTES_2, 3, FORM_SPIRITOFREDEMPTION))
++count;
}
Expand Down Expand Up @@ -1924,7 +1924,7 @@ void Battleground::Announce()
uint32 queue_id = 0;

for (std::map<uint64, BattlegroundPlayer>::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
if (Player *plr = sObjectMgr->GetPlayer(itr->first))
if (Player *plr = ObjectAccessor::FindPlayer(itr->first))
queue_id = plr->GetBattlegroundQueueIdFromLevel();

char const* bgName = GetName();
Expand Down

0 comments on commit 0971a03

Please sign in to comment.