Refactor the hungry debug command to be in line with thirsty (#30591)

refactor the hungry debug command to be in line with thirsty

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Mervill
2024-08-05 01:12:07 -07:00
committed by GitHub
parent d45810bbdb
commit c1eb319bda
2 changed files with 28 additions and 31 deletions

View File

@@ -4,40 +4,35 @@ using Content.Shared.Nutrition.Components;
using Content.Shared.Nutrition.EntitySystems; using Content.Shared.Nutrition.EntitySystems;
using Robust.Shared.Console; using Robust.Shared.Console;
namespace Content.Server.Nutrition namespace Content.Server.Nutrition;
[AdminCommand(AdminFlags.Debug)]
public sealed class Hungry : LocalizedEntityCommands
{ {
[AdminCommand(AdminFlags.Debug)] public override string Command => "hungry";
public sealed class Hungry : IConsoleCommand
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{ {
[Dependency] private readonly IEntityManager _entities = default!; var player = shell.Player;
if (player == null)
public string Command => "hungry";
public string Description => "Makes you hungry.";
public string Help => $"{Command}";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{ {
var player = shell.Player; shell.WriteError(Loc.GetString("cmd-nutrition-error-player"));
if (player == null) return;
{
shell.WriteLine("You cannot use this command unless you are a player.");
return;
}
if (player.AttachedEntity is not {Valid: true} playerEntity)
{
shell.WriteLine("You cannot use this command without an entity.");
return;
}
if (!_entities.TryGetComponent(playerEntity, out HungerComponent? hunger))
{
shell.WriteLine($"Your entity does not have a {nameof(HungerComponent)} component.");
return;
}
var hungryThreshold = hunger.Thresholds[HungerThreshold.Starving];
_entities.System<HungerSystem>().SetHunger(playerEntity, hungryThreshold, hunger);
} }
if (player.AttachedEntity is not {Valid: true} playerEntity)
{
shell.WriteError(Loc.GetString("cmd-nutrition-error-entity"));
return;
}
if (!EntityManager.TryGetComponent(playerEntity, out HungerComponent? hunger))
{
shell.WriteError(Loc.GetString("cmd-nutrition-error-component", ("comp", nameof(HungerComponent))));
return;
}
var hungryThreshold = hunger.Thresholds[HungerThreshold.Starving];
EntityManager.System<HungerSystem>().SetHunger(playerEntity, hungryThreshold, hunger);
} }
} }

View File

@@ -2,6 +2,8 @@ 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-entity = You cannot use this command without an entity.
cmd-nutrition-error-component = Your entity does not have a {$comp} component. cmd-nutrition-error-component = Your entity does not have a {$comp} component.
cmd-hungry-desc = makes you hungry
cmd-hungry-help = sets your hungry level to starving
cmd-setnutrit-desc = modify hunger and thirst cmd-setnutrit-desc = modify hunger and thirst
cmd-setnutrit-help = set your hunger or thirst to one of the built-in thresholds cmd-setnutrit-help = set your hunger or thirst to one of the built-in thresholds
cmd-setnutrit-error-invalid-threshold = invalid {$thresholdType} `{$thresholdString}` cmd-setnutrit-error-invalid-threshold = invalid {$thresholdType} `{$thresholdString}`