using System; using System.Collections.Generic; using System.Linq; using Sandbox; partial class Dedugan { public static IReadOnlyList All => InternalPlayers; public static List InternalPlayers = new List(); public static Dedugan Local { get; set; } private Guid _guid; public static Dedugan FindLocalPlayer() => Local; [Sync( SyncFlags.FromHost )] public Guid ConnectionID { get => _guid; set { _guid = value; Connection = Connection.Find( _guid ); if ( _guid == Connection.Local.Id ) { Local = this; // ILocalPlayerEvent.Post( x => x.OnInitialized() ); } InternalPlayers.RemoveAll( x => !x.IsValid() ); if ( !InternalPlayers.Contains( this ) ) InternalPlayers.Add( this ); } } public Connection Connection { get; private set; } public ulong SteamID => Connection.SteamId; public string Name => Connection.DisplayName; public void SetupConnection( Connection connection ) { ConnectionID = connection.Id; GameObject.Name = $"{Name} / {SteamID}"; } public static Dedugan GetByID( Guid id ) => InternalPlayers.FirstOrDefault( x => x.ConnectionID == id ); }