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; ent.Comp.NextAccountActionTime = Timing.CurTime + ent.Comp.AccountActionDelay;
Dirty(ent); UpdateBankAccount((station, bank), -args.Amount, ent.Comp.Account, dirty: false);
UpdateBankAccount((station, bank), -args.Amount, CreateAccountDistribution(ent.Comp.Account, bank));
_audio.PlayPvs(ApproveSound, ent); _audio.PlayPvs(ApproveSound, ent);
var tryGetIdentityShortInfoEvent = new TryGetIdentityShortInfoEvent(ent, args.Actor); var tryGetIdentityShortInfoEvent = new TryGetIdentityShortInfoEvent(ent, args.Actor);
@@ -65,7 +64,7 @@ public sealed partial class CargoSystem
else else
{ {
var otherAccount = _protoMan.Index(args.Account.Value); 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)) if (!_emag.CheckFlag(ent, EmagType.Interaction))
{ {

View File

@@ -51,7 +51,7 @@ namespace Content.Server.Cargo.Systems
return; return;
_audio.PlayPvs(ApproveSound, uid); _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); QueueDel(args.Used);
args.Handled = true; 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}"); $"{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); 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); UpdateOrders(station.Value);
} }

View File

@@ -334,13 +334,13 @@ public sealed partial class CargoSystem
if (!SellPallets(gridUid, out var goods)) if (!SellPallets(gridUid, out var goods))
return; return;
var baseDistribution = CreateAccountDistribution(bankAccount.PrimaryAccount, bankAccount, bankAccount.PrimaryCut); var baseDistribution = CreateAccountDistribution((station, bankAccount));
foreach (var (_, sellComponent, value) in goods) foreach (var (_, sellComponent, value) in goods)
{ {
Dictionary<ProtoId<CargoAccountPrototype>, double> distribution; Dictionary<ProtoId<CargoAccountPrototype>, double> distribution;
if (sellComponent != null) if (sellComponent != null)
{ {
distribution = new Dictionary<ProtoId<CargoAccountPrototype>, double>() distribution = new Dictionary<ProtoId<CargoAccountPrototype>, double>
{ {
{ sellComponent.OverrideAccount, bankAccount.PrimaryCut }, { sellComponent.OverrideAccount, bankAccount.PrimaryCut },
{ bankAccount.PrimaryAccount, 1.0 - bankAccount.PrimaryCut }, { bankAccount.PrimaryAccount, 1.0 - bankAccount.PrimaryCut },

View File

@@ -75,13 +75,26 @@ public sealed partial class CargoSystem : SharedCargoSystem
UpdateBounty(); 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> /// <summary>
/// Adds or removes funds from the <see cref="StationBankAccountComponent"/>. /// Adds or removes funds from the <see cref="StationBankAccountComponent"/>.
/// </summary> /// </summary>
/// <param name="ent">The station.</param> /// <param name="ent">The station.</param>
/// <param name="balanceAdded">The amount of funds to add or remove.</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="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] [PublicAPI]
public void UpdateBankAccount( public void UpdateBankAccount(
Entity<StationBankAccountComponent?> ent, Entity<StationBankAccountComponent?> ent,

View File

@@ -76,7 +76,7 @@ public sealed partial class DeliverySystem : SharedDeliverySystem
_cargo.UpdateBankAccount( _cargo.UpdateBankAccount(
(ent.Comp.RecipientStation.Value, account), (ent.Comp.RecipientStation.Value, account),
ent.Comp.SpesoReward, ent.Comp.SpesoReward,
_cargo.CreateAccountDistribution(account.PrimaryAccount, account, account.PrimaryCut)); _cargo.CreateAccountDistribution((ent.Comp.RecipientStation.Value, account)));
} }
public override void Update(float frameTime) public override void Update(float frameTime)

View File

@@ -1,4 +1,3 @@
using System.Linq;
using Content.Shared.Cargo.Components; using Content.Shared.Cargo.Components;
using Content.Shared.Cargo.Prototypes; using Content.Shared.Cargo.Prototypes;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
@@ -36,30 +35,21 @@ public abstract class SharedCargoSystem : EntitySystem
} }
/// <summary> /// <summary>
/// For a station, creates a distribution between one "primary" account and the other accounts. /// For a station, creates a distribution between one the bank's account and the other accounts.
/// The primary account receives the majority cut specified, with the remaining accounts getting cuts /// The primary account receives the majority percentage listed on the bank account, with the remaining
/// distributed through the remaining amount, based on <see cref="StationBankAccountComponent.RevenueDistribution"/> /// funds distributed to all accounts based on <see cref="StationBankAccountComponent.RevenueDistribution"/>
/// </summary> /// </summary>
public Dictionary<ProtoId<CargoAccountPrototype>, double> CreateAccountDistribution( public Dictionary<ProtoId<CargoAccountPrototype>, double> CreateAccountDistribution(Entity<StationBankAccountComponent> stationBank)
ProtoId<CargoAccountPrototype> primary,
StationBankAccountComponent stationBank,
double primaryCut = 1.0)
{ {
var distribution = new Dictionary<ProtoId<CargoAccountPrototype>, double> 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); foreach (var (account, percentage) in stationBank.Comp.RevenueDistribution)
allAccountPercentages.Remove(primary);
var weightsSum = allAccountPercentages.Values.Sum();
foreach (var (account, percentage) in allAccountPercentages)
{ {
var adjustedPercentage = percentage / weightsSum; distribution.Add(account, remaining * percentage);
distribution.Add(account, remaining * adjustedPercentage);
} }
return distribution; return distribution;
} }