Fix inability to engage with economic Cargonia (#36668)

Fix inability to engage with cargo supremacy
This commit is contained in:
Nemanja
2025-04-17 22:06:29 -04:00
committed by GitHub
parent 1af3c599c5
commit 57bbf76ec6
6 changed files with 29 additions and 27 deletions

View File

@@ -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))
{

View File

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

View File

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

View File

@@ -75,13 +75,26 @@ public sealed partial class CargoSystem : SharedCargoSystem
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,

View File

@@ -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)

View File

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