From 34e6130754564b79634b08e303fb76124cefedd1 Mon Sep 17 00:00:00 2001 From: Hondacrx Date: Mon, 8 Dec 2025 14:47:43 -0500 Subject: [PATCH] Scripts/Commands: Improve .debug arena Port From (https://github.com/TrinityCore/TrinityCore/commit/16edee0b0ea805f5d8f0abf5eedb2c66a6edb23f) --- .../Game/BattleGrounds/BattleGroundManager.cs | 36 ++++++++++++++++--- Source/Game/Chat/Commands/DebugCommands.cs | 14 ++++++-- Source/Game/Handlers/BattleGroundHandler.cs | 13 +++++-- Source/Game/Networking/Packet.cs | 5 +++ .../Networking/Packets/BattleGroundPackets.cs | 2 +- 5 files changed, 60 insertions(+), 10 deletions(-) diff --git a/Source/Game/BattleGrounds/BattleGroundManager.cs b/Source/Game/BattleGrounds/BattleGroundManager.cs index 74c72410b..f148a03cb 100644 --- a/Source/Game/BattleGrounds/BattleGroundManager.cs +++ b/Source/Game/BattleGrounds/BattleGroundManager.cs @@ -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 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 m_QueueUpdateScheduler = new(); uint m_NextRatedArenaUpdate; uint m_UpdateTimer; - bool m_ArenaTesting; + uint m_ArenaTesting; bool m_Testing; } diff --git a/Source/Game/Chat/Commands/DebugCommands.cs b/Source/Game/Chat/Commands/DebugCommands.cs index cb6680068..3830d3a52 100644 --- a/Source/Game/Chat/Commands/DebugCommands.cs +++ b/Source/Game/Chat/Commands/DebugCommands.cs @@ -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; } diff --git a/Source/Game/Handlers/BattleGroundHandler.cs b/Source/Game/Handlers/BattleGroundHandler.cs index 5a10e5835..b3e329f0f 100644 --- a/Source/Game/Handlers/BattleGroundHandler.cs +++ b/Source/Game/Handlers/BattleGroundHandler.cs @@ -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); diff --git a/Source/Game/Networking/Packet.cs b/Source/Game/Networking/Packet.cs index dd9530da5..6d7600a94 100644 --- a/Source/Game/Networking/Packet.cs +++ b/Source/Game/Networking/Packet.cs @@ -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(); diff --git a/Source/Game/Networking/Packets/BattleGroundPackets.cs b/Source/Game/Networking/Packets/BattleGroundPackets.cs index fe64a066f..d97445a02 100644 --- a/Source/Game/Networking/Packets/BattleGroundPackets.cs +++ b/Source/Game/Networking/Packets/BattleGroundPackets.cs @@ -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) { }