Fixed inventory NRE

This commit is contained in:
Garry Newman 2018-02-01 19:30:43 +00:00
parent 3a4bb29f7e
commit 0beef36548
2 changed files with 20 additions and 11 deletions

View File

@ -96,6 +96,7 @@ internal Definition( Inventory i, int id )
Id = id;
SetupCommonProperties();
UpdatePrice();
}
/// <summary>
@ -219,6 +220,20 @@ internal void InRecipe( Recipe r )
IngredientFor = list.ToArray();
}
internal void UpdatePrice()
{
if ( inventory.inventory.GetItemPrice( Id, out ulong price) )
{
LocalPrice = price / 100.0;
LocalPriceFormatted = Utility.FormatPrice( inventory.Currency, price );
}
else
{
LocalPrice = 0;
LocalPriceFormatted = null;
}
}
}
/// <summary>

View File

@ -440,22 +440,16 @@ public void UpdatePrices()
if (IsServer)
return;
inventory.RequestPrices((result, b) =>
inventory.RequestPrices((result, b) =>
{
Currency = result.Currency;
if ( Definitions == null )
return;
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;
}
Definitions[i].UpdatePrice();
}
});