mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-24 13:45:37 +03:00
Added Item.Properties
This commit is contained in:
parent
627fa4c825
commit
bda8b5b956
@ -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()
|
||||
{
|
||||
|
@ -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>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user