Files
crystall-punk-14/Content.Server/Body/Commands/DestroyMechanismCommand.cs

60 lines
2.0 KiB
C#
Raw Permalink Normal View History

using Content.Server.Administration;
using Content.Server.Body.Systems;
using Content.Shared.Administration;
2021-06-09 22:19:39 +02:00
using Content.Shared.Body.Components;
using Robust.Shared.Console;
2021-06-09 22:19:39 +02:00
namespace Content.Server.Body.Commands
{
[AdminCommand(AdminFlags.Fun)]
internal sealed class DestroyMechanismCommand : LocalizedEntityCommands
{
[Dependency] private readonly IComponentFactory _compFactory = default!;
[Dependency] private readonly BodySystem _bodySystem = default!;
public override string Command => "destroymechanism";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player;
if (player == null)
{
shell.WriteLine(Loc.GetString($"shell-only-players-can-run-this-command"));
return;
}
if (args.Length == 0)
{
shell.WriteLine(Help);
return;
}
2021-12-06 15:34:46 +01:00
if (player.AttachedEntity is not {} attached)
{
shell.WriteLine(Loc.GetString($"shell-must-be-attached-to-entity"));
return;
}
if (!EntityManager.TryGetComponent(attached, out BodyComponent? body))
{
shell.WriteLine(Loc.GetString($"shell-must-have-body"));
return;
}
var mechanismName = string.Join(" ", args).ToLowerInvariant();
foreach (var organ in _bodySystem.GetBodyOrgans(attached, body))
{
if (_compFactory.GetComponentName(organ.Component.GetType()).ToLowerInvariant() == mechanismName)
{
EntityManager.QueueDeleteEntity(organ.Id);
shell.WriteLine(Loc.GetString($"cmd-destroymechanism-success", ("name", mechanismName)));
return;
}
}
shell.WriteLine(Loc.GetString($"cmd-destroymechanism-no-mechanism-found", ("name", mechanismName)));
}
}
}