Scripts/Commands: Improve .debug arena

Port From (https://github.com/TrinityCore/TrinityCore/commit/16edee0b0ea805f5d8f0abf5eedb2c66a6edb23f)
This commit is contained in:
Hondacrx
2025-12-08 14:47:43 -05:00
parent 17759869bb
commit 34e6130754
5 changed files with 60 additions and 10 deletions
@@ -244,6 +244,15 @@ namespace Game.BattleGrounds
return _battlegroundScriptTemplates.LookupByKey((mapId, BattlegroundTypeId.None));
}
public static void QueuePlayerForArena(Player player, byte teamSize, byte roles)
{
BattlemasterJoinArena packet = new(new Networking.WorldPacket(ClientOpcodes.BattlemasterJoinArena));
packet.TeamSizeIndex = teamSize;
packet.Roles = roles;
player.GetSession().HandleBattlemasterJoinArena(packet);
}
uint CreateClientVisibleInstanceId(BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id)
{
if (IsArenaType(bgTypeId))
@@ -448,10 +457,24 @@ namespace Game.BattleGrounds
Global.WorldMgr.SendWorldText(m_Testing ? CypherStrings.DebugBgOn : CypherStrings.DebugBgOff);
}
public 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.
public bool ToggleArenaTesting(uint battlemasterListId)
{
m_ArenaTesting = !m_ArenaTesting;
Global.WorldMgr.SendWorldText(m_ArenaTesting ? CypherStrings.DebugArenaOn : CypherStrings.DebugArenaOff);
if (battlemasterListId != 0)
{
BattlegroundTemplate bgTemplate = GetBattlegroundTemplateByTypeId((BattlegroundTypeId)battlemasterListId);
if (bgTemplate == null)
return false;
if (!bgTemplate.IsArena())
return false;
}
if (m_ArenaTesting != battlemasterListId)
Global.WorldMgr.SendWorldText((battlemasterListId != 0) ? CypherStrings.DebugArenaOn : CypherStrings.DebugArenaOff);
m_ArenaTesting = battlemasterListId;
return true;
}
public bool IsValidQueueId(BattlegroundQueueTypeId bgQueueTypeId)
@@ -642,6 +665,9 @@ namespace Game.BattleGrounds
BattlegroundTemplate bgTemplate = GetBattlegroundTemplateByTypeId(bgTypeId);
if (bgTemplate != null)
{
if (bgTemplate.IsArena() && IsArenaTesting())
return (BattlegroundTypeId)m_ArenaTesting;
List<BattlegroundTemplate> ids = new();
foreach (var mapId in bgTemplate.MapIDs)
{
@@ -698,7 +724,7 @@ namespace Game.BattleGrounds
return m_BattlegroundQueues[bgQueueTypeId];
}
public bool IsArenaTesting() { return m_ArenaTesting; }
public bool IsArenaTesting() { return m_ArenaTesting != 0; }
public bool IsTesting() { return m_Testing; }
public BattlegroundTypeId GetBattleMasterBG(uint entry)
@@ -760,7 +786,7 @@ namespace Game.BattleGrounds
List<ScheduledQueueUpdate> m_QueueUpdateScheduler = new();
uint m_NextRatedArenaUpdate;
uint m_UpdateTimer;
bool m_ArenaTesting;
uint m_ArenaTesting;
bool m_Testing;
}
+12 -2
View File
@@ -51,9 +51,19 @@ namespace Game.Chat
}
[Command("arena", RBACPermissions.CommandDebug, true)]
static bool HandleDebugArenaCommand(CommandHandler handler)
static bool HandleDebugArenaCommand(CommandHandler handler, uint battlemasterListId)
{
Global.BattlegroundMgr.ToggleArenaTesting();
bool successful = Global.BattlegroundMgr.ToggleArenaTesting(battlemasterListId);
if (!successful)
{
handler.SendSysMessage("BattlemasterListId %u does not exist or is not an arena.", battlemasterListId);
return true;
}
if (battlemasterListId == 0 || handler == null || handler.GetSession() == null)
return true;
BattlegroundManager.QueuePlayerForArena(handler.GetSession().GetPlayer(), 0, (byte)LfgRoles.Damage);
return true;
}
+11 -2
View File
@@ -479,7 +479,7 @@ namespace Game
}
[WorldPacketHandler(ClientOpcodes.BattlemasterJoinArena)]
void HandleBattlemasterJoinArena(BattlemasterJoinArena packet)
public void HandleBattlemasterJoinArena(BattlemasterJoinArena packet)
{
// ignore if we already in BG or BG queue
if (GetPlayer().InBattleground())
@@ -508,9 +508,16 @@ namespace Game
return;
Group group = GetPlayer().GetGroup();
if (group == null)
{
group = new Group();
group.Create(_player);
}
// no group found, error
if (group == null)
return;
if (group.GetLeaderGUID() != GetPlayer().GetGUID())
return;
@@ -534,7 +541,9 @@ namespace Game
GroupQueueInfo ginfo = null;
ObjectGuid errorGuid;
var err = group.CanJoinBattlegroundQueue(bgTemplate, bgQueueTypeId, (uint)arenatype, (uint)arenatype, true, packet.TeamSizeIndex, out errorGuid);
GroupJoinBattlegroundResult err = GroupJoinBattlegroundResult.None;
if (!Global.BattlegroundMgr.IsArenaTesting())
err = group.CanJoinBattlegroundQueue(bgTemplate, bgQueueTypeId, (uint)arenatype, (uint)arenatype, true, packet.TeamSizeIndex, out errorGuid);
if (err == 0)
{
Log.outDebug(LogFilter.Battleground, "Battleground: arena team id {0}, leader {1} queued with matchmaker rating {2} for type {3}", GetPlayer().GetArenaTeamId(packet.TeamSizeIndex), GetPlayer().GetName(), matchmakerRating, arenatype);
+5
View File
@@ -104,6 +104,11 @@ namespace Game.Networking
this.opcode = (uint)opcode;
}
public WorldPacket(ClientOpcodes opcode)
{
this.opcode = (uint)opcode;
}
public WorldPacket(byte[] data) : base(data)
{
opcode = ReadUInt32();
@@ -222,7 +222,7 @@ namespace Game.Networking.Packets
public int[] BlacklistMap = new int[2];
}
class BattlemasterJoinArena : ClientPacket
public class BattlemasterJoinArena : ClientPacket
{
public BattlemasterJoinArena(WorldPacket packet) : base(packet) { }