RemoveHandCommand.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Linq;
  2. using Content.Server.Administration;
  3. using Content.Server.Body.Systems;
  4. using Content.Shared.Administration;
  5. using Content.Shared.Body.Components;
  6. using Content.Shared.Body.Part;
  7. using Robust.Shared.Console;
  8. using Robust.Shared.Random;
  9. namespace Content.Server.Body.Commands
  10. {
  11. [AdminCommand(AdminFlags.Fun)]
  12. public sealed class RemoveHandCommand : IConsoleCommand
  13. {
  14. [Dependency] private readonly IEntityManager _entManager = default!;
  15. [Dependency] private readonly IRobustRandom _random = default!;
  16. public string Command => "removehand";
  17. public string Description => "Removes a hand from your entity.";
  18. public string Help => $"Usage: {Command}";
  19. public void Execute(IConsoleShell shell, string argStr, string[] args)
  20. {
  21. var player = shell.Player;
  22. if (player == null)
  23. {
  24. shell.WriteLine("Only a player can run this command.");
  25. return;
  26. }
  27. if (player.AttachedEntity == null)
  28. {
  29. shell.WriteLine("You have no entity.");
  30. return;
  31. }
  32. if (!_entManager.TryGetComponent(player.AttachedEntity, out BodyComponent? body))
  33. {
  34. var text = $"You have no body{(_random.Prob(0.2f) ? " and you must scream." : ".")}";
  35. shell.WriteLine(text);
  36. return;
  37. }
  38. var bodySystem = _entManager.System<BodySystem>();
  39. var hand = bodySystem.GetBodyChildrenOfType(player.AttachedEntity.Value, BodyPartType.Hand, body).FirstOrDefault();
  40. if (hand == default)
  41. {
  42. shell.WriteLine("You have no hands.");
  43. }
  44. else
  45. {
  46. _entManager.System<SharedTransformSystem>().AttachToGridOrMap(hand.Id);
  47. }
  48. }
  49. }
  50. }