From 5de7bae617eab672bb94b9a812f217dfdfe8bef9 Mon Sep 17 00:00:00 2001 From: mik1893 Date: Sun, 14 Aug 2016 13:31:19 +0100 Subject: [PATCH] Core/Battleground: New CrossFaction Battleground queue system with enabled premades and pre-balancing system --- src/game/Battlegrounds/Battleground.cpp | 20 +++++++++ src/game/Battlegrounds/Battleground.h | 13 ++++++ src/game/Battlegrounds/BattlegroundMgr.cpp | 43 ++++++++++++++++++++ src/game/Battlegrounds/BattlegroundQueue.cpp | 8 ++++ src/game/Handlers/BattleGroundHandler.cpp | 33 +++++++-------- 5 files changed, 101 insertions(+), 16 deletions(-) diff --git a/src/game/Battlegrounds/Battleground.cpp b/src/game/Battlegrounds/Battleground.cpp index ecf8c9b5e5..50581ac979 100644 --- a/src/game/Battlegrounds/Battleground.cpp +++ b/src/game/Battlegrounds/Battleground.cpp @@ -178,6 +178,12 @@ Battleground::Battleground() m_BgInvitedPlayers[TEAM_ALLIANCE]= 0; m_BgInvitedPlayers[TEAM_HORDE] = 0; + // [AZTH] crossfaction system + m_premadeAssigned[TEAM_ALLIANCE] = 0; + m_premadeAssigned[TEAM_HORDE] = 0; + m_hasPlayerJoinedPremade.clear(); + // [/AZTH] + m_TeamScores[TEAM_ALLIANCE] = 0; m_TeamScores[TEAM_HORDE] = 0; @@ -1201,6 +1207,11 @@ void Battleground::AddPlayer(Player* player) UpdatePlayersCountByTeam(teamId, false); // +1 player + //[AZTH] the player has joined premade - he went into the player count of BG, need to remove it from the pre-count + if (HasPlayerJoinPremade(guid)) + DecreasePremadeCount(teamId); + //[/AZTH] + WorldPacket data; sBattlegroundMgr->BuildPlayerJoinedBattlegroundPacket(&data, player); SendPacketToTeam(teamId, &data, player, false); @@ -1997,4 +2008,13 @@ void Battleground::RewardXPAtKill(Player* killer, Player* victim) uint8 Battleground::GetUniqueBracketId() const { return GetMinLevel() / 10; +} + +bool Battleground::HasPlayerJoinPremade(uint64 guid) +{ + for (UNORDERED_MAP::iterator itr = m_hasPlayerJoinedPremade.begin(); itr != m_hasPlayerJoinedPremade.end(); itr++) + if (itr->first == guid) + return itr->second; + + return false; } \ No newline at end of file diff --git a/src/game/Battlegrounds/Battleground.h b/src/game/Battlegrounds/Battleground.h index d3ae2a964f..045eff411c 100644 --- a/src/game/Battlegrounds/Battleground.h +++ b/src/game/Battlegrounds/Battleground.h @@ -415,6 +415,14 @@ class Battleground void IncreaseInvitedCount(TeamId teamId) { ++m_BgInvitedPlayers[teamId]; } uint32 GetInvitedCount(TeamId teamId) const { return m_BgInvitedPlayers[teamId]; } + //[AZTH] CrossFaction Battleground + void SetPlayerJoinPremade(uint64 guid, bool premade) { m_hasPlayerJoinedPremade[guid] = premade; } + bool HasPlayerJoinPremade(uint64 guid); + void DecreasePremadeCount(TeamId teamId) { if(m_premadeAssigned[teamId] > 0) --m_premadeAssigned[teamId]; } + void IncreasePremadeCount(TeamId teamId) { ++m_premadeAssigned[teamId]; } + uint32 GetPremadeCount(TeamId teamId) { return m_premadeAssigned[teamId]; } + //[/AZTH] + bool HasFreeSlots() const; uint32 GetFreeSlotsForTeam(TeamId teamId) const; uint32 GetMaxFreeSlots() const; @@ -733,6 +741,11 @@ class Battleground // Invited players counters uint32 m_BgInvitedPlayers[BG_TEAMS_COUNT]; + // [AZTH] Crossfaction Battleground + UNORDERED_MAP m_hasPlayerJoinedPremade; + uint32 m_premadeAssigned[BG_TEAMS_COUNT]; + // [AZTH] + // Raid Group Group* m_BgRaids[BG_TEAMS_COUNT]; // 0 - alliance, 1 - horde diff --git a/src/game/Battlegrounds/BattlegroundMgr.cpp b/src/game/Battlegrounds/BattlegroundMgr.cpp index 79304538f4..452b465d34 100644 --- a/src/game/Battlegrounds/BattlegroundMgr.cpp +++ b/src/game/Battlegrounds/BattlegroundMgr.cpp @@ -1049,6 +1049,8 @@ void BattlegroundMgr::InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg, T { ASSERT(!ginfo->IsInvitedToBGInstanceGUID); + bool increaseCountPremade = false; //[AZTH] needed later + // set side if needed if (teamId != TEAM_NEUTRAL) ginfo->teamId = teamId; @@ -1065,6 +1067,39 @@ void BattlegroundMgr::InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg, T ginfo->RemoveInviteTime = World::GetGameTimeMS() + INVITE_ACCEPT_WAIT_TIME; + //[AZTH] Preassign people to factions based on invite count as we ignore it completely during queuing + if (!bg->isArena() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_RANDOM_CROSSFACTION) && bgQueueTypeId == BATTLEGROUND_QUEUE_RB) + { + + // if it's a premade group, set the player as joined premade. + // also decide now where the premade group will go. The rest of the player will be switched later + + if (ginfo->Players.size() > 1) + increaseCountPremade = true; + + if (increaseCountPremade) + { + uint32 allyPremadeCount = bg->GetPremadeCount(TEAM_ALLIANCE); + uint32 hordePremadeCount = bg->GetPremadeCount(TEAM_HORDE); + + TeamId nextTeam = ginfo->teamId; + + if (hordePremadeCount < allyPremadeCount) // if there is already a premade in ally go horde + nextTeam = TEAM_HORDE; + else if (hordePremadeCount > allyPremadeCount) // else if premade horde go ally + nextTeam = TEAM_ALLIANCE; + else + { + if(roll_chance_i(50)) // else randomize where the group goes (50-50) + nextTeam = ginfo->teamId == TEAM_ALLIANCE ? TEAM_HORDE : TEAM_ALLIANCE; + } + + ginfo->teamId = nextTeam; + sLog->outError("A new team of size %u joined premade random battleground", uint32(ginfo->Players.size())); + } + } + // [/AZTH] + // loop through the players for (std::set::iterator itr = ginfo->Players.begin(); itr != ginfo->Players.end(); ++itr) { @@ -1077,6 +1112,14 @@ void BattlegroundMgr::InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg, T // update average wait time bgQueue.PlayerInvitedToBGUpdateAverageWaitTime(ginfo); + // [AZTH] Set player has joined premade if more than 1 player + if (increaseCountPremade) + { + bg->SetPlayerJoinPremade(*itr, true); + bg->IncreasePremadeCount(ginfo->teamId); + } + // [/AZTH] + // increase invited counter for each invited player bg->IncreaseInvitedCount(ginfo->teamId); diff --git a/src/game/Battlegrounds/BattlegroundQueue.cpp b/src/game/Battlegrounds/BattlegroundQueue.cpp index 86d6c519e1..5946a36714 100644 --- a/src/game/Battlegrounds/BattlegroundQueue.cpp +++ b/src/game/Battlegrounds/BattlegroundQueue.cpp @@ -314,8 +314,16 @@ void BattlegroundQueue::RemovePlayer(uint64 guid, bool sentToBg, uint32 playerQu // sending player to bg will increase it again if (groupInfo->IsInvitedToBGInstanceGUID) if (Battleground* bg = sBattlegroundMgr->GetBattleground(groupInfo->IsInvitedToBGInstanceGUID)) + { bg->DecreaseInvitedCount(groupInfo->teamId); + //[AZTH] Crossfaction BG - need to decrease premade count if the person is in a premade + if (bg->HasPlayerJoinPremade(guid)) + bg->DecreasePremadeCount(groupInfo->teamId); + //[/AZTH] + } + + // remove player queue info m_QueuedPlayers.erase(itr); diff --git a/src/game/Handlers/BattleGroundHandler.cpp b/src/game/Handlers/BattleGroundHandler.cpp index 7b8c806a9a..aceefe97e3 100644 --- a/src/game/Handlers/BattleGroundHandler.cpp +++ b/src/game/Handlers/BattleGroundHandler.cpp @@ -436,24 +436,25 @@ void WorldSession::HandleBattleFieldPortOpcode(WorldPacket &recvData) TeamId teamId = ginfo.teamId; // [AZTH] Random Battleground Randomizer - by Yehonal & Mik1893 - if (bgQueueTypeId == BATTLEGROUND_QUEUE_RB && bg->isBattleground() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_RANDOM_CROSSFACTION)) - { - uint32 allyCount = bg->GetPlayersCountByTeam(TEAM_ALLIANCE); - uint32 hordeCount = bg->GetPlayersCountByTeam(TEAM_HORDE); - - if (allyCount == hordeCount) + if(!bg->HasPlayerJoinPremade(_player->GetGUID())) // Premade players have already defined team and cf settings + if (bgQueueTypeId == BATTLEGROUND_QUEUE_RB && bg->isBattleground() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_RANDOM_CROSSFACTION)) { - if (roll_chance_i(50)) - teamId = _player->GetTeamId(true) == TEAM_ALLIANCE ? TEAM_HORDE : TEAM_ALLIANCE; - } - else if (allyCount < hordeCount) - teamId = TEAM_ALLIANCE; - else - teamId = TEAM_HORDE; + uint32 allyCount = bg->GetPlayersCountByTeam(TEAM_ALLIANCE) + bg->GetPremadeCount(TEAM_ALLIANCE); + uint32 hordeCount = bg->GetPlayersCountByTeam(TEAM_HORDE) + bg->GetPremadeCount(TEAM_HORDE); - _player->setTeamId(teamId); - _player->setFaction(teamId == TEAM_ALLIANCE ? 1 : 2); - } + if (allyCount == hordeCount) + { + if (roll_chance_i(50)) + teamId = _player->GetTeamId(true) == TEAM_ALLIANCE ? TEAM_HORDE : TEAM_ALLIANCE; + } + else if (allyCount < hordeCount) + teamId = TEAM_ALLIANCE; + else + teamId = TEAM_HORDE; + } + + _player->setTeamId(teamId); + _player->setFaction(teamId == TEAM_ALLIANCE ? 1 : 2); // [/AZTH] // remove player from all bg queues