diff options
Diffstat (limited to 'src/server/game/Battlegrounds/Battleground.cpp')
-rw-r--r-- | src/server/game/Battlegrounds/Battleground.cpp | 214 |
1 files changed, 13 insertions, 201 deletions
diff --git a/src/server/game/Battlegrounds/Battleground.cpp b/src/server/game/Battlegrounds/Battleground.cpp index a0d35d4c742..d17be29211a 100644 --- a/src/server/game/Battlegrounds/Battleground.cpp +++ b/src/server/game/Battlegrounds/Battleground.cpp @@ -17,8 +17,6 @@ */ #include "ArenaScore.h" -#include "ArenaTeam.h" -#include "ArenaTeamMgr.h" #include "Battleground.h" #include "BattlegroundMgr.h" #include "BattlegroundScore.h" @@ -36,7 +34,6 @@ #include "SpellAuraEffects.h" #include "SpellAuras.h" #include "Util.h" -#include "World.h" #include "WorldPacket.h" namespace Trinity @@ -127,7 +124,7 @@ Battleground::Battleground() m_InvitedHorde = 0; m_ArenaType = 0; m_IsArena = false; - m_Winner = 2; + _winnerTeamId = BG_TEAM_NEUTRAL; m_StartTime = 0; m_ResetStatTimer = 0; m_ValidStartPositionTimer = 0; @@ -249,8 +246,7 @@ void Battleground::Update(uint32 diff) { if (GetStartTime() >= 47 * MINUTE*IN_MILLISECONDS) { - UpdateArenaWorldState(); - CheckArenaAfterTimerConditions(); + EndBattleground(0); return; } } @@ -523,7 +519,7 @@ inline void Battleground::_ProcessJoin(uint32 diff) } } - CheckArenaWinConditions(); + CheckWinConditions(); } else { @@ -564,7 +560,7 @@ inline void Battleground::_ProcessLeave(uint32 diff) } } -inline Player* Battleground::_GetPlayer(uint64 guid, bool offlineRemove, char const* context) const +Player* Battleground::_GetPlayer(uint64 guid, bool offlineRemove, char const* context) const { Player* player = NULL; if (!offlineRemove) @@ -577,17 +573,7 @@ inline Player* Battleground::_GetPlayer(uint64 guid, bool offlineRemove, char co return player; } -inline Player* Battleground::_GetPlayer(BattlegroundPlayerMap::iterator itr, char const* context) -{ - return _GetPlayer(itr->first, itr->second.OfflineRemoveTime, context); -} - -inline Player* Battleground::_GetPlayer(BattlegroundPlayerMap::const_iterator itr, char const* context) const -{ - return _GetPlayer(itr->first, itr->second.OfflineRemoveTime, context); -} - -inline Player* Battleground::_GetPlayerForTeam(uint32 teamId, BattlegroundPlayerMap::const_iterator itr, char const* context) const +Player* Battleground::_GetPlayerForTeam(uint32 teamId, BattlegroundPlayerMap::const_iterator itr, char const* context) const { Player* player = _GetPlayer(itr, context); if (player) @@ -713,18 +699,6 @@ void Battleground::EndBattleground(uint32 winner) { RemoveFromBGFreeSlotQueue(); - ArenaTeam* winnerArenaTeam = NULL; - ArenaTeam* loserArenaTeam = NULL; - - uint32 loserTeamRating = 0; - uint32 loserMatchmakerRating = 0; - int32 loserChange = 0; - int32 loserMatchmakerChange = 0; - uint32 winnerTeamRating = 0; - uint32 winnerMatchmakerRating = 0; - int32 winnerChange = 0; - int32 winnerMatchmakerChange = 0; - int32 winmsg_id = 0; if (winner == ALLIANCE) @@ -733,7 +707,7 @@ void Battleground::EndBattleground(uint32 winner) PlaySoundToAll(SOUND_ALLIANCE_WINS); // alliance wins sound - SetWinner(WINNER_ALLIANCE); + SetWinner(BG_TEAM_ALLIANCE); } else if (winner == HORDE) { @@ -741,92 +715,26 @@ void Battleground::EndBattleground(uint32 winner) PlaySoundToAll(SOUND_HORDE_WINS); // horde wins sound - SetWinner(WINNER_HORDE); + SetWinner(BG_TEAM_HORDE); } else { - SetWinner(3); // weird + SetWinner(BG_TEAM_NEUTRAL); } SetStatus(STATUS_WAIT_LEAVE); //we must set it this way, because end time is sent in packet! m_EndTime = TIME_TO_AUTOREMOVE; - // arena rating calculation - if (isArena() && isRated()) - { - winnerArenaTeam = sArenaTeamMgr->GetArenaTeamById(GetArenaTeamIdForTeam(winner)); - loserArenaTeam = sArenaTeamMgr->GetArenaTeamById(GetArenaTeamIdForTeam(GetOtherTeam(winner))); - - if (winnerArenaTeam && loserArenaTeam && winnerArenaTeam != loserArenaTeam) - { - loserTeamRating = loserArenaTeam->GetRating(); - loserMatchmakerRating = GetArenaMatchmakerRating(GetOtherTeam(winner)); - winnerTeamRating = winnerArenaTeam->GetRating(); - winnerMatchmakerRating = GetArenaMatchmakerRating(winner); - - if (winner != WINNER_NONE) - { - winnerMatchmakerChange = winnerArenaTeam->WonAgainst(winnerMatchmakerRating, loserMatchmakerRating, winnerChange); - loserMatchmakerChange = loserArenaTeam->LostAgainst(loserMatchmakerRating, winnerMatchmakerRating, loserChange); - TC_LOG_DEBUG("bg.arena", "match Type: %u --- Winner: old rating: %u, rating gain: %d, old MMR: %u, MMR gain: %d --- Loser: old rating: %u, rating loss: %d, old MMR: %u, MMR loss: %d ---", m_ArenaType, winnerTeamRating, winnerChange, winnerMatchmakerRating, - winnerMatchmakerChange, loserTeamRating, loserChange, loserMatchmakerRating, loserMatchmakerChange); - SetArenaMatchmakerRating(winner, winnerMatchmakerRating + winnerMatchmakerChange); - SetArenaMatchmakerRating(GetOtherTeam(winner), loserMatchmakerRating + loserMatchmakerChange); - - // bg team that the client expects is different to TeamId - // alliance 1, horde 0 - uint8 winnerTeam = winner == ALLIANCE ? WINNER_ALLIANCE : WINNER_HORDE; - uint8 loserTeam = winner == ALLIANCE ? WINNER_HORDE : WINNER_ALLIANCE; - - _arenaTeamScores[winnerTeam].Assign(winnerChange, winnerMatchmakerRating, winnerArenaTeam->GetName()); - _arenaTeamScores[loserTeam].Assign(loserChange, loserMatchmakerRating, loserArenaTeam->GetName()); - - TC_LOG_DEBUG("bg.arena", "Arena match Type: %u for Team1Id: %u - Team2Id: %u ended. WinnerTeamId: %u. Winner rating: +%d, Loser rating: %d", m_ArenaType, m_ArenaTeamIds[TEAM_ALLIANCE], m_ArenaTeamIds[TEAM_HORDE], winnerArenaTeam->GetId(), winnerChange, loserChange); - if (sWorld->getBoolConfig(CONFIG_ARENA_LOG_EXTENDED_INFO)) - for (auto const& score : PlayerScores) - if (Player* player = ObjectAccessor::FindPlayer(MAKE_NEW_GUID(score.first, 0, HIGHGUID_PLAYER))) - { - TC_LOG_DEBUG("bg.arena", "Statistics match Type: %u for %s (GUID: %u, Team: %d, IP: %s): %s", - m_ArenaType, player->GetName().c_str(), score.first, player->GetArenaTeamId(m_ArenaType == 5 ? 2 : m_ArenaType == 3), - player->GetSession()->GetRemoteAddress().c_str(), score.second->ToString().c_str()); - } - } - // Deduct 16 points from each teams arena-rating if there are no winners after 45+2 minutes - else - { - _arenaTeamScores[WINNER_ALLIANCE].Assign(ARENA_TIMELIMIT_POINTS_LOSS, winnerMatchmakerRating, winnerArenaTeam->GetName()); - _arenaTeamScores[WINNER_HORDE].Assign(ARENA_TIMELIMIT_POINTS_LOSS, loserMatchmakerRating, loserArenaTeam->GetName()); - - winnerArenaTeam->FinishGame(ARENA_TIMELIMIT_POINTS_LOSS); - loserArenaTeam->FinishGame(ARENA_TIMELIMIT_POINTS_LOSS); - } - } - } - WorldPacket pvpLogData; BuildPvPLogDataPacket(pvpLogData); BattlegroundQueueTypeId bgQueueTypeId = BattlegroundMgr::BGQueueTypeId(GetTypeID(), GetArenaType()); - uint8 aliveWinners = GetAlivePlayersCountByTeam(winner); for (BattlegroundPlayerMap::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr) { uint32 team = itr->second.Team; - if (itr->second.OfflineRemoveTime) - { - //if rated arena match - make member lost! - if (isArena() && isRated() && winnerArenaTeam && loserArenaTeam && winnerArenaTeam != loserArenaTeam) - { - if (team == winner) - winnerArenaTeam->OfflineMemberLost(itr->first, loserMatchmakerRating, winnerMatchmakerChange); - else - loserArenaTeam->OfflineMemberLost(itr->first, winnerMatchmakerRating, loserMatchmakerChange); - } - continue; - } - Player* player = _GetPlayer(itr, "EndBattleground"); if (!player) continue; @@ -835,10 +743,6 @@ void Battleground::EndBattleground(uint32 winner) if (player->HasAuraType(SPELL_AURA_SPIRIT_OF_REDEMPTION)) player->RemoveAurasByType(SPELL_AURA_MOD_SHAPESHIFT); - // Last standing - Rated 5v5 arena & be solely alive player - if (team == winner && isArena() && isRated() && GetArenaType() == ARENA_TYPE_5v5 && aliveWinners == 1 && player->IsAlive()) - player->CastSpell(player, SPELL_THE_LAST_STANDING, true); - if (!player->IsAlive()) { player->ResurrectPlayer(1.0f); @@ -851,27 +755,6 @@ void Battleground::EndBattleground(uint32 winner) player->getHostileRefManager().deleteReferences(); } - // per player calculation - if (isArena() && isRated() && winnerArenaTeam && loserArenaTeam && winnerArenaTeam != loserArenaTeam) - { - if (team == winner) - { - // update achievement BEFORE personal rating update - uint32 rating = player->GetArenaPersonalRating(winnerArenaTeam->GetSlot()); - player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_WIN_RATED_ARENA, rating ? rating : 1); - player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_WIN_ARENA, GetMapId()); - - winnerArenaTeam->MemberWon(player, loserMatchmakerRating, winnerMatchmakerChange); - } - else - { - loserArenaTeam->MemberLost(player, winnerMatchmakerRating, loserMatchmakerChange); - - // Arena lost => reset the win_rated_arena having the "no_lose" condition - player->ResetAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_WIN_RATED_ARENA, ACHIEVEMENT_CRITERIA_CONDITION_NO_LOSE); - } - } - uint32 winner_kills = player->GetRandomWinner() ? sWorld->getIntConfig(CONFIG_BG_REWARD_WINNER_HONOR_LAST) : sWorld->getIntConfig(CONFIG_BG_REWARD_WINNER_HONOR_FIRST); uint32 loser_kills = player->GetRandomWinner() ? sWorld->getIntConfig(CONFIG_BG_REWARD_LOSER_HONOR_LAST) : sWorld->getIntConfig(CONFIG_BG_REWARD_LOSER_HONOR_FIRST); uint32 winner_arena = player->GetRandomWinner() ? sWorld->getIntConfig(CONFIG_BG_REWARD_WINNER_ARENA_LAST) : sWorld->getIntConfig(CONFIG_BG_REWARD_WINNER_ARENA_FIRST); @@ -909,17 +792,6 @@ void Battleground::EndBattleground(uint32 winner) player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_BATTLEGROUND, 1); } - if (isArena() && isRated() && winnerArenaTeam && loserArenaTeam && winnerArenaTeam != loserArenaTeam) - { - // save the stat changes - winnerArenaTeam->SaveToDB(); - loserArenaTeam->SaveToDB(); - // send updated arena team stats to players - // this way all arena team members will get notified, not only the ones who participated in this match - winnerArenaTeam->NotifyStatsChanged(); - loserArenaTeam->NotifyStatsChanged(); - } - if (winmsg_id) SendMessageToAll(winmsg_id, CHAT_MSG_BG_SYSTEM_NEUTRAL); } @@ -986,26 +858,16 @@ void Battleground::RemovePlayerAtLeave(uint64 guid, bool Transport, bool SendPac { player->ClearAfkReports(); - if (!team) team = player->GetTeam(); - // if arena, remove the specific arena auras if (isArena()) { - bgTypeId=BATTLEGROUND_AA; // set the bg type to all arenas (it will be used for queue refreshing) + bgTypeId = BATTLEGROUND_AA; // set the bg type to all arenas (it will be used for queue refreshing) // unsummon current and summon old pet if there was one and there isn't a current pet player->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT); player->ResummonPetTemporaryUnSummonedIfAny(); - - if (isRated() && GetStatus() == STATUS_IN_PROGRESS) - { - //left a rated match while the encounter was in progress, consider as loser - ArenaTeam* winnerArenaTeam = sArenaTeamMgr->GetArenaTeamById(GetArenaTeamIdForTeam(GetOtherTeam(team))); - ArenaTeam* loserArenaTeam = sArenaTeamMgr->GetArenaTeamById(GetArenaTeamIdForTeam(team)); - if (winnerArenaTeam && loserArenaTeam && winnerArenaTeam != loserArenaTeam) - loserArenaTeam->MemberLost(player, GetArenaMatchmakerRating(GetOtherTeam(team))); - } } + if (SendPacket) { WorldPacket data; @@ -1016,26 +878,12 @@ void Battleground::RemovePlayerAtLeave(uint64 guid, bool Transport, bool SendPac // this call is important, because player, when joins to battleground, this method is not called, so it must be called when leaving bg player->RemoveBattlegroundQueueId(bgQueueTypeId); } - else - // removing offline participant - { - if (isRated() && GetStatus() == STATUS_IN_PROGRESS) - { - //left a rated match while the encounter was in progress, consider as loser - ArenaTeam* others_arena_team = sArenaTeamMgr->GetArenaTeamById(GetArenaTeamIdForTeam(GetOtherTeam(team))); - ArenaTeam* players_arena_team = sArenaTeamMgr->GetArenaTeamById(GetArenaTeamIdForTeam(team)); - if (others_arena_team && players_arena_team) - players_arena_team->OfflineMemberLost(guid, GetArenaMatchmakerRating(GetOtherTeam(team))); - } - } // remove from raid group if player is member if (Group* group = GetBgRaid(team)) { if (!group->RemoveMember(guid)) // group was disbanded - { SetBgRaid(team, NULL); - } } DecreaseInvitedCount(team); //we should update battleground queue, but only if bg isn't ending @@ -1070,7 +918,7 @@ void Battleground::RemovePlayerAtLeave(uint64 guid, bool Transport, bool SendPac // this method is called when no players remains in battleground void Battleground::Reset() { - SetWinner(WINNER_NONE); + SetWinner(BG_TEAM_NEUTRAL); SetStatus(STATUS_WAIT_QUEUE); SetStartTime(0); SetEndTime(0); @@ -1143,21 +991,6 @@ void Battleground::AddPlayer(Player* player) if (isArena()) { player->RemoveArenaEnchantments(TEMP_ENCHANTMENT_SLOT); - if (team == ALLIANCE) // gold - { - if (player->GetTeam() == HORDE) - player->CastSpell(player, SPELL_HORDE_GOLD_FLAG, true); - else - player->CastSpell(player, SPELL_ALLIANCE_GOLD_FLAG, true); - } - else // green - { - if (player->GetTeam() == HORDE) - player->CastSpell(player, SPELL_HORDE_GREEN_FLAG, true); - else - player->CastSpell(player, SPELL_ALLIANCE_GREEN_FLAG, true); - } - player->DestroyConjuredItems(true); player->UnsummonPetTemporaryIfAny(); @@ -1379,10 +1212,10 @@ bool Battleground::UpdatePlayerScore(Player* player, uint32 type, uint32 value, if (itr == PlayerScores.end()) // player not found... return false; - itr->second->UpdateScore(type, value); - if (type == SCORE_BONUS_HONOR && doAddHonor && isBattleground()) player->RewardHonor(NULL, 1, value); // RewardHonor calls UpdatePlayerScore with doAddHonor = false + else + itr->second->UpdateScore(type, value); return true; } @@ -1900,27 +1733,6 @@ int32 Battleground::GetObjectType(uint64 guid) return -1; } -void Battleground::HandleKillUnit(Creature* /*victim*/, Player* /*killer*/) { } - -void Battleground::CheckArenaAfterTimerConditions() -{ - EndBattleground(WINNER_NONE); -} - -void Battleground::CheckArenaWinConditions() -{ - if (!GetAlivePlayersCountByTeam(ALLIANCE) && GetPlayersCountByTeam(HORDE)) - EndBattleground(HORDE); - else if (GetPlayersCountByTeam(ALLIANCE) && !GetAlivePlayersCountByTeam(HORDE)) - EndBattleground(ALLIANCE); -} - -void Battleground::UpdateArenaWorldState() -{ - UpdateWorldState(0xe10, GetAlivePlayersCountByTeam(HORDE)); - UpdateWorldState(0xe11, GetAlivePlayersCountByTeam(ALLIANCE)); -} - void Battleground::SetBgRaid(uint32 TeamID, Group* bg_raid) { Group*& old_raid = TeamID == ALLIANCE ? m_BgRaids[TEAM_ALLIANCE] : m_BgRaids[TEAM_HORDE]; |