134 lines
3.2 KiB
C#
134 lines
3.2 KiB
C#
using System.ComponentModel;
|
|
using LuckerGame.Components.Pawn;
|
|
using Sandbox;
|
|
|
|
namespace LuckerGame.Entities;
|
|
|
|
/// <summary>
|
|
/// Represents an entity in the world. Could be controlled by a Lucker or a minigame
|
|
/// </summary>
|
|
public partial class Pawn : AnimatedEntity
|
|
{
|
|
[ClientInput]
|
|
public Vector3 InputDirection { get; set; }
|
|
|
|
[ClientInput]
|
|
public Angles ViewAngles { get; set; }
|
|
|
|
/// <summary>
|
|
/// Position a player should be looking from in world space.
|
|
/// </summary>
|
|
[Browsable( false )]
|
|
public Vector3 EyePosition
|
|
{
|
|
get => Transform.PointToWorld( EyeLocalPosition );
|
|
set => EyeLocalPosition = Transform.PointToLocal( value );
|
|
}
|
|
|
|
/// <summary>
|
|
/// Position a player should be looking from in local to the entity coordinates.
|
|
/// </summary>
|
|
[Net, Predicted, Browsable( false )]
|
|
public Vector3 EyeLocalPosition { get; set; }
|
|
|
|
/// <summary>
|
|
/// Rotation of the entity's "eyes", i.e. rotation for the camera when this entity is used as the view entity.
|
|
/// </summary>
|
|
[Browsable( false )]
|
|
public Rotation EyeRotation
|
|
{
|
|
get => Transform.RotationToWorld( EyeLocalRotation );
|
|
set => EyeLocalRotation = Transform.RotationToLocal( value );
|
|
}
|
|
|
|
/// <summary>
|
|
/// Rotation of the entity's "eyes", i.e. rotation for the camera when this entity is used as the view entity. In local to the entity coordinates.
|
|
/// </summary>
|
|
[Net, Predicted, Browsable( false )]
|
|
public Rotation EyeLocalRotation { get; set; }
|
|
|
|
public BBox Hull
|
|
{
|
|
get => new
|
|
(
|
|
new Vector3( -16, -16, 0 ),
|
|
new Vector3( 16, 16, 64 )
|
|
);
|
|
}
|
|
|
|
[BindComponent] public UserPawnController Controller { get; }
|
|
[BindComponent] public PawnAnimator Animator { get; }
|
|
|
|
public override Ray AimRay => new Ray( EyePosition, EyeRotation.Forward );
|
|
|
|
/// <summary>
|
|
/// Called when the entity is first created
|
|
/// </summary>
|
|
public override void Spawn()
|
|
{
|
|
SetModel( "models/citizen/citizen.vmdl" );
|
|
|
|
EnableDrawing = true;
|
|
EnableHideInFirstPerson = true;
|
|
EnableShadowInFirstPerson = true;
|
|
}
|
|
|
|
public void Respawn()
|
|
{
|
|
Components.Create<UserPawnController>();
|
|
Components.Create<PawnAnimator>();
|
|
}
|
|
|
|
public void DressFromClient( IClient cl )
|
|
{
|
|
var c = new ClothingContainer();
|
|
c.LoadFromClient( cl );
|
|
c.DressEntity( this );
|
|
}
|
|
|
|
public override void Simulate( IClient cl )
|
|
{
|
|
SimulateRotation();
|
|
Controller?.Simulate( cl );
|
|
Animator?.Simulate();
|
|
}
|
|
|
|
public override void BuildInput()
|
|
{
|
|
}
|
|
|
|
public override void FrameSimulate( IClient cl )
|
|
{
|
|
SimulateRotation();
|
|
}
|
|
|
|
public TraceResult TraceBBox( Vector3 start, Vector3 end, float liftFeet = 0.0f )
|
|
{
|
|
return TraceBBox( start, end, Hull.Mins, Hull.Maxs, liftFeet );
|
|
}
|
|
|
|
public TraceResult TraceBBox( Vector3 start, Vector3 end, Vector3 mins, Vector3 maxs, float liftFeet = 0.0f )
|
|
{
|
|
if ( liftFeet > 0 )
|
|
{
|
|
start += Vector3.Up * liftFeet;
|
|
maxs = maxs.WithZ( maxs.z - liftFeet );
|
|
}
|
|
|
|
var tr = Trace.Ray( start, end )
|
|
.Size( mins, maxs )
|
|
.WithAnyTags( "solid", "playerclip", "passbullets" )
|
|
.Ignore( this )
|
|
.Run();
|
|
|
|
return tr;
|
|
}
|
|
|
|
protected void SimulateRotation()
|
|
{
|
|
var idealRotation = ViewAngles.ToRotation();
|
|
EyeRotation = Rotation.Slerp( Rotation, idealRotation, Time.Delta * 10f );
|
|
Rotation = EyeRotation;
|
|
}
|
|
}
|