2020-12-03 03:40:47 +01:00
|
|
|
using Content.Server.Administration;
|
|
|
|
|
using Content.Shared.Administration;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Body.Components;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Server.Player;
|
2021-02-01 16:49:43 -08:00
|
|
|
using Robust.Shared.Console;
|
2021-12-03 14:17:01 +01:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-12-03 03:40:47 +01:00
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Random;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Body.Commands
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
|
|
|
|
[AdminCommand(AdminFlags.Fun)]
|
2022-02-16 00:23:23 -07:00
|
|
|
sealed class DestroyMechanismCommand : IConsoleCommand
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
|
|
|
|
public string Command => "destroymechanism";
|
|
|
|
|
public string Description => "Destroys a mechanism from your entity";
|
|
|
|
|
public string Help => $"Usage: {Command} <mechanism>";
|
|
|
|
|
|
2021-02-01 16:49:43 -08:00
|
|
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
var player = shell.Player as IPlayerSession;
|
2020-12-03 03:40:47 +01:00
|
|
|
if (player == null)
|
|
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine("Only a player 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
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine("You have no entity.");
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-06 15:34:46 +01:00
|
|
|
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(attached, out SharedBodyComponent? body))
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
|
|
|
|
var random = IoCManager.Resolve<IRobustRandom>();
|
|
|
|
|
var text = $"You have no body{(random.Prob(0.2f) ? " and you must scream." : ".")}";
|
|
|
|
|
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine(text);
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var mechanismName = string.Join(" ", args).ToLowerInvariant();
|
|
|
|
|
|
2021-04-05 14:54:51 +02:00
|
|
|
foreach (var (part, _) in body.Parts)
|
2020-12-03 03:40:47 +01:00
|
|
|
foreach (var mechanism in part.Mechanisms)
|
|
|
|
|
{
|
|
|
|
|
if (mechanism.Name.ToLowerInvariant() == mechanismName)
|
|
|
|
|
{
|
|
|
|
|
part.DeleteMechanism(mechanism);
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine($"Mechanism with name {mechanismName} has been destroyed.");
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine($"No mechanism was found with name {mechanismName}.");
|
2020-12-03 03:40:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|