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

@@ -127,7 +127,7 @@ namespace OpenRA.Mods.Common.Traits
self.Owner.Shroud.ExploreAll();
var amount = order.ExtraData != 0 ? (int)order.ExtraData : info.Cash;
self.Trait<PlayerResources>().GiveCash(amount);
self.Trait<PlayerResources>().ChangeCash(amount);
}
else
self.Owner.Shroud.ResetExploration();
@@ -160,7 +160,7 @@ namespace OpenRA.Mods.Common.Traits
case "DevGiveCash":
{
var amount = order.ExtraData != 0 ? (int)order.ExtraData : info.Cash;
self.Trait<PlayerResources>().GiveCash(amount);
self.Trait<PlayerResources>().ChangeCash(amount);
break;
}

View File

@@ -86,6 +86,21 @@ namespace OpenRA.Mods.Common.Traits
int lastNotificationTick;
public int ChangeCash(int amount)
{
if (amount >= 0)
GiveCash(amount);
else
{
// Don't put the player into negative funds
amount = Math.Max(-(Cash + Resources), amount);
TakeCash(-amount);
}
return amount;
}
public bool CanGiveResources(int amount)
{
return Resources + amount <= ResourceCapacity;