mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-01-12 14:48:02 +03:00
Added Item.Properties
This commit is contained in:
parent
627fa4c825
commit
bda8b5b956
@ -113,6 +113,34 @@ namespace Facepunch.Steamworks.Test
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[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]
|
[TestMethod]
|
||||||
public void Deserialize()
|
public void Deserialize()
|
||||||
{
|
{
|
||||||
|
@ -24,6 +24,8 @@ namespace Facepunch.Steamworks
|
|||||||
|
|
||||||
public int DefinitionId;
|
public int DefinitionId;
|
||||||
|
|
||||||
|
public Dictionary<string, string> Properties { get; internal set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Careful, this might not be available. Especially on a game server.
|
/// Careful, this might not be available. Especially on a game server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -86,6 +86,7 @@ namespace Facepunch.Steamworks
|
|||||||
this.inventory = inventory;
|
this.inventory = inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal void Fill()
|
internal void Fill()
|
||||||
{
|
{
|
||||||
if ( _gotResult )
|
if ( _gotResult )
|
||||||
@ -106,44 +107,31 @@ namespace Facepunch.Steamworks
|
|||||||
if ( steamItems == null )
|
if ( steamItems == null )
|
||||||
return;
|
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 )
|
var tempItems = new List<Item>();
|
||||||
.Select( x =>
|
var tempRemoved = new List<Item>();
|
||||||
{
|
var tempConsumed = new List<Item>();
|
||||||
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();
|
|
||||||
|
|
||||||
Removed = steamItems.Where( x => ( (int)x.Flags & (int)SteamNative.SteamItemFlags.Removed ) != 0 )
|
for ( int i=0; i< steamItems.Length; i++ )
|
||||||
.Select( x =>
|
|
||||||
{
|
{
|
||||||
return new Inventory.Item()
|
var item = inventory.ItemFrom( Handle, steamItems[i], i );
|
||||||
{
|
|
||||||
Quantity = x.Quantity,
|
|
||||||
Id = x.ItemId,
|
|
||||||
DefinitionId = x.Definition,
|
|
||||||
TradeLocked = ( (int)x.Flags & (int)SteamNative.SteamItemFlags.NoTrade ) != 0,
|
|
||||||
Definition = inventory.FindDefinition( x.Definition )
|
|
||||||
};
|
|
||||||
} ).ToArray();
|
|
||||||
|
|
||||||
Consumed = steamItems.Where( x => ( (int)x.Flags & (int)SteamNative.SteamItemFlags.Consumed ) != 0 )
|
if ( ( steamItems[i].Flags & (int)SteamNative.SteamItemFlags.Removed ) != 0 )
|
||||||
.Select( x =>
|
|
||||||
{
|
{
|
||||||
return new Inventory.Item()
|
tempRemoved.Add(item);
|
||||||
|
}
|
||||||
|
else if ((steamItems[i].Flags & (int)SteamNative.SteamItemFlags.Consumed) != 0)
|
||||||
{
|
{
|
||||||
Quantity = x.Quantity,
|
tempConsumed.Add(item);
|
||||||
Id = x.ItemId,
|
}
|
||||||
DefinitionId = x.Definition,
|
else
|
||||||
TradeLocked = ( (int)x.Flags & (int)SteamNative.SteamItemFlags.NoTrade ) != 0,
|
{
|
||||||
Definition = inventory.FindDefinition( x.Definition )
|
tempItems.Add(item);
|
||||||
};
|
}
|
||||||
} ).ToArray();
|
}
|
||||||
|
|
||||||
|
Items = tempItems.ToArray();
|
||||||
|
Removed = tempRemoved.ToArray();
|
||||||
|
Consumed = tempConsumed.ToArray();
|
||||||
|
|
||||||
if ( OnResult != null )
|
if ( OnResult != null )
|
||||||
{
|
{
|
||||||
@ -186,5 +174,33 @@ namespace Facepunch.Steamworks
|
|||||||
inventory = null;
|
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…
x
Reference in New Issue
Block a user