}
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);
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))
{
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;
}
$"{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);
}
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<ProtoId<CargoAccountPrototype>, double> distribution;
if (sellComponent != null)
{
- distribution = new Dictionary<ProtoId<CargoAccountPrototype>, double>()
+ distribution = new Dictionary<ProtoId<CargoAccountPrototype>, double>
{
{ sellComponent.OverrideAccount, bankAccount.PrimaryCut },
{ bankAccount.PrimaryAccount, 1.0 - bankAccount.PrimaryCut },
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 accoujnt component as dirty.</param>
+ /// <param name="dirty">Whether to mark the bank account component as dirty.</param>
[PublicAPI]
public void UpdateBankAccount(
Entity<StationBankAccountComponent?> ent,
_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)
-using System.Linq;
using Content.Shared.Cargo.Components;
using Content.Shared.Cargo.Prototypes;
using Robust.Shared.Prototypes;
}
/// <summary>
- /// 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 <see cref="StationBankAccountComponent.RevenueDistribution"/>
+ /// 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 <see cref="StationBankAccountComponent.RevenueDistribution"/>
/// </summary>
- public Dictionary<ProtoId<CargoAccountPrototype>, double> CreateAccountDistribution(
- ProtoId<CargoAccountPrototype> primary,
- StationBankAccountComponent stationBank,
- double primaryCut = 1.0)
+ public Dictionary<ProtoId<CargoAccountPrototype>, double> CreateAccountDistribution(Entity<StationBankAccountComponent> stationBank)
{
var distribution = new Dictionary<ProtoId<CargoAccountPrototype>, 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<ProtoId<CargoAccountPrototype>, 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;
}