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