Added a Inventory.CraftItem version which allows you to specify stack amounts

This commit is contained in:
Garry Newman 2017-02-01 15:00:53 +00:00
parent b06411c42c
commit 287744fd83
2 changed files with 28 additions and 1 deletions

View File

@ -13,6 +13,12 @@ public partial class Inventory
/// </summary>
public struct Item : IEquatable<Item>
{
public struct Amount
{
public Item Item;
public int Quantity;
}
public ulong Id;
public int Quantity;

View File

@ -298,7 +298,7 @@ public unsafe Result Deserialize( byte[] data, int dataLength = -1 )
/// <summary>
/// Crafting! Uses the passed items to buy the target item.
/// You need to have set up the appropriate exchange rules in your item
/// definitions.
/// definitions. This assumes all the items passed in aren't stacked.
/// </summary>
public Result CraftItem( Item[] list, Definition target )
{
@ -316,6 +316,27 @@ public Result CraftItem( Item[] list, Definition target )
return new Result( this, resultHandle, true );
}
/// <summary>
/// Crafting! Uses the passed items to buy the target item.
/// You need to have set up the appropriate exchange rules in your item
/// definitions.
/// </summary>
public Result CraftItem( Item.Amount[] list, Definition target )
{
SteamNative.SteamInventoryResult_t resultHandle = -1;
var newItems = new SteamNative.SteamItemDef_t[] { new SteamNative.SteamItemDef_t() { Value = target.Id } };
var newItemC = new uint[] { 1 };
var takeItems = list.Select( x => (SteamNative.SteamItemInstanceID_t)x.Item.Id ).ToArray();
var takeItemsC = list.Select( x => (uint)x.Quantity ).ToArray();
if ( !inventory.ExchangeItems( ref resultHandle, newItems, newItemC, 1, takeItems, takeItemsC, (uint)takeItems.Length ) )
return null;
return new Result( this, resultHandle, true );
}
/// <summary>
/// Split stack into two items
/// </summary>