Fixes money being debitted multiple times (#4078)

This commit is contained in:
esguard
2021-05-30 07:19:14 +02:00
committed by GitHub
parent 5fad2123d9
commit 0ef61ba47a
3 changed files with 32 additions and 11 deletions

View File

@@ -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;
}