Added checks to make sure cash can't be < 0.

This commit is contained in:
GSonderling
2018-05-07 10:42:38 +00:00
committed by reaperrr
parent b8fd4abc4a
commit bf4dbd9b80
9 changed files with 28 additions and 35 deletions

View File

@@ -84,21 +84,10 @@ namespace OpenRA.Mods.Common.Traits
void ModifyCash(Actor self, Player newOwner, int amount)
{
if (amount < 0)
{
// Check whether the amount of cash to be removed would exceed available player cash, in that case only remove all the player cash
var drain = Math.Min(resources.Cash + resources.Resources, -amount);
resources.TakeCash(drain);
amount = resources.ChangeCash(amount);
if (info.ShowTicks)
AddCashTick(self, -drain);
}
else
{
resources.GiveCash(amount);
if (info.ShowTicks)
AddCashTick(self, amount);
}
if (info.ShowTicks)
AddCashTick(self, amount);
}
}
}