Added Item.Properties

This commit is contained in:
Garry Newman 2018-01-31 13:30:51 +00:00
parent 627fa4c825
commit bda8b5b956
3 changed files with 80 additions and 34 deletions

View File

@ -113,6 +113,34 @@ public void InventoryItemList()
}
}
[TestMethod]
public void InventoryItemProperties()
{
using (var client = new Facepunch.Steamworks.Client(252490))
{
while ( true )
{
client.Update();
if (client.Inventory.Items == null) continue;
foreach (var item in client.Inventory.Items)
{
Console.WriteLine($"{item.Id} ({item.Definition.Name})");
foreach (var property in item.Properties)
{
Console.WriteLine($" {property.Key} = {property.Value}");
}
Console.WriteLine("");
}
return;
}
}
}
[TestMethod]
public void Deserialize()
{

View File

@ -24,6 +24,8 @@ public struct Amount
public int DefinitionId;
public Dictionary<string, string> Properties { get; internal set; }
/// <summary>
/// Careful, this might not be available. Especially on a game server.
/// </summary>

View File

@ -86,6 +86,7 @@ internal Result( Inventory inventory, int Handle, bool pending )
this.inventory = inventory;
}
internal void Fill()
{
if ( _gotResult )
@ -106,44 +107,31 @@ internal void Fill()
if ( steamItems == null )
return;
Items = steamItems.Where( x => ( (int)x.Flags & (int)SteamNative.SteamItemFlags.Removed ) != (int)SteamNative.SteamItemFlags.Removed && ( (int)x.Flags & (int)SteamNative.SteamItemFlags.Consumed ) != (int)SteamNative.SteamItemFlags.Consumed )
.Select( x =>
{
return new Inventory.Item()
{
Quantity = x.Quantity,
Id = x.ItemId,
DefinitionId = x.Definition,
TradeLocked = ( (int)x.Flags & (int)SteamNative.SteamItemFlags.NoTrade ) != 0,
Definition = inventory.FindDefinition( x.Definition )
};
} ).ToArray();
var tempItems = new List<Item>();
var tempRemoved = new List<Item>();
var tempConsumed = new List<Item>();
Removed = steamItems.Where( x => ( (int)x.Flags & (int)SteamNative.SteamItemFlags.Removed ) != 0 )
.Select( x =>
for ( int i=0; i< steamItems.Length; i++ )
{
return new Inventory.Item()
{
Quantity = x.Quantity,
Id = x.ItemId,
DefinitionId = x.Definition,
TradeLocked = ( (int)x.Flags & (int)SteamNative.SteamItemFlags.NoTrade ) != 0,
Definition = inventory.FindDefinition( x.Definition )
};
} ).ToArray();
var item = inventory.ItemFrom( Handle, steamItems[i], i );
Consumed = steamItems.Where( x => ( (int)x.Flags & (int)SteamNative.SteamItemFlags.Consumed ) != 0 )
.Select( x =>
{
return new Inventory.Item()
if ( ( steamItems[i].Flags & (int)SteamNative.SteamItemFlags.Removed ) != 0 )
{
Quantity = x.Quantity,
Id = x.ItemId,
DefinitionId = x.Definition,
TradeLocked = ( (int)x.Flags & (int)SteamNative.SteamItemFlags.NoTrade ) != 0,
Definition = inventory.FindDefinition( x.Definition )
};
} ).ToArray();
tempRemoved.Add(item);
}
else if ((steamItems[i].Flags & (int)SteamNative.SteamItemFlags.Consumed) != 0)
{
tempConsumed.Add(item);
}
else
{
tempItems.Add(item);
}
}
Items = tempItems.ToArray();
Removed = tempRemoved.ToArray();
Consumed = tempConsumed.ToArray();
if ( OnResult != null )
{
@ -186,5 +174,33 @@ public void Dispose()
inventory = null;
}
}
internal Item ItemFrom( SteamInventoryResult_t handle, SteamItemDetails_t detail, int index )
{
var props = new Dictionary<string, string>();
if ( inventory.GetResultItemProperty(handle, (uint) index, null, out string propertyNames) )
{
foreach ( var propertyName in propertyNames.Split( ',' ) )
{
if ( inventory.GetResultItemProperty(handle, (uint)index, propertyName, out string propertyValue ) )
{
props.Add(propertyName, propertyValue);
}
}
}
var item = new Item()
{
Quantity = detail.Quantity,
Id = detail.ItemId,
DefinitionId = detail.Definition,
TradeLocked = ((int)detail.Flags & (int)SteamNative.SteamItemFlags.NoTrade) != 0,
Definition = FindDefinition(detail.Definition),
Properties = props
};
return item;
}
}
}