Don't count refunds as income and deduct them from expenses.
This commit is contained in:
committed by
Gustas Kažukauskas
parent
4823c3365f
commit
3f73e7a1fb
@@ -100,7 +100,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
if (!self.IsInWorld || self.IsDead)
|
||||
{
|
||||
owner.PlayerActor.Trait<PlayerResources>().GiveCash(refundableValue);
|
||||
owner.PlayerActor.Trait<PlayerResources>().RefundCash(refundableValue);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
if (!self.IsInWorld || self.IsDead)
|
||||
{
|
||||
owner.PlayerActor.Trait<PlayerResources>().GiveCash(refundableValue);
|
||||
owner.PlayerActor.Trait<PlayerResources>().RefundCash(refundableValue);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -291,8 +291,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
foreach (var actorData in ActorsReadyForDelivery)
|
||||
{
|
||||
playerResources.GiveResources(actorData.Resources);
|
||||
playerResources.GiveCash(actorData.Cash);
|
||||
playerResources.RefundResources(actorData.Resources);
|
||||
playerResources.RefundCash(actorData.Cash);
|
||||
}
|
||||
|
||||
ActorsReadyForDelivery.Clear();
|
||||
@@ -304,8 +304,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var actor = ActorsReadyForDelivery.LastOrDefault(actor => actor.Actor.Name == itemName);
|
||||
if (actor.Actor == null)
|
||||
break;
|
||||
playerResources.GiveResources(actor.Resources);
|
||||
playerResources.GiveCash(actor.Cash);
|
||||
playerResources.RefundResources(actor.Resources);
|
||||
playerResources.RefundCash(actor.Cash);
|
||||
ActorsReadyForDelivery.Remove(actor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,18 +127,31 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return Resources + amount <= ResourceCapacity;
|
||||
}
|
||||
|
||||
public void GiveResources(int num)
|
||||
public void GiveResources(int num, bool isRefund = false)
|
||||
{
|
||||
Resources += num;
|
||||
Earned += num;
|
||||
|
||||
if (!isRefund)
|
||||
Earned += num;
|
||||
else
|
||||
Spent -= num;
|
||||
|
||||
if (Resources > ResourceCapacity)
|
||||
{
|
||||
Earned -= Resources - ResourceCapacity;
|
||||
if (!isRefund)
|
||||
Earned -= Resources - ResourceCapacity;
|
||||
else
|
||||
Spent += Resources - ResourceCapacity;
|
||||
|
||||
Resources = ResourceCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
public void RefundResources(int num)
|
||||
{
|
||||
GiveResources(num, isRefund: true);
|
||||
}
|
||||
|
||||
public bool TakeResources(int num)
|
||||
{
|
||||
if (Resources < num) return false;
|
||||
@@ -148,7 +161,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return true;
|
||||
}
|
||||
|
||||
public void GiveCash(int num)
|
||||
public void GiveCash(int num, bool isRefund = false)
|
||||
{
|
||||
if (Cash < int.MaxValue)
|
||||
{
|
||||
@@ -165,7 +178,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
if (Earned < int.MaxValue)
|
||||
if (!isRefund && Earned < int.MaxValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -179,6 +192,25 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Earned = int.MaxValue;
|
||||
}
|
||||
}
|
||||
else if (isRefund && Spent > int.MinValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
checked
|
||||
{
|
||||
Spent -= num;
|
||||
}
|
||||
}
|
||||
catch (OverflowException)
|
||||
{
|
||||
Spent = int.MinValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RefundCash(int num)
|
||||
{
|
||||
GiveCash(num, isRefund: true);
|
||||
}
|
||||
|
||||
public bool TakeCash(int num, bool notifyLowFunds = false)
|
||||
|
||||
@@ -191,11 +191,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
if (item.ResourcesPaid > 0)
|
||||
{
|
||||
playerResources.GiveResources(item.ResourcesPaid);
|
||||
playerResources.RefundResources(item.ResourcesPaid);
|
||||
item.RemainingCost += item.ResourcesPaid;
|
||||
}
|
||||
|
||||
playerResources.GiveCash(item.TotalCost - item.RemainingCost);
|
||||
playerResources.RefundCash(item.TotalCost - item.RemainingCost);
|
||||
}
|
||||
|
||||
Queue.Clear();
|
||||
@@ -383,12 +383,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Refund spent resources
|
||||
if (Queue[i].ResourcesPaid > 0)
|
||||
{
|
||||
playerResources.GiveResources(Queue[i].ResourcesPaid);
|
||||
playerResources.RefundResources(Queue[i].ResourcesPaid);
|
||||
Queue[i].RemainingCost += Queue[i].ResourcesPaid;
|
||||
}
|
||||
|
||||
// Refund what's been paid so far
|
||||
playerResources.GiveCash(Queue[i].TotalCost - Queue[i].RemainingCost);
|
||||
playerResources.RefundCash(Queue[i].TotalCost - Queue[i].RemainingCost);
|
||||
EndProduction(Queue[i]);
|
||||
cancelledAnItem = true;
|
||||
}
|
||||
@@ -592,11 +592,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Refund what has been paid
|
||||
if (item.ResourcesPaid > 0)
|
||||
{
|
||||
playerResources.GiveResources(item.ResourcesPaid);
|
||||
playerResources.RefundResources(item.ResourcesPaid);
|
||||
item.RemainingCost += item.ResourcesPaid;
|
||||
}
|
||||
|
||||
playerResources.GiveCash(item.TotalCost - item.RemainingCost);
|
||||
playerResources.RefundCash(item.TotalCost - item.RemainingCost);
|
||||
EndProduction(item);
|
||||
}
|
||||
|
||||
@@ -649,11 +649,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Refund what has been paid
|
||||
if (queued[i].ResourcesPaid > 0)
|
||||
{
|
||||
playerResources.GiveResources(queued[i].ResourcesPaid);
|
||||
playerResources.RefundResources(queued[i].ResourcesPaid);
|
||||
queued[i].RemainingCost += queued[i].ResourcesPaid;
|
||||
}
|
||||
|
||||
playerResources.GiveCash(queued[i].TotalCost - queued[i].RemainingCost);
|
||||
playerResources.RefundCash(queued[i].TotalCost - queued[i].RemainingCost);
|
||||
EndProduction(queued[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
if (!self.IsInWorld || self.IsDead)
|
||||
{
|
||||
owner.PlayerActor.Trait<PlayerResources>().GiveCash(refundableValue);
|
||||
owner.PlayerActor.Trait<PlayerResources>().RefundCash(refundableValue);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
if (!self.IsInWorld || self.IsDead)
|
||||
{
|
||||
owner.PlayerActor.Trait<PlayerResources>().GiveCash(refundableValue);
|
||||
owner.PlayerActor.Trait<PlayerResources>().RefundCash(refundableValue);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user