Skip to content

Commit

Permalink
Make it work again
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Oct 6, 2024
1 parent d5b6f93 commit c3407ec
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 56 deletions.
35 changes: 31 additions & 4 deletions src/game/BattleGround/BattleGround.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,16 @@ uint32 BattleGround::GetBonusHonorFromKill(uint32 kills) const
return (uint32)MaNGOS::Honor::hk_honor_at_level(GetMaxLevel(), kills);
}

void BattleGround::SetStatus(BattleGroundStatus status)
{
m_status = status;
sWorld.GetBGQueue().GetMessager().AddMessage([status, bgTypeId = GetTypeId(), instanceId = GetInstanceId()](BattleGroundQueue* queue)
{
if (BattleGroundInQueueInfo* bgInstance = queue->GetFreeSlotInstance(bgTypeId, instanceId))
bgInstance->status = status;
});
}

/**
Function that returns the battleground master entry
*/
Expand Down Expand Up @@ -1266,12 +1276,19 @@ void BattleGround::RemovePlayerAtLeave(ObjectGuid playerGuid, bool isOnTransport
delete group;
}
}
DecreaseInvitedCount(team);

// we should update battleground queue, but only if bg isn't ending
if (IsBattleGround() && GetStatus() < STATUS_WAIT_LEAVE)
{
// a player has left the battleground, so there are free slots -> add to queue
AddToBgFreeSlotQueue();
if (!AddToBgFreeSlotQueue()) // avoid setting two messages - if was already in queue, just update count
{
sWorld.GetBGQueue().GetMessager().AddMessage([bgTypeId, instanceId = GetInstanceId(), team](BattleGroundQueue* queue)
{
if (BattleGroundInQueueInfo* bgInstance = queue->GetFreeSlotInstance(bgTypeId, instanceId))
bgInstance->DecreaseInvitedCount(team);
});
}
sWorld.GetBGQueue().GetMessager().AddMessage([bgQueueTypeId, bgTypeId, bracketId = GetBracketId()](BattleGroundQueue* queue)
{
queue->ScheduleQueueUpdate(0, ARENA_TYPE_NONE, bgQueueTypeId, bgTypeId, bracketId);
Expand Down Expand Up @@ -1506,19 +1523,21 @@ void BattleGround::EventPlayerLoggedOut(Player* player)
/**
Function that returns the number of players that can join a battleground based on the provided team
*/
void BattleGround::AddToBgFreeSlotQueue()
bool BattleGround::AddToBgFreeSlotQueue()
{
// make sure to add only once
if (!m_hasBgFreeSlotQueue && IsBattleGround())
{
m_hasBgFreeSlotQueue = true;
BattleGroundInQueueInfo bgInfo;
// TODO: Fill
bgInfo.Fill(this);
sWorld.GetBGQueue().GetMessager().AddMessage([bgInfo](BattleGroundQueue* queue)
{
queue->AddBgToFreeSlots(bgInfo);
});
return true;
}
return false;
}

/**
Expand All @@ -1537,6 +1556,14 @@ void BattleGround::RemovedFromBgFreeSlotQueue(bool removeFromQueue)
m_hasBgFreeSlotQueue = false;
}

void BattleGround::SetInvitedCount(Team team, uint32 count)
{
if (team == ALLIANCE)
m_invitedAlliance = count;
else
m_invitedHorde = count;
}

/**
Function that returns the number of players that can join a battleground based on the provided team
Expand Down
7 changes: 3 additions & 4 deletions src/game/BattleGround/BattleGround.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class BattleGround
void SetName(char const* name) { m_name = name; }
void SetTypeId(BattleGroundTypeId typeId) { m_typeId = typeId; }
void SetBracketId(BattleGroundBracketId id) { m_bracketId = id; }
void SetStatus(BattleGroundStatus status) { m_status = status; }
void SetStatus(BattleGroundStatus status);
void SetClientInstanceId(uint32 instanceId) { m_clientInstanceId = instanceId; }
void SetStartTime(uint32 time) { m_startTime = time; }
void SetEndTime(uint32 time) { m_endTime = time; }
Expand All @@ -353,12 +353,11 @@ class BattleGround
void SetMaxPlayersPerTeam(uint32 maxPlayers) { m_maxPlayersPerTeam = maxPlayers; }
void SetMinPlayersPerTeam(uint32 minPlayers) { m_minPlayersPerTeam = minPlayers; }

void AddToBgFreeSlotQueue(); // this queue will be useful when more battlegrounds instances will be available
bool AddToBgFreeSlotQueue(); // this queue will be useful when more battlegrounds instances will be available
void RemovedFromBgFreeSlotQueue(bool removeFromQueue); // this method could delete whole BG instance, if another free is available

// Functions to decrease or increase player count
void DecreaseInvitedCount(Team team) { (team == ALLIANCE) ? --m_invitedAlliance : --m_invitedHorde; }
void IncreaseInvitedCount(Team team) { (team == ALLIANCE) ? ++m_invitedAlliance : ++m_invitedHorde; }
void SetInvitedCount(Team team, uint32 count);
uint32 GetInvitedCount(Team team) const
{
if (team == ALLIANCE)
Expand Down
30 changes: 15 additions & 15 deletions src/game/BattleGround/BattleGroundHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ void WorldSession::HandleBattlefieldPortOpcode(WorldPacket& recv_data)
MANGOS_ASSERT(bgInQueue); // at this point must always exist

// remove battleground queue status from BGmgr
queueItem.RemovePlayer(playerGuid, false);
queueItem.RemovePlayer(*queue, playerGuid, false);

sWorld.GetMessager().AddMessage([playerGuid, invitedTo = queueInfo.isInvitedToBgInstanceGuid, bgTypeId, bgQueueTypeId, groupTeam = queueInfo.groupTeam, queueSlot, bgClientInstanceId = bgInQueue->GetClientInstanceId(), isRated = bgInQueue->IsRated(), mapId = bgInQueue->GetMapId(), arenaType = bgInQueue->GetArenaType()](World* world)
{
Expand Down Expand Up @@ -524,22 +524,22 @@ void WorldSession::HandleBattlefieldPortOpcode(WorldPacket& recv_data)
at->SaveToDB();
}
});
}

queueItem.RemovePlayer(playerGuid, true);
sWorld.GetMessager().AddMessage([playerGuid, bgQueueTypeId, queueSlot, bgTypeId, bgClientInstanceId = queueInfo.clientInstanceId, isRated = queueInfo.isRated, mapId = queueInfo.mapId](World* world)
{
Player* player = sObjectMgr.GetPlayer(playerGuid);
if (!player)
return;
player->RemoveBattleGroundQueueId(bgQueueTypeId);
WorldPacket data;
sBattleGroundMgr.BuildBattleGroundStatusPacket(data, true, bgTypeId, bgClientInstanceId, isRated, mapId, queueSlot, STATUS_NONE, 0, 0, ARENA_TYPE_NONE, TEAM_NONE);
player->GetSession()->SendPacket(data);
});
queueItem.RemovePlayer(*queue, playerGuid, true);
sWorld.GetMessager().AddMessage([playerGuid, bgQueueTypeId, queueSlot, bgTypeId, bgClientInstanceId = queueInfo.clientInstanceId, isRated = queueInfo.isRated, mapId = queueInfo.mapId](World* world)
{
Player* player = sObjectMgr.GetPlayer(playerGuid);
if (!player)
return;
player->RemoveBattleGroundQueueId(bgQueueTypeId);
WorldPacket data;
sBattleGroundMgr.BuildBattleGroundStatusPacket(data, true, bgTypeId, bgClientInstanceId, isRated, mapId, queueSlot, STATUS_NONE, 0, 0, ARENA_TYPE_NONE, TEAM_NONE);
player->GetSession()->SendPacket(data);
});

if (queueInfo.arenaType == ARENA_TYPE_NONE)
queue->ScheduleQueueUpdate(queueInfo.arenaTeamRating, queueInfo.arenaType, bgQueueTypeId, bgTypeId, queueInfo.bgBracketId);
}
if (queueInfo.arenaType == ARENA_TYPE_NONE)
queue->ScheduleQueueUpdate(queueInfo.arenaTeamRating, queueInfo.arenaType, bgQueueTypeId, bgTypeId, queueInfo.bgBracketId);
break;
default:
sLog.outError("Battleground port: unknown action %u", action);
Expand Down
11 changes: 9 additions & 2 deletions src/game/BattleGround/BattleGroundMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ INSTANTIATE_SINGLETON_1(BattleGroundMgr);
/*** BATTLEGROUND MANAGER ***/
/*********************************************************/

BattleGroundMgr::BattleGroundMgr() : m_arenaTesting(false)
BattleGroundMgr::BattleGroundMgr() : m_arenaTesting(false), m_testing(false)
{
for (uint8 i = BATTLEGROUND_TYPE_NONE; i < MAX_BATTLEGROUND_TYPE_ID; ++i)
m_battleGrounds[i].clear();
m_testing = false;
}

BattleGroundMgr::~BattleGroundMgr()
Expand Down Expand Up @@ -1139,6 +1138,10 @@ void BattleGroundMgr::ToggleTesting()
sWorld.SendWorldText(LANG_DEBUG_BG_ON);
else
sWorld.SendWorldText(LANG_DEBUG_BG_OFF);
sWorld.GetBGQueue().GetMessager().AddMessage([testing = m_testing](BattleGroundQueue* queue)
{
queue->SetTesting(testing);
});
}

/**
Expand All @@ -1151,6 +1154,10 @@ void BattleGroundMgr::ToggleArenaTesting()
sWorld.SendWorldText(LANG_DEBUG_ARENA_ON);
else
sWorld.SendWorldText(LANG_DEBUG_ARENA_OFF);
sWorld.GetBGQueue().GetMessager().AddMessage([arenaTesting = m_arenaTesting](BattleGroundQueue* queue)
{
queue->SetArenaTesting(arenaTesting);
});
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/game/BattleGround/BattleGroundMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ class BattleGroundMgr
BattleGroundSet m_battleGrounds[MAX_BATTLEGROUND_TYPE_ID];
typedef std::set<uint32> ClientBattleGroundIdSet;
ClientBattleGroundIdSet m_clientBattleGroundIds[MAX_BATTLEGROUND_TYPE_ID][MAX_BATTLEGROUND_BRACKETS]; // the instanceids just visible for the client
bool m_arenaTesting;
bool m_testing;
bool m_arenaTesting;
bool m_testing;
std::set<uint32> m_usedRefloot;
};

Expand Down
Loading

0 comments on commit c3407ec

Please sign in to comment.