From 18f81573f5ce1983d64395f951ef45808b43b5a5 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Tue, 7 May 2019 21:25:41 +0100 Subject: [PATCH] Added CraftItemAsync with Amounts --- Facepunch.Steamworks/SteamInventory.cs | 21 +++++++++++++++++++ Facepunch.Steamworks/Structs/InventoryItem.cs | 9 ++++++++ 2 files changed, 30 insertions(+) diff --git a/Facepunch.Steamworks/SteamInventory.cs b/Facepunch.Steamworks/SteamInventory.cs index 94c2a79..18d8a86 100644 --- a/Facepunch.Steamworks/SteamInventory.cs +++ b/Facepunch.Steamworks/SteamInventory.cs @@ -239,6 +239,27 @@ namespace Steamworks return await InventoryResult.GetAsync( sresult ); } + /// + /// 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. + /// + public static async Task 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 ); + } + /// /// Deserializes a result set and verifies the signature bytes. /// This call has a potential soft-failure mode where the Result is expired, it will diff --git a/Facepunch.Steamworks/Structs/InventoryItem.cs b/Facepunch.Steamworks/Structs/InventoryItem.cs index c33ba66..7036d1a 100644 --- a/Facepunch.Steamworks/Structs/InventoryItem.cs +++ b/Facepunch.Steamworks/Structs/InventoryItem.cs @@ -122,5 +122,14 @@ namespace Steamworks return props; } + + /// + /// Small utility class to describe an item with a quantity + /// + public struct Amount + { + public InventoryItem Item; + public int Quantity; + } } } \ No newline at end of file