From 914512435d37d9f1e1ea4c045afd4ec5612b7534 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Sun, 30 Jul 2023 02:45:36 +0100 Subject: Replace movement controllers --- code/pawn/Player.cs | 74 +++++++++++++++-------------------------------------- 1 file changed, 20 insertions(+), 54 deletions(-) (limited to 'code/pawn/Player.cs') diff --git a/code/pawn/Player.cs b/code/pawn/Player.cs index cd2f83a..7462c6e 100644 --- a/code/pawn/Player.cs +++ b/code/pawn/Player.cs @@ -44,10 +44,11 @@ public partial class Player : AnimatedEntity [Net] public Team CurrentTeam { get; set; } - [BindComponent] public PlayerController Controller { get; } - [BindComponent] public PlayerAnimator Animator { get; } - [BindComponent] public PlayerInventory Inventory { get; } - [BindComponent] public PlayerSpectator Spectator { get; } + public BaseCameraComponent Camera => Components.Get(); + public BaseControllerComponent Controller => Components.Get(); + [BindComponent] public AnimatorComponent Animator { get; } + [BindComponent] public InventoryComponent Inventory { get; } + [BindComponent] public FallDamageComponent FallDamage { get; } [Net] public Ragdoll PlayerRagdoll { get; set; } @@ -87,9 +88,11 @@ public partial class Player : AnimatedEntity EnableDrawing = true; Components.RemoveAll(); - Components.Create(); - Components.Create(); - Components.Create(); + Components.Create(); + Components.Create(); + Components.Create(); + Components.Create(); + Components.Create(); Health = 100f; LifeState = LifeState.Alive; @@ -119,7 +122,6 @@ public partial class Player : AnimatedEntity EnableDrawing = false; Inventory?.Clear(); - Components.RemoveAll(); LifeState = LifeState.Dead; } @@ -174,67 +176,31 @@ public partial class Player : AnimatedEntity SimulateRotation(); TickPlayerUse(); - Controller?.Simulate( this ); + Controller?.Simulate( cl ); + Camera?.Simulate( cl ); Animator?.Simulate(); Inventory?.Simulate( cl ); - Spectator?.Simulate(); - - EyeLocalPosition = Vector3.Up * (64f * Scale); + FallDamage?.Simulate( cl ); - if (Game.IsServer && Spectator == null && LifeState == LifeState.Dead && TimeSinceDeath > 3) + if (Game.IsServer && Camera is not SpectatorCameraComponent && LifeState == LifeState.Dead && TimeSinceDeath > 3.5) { - Log.Info( "Spectator created" ); DeathOverlay.Hide( To.Single( Client ) ); - Components.Create(); + Components.RemoveAll(); + Components.Create(); } } public override void BuildInput() { - InputDirection = Input.AnalogMove; - - if ( Input.StopProcessing ) - return; - - var look = Input.AnalogLook; - - if ( ViewAngles.pitch > 90f || ViewAngles.pitch < -90f ) - { - look = look.WithYaw( look.yaw * -1f ); - } - - var viewAngles = ViewAngles; - viewAngles += look; - viewAngles.pitch = viewAngles.pitch.Clamp( -89f, 89f ); - viewAngles.roll = 0f; - ViewAngles = viewAngles.Normal; + Controller?.BuildInput(); + Camera?.BuildInput(); } public override void FrameSimulate( IClient cl ) { - if (Spectator != null) - { - Spectator.FrameSimulate(this); - return; - } - else if (Controller != null) - { - //TOOD move below logic to controller - } - SimulateRotation(); - - Camera.Rotation = ViewAngles.ToRotation(); - Camera.FieldOfView = Screen.CreateVerticalFieldOfView( Game.Preferences.FieldOfView ); - - Camera.FirstPersonViewer = this; - if (PlayerRagdoll != null && PlayerRagdoll.IsValid) - { - Camera.Position = PlayerRagdoll.Position; - } else - { - Camera.Position = EyePosition; - } + Controller?.FrameSimulate( cl ); + Camera?.FrameSimulate( cl ); } public TraceResult TraceBBox( Vector3 start, Vector3 end, float liftFeet = 0.0f ) -- cgit v1.2.3-70-g09d2