Fixed crashing when attempting to increase buy quantity in campaign UI when money is at zero, fixed capping the number input to the value the player can afford (the previous calculation only clamped it above zero). Closes #531

This commit is contained in:
Joonas Rikkonen
2018-07-26 16:42:11 +03:00
parent 90f6d351e5
commit ce18309a78

View File

@@ -270,7 +270,8 @@ namespace Barotrauma
{
int quantity = numberInput.IntValue - purchasedItem.quantity;
//Cap the numberbox based on the amount we can afford.
quantity = Math.Max((quantity * (purchasedItem.itemPrefab.Price / Campaign.Money)), quantity);
quantity = campaign.Money <= 0 ?
0 : Math.Min((int)(Campaign.Money / (float)purchasedItem.itemPrefab.Price), quantity);
for (int i = 0; i < quantity; i++)
{
BuyItem(numberInput, purchasedItem);