2023-01-29 20:42:03 +00:00
|
|
|
|
using Comfort.Common;
|
|
|
|
|
using EFT;
|
|
|
|
|
using EFT.UI;
|
2023-01-17 19:34:30 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2023-01-29 20:42:03 +00:00
|
|
|
|
using UnityEngine;
|
2023-04-08 17:59:17 +01:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
using CWX_DebuggingTool.Models;
|
2023-01-17 19:34:30 +00:00
|
|
|
|
|
|
|
|
|
namespace CWX_DebuggingTool
|
|
|
|
|
{
|
|
|
|
|
public sealed class BotmonClass : MonoBehaviour, IDisposable
|
|
|
|
|
{
|
2023-01-21 11:21:21 +00:00
|
|
|
|
private static BotmonClass _instance;
|
|
|
|
|
|
|
|
|
|
private GUIContent _guiContent;
|
2023-01-17 19:34:30 +00:00
|
|
|
|
private GUIStyle _textStyle;
|
|
|
|
|
private Player _player;
|
|
|
|
|
private Dictionary<string, List<Player>> _zoneAndPlayers = new Dictionary<string, List<Player>>();
|
2023-04-08 17:59:17 +01:00
|
|
|
|
private Dictionary<string, BotRoleAndDiffClass> _playerRoleAndDiff = new Dictionary<string, BotRoleAndDiffClass>();
|
2023-01-21 11:21:21 +00:00
|
|
|
|
private List<BotZone> _zones;
|
|
|
|
|
private GameWorld _gameWorld;
|
2023-01-17 21:08:50 +00:00
|
|
|
|
private IBotGame _botGame;
|
2023-01-17 21:46:54 +00:00
|
|
|
|
private Rect _rect;
|
2023-04-08 17:59:17 +01:00
|
|
|
|
private string _content = "";
|
2023-01-17 23:08:02 +00:00
|
|
|
|
private Vector2 _guiSize;
|
|
|
|
|
private float _distance;
|
2023-01-17 19:34:30 +00:00
|
|
|
|
|
|
|
|
|
private BotmonClass()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-21 11:21:21 +00:00
|
|
|
|
public int Mode { get; set; }
|
|
|
|
|
|
2023-01-17 19:34:30 +00:00
|
|
|
|
public static BotmonClass Instance
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_instance == null)
|
|
|
|
|
{
|
|
|
|
|
_instance = new BotmonClass();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _instance;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
var gameWorld = Singleton<GameWorld>.Instance;
|
|
|
|
|
|
|
|
|
|
var gameobj = gameWorld.GetComponent<BotmonClass>();
|
|
|
|
|
Destroy(gameobj);
|
|
|
|
|
_instance = null;
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~BotmonClass()
|
|
|
|
|
{
|
|
|
|
|
ConsoleScreen.Log("BotMonitor Disabled on game end");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Awake()
|
|
|
|
|
{
|
2023-01-21 11:21:21 +00:00
|
|
|
|
// Get GameWorld Instance
|
2023-01-17 19:34:30 +00:00
|
|
|
|
_gameWorld = Singleton<GameWorld>.Instance;
|
|
|
|
|
|
2023-01-21 11:21:21 +00:00
|
|
|
|
// Get BotGame Instance
|
2023-01-17 21:08:50 +00:00
|
|
|
|
_botGame = Singleton<IBotGame>.Instance;
|
|
|
|
|
|
2023-01-21 11:21:21 +00:00
|
|
|
|
// Get Player from GameWorld
|
|
|
|
|
_player = _gameWorld.MainPlayer;
|
|
|
|
|
|
|
|
|
|
// Make new rect to use for GUI
|
|
|
|
|
_rect = new Rect(0, 60, 0, 0);
|
|
|
|
|
|
|
|
|
|
// Get all BotZones
|
2023-01-17 19:34:30 +00:00
|
|
|
|
_zones = LocationScene.GetAllObjects<BotZone>().ToList();
|
|
|
|
|
|
2023-01-21 11:21:21 +00:00
|
|
|
|
// Set up the Dictionary
|
2023-01-17 21:08:50 +00:00
|
|
|
|
foreach (var botZone in _zones)
|
2023-01-17 19:34:30 +00:00
|
|
|
|
{
|
2023-01-17 21:08:50 +00:00
|
|
|
|
_zoneAndPlayers.Add(botZone.name, new List<Player>());
|
2023-01-17 19:34:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-21 11:21:21 +00:00
|
|
|
|
// Add existing Bots to list
|
2023-08-08 19:34:27 +01:00
|
|
|
|
if (_gameWorld.RegisteredPlayers.Count > 1)
|
2023-01-17 19:34:30 +00:00
|
|
|
|
{
|
2023-08-08 19:34:27 +01:00
|
|
|
|
foreach (var player in _gameWorld.AllAlivePlayersList)
|
2023-01-17 19:34:30 +00:00
|
|
|
|
{
|
2023-04-08 17:59:17 +01:00
|
|
|
|
if (player.IsYourPlayer) continue;
|
2023-01-17 19:34:30 +00:00
|
|
|
|
|
2023-04-08 17:59:17 +01:00
|
|
|
|
_playerRoleAndDiff.Add(player.ProfileId, GetBotRoleAndDiffClass(player.Profile.Info));
|
|
|
|
|
|
|
|
|
|
var theirZone = player.AIData.BotOwner.BotsGroup.BotZone.NameZone;
|
|
|
|
|
|
|
|
|
|
_zoneAndPlayers[theirZone].Add(player);
|
2023-01-17 19:34:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-17 21:08:50 +00:00
|
|
|
|
|
2023-01-21 11:21:21 +00:00
|
|
|
|
// Sub to Event to get and add Bot when they spawn
|
2023-01-17 21:08:50 +00:00
|
|
|
|
_botGame.BotsController.BotSpawner.OnBotCreated += owner =>
|
|
|
|
|
{
|
2023-04-08 17:59:17 +01:00
|
|
|
|
var player = owner.GetPlayer;
|
|
|
|
|
_zoneAndPlayers[player.AIData.BotOwner.BotsGroup.BotZone.NameZone].Add(player);
|
|
|
|
|
_playerRoleAndDiff.Add(player.ProfileId, GetBotRoleAndDiffClass(player.Profile.Info));
|
2023-01-17 21:08:50 +00:00
|
|
|
|
};
|
2023-01-17 19:34:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-08 17:59:17 +01:00
|
|
|
|
public BotRoleAndDiffClass GetBotRoleAndDiffClass(InfoClass info)
|
|
|
|
|
{
|
2023-10-06 18:46:03 +01:00
|
|
|
|
var settings = info.GetType().GetField("Settings", BindingFlags.Public | BindingFlags.Instance)?.GetValue(info);
|
2023-04-08 17:59:17 +01:00
|
|
|
|
|
2023-10-06 18:46:03 +01:00
|
|
|
|
var role = settings.GetType().GetField("Role", BindingFlags.Instance | BindingFlags.Public)?.GetValue(settings).ToString();
|
|
|
|
|
var diff = settings.GetType().GetField("BotDifficulty", BindingFlags.Instance | BindingFlags.Public)?.GetValue(settings).ToString();
|
2023-04-08 17:59:17 +01:00
|
|
|
|
|
|
|
|
|
return new BotRoleAndDiffClass(string.IsNullOrEmpty(role) ? "" : role, string.IsNullOrEmpty(diff) ? "" : diff);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-17 19:34:30 +00:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-21 11:21:21 +00:00
|
|
|
|
// If Mode Greater than or equal to 1 show total
|
|
|
|
|
if (Mode >= 1)
|
2023-01-17 19:34:30 +00:00
|
|
|
|
{
|
2023-01-21 11:21:21 +00:00
|
|
|
|
_content = string.Empty;
|
2023-08-08 19:34:27 +01:00
|
|
|
|
//_content += $"Total = {_gameWorld.AllPlayers.Count - 1}\n";
|
2023-01-21 11:21:21 +00:00
|
|
|
|
}
|
2023-01-17 19:34:30 +00:00
|
|
|
|
|
2023-01-21 11:21:21 +00:00
|
|
|
|
// If Mode Greater than or equal to 2 show total for each zone
|
2023-04-08 17:59:17 +01:00
|
|
|
|
if (Mode >= 2 && _zoneAndPlayers != null)
|
2023-01-21 11:21:21 +00:00
|
|
|
|
{
|
2023-04-08 17:59:17 +01:00
|
|
|
|
foreach (var zone in _zoneAndPlayers)
|
2023-01-17 19:34:30 +00:00
|
|
|
|
{
|
2023-04-08 17:59:17 +01:00
|
|
|
|
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";
|
|
|
|
|
|
|
|
|
|
// If Mode Greater than or equal to 3 show Bots individually also
|
|
|
|
|
if (Mode < 3) continue;
|
|
|
|
|
|
|
|
|
|
foreach (var player in _zoneAndPlayers[zone.Key].Where(player => player.HealthController.IsAlive))
|
2023-01-17 19:34:30 +00:00
|
|
|
|
{
|
2023-04-08 17:59:17 +01:00
|
|
|
|
_distance = Vector3.Distance(player.Position, _player.Position);
|
|
|
|
|
_content += $"> [{_distance:n2}m] [{_playerRoleAndDiff.First(x => x.Key == player.ProfileId).Value.Role}] " +
|
|
|
|
|
$"[{player.Profile.Side}] [{_playerRoleAndDiff.First(x => x.Key == player.ProfileId).Value.Difficulty}] {player.Profile.Nickname}\n";
|
2023-01-17 19:34:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-17 23:08:02 +00:00
|
|
|
|
_guiContent.text = _content;
|
2023-01-17 19:34:30 +00:00
|
|
|
|
|
2023-01-17 23:08:02 +00:00
|
|
|
|
_guiSize = _textStyle.CalcSize(_guiContent);
|
2023-01-17 19:34:30 +00:00
|
|
|
|
|
2023-01-17 23:08:02 +00:00
|
|
|
|
_rect.x = Screen.width - _guiSize.x - 5f;
|
|
|
|
|
_rect.width = _guiSize.x;
|
|
|
|
|
_rect.height = _guiSize.y;
|
2023-01-17 21:46:54 +00:00
|
|
|
|
|
|
|
|
|
GUI.Box(_rect, _guiContent, _textStyle);
|
2023-01-17 19:34:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|