bool CPlayer::SendBattleGroundChat(ChatMsg msgtype, std::string message) { // Select distance to broadcast to. float distance = sWorld.getConfig(CONFIG_FLOAT_LISTEN_RANGE_SAY); if (msgtype == CHAT_MSG_YELL) sWorld.getConfig(CONFIG_FLOAT_LISTEN_RANGE_YELL); else if (msgtype == CHAT_MSG_EMOTE) sWorld.getConfig(CONFIG_FLOAT_LISTEN_RANGE_TEXTEMOTE); BattleGround* pBattleGround = GetBattleGround(); if (!pBattleGround || pBattleGround->isArena()) // Only fake chat in BG's. CFBG should not interfere with arenas. return false; for (auto& itr : pBattleGround->GetPlayers()) { if (Player* pPlayer = sObjectMgr.GetPlayer(itr.first)) { if (GetDistance2d(pPlayer->GetPositionX(), pPlayer->GetPositionY()) <= distance) { WorldPacket data(SMSG_MESSAGECHAT, 200); if (GetTeam() == pPlayer->GetTeam()) ChatHandler::BuildChatPacket(data, msgtype, message.c_str(), LANG_UNIVERSAL, GetChatTag(), GetObjectGuid(), GetName()); else if (msgtype != CHAT_MSG_EMOTE) ChatHandler::BuildChatPacket(data, msgtype, message.c_str(), pPlayer->GetOTeam() == ALLIANCE ? LANG_ORCISH : LANG_COMMON, GetChatTag(), GetObjectGuid(), GetName()); pPlayer->GetSession()->SendPacket(&data); } } } return true; }
void CPlayer::RecachePlayersFromBG() { BattleGround* bg = GetBattleGround(); if (!bg) return; for (auto& itr : bg->GetPlayers()) { if (Player* player = sObjectMgr.GetPlayer(itr.first)) { if (!player->ToCPlayer()->NativeTeam()) { // Erase bg players from source player cache WorldPacket data(SMSG_INVALIDATE_PLAYER, 8); data << player->GetObjectGuid(); GetSession()->SendPacket(&data); // Send bg player data to source player data = player->ToCPlayer()->BuildNameQuery(); GetSession()->SendPacket(&data); } if (!NativeTeam()) { // Erase source player from bg players cache WorldPacket data(SMSG_INVALIDATE_PLAYER, 8); data << GetObjectGuid(); player->GetSession()->SendPacket(&data); // Send new source data to bg players data = BuildNameQuery(); player->GetSession()->SendPacket(&data); } } else { // Couldn't find bgplayer, recache him for source player in case he logs in again. WorldPacket data(SMSG_INVALIDATE_PLAYER, 8); data << itr.first; GetSession()->SendPacket(&data); } } }