using LuckerGame.Components.Lucker.Cameras;
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 currently controls
///
[Net]
public Entity Pawn { get; set; }
///
/// 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; }
///
/// 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();
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 );
Pawn?.Simulate(cl);
}
public override void FrameSimulate( IClient cl )
{
base.FrameSimulate( cl );
Camera?.Update();
Pawn?.FrameSimulate(cl);
}
public override void BuildInput()
{
base.BuildInput();
Camera?.BuildInput();
Pawn?.BuildInput();
}
}