fix up BotMon, now has three options, each giving more info

This commit is contained in:
CWX 2023-01-21 11:21:21 +00:00
parent 2a726ec4d7
commit 9209a7125b
2 changed files with 57 additions and 34 deletions

View File

@ -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<string, List<Player>> _zoneAndPlayers = new Dictionary<string, List<Player>>();
private List<BotZone> _zones = null;
private GameWorld _gameWorld = null;
private List<BotZone> _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<GameWorld>.Instance;
// Get BotGame Instance
_botGame = Singleton<IBotGame>.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<BotZone>().ToList();
// Set up the Dictionary
foreach (var botZone in _zones)
{
_zoneAndPlayers.Add(botZone.name, new List<Player>());
}
// 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;
@ -117,28 +124,37 @@ namespace CWX_DebuggingTool
_guiContent = new GUIContent();
}
// If Mode Greater than or equal to 1 show total
if (Mode >= 1)
{
_content = string.Empty;
_content += $"Total = {_gameWorld.AllPlayers.Count - 1}\n";
}
// If Mode Greater than or equal to 2 show total for each zone
if (Mode >= 2)
{
if (_zoneAndPlayers != null)
{
_content += $"Total = {_gameWorld.AllPlayers.Count - 1}\n";
foreach (var zone in _zoneAndPlayers)
{
if (_zoneAndPlayers[zone.Key].FindAll(x => x.HealthController.IsAlive).Count > 0)
{
_content += $"{zone.Key} = {_zoneAndPlayers[zone.Key].FindAll(x => x.HealthController.IsAlive).Count}\n";
foreach (var player in _zoneAndPlayers[zone.Key])
// If Mode Greater than or equal to 3 show Bots individually also
if (Mode >= 3)
{
if (!player.HealthController.IsAlive)
foreach (var player in _zoneAndPlayers[zone.Key].Where(player => player.HealthController.IsAlive))
{
continue;
}
_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";
}
}
}
}
}
}
_guiContent.text = _content;

View File

@ -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<GameWorld>.Instance;
gameWorld.GetOrAddComponent<BotmonClass>();
var btmInstance = gameWorld.GetOrAddComponent<BotmonClass>();
btmInstance.Mode = option;
}
}
}