From 8771cc03db72ab4c001fed6fb8609dccb0374f3c Mon Sep 17 00:00:00 2001 From: Mervill Date: Mon, 5 Aug 2024 00:36:26 -0700 Subject: [PATCH] Debug command to set either your hunger or thirst to one of their respective threshold levels (#30563) * 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 | 115 ++++++++++++++++++ .../en-US/nutrition/nutrition-commands.ftl | 4 + 2 files changed, 119 insertions(+) create mode 100644 Content.Server/Nutrition/SetNutrit.cs diff --git a/Content.Server/Nutrition/SetNutrit.cs b/Content.Server/Nutrition/SetNutrit.cs new file mode 100644 index 0000000000..c7c716b78c --- /dev/null +++ b/Content.Server/Nutrition/SetNutrit.cs @@ -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().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().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(), nameof(HungerThreshold)), + "thirst" => CompletionResult.FromHintOptions(Enum.GetNames(), nameof(ThirstThreshold)), + _ => CompletionResult.Empty, + }; + } + default: + return CompletionResult.Empty; + } + } +} diff --git a/Resources/Locale/en-US/nutrition/nutrition-commands.ftl b/Resources/Locale/en-US/nutrition/nutrition-commands.ftl index 8e6712c52f..d441026456 100644 --- a/Resources/Locale/en-US/nutrition/nutrition-commands.ftl +++ b/Resources/Locale/en-US/nutrition/nutrition-commands.ftl @@ -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