From f137095304f456b06229e4d17ee8249e974fceaf Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Fri, 28 Jul 2023 13:37:17 +0100 Subject: Add spectator mode --- code/pawn/Player.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'code/pawn/Player.cs') diff --git a/code/pawn/Player.cs b/code/pawn/Player.cs index a1b126a..68d383d 100644 --- a/code/pawn/Player.cs +++ b/code/pawn/Player.cs @@ -47,6 +47,7 @@ public partial class Player : AnimatedEntity [BindComponent] public PlayerController Controller { get; } [BindComponent] public PlayerAnimator Animator { get; } [BindComponent] public PlayerInventory Inventory { get; } + [BindComponent] public PlayerSpectator Spectator { get; } public Ragdoll PlayerRagdoll { get; set; } public ClothingContainer PlayerClothingContainer { get; set; } @@ -74,6 +75,7 @@ public partial class Player : AnimatedEntity Tags.Add( "livingplayer" ); EnableAllCollisions = true; EnableDrawing = true; + Components.Remove( Spectator ); Components.Create(); Components.Create(); Components.Create(); @@ -85,6 +87,7 @@ public partial class Player : AnimatedEntity { DisablePlayer(); DeleteRagdoll(); + Components.RemoveAll(); } public void DeleteRagdoll() @@ -118,6 +121,7 @@ public partial class Player : AnimatedEntity ragdoll.PhysicsGroup.AddVelocity(LastAttackForce / 100); PlayerClothingContainer.DressEntity( ragdoll ); PlayerRagdoll = ragdoll; + Components.Create(); } public override void TakeDamage( DamageInfo info ) @@ -150,6 +154,7 @@ public partial class Player : AnimatedEntity Controller?.Simulate( cl ); Animator?.Simulate(); Inventory?.Simulate( cl ); + Spectator?.Simulate(); EyeLocalPosition = Vector3.Up * (64f * Scale); } @@ -174,10 +179,13 @@ public partial class Player : AnimatedEntity ViewAngles = viewAngles.Normal; } - bool IsThirdPerson { get; set; } = false; - public override void FrameSimulate( IClient cl ) { + if (Spectator != null) + { + Spectator.FrameSimulate(this); + return; + } SimulateRotation(); Camera.Rotation = ViewAngles.ToRotation(); -- cgit v1.2.3-70-g09d2