]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Debug command to set either your hunger or thirst to one of their respective threshol...
authorMervill <mervills.email@gmail.com>
Mon, 5 Aug 2024 07:36:26 +0000 (00:36 -0700)
committerGitHub <noreply@github.com>
Mon, 5 Aug 2024 07:36:26 +0000 (17:36 +1000)
* Debug command to set either your hunger or thirst to one of their respective threshold levels

* code updates

* code + loc changes

Content.Server/Nutrition/SetNutrit.cs [new file with mode: 0644]
Resources/Locale/en-US/nutrition/nutrition-commands.ftl

diff --git a/Content.Server/Nutrition/SetNutrit.cs b/Content.Server/Nutrition/SetNutrit.cs
new file mode 100644 (file)
index 0000000..c7c716b
--- /dev/null
@@ -0,0 +1,115 @@
+using Content.Server.Administration;
+using Content.Server.Database.Migrations.Postgres;
+using Content.Shared.Administration;
+using Content.Shared.Nutrition.Components;
+using Content.Shared.Nutrition.EntitySystems;
+using Robust.Shared.Console;
+using System.Linq;
+
+namespace Content.Server.Nutrition;
+
+[AdminCommand(AdminFlags.Debug)]
+public sealed class SetNutrit : LocalizedEntityCommands
+{
+    public override string Command => "setnutrit";
+
+    public override void Execute(IConsoleShell shell, string argStr, string[] args)
+    {
+        var player = shell.Player;
+        if (player == null)
+        {
+            shell.WriteError(Loc.GetString("cmd-nutrition-error-player"));
+            return;
+        }
+
+        if (player.AttachedEntity is not { Valid: true } playerEntity)
+        {
+            shell.WriteError(Loc.GetString("cmd-nutrition-error-entity"));
+            return;
+        }
+
+        if (args.Length != 2)
+        {
+            shell.WriteError(Loc.GetString("shell-wrong-arguments-number-need-specific",
+                ("properAmount", 2),
+                ("currentAmount", args.Length)
+            ));
+            return;
+        }
+
+        var systemString = args[0];
+        switch (systemString)
+        {
+            case "hunger":
+            {
+                if (!EntityManager.TryGetComponent(playerEntity, out HungerComponent? hunger))
+                {
+                    shell.WriteError(Loc.GetString("cmd-nutrition-error-component", ("comp", nameof(HungerComponent))));
+                    return;
+                }
+
+                if (!Enum.TryParse(args[1], out HungerThreshold hungerThreshold))
+                {
+                    shell.WriteError(Loc.GetString("cmd-setnutrit-error-invalid-threshold",
+                        ("thresholdType", nameof(HungerThreshold)),
+                        ("thresholdString", args[1])
+                    ));
+                    return;
+                }
+
+                var hungerValue = hunger.Thresholds[hungerThreshold];
+                EntityManager.System<HungerSystem>().SetHunger(playerEntity, hungerValue, hunger);
+                return;
+            }
+            case "thirst":
+            {
+                if (!EntityManager.TryGetComponent(playerEntity, out ThirstComponent? thirst))
+                {
+                    shell.WriteError(Loc.GetString("cmd-nutrition-error-component", ("comp", nameof(ThirstComponent))));
+                    return;
+                }
+
+                if (!Enum.TryParse(args[1], out ThirstThreshold thirstThreshold))
+                {
+                    shell.WriteError(Loc.GetString("cmd-setnutrit-error-invalid-threshold",
+                         ("thresholdType", nameof(ThirstThreshold)),
+                         ("thresholdString", args[1])
+                     ));
+                    return;
+                }
+
+                var thirstValue = thirst.ThirstThresholds[thirstThreshold];
+                EntityManager.System<ThirstSystem>().SetThirst(playerEntity, thirst, thirstValue);
+                return;
+            }
+            default:
+            {
+                shell.WriteError($"invalid nutrition system ${systemString}");
+                return;
+            }
+        }
+    }
+
+    public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
+    {
+        switch (args.Length)
+        {
+            case 1:
+            {
+                string[] kinds = { "hunger", "thirst" };
+                return CompletionResult.FromHintOptions(kinds, "nutrition system");
+            }
+            case 2:
+            {
+                return args[0] switch
+                {
+                    "hunger" => CompletionResult.FromHintOptions(Enum.GetNames<HungerThreshold>(), nameof(HungerThreshold)),
+                    "thirst" => CompletionResult.FromHintOptions(Enum.GetNames<ThirstThreshold>(), nameof(ThirstThreshold)),
+                    _ => CompletionResult.Empty,
+                };
+            }
+            default:
+                return CompletionResult.Empty;
+        }
+    }
+}
index 8e6712c52fdc62fdf20af769fe2221c6525f82b0..d4410264560eb4c39243930f4020ba5cb201efb7 100644 (file)
@@ -2,5 +2,9 @@ cmd-nutrition-error-player = You cannot use this command unless you are a player
 cmd-nutrition-error-entity = You cannot use this command without an entity.
 cmd-nutrition-error-component = Your entity does not have a {$comp} component.
 
+cmd-setnutrit-desc = modify hunger and thirst
+cmd-setnutrit-help = set your hunger or thirst to one of the built-in thresholds
+cmd-setnutrit-error-invalid-threshold = invalid {$thresholdType} `{$thresholdString}`
+
 cmd-thirsty-desc = makes you thirsty
 cmd-thirsty-help = sets your thirst level to partched