namespace Sandbox.Services; /// /// Allows access to stats for the current game. Stats are defined by the game's author /// and can be used to track anything from player actions to performance metrics. They are /// how you submit data to leaderboards. /// public static partial class Stats { /// /// Stats for the current map /// public static class Map { /// /// Get the stats for the local player /// public static PlayerStats Local => Stats.GetLocalPlayerStats( Application.MapPackage?.GetIdent( false, false ) ?? "local.map" ); /// /// Get the global stats /// [Title( "Get Global Map Stats" )] [Category( "Services/Stats" )] [Icon( "emoji_events" )] [ActionGraphNode( "services.stats.map.getglobal" )] public static GlobalStats Global => Stats.GetGlobalStats( Application.MapPackage?.GetIdent( false, false ) ?? "local.map" ); /// /// Add a stat value for this package /// [Title( "Set Map Stat" )] [Category( "Services/Stats" )] [Icon( "emoji_events" )] [ActionGraphNode( "services.stats.map.set" )] public static void SetValue( string name, double amount, Dictionary data = default ) { var package = Application.MapPackage; if ( package is not null ) { var ident = package.GetIdent( false, false ); Api.Stats.AddIncrement( ident, name, amount, GetObjectDictionary( data ) ); } Local?.Predict( name, amount ); } /// /// Get a stat for the local player /// [Title( "Get Local" )] [Category( "Services/Stats" )] [Icon( "emoji_events" )] [ActionGraphNode( "services.stats.map.getlocal" ), Pure] public static PlayerStat GetLocal( string name ) => Local.Get( name ); /// /// Get a stat for the local player /// [Title( "Get Local" )] [Category( "Services/Stats" )] [Icon( "emoji_events" )] [ActionGraphNode( "services.stats.map.getglobal" ), Pure] public static GlobalStat GetGlobal( string name ) => Global.Get( name ); } }