From 208af219d232fa283bb8b6b1485ce1ea634345bd Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Tue, 14 May 2019 20:17:01 +0100 Subject: [PATCH] Added Acquired and Origin properties to InventoryItem --- Facepunch.Steamworks.Test/InventoryTest.cs | 26 +++++++++++++ Facepunch.Steamworks/Structs/InventoryItem.cs | 37 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/Facepunch.Steamworks.Test/InventoryTest.cs b/Facepunch.Steamworks.Test/InventoryTest.cs index fff40a3..44f5d64 100644 --- a/Facepunch.Steamworks.Test/InventoryTest.cs +++ b/Facepunch.Steamworks.Test/InventoryTest.cs @@ -74,6 +74,32 @@ namespace Steamworks } } + [TestMethod] + public async Task GetItemSpecialProperties() + { + await SteamInventory.WaitForDefinitions(); + + var result = await SteamInventory.GetAllItemsAsync(); + + Assert.IsTrue( result.HasValue ); + Assert.IsTrue( result.Value.ItemCount > 0 ); + + using ( result ) + { + var items = result.Value.GetItems( true ); + + Assert.IsNotNull( items ); + + foreach ( var item in items ) + { + Console.WriteLine( $"{item.Id} / {item.DefId} / {item.Quantity} / {item.Def?.Name} " ); + + Console.WriteLine( $" Acquired: {item.Acquired}" ); + Console.WriteLine( $" Origin: {item.Origin}" ); + } + } + } + [TestMethod] public async Task GetAllItemsMultipleTimes() { diff --git a/Facepunch.Steamworks/Structs/InventoryItem.cs b/Facepunch.Steamworks/Structs/InventoryItem.cs index 5cade39..ff0b36a 100644 --- a/Facepunch.Steamworks/Structs/InventoryItem.cs +++ b/Facepunch.Steamworks/Structs/InventoryItem.cs @@ -123,6 +123,43 @@ namespace Steamworks return props; } + /// + /// Will try to return the date that this item was aquired. You need to have for the items + /// with their properties for this to work. + /// + public DateTime Acquired + { + get + { + if ( Properties == null ) return DateTime.UtcNow; + + var str = Properties["acquired"]; + + var y = int.Parse( str.Substring( 0, 4 ) ); + var m = int.Parse( str.Substring( 4, 2 ) ); + var d = int.Parse( str.Substring( 6, 2 ) ); + + var h = int.Parse( str.Substring( 9, 2 ) ); + var mn = int.Parse( str.Substring( 11, 2 ) ); + var s = int.Parse( str.Substring( 13, 2 ) ); + + return new DateTime( y, m, d, h, mn, s, DateTimeKind.Utc ); + } + } + + /// + /// Tries to get the origin property. Need properties for this to work. + /// Will return a string like "market" + /// + public string Origin + { + get + { + if ( Properties == null ) return null; + return Properties["origin"]; + } + } + /// /// Small utility class to describe an item with a quantity ///