Fixes money being debitted multiple times (#4078)
This commit is contained in:
@@ -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