From 9209a7125ba6cce34d979f830d6007144e888808 Mon Sep 17 00:00:00 2001 From: CWX Date: Sat, 21 Jan 2023 11:21:21 +0000 Subject: [PATCH] fix up BotMon, now has three options, each giving more info --- Live/CWX_DebuggingTool/BotmonClass.cs | 64 +++++++++++++++---------- Live/CWX_DebuggingTool/DebuggingTool.cs | 27 +++++++---- 2 files changed, 57 insertions(+), 34 deletions(-) diff --git a/Live/CWX_DebuggingTool/BotmonClass.cs b/Live/CWX_DebuggingTool/BotmonClass.cs index 209d2d3..c0b1a9c 100644 --- a/Live/CWX_DebuggingTool/BotmonClass.cs +++ b/Live/CWX_DebuggingTool/BotmonClass.cs @@ -11,26 +11,27 @@ namespace CWX_DebuggingTool { public sealed class BotmonClass : MonoBehaviour, IDisposable { - private static BotmonClass _instance = null; - private GUIContent _guiContent = null; + private static BotmonClass _instance; + + private GUIContent _guiContent; private GUIStyle _textStyle; - private StringBuilder _stringBuilder = new StringBuilder(200); private Player _player; private Dictionary> _zoneAndPlayers = new Dictionary>(); - private List _zones = null; - private GameWorld _gameWorld = null; + private List _zones; + private GameWorld _gameWorld; private IBotGame _botGame; private Rect _rect; private String _content = ""; private Vector2 _guiSize; private float _distance; - private float _timer; private BotmonClass() { } + public int Mode { get; set; } + public static BotmonClass Instance { get @@ -61,21 +62,28 @@ namespace CWX_DebuggingTool public void Awake() { - // Set Basics + // Get GameWorld Instance _gameWorld = Singleton.Instance; + // Get BotGame Instance _botGame = Singleton.Instance; + // Get Player from GameWorld + _player = _gameWorld.MainPlayer; + + // Make new rect to use for GUI + _rect = new Rect(0, 60, 0, 0); + + // Get all BotZones _zones = LocationScene.GetAllObjects().ToList(); + // Set up the Dictionary foreach (var botZone in _zones) { _zoneAndPlayers.Add(botZone.name, new List()); } - // get player - _player = _gameWorld.AllPlayers.Find(x => x.IsYourPlayer); - + // Add existing Bots to list if (_gameWorld.AllPlayers.Count > 1) { foreach (var player in _gameWorld.AllPlayers) @@ -89,8 +97,7 @@ namespace CWX_DebuggingTool } } - _rect = new Rect(0, 60, 0, 0); - + // Sub to Event to get and add Bot when they spawn _botGame.BotsController.BotSpawner.OnBotCreated += owner => { Player player = owner.GetPlayer; @@ -116,26 +123,35 @@ namespace CWX_DebuggingTool { _guiContent = new GUIContent(); } - - _content = string.Empty; - if (_zoneAndPlayers != null) + // If Mode Greater than or equal to 1 show total + if (Mode >= 1) { + _content = string.Empty; _content += $"Total = {_gameWorld.AllPlayers.Count - 1}\n"; + } - foreach (var zone in _zoneAndPlayers) + // If Mode Greater than or equal to 2 show total for each zone + if (Mode >= 2) + { + if (_zoneAndPlayers != null) { - _content += $"{zone.Key} = {_zoneAndPlayers[zone.Key].FindAll(x => x.HealthController.IsAlive).Count}\n"; - - foreach (var player in _zoneAndPlayers[zone.Key]) + foreach (var zone in _zoneAndPlayers) { - if (!player.HealthController.IsAlive) + if (_zoneAndPlayers[zone.Key].FindAll(x => x.HealthController.IsAlive).Count > 0) { - continue; - } + _content += $"{zone.Key} = {_zoneAndPlayers[zone.Key].FindAll(x => x.HealthController.IsAlive).Count}\n"; - _distance = Vector3.Distance(player.Position, _player.Position); - _content += $"> [{_distance:n2}m] [{player.Profile.Info.Settings.Role}] [{player.Profile.Side}] [{player.Profile.Info.Settings.BotDifficulty}] {player.Profile.Nickname}\n"; + // If Mode Greater than or equal to 3 show Bots individually also + if (Mode >= 3) + { + foreach (var player in _zoneAndPlayers[zone.Key].Where(player => player.HealthController.IsAlive)) + { + _distance = Vector3.Distance(player.Position, _player.Position); + _content += $"> [{_distance:n2}m] [{player.Profile.Info.Settings.Role}] [{player.Profile.Side}] [{player.Profile.Info.Settings.BotDifficulty}] {player.Profile.Nickname}\n"; + } + } + } } } } diff --git a/Live/CWX_DebuggingTool/DebuggingTool.cs b/Live/CWX_DebuggingTool/DebuggingTool.cs index 16e6056..0dba75c 100644 --- a/Live/CWX_DebuggingTool/DebuggingTool.cs +++ b/Live/CWX_DebuggingTool/DebuggingTool.cs @@ -1,5 +1,4 @@ -using System; -using BepInEx; +using BepInEx; using Comfort.Common; using EFT; using EFT.Console.Core; @@ -16,7 +15,7 @@ namespace CWX_DebuggingTool } [ConsoleCommand("BotMonitor")] - public static void BotMonitorConsoleCommand([ConsoleArgument("", "Options: 0 = off, 1 = on")] int value ) + public static void BotMonitorConsoleCommand([ConsoleArgument("", "Options: 0 = off, 1 = Total bots, 2 = 1+Total bots per Zone, 3 = 2+Each bot")] int value ) { switch (value) { @@ -25,12 +24,20 @@ namespace CWX_DebuggingTool ConsoleScreen.Log("BotMonitor disabled"); break; case 1: - EnableBotMonitor(); - ConsoleScreen.Log("BotMonitor enabled"); + EnableBotMonitor(1); + ConsoleScreen.Log("BotMonitor enabled with only Total"); + break; + case 2: + EnableBotMonitor(2); + ConsoleScreen.Log("BotMonitor enabled with Total and per zone Total"); + break; + case 3: + EnableBotMonitor(3); + ConsoleScreen.Log("BotMonitor enabled with Total, per zone Total and each bot"); break; default: // fail to load, or wrong option used - ConsoleScreen.LogError("Wrong Option used, please use 0 or 1"); + ConsoleScreen.LogError("Wrong Option used, please use 0, 1, 2 or 3"); break; } } @@ -40,13 +47,13 @@ namespace CWX_DebuggingTool BotmonClass.Instance.Dispose(); } - public static void EnableBotMonitor() + public static void EnableBotMonitor(int option) { - var botmon = BotmonClass.Instance; - var gameWorld = Singleton.Instance; - gameWorld.GetOrAddComponent(); + var btmInstance = gameWorld.GetOrAddComponent(); + + btmInstance.Mode = option; } } } \ No newline at end of file