Skip to content

Commit

Permalink
Refactor the hungry debug command to be in line with thirsty (#30591
Browse files Browse the repository at this point in the history
)

refactor the hungry debug command to be in line with thirsty

Co-authored-by: metalgearsloth <[email protected]>
  • Loading branch information
Mervill and metalgearsloth authored Aug 5, 2024
1 parent d45810b commit c1eb319
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
53 changes: 24 additions & 29 deletions Content.Server/Nutrition/Hungry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,35 @@
using Content.Shared.Nutrition.EntitySystems;
using Robust.Shared.Console;

namespace Content.Server.Nutrition
{
[AdminCommand(AdminFlags.Debug)]
public sealed class Hungry : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entities = default!;
namespace Content.Server.Nutrition;

public string Command => "hungry";
public string Description => "Makes you hungry.";
public string Help => $"{Command}";
[AdminCommand(AdminFlags.Debug)]
public sealed class Hungry : LocalizedEntityCommands
{
public override string Command => "hungry";

public void Execute(IConsoleShell shell, string argStr, string[] args)
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player;
if (player == null)
{
var player = shell.Player;
if (player == null)
{
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;
}
shell.WriteError(Loc.GetString("cmd-nutrition-error-player"));
return;
}

if (!_entities.TryGetComponent(playerEntity, out HungerComponent? hunger))
{
shell.WriteLine($"Your entity does not have a {nameof(HungerComponent)} component.");
return;
}
if (player.AttachedEntity is not {Valid: true} playerEntity)
{
shell.WriteError(Loc.GetString("cmd-nutrition-error-entity"));
return;
}

var hungryThreshold = hunger.Thresholds[HungerThreshold.Starving];
_entities.System<HungerSystem>().SetHunger(playerEntity, hungryThreshold, hunger);
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);
}
}
2 changes: 2 additions & 0 deletions Resources/Locale/en-US/nutrition/nutrition-commands.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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-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-help = set your hunger or thirst to one of the built-in thresholds
cmd-setnutrit-error-invalid-threshold = invalid {$thresholdType} `{$thresholdString}`
Expand Down

0 comments on commit c1eb319

Please sign in to comment.