From 2da780df7cb8c5d17e5e0673946c94fd0ee45780 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Wed, 31 Jan 2018 12:53:01 +0000 Subject: [PATCH] Added Inventory.UpdatePrices (shouldn't need to call manually) --- Facepunch.Steamworks/Interfaces/Inventory.cs | 39 +++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/Facepunch.Steamworks/Interfaces/Inventory.cs b/Facepunch.Steamworks/Interfaces/Inventory.cs index 26acb2c..d278dfe 100644 --- a/Facepunch.Steamworks/Interfaces/Inventory.cs +++ b/Facepunch.Steamworks/Interfaces/Inventory.cs @@ -50,6 +50,7 @@ namespace Facepunch.Steamworks inventory.LoadItemDefinitions(); FetchItemDefinitions(); + UpdatePrices(); if ( !server ) { @@ -87,12 +88,13 @@ namespace Facepunch.Steamworks result.OnSteamResult( data, error ); - if ( !error && data.Esult == SteamNative.Result.OK ) + if ( !error && data.Result == SteamNative.Result.OK ) { onResult( result, false ); } Result.Pending.Remove( data.Handle ); + result.Dispose(); } } @@ -195,7 +197,7 @@ namespace Facepunch.Steamworks /// public Definition CreateDefinition( int id ) { - return new Definition( inventory, id ); + return new Definition( this, id ); } internal void FetchItemDefinitions() @@ -293,6 +295,9 @@ namespace Facepunch.Steamworks public unsafe Result Deserialize( byte[] data, int dataLength = -1 ) { + if (data == null) + throw new ArgumentException("data should nto be null"); + if ( dataLength == -1 ) dataLength = data.Length; @@ -394,5 +399,35 @@ namespace Facepunch.Steamworks return new Result( this, resultHandle, true ); } + /// + /// This might be null until Steam has actually recieved the prices. + /// + public string Currency { get; private set; } + + public void UpdatePrices() + { + if (IsServer) + return; + + inventory.RequestPrices((result, b) => + { + Currency = result.Currency; + + for (int i = 0; i < Definitions.Length; i++) + { + if (inventory.GetItemPrice(Definitions[i].Id, out ulong price)) + { + Definitions[i].LocalPrice = price / 100.0; + Definitions[i].LocalPriceFormatted = Utility.FormatPrice( Currency, price ); + } + else + { + Definitions[i].LocalPrice = 0; + Definitions[i].LocalPriceFormatted = null; + } + } + + }); + } } }