diff --git a/Facepunch.Steamworks.Test/UserStatsTest.cs b/Facepunch.Steamworks.Test/UserStatsTest.cs index 3e622fe..077d5d3 100644 --- a/Facepunch.Steamworks.Test/UserStatsTest.cs +++ b/Facepunch.Steamworks.Test/UserStatsTest.cs @@ -168,6 +168,30 @@ public void GetStatInt() Assert.AreNotEqual( 0, deaths.GetInt() ); } + [TestMethod] + public async Task GetFriendStats() + { + var friend = new Friend( 76561197965732579 ); // Hezzy + + // Download stats + var status = await friend.RequestUserStats(); + Assert.AreNotEqual( false, status ); + + var deaths = friend.GetStatInt( "deaths" ); + + Console.WriteLine( $"Hezzy has died {deaths} times" ); + + Assert.AreNotEqual( 0, deaths ); + + var unlocked = friend.GetAchievement( "COLLECT_100_WOOD" ); + Assert.AreNotEqual( false, unlocked ); + + var when = friend.GetAchievementUnlockTime( "COLLECT_100_WOOD" ); + Assert.AreNotEqual( when, DateTime.MinValue ); + + Console.WriteLine( $"Hezzy unlocked COLLECT_100_WOOD {when}" ); + } + [TestMethod] public async Task GetStatGlobalInt() { diff --git a/Facepunch.Steamworks/Structs/Friend.cs b/Facepunch.Steamworks/Structs/Friend.cs index 5a3da5e..f1b1a4c 100644 --- a/Facepunch.Steamworks/Structs/Friend.cs +++ b/Facepunch.Steamworks/Structs/Friend.cs @@ -184,5 +184,16 @@ public bool SendMessage( string message ) return SteamFriends.Internal.ReplyToFriendMessage( Id, message ); } + + /// + /// Tries to get download the latest user stats + /// + /// True if successful, False if failure + public async Task RequestUserStats() + { + var result = await SteamUserStats.Internal.RequestUserStats( Id ); + return result.HasValue && result.Value.Result == Result.OK; + } + } } \ No newline at end of file