Player/Player.Status.cs

Player status component. Tracks stun, trip, and slip timers synced over network, provides RPCs to apply and reset those statuses, updates velocity on slip, and plays sound events.

Networking
using System;
using Sandbox;

namespace BrickJam;

public sealed partial class Player
{
	[Sync] public TimeUntil StunLeft { get; set; }
	[Sync] public TimeUntil TripLeft { get; set; }
	[Sync] public TimeUntil SlipLeft { get; set; }

	public bool IsStunned => !StunLeft;
	public bool IsTripping => !TripLeft;
	public bool IsSlipping => !SlipLeft;

	[Rpc.Owner]
	public void Stun( float multiplier = 1f )
	{
		ResetStatus();

		multiplier = Math.Clamp( multiplier, 0.1f, 1f );
		StunLeft = StunDuration * multiplier;

		SoundExtensions.BroadcastPlay( "sounds/crash/crash.sound", WorldPosition, 0.55f ); // the "smash" when you slam into a wall
	}

	[Rpc.Owner]
	public void Trip()
	{
		ResetStatus();
		TripLeft = TripDuration;

		SoundExtensions.BroadcastPlay( "sounds/pipe.sound", WorldPosition, 0.5f );
	}

	[Rpc.Owner]
	public void Slip()
	{
		ResetStatus();

		SlipLeft = SlipDuration;
		Velocity = (Velocity.WithZ( 0 ).Normal * RunSpeed).WithZ( Velocity.z );

		SoundExtensions.BroadcastPlay( "sounds/pipe.sound", WorldPosition, 0.5f );
	}

	[Rpc.Owner]
	public void ResetStatus()
	{
		StunLeft = -1f;
		TripLeft = -1f;
		SlipLeft = -1f;
	}
}