]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
addcurrency command (#15000)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Fri, 31 Mar 2023 03:02:39 +0000 (23:02 -0400)
committerGitHub <noreply@github.com>
Fri, 31 Mar 2023 03:02:39 +0000 (23:02 -0400)
Content.Server/Store/Systems/StoreSystem.Command.cs [new file with mode: 0644]
Content.Server/Store/Systems/StoreSystem.cs

diff --git a/Content.Server/Store/Systems/StoreSystem.Command.cs b/Content.Server/Store/Systems/StoreSystem.Command.cs
new file mode 100644 (file)
index 0000000..5823bfe
--- /dev/null
@@ -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 <uid> <currency prototype> <amount>",
+            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<StoreComponent>(uid, out var store))
+            return;
+
+        var currency = new Dictionary<string, FixedPoint2>
+        {
+            { args[1], id }
+        };
+
+        TryAddCurrency(currency, uid, store);
+    }
+
+    private CompletionResult AddCurrencyCommandCompletions(IConsoleShell shell, string[] args)
+    {
+        if (args.Length == 1)
+        {
+            var query = EntityQueryEnumerator<StoreComponent>();
+            var allStores = new List<string>();
+            while (query.MoveNext(out var storeuid, out _))
+            {
+                allStores.Add(storeuid.ToString());
+            }
+            return CompletionResult.FromHintOptions(allStores, "<uid>");
+        }
+
+        if (args.Length == 2 && EntityUid.TryParse(args[0], out var uid))
+        {
+            if (TryComp<StoreComponent>(uid, out var store))
+                return CompletionResult.FromHintOptions(store.CurrencyWhitelist, "<currency prototype>");
+        }
+
+        return CompletionResult.Empty;
+    }
+}
index 9330538e2c1af9c202795de6139767adc03b2315..24efd4378e564f787ad0ca1c4328ab56c97e1977 100644 (file)
@@ -32,6 +32,7 @@ public sealed partial class StoreSystem : EntitySystem
         SubscribeLocalEvent<StoreComponent, ComponentShutdown>(OnShutdown);
 
         InitializeUi();
+        InitializeCommand();
     }
 
     private void OnMapInit(EntityUid uid, StoreComponent component, MapInitEvent args)