Added CraftItemAsync with Amounts

This commit is contained in:
Garry Newman 2019-05-07 21:25:41 +01:00
parent d40efa8612
commit 18f81573f5
2 changed files with 30 additions and 0 deletions

View File

@ -239,6 +239,27 @@ public static bool GetAllItems()
return await InventoryResult.GetAsync( sresult );
}
/// <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. This assumes all the items passed in aren't stacked.
/// </summary>
public static async Task<InventoryResult?> CraftItemAsync( InventoryItem.Amount[] list, InventoryDef target )
{
var sresult = default( SteamInventoryResult_t );
var give = new InventoryDefId[] { target.Id };
var givec = new uint[] { 1 };
var sell = list.Select( x => x.Item.Id ).ToArray();
var sellc = list.Select( x => (uint) x.Quantity ).ToArray();
if ( !Internal.ExchangeItems( ref sresult, give, givec, 1, sell, sellc, (uint)sell.Length ) )
return null;
return await InventoryResult.GetAsync( sresult );
}
/// <summary>
/// Deserializes a result set and verifies the signature bytes.
/// This call has a potential soft-failure mode where the Result is expired, it will

View File

@ -122,5 +122,14 @@ internal static Dictionary<string, string> GetProperties( SteamInventoryResult_t
return props;
}
/// <summary>
/// Small utility class to describe an item with a quantity
/// </summary>
public struct Amount
{
public InventoryItem Item;
public int Quantity;
}
}
}