Fixes money being debitted multiple times (#4078)
This commit is contained in:
@@ -84,20 +84,23 @@ namespace Content.Server.Cargo
|
||||
/// Approves an order in the database.
|
||||
/// </summary>
|
||||
/// <param name="order">The order to be approved.</param>
|
||||
public void ApproveOrder(int orderNumber)
|
||||
public bool ApproveOrder(int orderNumber)
|
||||
{
|
||||
if (CurrentOrderSize == MaxOrderSize)
|
||||
return;
|
||||
return false;
|
||||
if (!_orders.TryGetValue(orderNumber, out var order))
|
||||
return;
|
||||
return false;
|
||||
if (order.Approved)
|
||||
return false;
|
||||
else if (CurrentOrderSize + order.Amount > MaxOrderSize)
|
||||
{
|
||||
AddOrder(order.Requester, Loc.GetString("{0} (Overflow)", order.Reason.Replace(" (Overflow)","")), order.ProductId,
|
||||
AddOrder(order.Requester, Loc.GetString("{0} (Overflow)", order.Reason.Replace(" (Overflow)", "")), order.ProductId,
|
||||
order.Amount - MaxOrderSize - CurrentOrderSize, order.PayingAccountId);
|
||||
order.Amount = MaxOrderSize - CurrentOrderSize;
|
||||
}
|
||||
order.Approved = true;
|
||||
CurrentOrderSize += order.Amount;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -133,9 +133,13 @@ namespace Content.Server.GameObjects.Components.Cargo
|
||||
var capacity = _cargoConsoleSystem.GetCapacity(orders.Database.Id);
|
||||
if (capacity.CurrentCapacity == capacity.MaxCapacity)
|
||||
break;
|
||||
if (!_cargoConsoleSystem.CheckBalance(_bankAccount.Id, (-product.PointCost) * order.Amount))
|
||||
break;
|
||||
if (!_cargoConsoleSystem.ApproveOrder(orders.Database.Id, msg.OrderNumber))
|
||||
break;
|
||||
if (!_cargoConsoleSystem.ChangeBalance(_bankAccount.Id, (-product.PointCost) * order.Amount))
|
||||
break;
|
||||
_cargoConsoleSystem.ApproveOrder(orders.Database.Id, msg.OrderNumber);
|
||||
|
||||
UpdateUIState();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -114,7 +114,25 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
{
|
||||
return _databasesDict.TryGetValue(id, out database);
|
||||
}
|
||||
/// <summary>
|
||||
/// Verifies if there is enough money in the account's balance to pay the amount.
|
||||
/// Returns false if there's no account associated with the given ID
|
||||
/// or if the balance would end up being negative.
|
||||
/// </summary>
|
||||
public bool CheckBalance(int id, int amount)
|
||||
{
|
||||
if (!TryGetBankAccount(id, out var account))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (account.Balance + amount < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Attempts to change the given account's balance.
|
||||
/// Returns false if there's no account associated with the given ID
|
||||
@@ -127,11 +145,6 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
return false;
|
||||
}
|
||||
|
||||
if (account.Balance + amount < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
account.Balance += amount;
|
||||
return true;
|
||||
}
|
||||
@@ -158,7 +171,8 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
{
|
||||
if (!TryGetOrderDatabase(id, out var database))
|
||||
return false;
|
||||
database.ApproveOrder(orderNumber);
|
||||
if (!database.ApproveOrder(orderNumber))
|
||||
return false;
|
||||
SyncComponentsWithId(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user