Add bank toolshed commands (#40614)

* add bank commands

* Follow convention

* use protoId

* make logic better

* Move stuff to shared

* Make things dirty

* Move UpdateBankAccount to shared as well

* nullable + resolve

* Fix commands

* make things less legible

* typo

* same typo

* im dumb

* I don't know how to spell

* replace select with foreach

Co-authored-by: Simon <63975668+Simyon264@users.noreply.github.com>

* replace select with foreach again

---------

Co-authored-by: Simon <63975668+Simyon264@users.noreply.github.com>
This commit is contained in:
Samuka-C
2025-10-15 12:10:25 -03:00
committed by GitHub
parent 68f9d748a2
commit 71bbe926a0
4 changed files with 249 additions and 50 deletions

View File

@@ -1,20 +1,15 @@
using Content.Server.Cargo.Components;
using Content.Server.DeviceLinking.Systems;
using Content.Server.Popups;
using Content.Server.Shuttles.Systems;
using Content.Server.Stack;
using Content.Server.Station.Systems;
using Content.Shared.Access.Systems;
using Content.Shared.Administration.Logs;
using Content.Server.Radio.EntitySystems;
using Content.Shared.Cargo;
using Content.Shared.Cargo.Components;
using Content.Shared.Cargo.Prototypes;
using Content.Shared.CCVar;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Mobs.Components;
using Content.Shared.Paper;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Configuration;
@@ -76,49 +71,4 @@ public sealed partial class CargoSystem : SharedCargoSystem
UpdateTelepad(frameTime);
UpdateBounty();
}
public void UpdateBankAccount(
Entity<StationBankAccountComponent?> ent,
int balanceAdded,
ProtoId<CargoAccountPrototype> account,
bool dirty = true)
{
UpdateBankAccount(
ent,
balanceAdded,
new Dictionary<ProtoId<CargoAccountPrototype>, double> { {account, 1} },
dirty: dirty);
}
/// <summary>
/// Adds or removes funds from the <see cref="StationBankAccountComponent"/>.
/// </summary>
/// <param name="ent">The station.</param>
/// <param name="balanceAdded">The amount of funds to add or remove.</param>
/// <param name="accountDistribution">The distribution between individual <see cref="CargoAccountPrototype"/>.</param>
/// <param name="dirty">Whether to mark the bank account component as dirty.</param>
[PublicAPI]
public void UpdateBankAccount(
Entity<StationBankAccountComponent?> ent,
int balanceAdded,
Dictionary<ProtoId<CargoAccountPrototype>, double> accountDistribution,
bool dirty = true)
{
if (!Resolve(ent, ref ent.Comp))
return;
foreach (var (account, percent) in accountDistribution)
{
var accountBalancedAdded = (int) Math.Round(percent * balanceAdded);
ent.Comp.Accounts[account] += accountBalancedAdded;
}
var ev = new BankBalanceUpdatedEvent(ent, ent.Comp.Accounts);
RaiseLocalEvent(ent, ref ev, true);
if (!dirty)
return;
Dirty(ent);
}
}