Fix currency duplication bug (#32524)

This commit is contained in:
Leon Friedrich
2024-09-30 01:13:22 +13:00
committed by GitHub
parent a5840b925b
commit d806db264a
5 changed files with 66 additions and 22 deletions

View File

@@ -283,6 +283,9 @@ public sealed partial class StoreSystem
/// </remarks>
private void OnRequestWithdraw(EntityUid uid, StoreComponent component, StoreRequestWithdrawMessage msg)
{
if (msg.Amount <= 0)
return;
//make sure we have enough cash in the bank and we actually support this currency
if (!component.Balance.TryGetValue(msg.Currency, out var currentAmount) || currentAmount < msg.Amount)
return;
@@ -306,7 +309,8 @@ public sealed partial class StoreSystem
var cashId = proto.Cash[value];
var amountToSpawn = (int) MathF.Floor((float) (amountRemaining / value));
var ents = _stack.SpawnMultiple(cashId, amountToSpawn, coordinates);
_hands.PickupOrDrop(buyer, ents.First());
if (ents.FirstOrDefault() is {} ent)
_hands.PickupOrDrop(buyer, ent);
amountRemaining -= value * amountToSpawn;
}