using LuckerGame.Components.Lucker.Cameras;
using LuckerGame.EntityComponents.Lucker;
using LuckerGame.Events;
using Sandbox;
namespace LuckerGame.Entities;
///
/// Represents a Player.
/// This could belong to a Client or a Bot and represents a common entity to operate on for games and keeping score
///
public partial class Lucker : Entity
{
///
/// The entity this player controls. This value is networked and should be accessed through .
///
[Net] private Entity InternalPawn { get; set; }
///
/// Accesses or sets the entity this player current controls
///
public Entity Pawn
{
get => InternalPawn;
set
{
InternalPawn = value;
if ( value != null )
{
value.Owner = this;
}
}
}
///
/// Before the round has started, this player indicated they were ready
///
[Net] public bool Ready { get; set; }
///
/// This Lucker's camera
///
[BindComponent] public AbstractCamera Camera { get; }
[BindComponent] public LuckerStats Stats { get; }
///
/// Creates and properly sets up a Player entity for a given client
///
/// the client to own the player
/// the newly created player
public static Lucker CreateLuckerForClient( IClient client )
{
var player = new Lucker();
client.Pawn = player;
player.Owner = client as Entity;
player.Name = client.Name;
var camera = player.Components.Create();
var stats = player.Components.Create();
return player;
}
///
/// Allows clients to request setting their ready state
///
/// whether they are readying up or calming down
[ConCmd.Server("set_ready")]
public static void ReadyUpCommand(bool readyState)
{
var client = ConsoleSystem.Caller;
var player = client.Pawn as Lucker;
player.SetReady( readyState );
}
///
/// Sets this player's ready state
///
/// the ready state being set
public void SetReady(bool ready)
{
Ready = ready;
if ( Game.IsServer )
{
Event.Run( LuckerEvent.PlayerReady, this, ready );
}
}
///
public override void Simulate( IClient cl )
{
base.Simulate( cl );
}
public override void FrameSimulate( IClient cl )
{
base.FrameSimulate( cl );
Camera?.Update();
}
public override void BuildInput()
{
base.BuildInput();
Camera?.BuildInput();
}
}