void BattleGround::RemovePlayerAtLeave(uint64 guid, bool Transport, bool SendPacket) { // Remove from lists/maps std::map<uint64, BattleGroundPlayer>::iterator itr = m_Players.find(guid); if(itr != m_Players.end()) { UpdatePlayersCountByTeam(itr->second.Team, true); // -1 player m_Players.erase(itr); } std::map<uint64, BattleGroundScore*>::iterator itr2 = m_PlayerScores.find(guid); if(itr2 != m_PlayerScores.end()) { delete itr2->second; // delete player's score m_PlayerScores.erase(itr2); } RemovePlayerFromResurrectQueue(guid); Player *plr = objmgr.GetPlayer(guid); if(plr && !plr->isAlive()) // resurrect on exit { plr->ResurrectPlayer(1.0f); plr->SpawnCorpseBones(); } RemovePlayer(plr, guid); // BG subclass specific code if(plr) { plr->ClearAfkReports(); if(isArena()) { if(!sWorld.IsFFAPvPRealm()) plr->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_FFA_PVP); } WorldPacket data; if(SendPacket) { sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, this, plr->GetTeam(), plr->GetBattleGroundQueueIndex(m_TypeID), STATUS_NONE, 0, 0); plr->GetSession()->SendPacket(&data); } // this call is important, because player, when joins to battleground, this method is not called, so it must be called when leaving bg plr->RemoveBattleGroundQueueId(m_TypeID); DecreaseInvitedCount(plr->GetTeam()); //we should update battleground queue, but only if bg isn't ending if (GetQueueType() < MAX_BATTLEGROUND_QUEUES) sBattleGroundMgr.m_BattleGroundQueues[GetTypeID()].Update(GetTypeID(), GetQueueType()); if(!plr->GetBattleGroundId()) return; Group * group = plr->GetGroup(); // remove from raid group if exist if(group && group == GetBgRaid(plr->GetTeam())) { if(!group->RemoveMember(guid, 0)) // group was disbanded { SetBgRaid(plr->GetTeam(), NULL); delete group; } } // Do next only if found in battleground plr->SetBattleGroundId(0); // We're not in BG. // Let others know sBattleGroundMgr.BuildPlayerLeftBattleGroundPacket(&data, plr); SendPacketToTeam(plr->GetTeam(), &data, plr, false); if(Transport) { plr->TeleportTo(plr->GetBattleGroundEntryPointMap(), plr->GetBattleGroundEntryPointX(), plr->GetBattleGroundEntryPointY(), plr->GetBattleGroundEntryPointZ(), plr->GetBattleGroundEntryPointO()); //sLog.outDetail("BATTLEGROUND: Sending %s to %f,%f,%f,%f", pl->GetName(), x,y,z,O); } // Log sLog.outDetail("BATTLEGROUND: Removed player %s from BattleGround.", plr->GetName()); } /// there will be code which will add battleground to BGFreeSlotQueue , when battleground instance will exist // we always should check if BG is in that queue before adding.. if(!GetPlayersSize()) { Reset(); } }
void BattleGround::RemovePlayerAtLeave(uint64 guid, bool Transport, bool SendPacket) { uint32 team = GetPlayerTeam(guid); bool participant = false; // Remove from lists/maps std::map<uint64, BattleGroundPlayer>::iterator itr = m_Players.find(guid); if(itr != m_Players.end()) { UpdatePlayersCountByTeam(team, true); // -1 player m_Players.erase(itr); // check if the player was a participant of the match, or only entered through gm command (goname) participant = true; } std::map<uint64, BattleGroundScore*>::iterator itr2 = m_PlayerScores.find(guid); if(itr2 != m_PlayerScores.end()) { delete itr2->second; // delete player's score m_PlayerScores.erase(itr2); } RemovePlayerFromResurrectQueue(guid); Player *plr = objmgr.GetPlayer(guid); // should remove spirit of redemption if(plr && plr->HasAuraType(SPELL_AURA_SPIRIT_OF_REDEMPTION)) plr->RemoveSpellsCausingAura(SPELL_AURA_MOD_SHAPESHIFT); if(plr && !plr->isAlive()) // resurrect on exit { plr->ResurrectPlayer(1.0f); plr->SpawnCorpseBones(); } RemovePlayer(plr, guid); // BG subclass specific code if(plr) { plr->ClearAfkReports(); if(participant) // if the player was a match participant, remove auras, calc rating, update queue { if(!team) team = plr->GetTeam(); uint32 bgTypeId = GetTypeID(); uint32 bgQueueTypeId = sBattleGroundMgr.BGQueueTypeId(GetTypeID()); WorldPacket data; if(SendPacket) { sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, this, team, plr->GetBattleGroundQueueIndex(bgQueueTypeId), STATUS_NONE, 0, 0); plr->GetSession()->SendPacket(&data); } // this call is important, because player, when joins to battleground, this method is not called, so it must be called when leaving bg plr->RemoveBattleGroundQueueId(bgQueueTypeId); DecreaseInvitedCount(team); //we should update battleground queue, but only if bg isn't ending if (GetQueueType() < MAX_BATTLEGROUND_QUEUES) sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].Update(bgTypeId, GetQueueType()); Group * group = plr->GetGroup(); // remove from raid group if exist if(group && group == GetBgRaid(team)) { if(!group->RemoveMember(guid, 0)) // group was disbanded { SetBgRaid(team, NULL); delete group; } } // Let others know sBattleGroundMgr.BuildPlayerLeftBattleGroundPacket(&data, plr); SendPacketToTeam(team, &data, plr, false); } // Do next only if found in battleground plr->SetBattleGroundId(0); // We're not in BG. // reset destination bg team plr->SetBGTeam(0); if(Transport) { plr->TeleportTo(plr->GetBattleGroundEntryPointMap(), plr->GetBattleGroundEntryPointX(), plr->GetBattleGroundEntryPointY(), plr->GetBattleGroundEntryPointZ(), plr->GetBattleGroundEntryPointO()); } // Log sLog.outDetail("BATTLEGROUND: Removed player %s from BattleGround.", plr->GetName()); } if(!GetPlayersSize() && !GetInvitedCount(HORDE) && !GetInvitedCount(ALLIANCE)) { // if no players left AND no invitees left, set this bg to delete in next update // direct deletion could cause crashes m_SetDeleteThis = true; // return to prevent addition to freeslotqueue return; } // a player exited the battleground, so there are free slots. add to queue this->AddToBGFreeSlotQueue(); }