things/items/RerollItem.cs

Item entity representing a reroll pickup. It sets lifetime/physics, animates a bobbing/rotation in Update, and when a Player collides it grants one reroll, plays a nearby SFX via Manager RPC, triggers the player's collect effect, and removes itself.

Networking
using System;
using Sandbox;
using Sandbox.Diagnostics;
using Sandbox.Utility;

public class RerollItem : Item
{
	private float _rotateTimeOffset;
	private float _personalRotateSpeed;

	public override Vector3 SpawnScale => new Vector3( 1.3f );

	private Vector3 _baseRotation;
	protected override float AttractRangeFactor => 1f;
	protected override float AttractStrengthFactor => 0.8f;

	protected override void OnStart()
	{
		base.OnStart();

		Lifetime = 65f;
		ShouldCheckBounds = true;
		PushStrength = 500f;

		BaseZPos = 11f;
		WorldPosition = WorldPosition.WithZ( BaseZPos );

		if ( IsProxy )
			return;

		Deceleration = 0.92f;

		_rotateTimeOffset = Game.Random.Float( 0f, 10f );
		_personalRotateSpeed = Game.Random.Float( 4f, 8f );

		_baseRotation = new Vector3( Game.Random.Float( 0f, 360f ), Game.Random.Float( 0f, 360f ), Game.Random.Float( 0f, 360f ) );
	}

	protected override void OnUpdate()
	{
		base.OnUpdate();

		if ( Manager.Instance.IsGameOver )
			return;

		if ( IsProxy )
			return;

		LocalRotation = Rotation.From( new Angles( _baseRotation.x, _baseRotation.y, _baseRotation.z + Utils.FastSin( _rotateTimeOffset + Time.Now * _personalRotateSpeed ) * 7f ) );

		if ( !IsInTheAir )
			WorldPosition = WorldPosition.WithZ( BaseZPos + 3f + Utils.MapReturn( Utils.FastSin( _rotateTimeOffset + Time.Now * _personalRotateSpeed ), -1f, 1f, -1f, 1f, EasingType.Linear ) * 3f );
	}

	public override void Colliding( Thing other, float percent, float dt )
	{
		base.Colliding( other, percent, dt );

		if ( CantBeCollected )
			return;

		if ( other is Player player )
		{
			if ( !player.IsDead )
			{
				player.AddRerolls(1);
				Manager.Instance.PlaySfxNearbyRpc( "heal", player.Position2D, pitch: Game.Random.Float( 2.7f, 2.8f ), volume: 1.1f, maxDist: 350f );

				player.CollectItemEffect();

				Remove();
			}
		}
	}
}