Scripts/Commands: Improve .debug arena (#31292)

This commit is contained in:
Jeremy
2025-10-02 21:38:53 +02:00
committed by GitHub
parent 3fb6401b04
commit 16edee0b0e
4 changed files with 61 additions and 10 deletions

View File

@@ -32,6 +32,7 @@
#include "Player.h"
#include "SharedDefines.h"
#include "World.h"
#include "WorldSession.h"
bool BattlegroundTemplate::IsArena() const
{
@@ -64,7 +65,7 @@ uint8 BattlegroundTemplate::GetMaxLevel() const
BattlegroundMgr::BattlegroundMgr() :
m_NextRatedArenaUpdate(sWorld->getIntConfig(CONFIG_ARENA_RATED_UPDATE_TIMER)),
m_UpdateTimer(0), m_ArenaTesting(false), m_Testing(false)
m_UpdateTimer(0), m_ArenaTesting(0), m_Testing(false)
{ }
BattlegroundMgr::~BattlegroundMgr()
@@ -300,6 +301,15 @@ BattlegroundScriptTemplate const* BattlegroundMgr::FindBattlegroundScriptTemplat
return Trinity::Containers::MapGetValuePtr(_battlegroundScriptTemplates, { mapId, BATTLEGROUND_TYPE_NONE });
}
void BattlegroundMgr::QueuePlayerForArena(Player const* player, uint8 teamSize, uint8 roles)
{
WorldPackets::Battleground::BattlemasterJoinArena packet((WorldPacket(CMSG_BATTLEMASTER_JOIN_ARENA)));
packet.TeamSizeIndex = teamSize;
packet.Roles = roles;
player->GetSession()->HandleBattlemasterJoinArena(packet);
}
uint32 BattlegroundMgr::CreateClientVisibleInstanceId(BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id)
{
if (IsArenaType(bgTypeId))
@@ -507,10 +517,23 @@ void BattlegroundMgr::ToggleTesting()
sWorld->SendWorldText(m_Testing ? LANG_DEBUG_BG_ON : LANG_DEBUG_BG_OFF);
}
void BattlegroundMgr::ToggleArenaTesting()
bool BattlegroundMgr::ToggleArenaTesting(uint32 battlemasterListId)
{
m_ArenaTesting = !m_ArenaTesting;
sWorld->SendWorldText(m_ArenaTesting ? LANG_DEBUG_ARENA_ON : LANG_DEBUG_ARENA_OFF);
if (battlemasterListId != 0)
{
BattlegroundTemplate const* bgTemplate = GetBattlegroundTemplateByTypeId(static_cast<BattlegroundTypeId>(battlemasterListId));
if (!bgTemplate)
return false;
if (!bgTemplate->IsArena())
return false;
}
if (m_ArenaTesting != battlemasterListId)
sWorld->SendWorldText((battlemasterListId != 0) ? LANG_DEBUG_ARENA_ON : LANG_DEBUG_ARENA_OFF);
m_ArenaTesting = battlemasterListId;
return true;
}
bool BattlegroundMgr::IsValidQueueId(BattlegroundQueueTypeId bgQueueTypeId)
@@ -686,6 +709,9 @@ BattlegroundTypeId BattlegroundMgr::GetRandomBG(BattlegroundTypeId bgTypeId)
{
if (BattlegroundTemplate const* bgTemplate = GetBattlegroundTemplateByTypeId(bgTypeId))
{
if (bgTemplate->IsArena() && isArenaTesting())
return static_cast<BattlegroundTypeId>(m_ArenaTesting);
std::vector<BattlegroundTemplate const*> ids;
ids.reserve(bgTemplate->MapIDs.size());
for (int32 mapId : bgTemplate->MapIDs)

View File

@@ -126,10 +126,11 @@ class TC_GAME_API BattlegroundMgr
void ScheduleQueueUpdate(uint32 arenaMatchmakerRating, BattlegroundQueueTypeId bgQueueTypeId, BattlegroundBracketId bracket_id);
uint32 GetPrematureFinishTime() const;
void ToggleArenaTesting();
// Return whether toggling was successful. In case of a non-existing battlemasterListId, or this battlemasterListId is not an arena, this would return false.
bool ToggleArenaTesting(uint32 battlemasterListId);
void ToggleTesting();
bool isArenaTesting() const { return m_ArenaTesting; }
bool isArenaTesting() const { return m_ArenaTesting != 0; }
bool isTesting() const { return m_Testing; }
static bool IsRandomBattleground(uint32 battlemasterListId);
@@ -162,6 +163,8 @@ class TC_GAME_API BattlegroundMgr
void LoadBattlegroundScriptTemplate();
BattlegroundScriptTemplate const* FindBattlegroundScriptTemplate(uint32 mapId, BattlegroundTypeId bgTypeId) const;
static void QueuePlayerForArena(Player const* player, uint8 teamSize, uint8 roles);
private:
uint32 CreateClientVisibleInstanceId(BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id);
static bool IsArenaType(BattlegroundTypeId bgTypeId);
@@ -185,7 +188,7 @@ class TC_GAME_API BattlegroundMgr
std::vector<ScheduledQueueUpdate> m_QueueUpdateScheduler;
uint32 m_NextRatedArenaUpdate;
uint32 m_UpdateTimer;
bool m_ArenaTesting;
uint32 m_ArenaTesting;
bool m_Testing;
BattleMastersMap mBattleMastersMap;

View File

@@ -540,9 +540,16 @@ void WorldSession::HandleBattlemasterJoinArena(WorldPackets::Battleground::Battl
return;
Group* grp = _player->GetGroup();
if (!grp)
{
grp = new Group();
grp->Create(_player);
}
// no group found, error
if (!grp)
return;
if (grp->GetLeaderGUID() != _player->GetGUID())
return;
@@ -559,7 +566,10 @@ void WorldSession::HandleBattlemasterJoinArena(WorldPackets::Battleground::Battl
GroupQueueInfo* ginfo = nullptr;
ObjectGuid errorGuid;
GroupJoinBattlegroundResult err = grp->CanJoinBattlegroundQueue(bgTemplate, bgQueueTypeId, arenatype, arenatype, true, packet.TeamSizeIndex, errorGuid);
GroupJoinBattlegroundResult err = ERR_BATTLEGROUND_NONE;
if (!sBattlegroundMgr->isArenaTesting())
err = grp->CanJoinBattlegroundQueue(bgTemplate, bgQueueTypeId, arenatype, arenatype, true, packet.TeamSizeIndex, errorGuid);
if (!err)
{
TC_LOG_DEBUG("bg.battleground", "Battleground: arena team id {}, leader {} queued with matchmaker rating {} for type {}", _player->GetArenaTeamId(packet.TeamSizeIndex), _player->GetName(), matchmakerRating, arenatype);

View File

@@ -39,6 +39,7 @@ EndScriptData */
#include "GridNotifiersImpl.h"
#include "InstanceScript.h"
#include "Language.h"
#include "LFG.h"
#include "Log.h"
#include "M2Stores.h"
#include "MapManager.h"
@@ -856,9 +857,20 @@ public:
return true;
}
static bool HandleDebugArenaCommand(ChatHandler* /*handler*/)
static bool HandleDebugArenaCommand(ChatHandler* handler, uint32 battlemasterListId)
{
sBattlegroundMgr->ToggleArenaTesting();
bool successful = sBattlegroundMgr->ToggleArenaTesting(battlemasterListId);
if (!successful)
{
handler->PSendSysMessage("BattlemasterListId %u does not exist or is not an arena.", battlemasterListId);
handler->SetSentErrorMessage(true);
return true;
}
if (!battlemasterListId || !handler || !handler->GetSession())
return true;
BattlegroundMgr::QueuePlayerForArena(handler->GetSession()->GetPlayer(), 0, lfg::PLAYER_ROLE_DAMAGE);
return true;
}