Player/Player.Stats.cs

Partial Player component with RPC methods that run on the owning client to record player stats, unlock achievements, and notify level escapes by calling GameStats and AchievementTracker helpers.

Networking
using Sandbox;

namespace BrickJam;

public sealed partial class Player
{
	/// <summary>
	/// Report a stat increment for THIS player's own s&box account. Stats are per-account, so this is
	/// <c>[Rpc.Owner]</c>: host-side gameplay code calls it on any player and it lands on that player's
	/// own client (see <see cref="GameStats"/>).
	/// </summary>
	[Rpc.Owner]
	public void TrackStat( string name, double amount )
	{
		GameStats.Increment( name, amount );
	}

	/// <summary>
	/// Unlock an achievement for THIS player's own account. Runs on the owning client and routes through
	/// <see cref="AchievementTracker"/> so the unlock is deduped + recorded locally before hitting Services.
	/// </summary>
	[Rpc.Owner]
	public void TrackAchievement( string ident )
	{
		AchievementTracker.Unlock( ident );
	}

	/// <summary>Owner client: record an escaped level (Grand Tour stat). Argument is a <see cref="LevelType"/>.</summary>
	[Rpc.Owner]
	public void NotifyLevelEscaped( int level )
	{
		AchievementTracker.OnLevelEscaped( (LevelType)level );
	}
}