Make funding allocation computer more configurable (#36790)
* Make funding allocation computer more configurable * admin logging * unused * ccvar enabled --------- Co-authored-by: ScarKy0 <scarky0@onet.eu>
This commit is contained in:
committed by
GitHub
parent
1197d9b038
commit
907f4b39cd
@@ -1,5 +1,6 @@
|
||||
using System.Linq;
|
||||
using Content.Shared.Cargo.Components;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Emag.Systems;
|
||||
using Content.Shared.IdentityManagement;
|
||||
@@ -9,12 +10,18 @@ namespace Content.Server.Cargo.Systems;
|
||||
|
||||
public sealed partial class CargoSystem
|
||||
{
|
||||
private bool _allowPrimaryAccountAllocation;
|
||||
private bool _allowPrimaryCutAdjustment;
|
||||
|
||||
public void InitializeFunds()
|
||||
{
|
||||
SubscribeLocalEvent<CargoOrderConsoleComponent, CargoConsoleWithdrawFundsMessage>(OnWithdrawFunds);
|
||||
SubscribeLocalEvent<CargoOrderConsoleComponent, CargoConsoleToggleLimitMessage>(OnToggleLimit);
|
||||
SubscribeLocalEvent<FundingAllocationConsoleComponent, SetFundingAllocationBuiMessage>(OnSetFundingAllocation);
|
||||
SubscribeLocalEvent<FundingAllocationConsoleComponent, BeforeActivatableUIOpenEvent>(OnFundAllocationBuiOpen);
|
||||
|
||||
_cfg.OnValueChanged(CCVars.AllowPrimaryAccountAllocation, enabled => { _allowPrimaryAccountAllocation = enabled; }, true);
|
||||
_cfg.OnValueChanged(CCVars.AllowPrimaryCutAdjustment, enabled => { _allowPrimaryCutAdjustment = enabled; }, true);
|
||||
}
|
||||
|
||||
private void OnWithdrawFunds(Entity<CargoOrderConsoleComponent> ent, ref CargoConsoleWithdrawFundsMessage args)
|
||||
@@ -102,7 +109,8 @@ public sealed partial class CargoSystem
|
||||
!TryComp<StationBankAccountComponent>(station, out var bank))
|
||||
return;
|
||||
|
||||
if (args.Percents.Count != bank.RevenueDistribution.Count)
|
||||
var expectedCount = _allowPrimaryAccountAllocation ? bank.RevenueDistribution.Count : bank.RevenueDistribution.Count - 1;
|
||||
if (args.Percents.Count != expectedCount)
|
||||
return;
|
||||
|
||||
var differs = false;
|
||||
@@ -114,6 +122,7 @@ public sealed partial class CargoSystem
|
||||
break;
|
||||
}
|
||||
}
|
||||
differs = differs || args.PrimaryCut != bank.PrimaryCut || args.LockboxCut != bank.LockboxCut;
|
||||
|
||||
if (!differs)
|
||||
return;
|
||||
@@ -121,18 +130,33 @@ public sealed partial class CargoSystem
|
||||
if (args.Percents.Values.Sum() != 100)
|
||||
return;
|
||||
|
||||
var primaryCut = bank.RevenueDistribution[bank.PrimaryAccount];
|
||||
bank.RevenueDistribution.Clear();
|
||||
foreach (var (account, percent )in args.Percents)
|
||||
{
|
||||
bank.RevenueDistribution.Add(account, percent / 100.0);
|
||||
}
|
||||
if (!_allowPrimaryAccountAllocation)
|
||||
{
|
||||
bank.RevenueDistribution.Add(bank.PrimaryAccount, 0);
|
||||
}
|
||||
|
||||
if (_allowPrimaryCutAdjustment && args.PrimaryCut is >= 0.0 and <= 1.0)
|
||||
{
|
||||
bank.PrimaryCut = args.PrimaryCut;
|
||||
}
|
||||
if (_lockboxCutEnabled && args.LockboxCut is >= 0.0 and <= 1.0)
|
||||
{
|
||||
bank.LockboxCut = args.LockboxCut;
|
||||
}
|
||||
|
||||
Dirty(station, bank);
|
||||
|
||||
_audio.PlayPvs(ent.Comp.SetDistributionSound, ent);
|
||||
_adminLogger.Add(
|
||||
LogType.Action,
|
||||
LogImpact.Medium,
|
||||
$"{ToPrettyString(args.Actor):player} set station {ToPrettyString(station)} fund distribution: {string.Join(',', bank.RevenueDistribution.Select(p => $"{p.Key}: {p.Value}").ToList())}");
|
||||
$"{ToPrettyString(args.Actor):player} set station {ToPrettyString(station)} fund distribution: {string.Join(',', bank.RevenueDistribution.Select(p => $"{p.Key}: {p.Value}").ToList())}, primary cut: {bank.PrimaryCut}, lockbox cut: {bank.LockboxCut}");
|
||||
}
|
||||
|
||||
private void OnFundAllocationBuiOpen(Entity<FundingAllocationConsoleComponent> ent, ref BeforeActivatableUIOpenEvent args)
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Shared.Cargo.BUI;
|
||||
using Content.Shared.Cargo.Components;
|
||||
using Content.Shared.Cargo.Events;
|
||||
using Content.Shared.Cargo.Prototypes;
|
||||
using Content.Shared.CCVar;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -18,6 +19,7 @@ public sealed partial class CargoSystem
|
||||
*/
|
||||
|
||||
private static readonly SoundPathSpecifier ApproveSound = new("/Audio/Effects/Cargo/ping.ogg");
|
||||
private bool _lockboxCutEnabled;
|
||||
|
||||
private void InitializeShuttle()
|
||||
{
|
||||
@@ -28,6 +30,8 @@ public sealed partial class CargoSystem
|
||||
SubscribeLocalEvent<CargoPalletConsoleComponent, CargoPalletSellMessage>(OnPalletSale);
|
||||
SubscribeLocalEvent<CargoPalletConsoleComponent, CargoPalletAppraiseMessage>(OnPalletAppraise);
|
||||
SubscribeLocalEvent<CargoPalletConsoleComponent, BoundUIOpenedEvent>(OnPalletUIOpen);
|
||||
|
||||
_cfg.OnValueChanged(CCVars.LockboxCutEnabled, (enabled) => { _lockboxCutEnabled = enabled; }, true);
|
||||
}
|
||||
|
||||
#region Console
|
||||
@@ -340,10 +344,11 @@ public sealed partial class CargoSystem
|
||||
Dictionary<ProtoId<CargoAccountPrototype>, double> distribution;
|
||||
if (sellComponent != null)
|
||||
{
|
||||
var cut = _lockboxCutEnabled ? bankAccount.LockboxCut : bankAccount.PrimaryCut;
|
||||
distribution = new Dictionary<ProtoId<CargoAccountPrototype>, double>
|
||||
{
|
||||
{ sellComponent.OverrideAccount, sellComponent.OverrideCut },
|
||||
{ bankAccount.PrimaryAccount, 1.0 - sellComponent.OverrideCut },
|
||||
{ sellComponent.OverrideAccount, cut },
|
||||
{ bankAccount.PrimaryAccount, 1.0 - cut },
|
||||
};
|
||||
}
|
||||
else
|
||||
|
||||
@@ -10,12 +10,14 @@ 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;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
@@ -23,6 +25,7 @@ namespace Content.Server.Cargo.Systems;
|
||||
|
||||
public sealed partial class CargoSystem : SharedCargoSystem
|
||||
{
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
[Dependency] private readonly IPrototypeManager _protoMan = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
||||
|
||||
Reference in New Issue
Block a user