Added Acquired and Origin properties to InventoryItem

This commit is contained in:
Garry Newman 2019-05-14 20:17:01 +01:00
parent 17d7263973
commit 208af219d2
2 changed files with 63 additions and 0 deletions

View File

@ -74,6 +74,32 @@ public async Task GetAllItems()
} }
} }
[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] [TestMethod]
public async Task GetAllItemsMultipleTimes() public async Task GetAllItemsMultipleTimes()
{ {

View File

@ -123,6 +123,43 @@ internal static Dictionary<string, string> GetProperties( SteamInventoryResult_t
return props; return props;
} }
/// <summary>
/// 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.
/// </summary>
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 );
}
}
/// <summary>
/// Tries to get the origin property. Need properties for this to work.
/// Will return a string like "market"
/// </summary>
public string Origin
{
get
{
if ( Properties == null ) return null;
return Properties["origin"];
}
}
/// <summary> /// <summary>
/// Small utility class to describe an item with a quantity /// Small utility class to describe an item with a quantity
/// </summary> /// </summary>