Utility static class with helper methods for player and spawn queries. It exposes cached enumerables of PlayerState, lookup by player id, filtering by team, getting IDescription from GameObject/Component, and methods to find spawn points and random team spawns.
using System.IO;
namespace KOTH;
// TODO : destroy this shit
// move player state utils to player state
// move : spawns to world or some bullshit
public static partial class GameUtils
{
public static IEnumerable<PlayerState> AllPlayers => Game.ActiveScene.GetAllComponents<PlayerState>();
public static PlayerState GetPlayerState(Guid? id) => AllPlayers.FirstOrDefault(n => n.PlayerPawn?.Id == id);
public static IEnumerable<PlayerState> GetPlayers(Team team) => AllPlayers.Where(x => x.Team == team);
public static IDescription GetDescription(GameObject go) => go?.Components.Get<IDescription>(FindMode.EverythingInSelfAndDescendants);
public static IDescription GetDescription(Component component) => GetDescription(component?.GameObject);
public static List<TeamSpawnPoint> GetAllSpawns()
{
if (Game.ActiveScene == null)
{
return [];
}
return Game.ActiveScene.GetAllComponents<TeamSpawnPoint>().ToList();
}
public static TeamSpawnPoint GetRandomTeamSpawn(Team Team)
{
return Random.Shared.FromList(GetAllSpawns().Where(Spawn => Spawn.Team == Team && !Spawn.IsDummy).ToList());
}
public static List<TeamSpawnPoint> GetDummySpawns()
{
return GetAllSpawns().Where(Spawn => Spawn.IsDummy).ToList();
}
}