diff --git a/Content.Server/Cargo/Systems/CargoSystem.Funds.cs b/Content.Server/Cargo/Systems/CargoSystem.Funds.cs index 7990fbce1c..d64c467664 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Funds.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Funds.cs @@ -39,8 +39,7 @@ public sealed partial class CargoSystem } ent.Comp.NextAccountActionTime = Timing.CurTime + ent.Comp.AccountActionDelay; - Dirty(ent); - UpdateBankAccount((station, bank), -args.Amount, CreateAccountDistribution(ent.Comp.Account, bank)); + UpdateBankAccount((station, bank), -args.Amount, ent.Comp.Account, dirty: false); _audio.PlayPvs(ApproveSound, ent); var tryGetIdentityShortInfoEvent = new TryGetIdentityShortInfoEvent(ent, args.Actor); @@ -65,7 +64,7 @@ public sealed partial class CargoSystem else { var otherAccount = _protoMan.Index(args.Account.Value); - UpdateBankAccount((station, bank), args.Amount, CreateAccountDistribution(args.Account.Value, bank)); + UpdateBankAccount((station, bank), args.Amount, args.Account.Value); if (!_emag.CheckFlag(ent, EmagType.Interaction)) { diff --git a/Content.Server/Cargo/Systems/CargoSystem.Orders.cs b/Content.Server/Cargo/Systems/CargoSystem.Orders.cs index ef9a601a89..f89f1b0e8f 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Orders.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Orders.cs @@ -51,7 +51,7 @@ namespace Content.Server.Cargo.Systems return; _audio.PlayPvs(ApproveSound, uid); - UpdateBankAccount((stationUid.Value, bank), (int) price, CreateAccountDistribution(component.Account, bank)); + UpdateBankAccount((stationUid.Value, bank), (int) price, component.Account); QueueDel(args.Used); args.Handled = true; } @@ -203,7 +203,7 @@ namespace Content.Server.Cargo.Systems $"{ToPrettyString(player):user} approved order [orderId:{order.OrderId}, quantity:{order.OrderQuantity}, product:{order.ProductId}, requester:{order.Requester}, reason:{order.Reason}] on account {component.Account} with balance at {accountBalance}"); orderDatabase.Orders[component.Account].Remove(order); - UpdateBankAccount((station.Value, bank), -cost, CreateAccountDistribution(component.Account, bank)); + UpdateBankAccount((station.Value, bank), -cost, component.Account); UpdateOrders(station.Value); } diff --git a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs index 84319ab793..aaa14d196f 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs @@ -334,13 +334,13 @@ public sealed partial class CargoSystem if (!SellPallets(gridUid, out var goods)) return; - var baseDistribution = CreateAccountDistribution(bankAccount.PrimaryAccount, bankAccount, bankAccount.PrimaryCut); + var baseDistribution = CreateAccountDistribution((station, bankAccount)); foreach (var (_, sellComponent, value) in goods) { Dictionary, double> distribution; if (sellComponent != null) { - distribution = new Dictionary, double>() + distribution = new Dictionary, double> { { sellComponent.OverrideAccount, bankAccount.PrimaryCut }, { bankAccount.PrimaryAccount, 1.0 - bankAccount.PrimaryCut }, diff --git a/Content.Server/Cargo/Systems/CargoSystem.cs b/Content.Server/Cargo/Systems/CargoSystem.cs index 646625d5d8..d0ec138e4e 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.cs @@ -75,13 +75,26 @@ public sealed partial class CargoSystem : SharedCargoSystem UpdateBounty(); } + public void UpdateBankAccount( + Entity ent, + int balanceAdded, + ProtoId account, + bool dirty = true) + { + UpdateBankAccount( + ent, + balanceAdded, + new Dictionary, double> { {account, 1} }, + dirty: dirty); + } + /// /// Adds or removes funds from the . /// /// The station. /// The amount of funds to add or remove. /// The distribution between individual . - /// Whether to mark the bank accoujnt component as dirty. + /// Whether to mark the bank account component as dirty. [PublicAPI] public void UpdateBankAccount( Entity ent, diff --git a/Content.Server/Delivery/DeliverySystem.cs b/Content.Server/Delivery/DeliverySystem.cs index 91dff3b855..329e3d11ed 100644 --- a/Content.Server/Delivery/DeliverySystem.cs +++ b/Content.Server/Delivery/DeliverySystem.cs @@ -76,7 +76,7 @@ public sealed partial class DeliverySystem : SharedDeliverySystem _cargo.UpdateBankAccount( (ent.Comp.RecipientStation.Value, account), ent.Comp.SpesoReward, - _cargo.CreateAccountDistribution(account.PrimaryAccount, account, account.PrimaryCut)); + _cargo.CreateAccountDistribution((ent.Comp.RecipientStation.Value, account))); } public override void Update(float frameTime) diff --git a/Content.Shared/Cargo/SharedCargoSystem.cs b/Content.Shared/Cargo/SharedCargoSystem.cs index 8f76f77888..84633073b5 100644 --- a/Content.Shared/Cargo/SharedCargoSystem.cs +++ b/Content.Shared/Cargo/SharedCargoSystem.cs @@ -1,4 +1,3 @@ -using System.Linq; using Content.Shared.Cargo.Components; using Content.Shared.Cargo.Prototypes; using Robust.Shared.Prototypes; @@ -36,30 +35,21 @@ public abstract class SharedCargoSystem : EntitySystem } /// - /// For a station, creates a distribution between one "primary" account and the other accounts. - /// The primary account receives the majority cut specified, with the remaining accounts getting cuts - /// distributed through the remaining amount, based on + /// For a station, creates a distribution between one the bank's account and the other accounts. + /// The primary account receives the majority percentage listed on the bank account, with the remaining + /// funds distributed to all accounts based on /// - public Dictionary, double> CreateAccountDistribution( - ProtoId primary, - StationBankAccountComponent stationBank, - double primaryCut = 1.0) + public Dictionary, double> CreateAccountDistribution(Entity stationBank) { var distribution = new Dictionary, double> { - { primary, primaryCut } + { stationBank.Comp.PrimaryAccount, stationBank.Comp.PrimaryCut } }; - var remaining = 1.0 - primaryCut; + var remaining = 1.0 - stationBank.Comp.PrimaryCut; - var allAccountPercentages = new Dictionary, double>(stationBank.RevenueDistribution); - allAccountPercentages.Remove(primary); - var weightsSum = allAccountPercentages.Values.Sum(); - - foreach (var (account, percentage) in allAccountPercentages) + foreach (var (account, percentage) in stationBank.Comp.RevenueDistribution) { - var adjustedPercentage = percentage / weightsSum; - - distribution.Add(account, remaining * adjustedPercentage); + distribution.Add(account, remaining * percentage); } return distribution; }