using EFT.UI; using System; using UnityEngine; using System.Collections.Generic; using System.Linq; using System.Text; using Comfort.Common; using EFT; namespace CWX_DebuggingTool { public sealed class BotmonClass : MonoBehaviour, IDisposable { private static BotmonClass _instance = null; private GUIContent _guiContent = null; 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 IBotGame _botGame; private BotmonClass() { } public static BotmonClass Instance { get { if (_instance == null) { _instance = new BotmonClass(); } return _instance; } } public void Dispose() { var gameWorld = Singleton.Instance; var gameobj = gameWorld.GetComponent(); Destroy(gameobj); _instance = null; GC.SuppressFinalize(this); } ~BotmonClass() { ConsoleScreen.Log("BotMonitor Disabled on game end"); } public void Awake() { // Set Basics _gameWorld = Singleton.Instance; _botGame = Singleton.Instance; _zones = LocationScene.GetAllObjects().ToList(); foreach (var botZone in _zones) { _zoneAndPlayers.Add(botZone.name, new List()); } // get player _player = _gameWorld.AllPlayers.Find(x => x.IsYourPlayer); if (_gameWorld.AllPlayers.Count > 1) { foreach (var player in _gameWorld.AllPlayers) { if (!player.IsYourPlayer) { var theirZone = player.AIData.BotOwner.BotsGroup.BotZone.NameZone; _zoneAndPlayers[theirZone].Add(player); } } } _botGame.BotsController.BotSpawner.OnBotCreated += owner => { Player player = owner.GetPlayer; var theirZone = player.AIData.BotOwner.BotsGroup.BotZone.NameZone; _zoneAndPlayers[theirZone].Add(player); }; } public void OnGUI() { // set basics on GUI if (_textStyle == null) { _textStyle = new GUIStyle(GUI.skin.box); _textStyle.alignment = TextAnchor.MiddleLeft; _textStyle.fontSize = 20; _textStyle.margin = new RectOffset(3, 3, 3, 3); } // new GUI Content if (_guiContent == null) { _guiContent = new GUIContent(); } _stringBuilder.Clear(); if (_zoneAndPlayers != null) { _stringBuilder.AppendLine($"Total = {_gameWorld.AllPlayers.Count - 1}"); foreach (var zone in _zoneAndPlayers) { if (_zoneAndPlayers[zone.Key].Count > 0) { _stringBuilder.AppendLine($"{zone.Key} = {_zoneAndPlayers[zone.Key].Count}"); } foreach (var player in _zoneAndPlayers[zone.Key]) { if (!player.HealthController.IsAlive) { return; } var distance = Vector3.Distance(player.Position, _player.Position); _stringBuilder.AppendLine($"> [{distance:n2}m] [{player.Profile.Info.Settings.Role}] [{player.Profile.Side}] [{player.Profile.Info.Settings.BotDifficulty}]{player.Profile.Nickname}"); } } } _guiContent.text = _stringBuilder.ToString(); var size = _textStyle.CalcSize(_guiContent); GUI.Box(new Rect(Screen.width - size.x - 5f, 60f, size.x, size.y), _guiContent, _textStyle); } } }