diff --git a/Content.Server/Store/Systems/StoreSystem.Command.cs b/Content.Server/Store/Systems/StoreSystem.Command.cs new file mode 100644 index 0000000000..5823bfe028 --- /dev/null +++ b/Content.Server/Store/Systems/StoreSystem.Command.cs @@ -0,0 +1,64 @@ +using Content.Server.Store.Components; +using Content.Shared.FixedPoint; +using Content.Server.Administration; +using Content.Shared.Administration; +using Robust.Shared.Console; + +namespace Content.Server.Store.Systems; + +public sealed partial class StoreSystem +{ + [Dependency] private readonly IConsoleHost _consoleHost = default!; + + public void InitializeCommand() + { + _consoleHost.RegisterCommand("addcurrency", "Adds currency to the specified store", "addcurrency ", + AddCurrencyCommand, + AddCurrencyCommandCompletions); + } + + [AdminCommand(AdminFlags.Fun)] + private void AddCurrencyCommand(IConsoleShell shell, string argstr, string[] args) + { + if (args.Length != 3) + { + shell.WriteError("Argument length must be 3"); + return; + } + + if (!EntityUid.TryParse(args[0], out var uid) || !float.TryParse(args[2], out var id)) + return; + + if (!TryComp(uid, out var store)) + return; + + var currency = new Dictionary + { + { args[1], id } + }; + + TryAddCurrency(currency, uid, store); + } + + private CompletionResult AddCurrencyCommandCompletions(IConsoleShell shell, string[] args) + { + if (args.Length == 1) + { + var query = EntityQueryEnumerator(); + var allStores = new List(); + while (query.MoveNext(out var storeuid, out _)) + { + allStores.Add(storeuid.ToString()); + } + return CompletionResult.FromHintOptions(allStores, ""); + } + + if (args.Length == 2 && EntityUid.TryParse(args[0], out var uid)) + { + if (TryComp(uid, out var store)) + return CompletionResult.FromHintOptions(store.CurrencyWhitelist, ""); + } + + return CompletionResult.Empty; + } +} diff --git a/Content.Server/Store/Systems/StoreSystem.cs b/Content.Server/Store/Systems/StoreSystem.cs index 9330538e2c..24efd4378e 100644 --- a/Content.Server/Store/Systems/StoreSystem.cs +++ b/Content.Server/Store/Systems/StoreSystem.cs @@ -32,6 +32,7 @@ public sealed partial class StoreSystem : EntitySystem SubscribeLocalEvent(OnShutdown); InitializeUi(); + InitializeCommand(); } private void OnMapInit(EntityUid uid, StoreComponent component, MapInitEvent args)