From ce18309a7867b2587e7561109c58dac980c2dec6 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Thu, 26 Jul 2018 16:42:11 +0300 Subject: [PATCH] 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 --- Barotrauma/BarotraumaClient/Source/Screens/CampaignUI.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Barotrauma/BarotraumaClient/Source/Screens/CampaignUI.cs b/Barotrauma/BarotraumaClient/Source/Screens/CampaignUI.cs index 6ac7b4783..99a3b3a45 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/CampaignUI.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/CampaignUI.cs @@ -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);