DestroyMechanismCommand.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using Content.Server.Administration;
  2. using Content.Server.Body.Systems;
  3. using Content.Shared.Administration;
  4. using Content.Shared.Body.Components;
  5. using Robust.Shared.Console;
  6. using Robust.Shared.Random;
  7. namespace Content.Server.Body.Commands
  8. {
  9. [AdminCommand(AdminFlags.Fun)]
  10. sealed class DestroyMechanismCommand : IConsoleCommand
  11. {
  12. public string Command => "destroymechanism";
  13. public string Description => "Destroys a mechanism from your entity";
  14. public string Help => $"Usage: {Command} <mechanism>";
  15. public void Execute(IConsoleShell shell, string argStr, string[] args)
  16. {
  17. var player = shell.Player;
  18. if (player == null)
  19. {
  20. shell.WriteLine("Only a player can run this command.");
  21. return;
  22. }
  23. if (args.Length == 0)
  24. {
  25. shell.WriteLine(Help);
  26. return;
  27. }
  28. if (player.AttachedEntity is not {} attached)
  29. {
  30. shell.WriteLine("You have no entity.");
  31. return;
  32. }
  33. var entityManager = IoCManager.Resolve<IEntityManager>();
  34. var fac = IoCManager.Resolve<IComponentFactory>();
  35. if (!entityManager.TryGetComponent(attached, out BodyComponent? body))
  36. {
  37. var random = IoCManager.Resolve<IRobustRandom>();
  38. var text = $"You have no body{(random.Prob(0.2f) ? " and you must scream." : ".")}";
  39. shell.WriteLine(text);
  40. return;
  41. }
  42. var mechanismName = string.Join(" ", args).ToLowerInvariant();
  43. var bodySystem = entityManager.System<BodySystem>();
  44. foreach (var organ in bodySystem.GetBodyOrgans(attached, body))
  45. {
  46. if (fac.GetComponentName(organ.Component.GetType()).ToLowerInvariant() == mechanismName)
  47. {
  48. entityManager.QueueDeleteEntity(organ.Id);
  49. shell.WriteLine($"Mechanism with name {mechanismName} has been destroyed.");
  50. return;
  51. }
  52. }
  53. shell.WriteLine($"No mechanism was found with name {mechanismName}.");
  54. }
  55. }
  56. }