MakeSentientCommand.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Content.Server.Administration;
  2. using Content.Shared.Administration;
  3. using Content.Shared.Emoting;
  4. using Content.Shared.Examine;
  5. using Content.Shared.Mind.Components;
  6. using Content.Shared.Movement.Components;
  7. using Content.Shared.Speech;
  8. using Robust.Shared.Console;
  9. namespace Content.Server.Mind.Commands
  10. {
  11. [AdminCommand(AdminFlags.Admin)]
  12. public sealed class MakeSentientCommand : IConsoleCommand
  13. {
  14. [Dependency] private readonly IEntityManager _entManager = default!;
  15. public string Command => "makesentient";
  16. public string Description => "Makes an entity sentient (able to be controlled by a player)";
  17. public string Help => "makesentient <entity id>";
  18. public void Execute(IConsoleShell shell, string argStr, string[] args)
  19. {
  20. if (args.Length != 1)
  21. {
  22. shell.WriteLine("Wrong number of arguments.");
  23. return;
  24. }
  25. if (!NetEntity.TryParse(args[0], out var entNet) || !_entManager.TryGetEntity(entNet, out var entId))
  26. {
  27. shell.WriteLine("Invalid argument.");
  28. return;
  29. }
  30. if (!_entManager.EntityExists(entId))
  31. {
  32. shell.WriteLine("Invalid entity specified!");
  33. return;
  34. }
  35. MakeSentient(entId.Value, _entManager, true, true);
  36. }
  37. public static void MakeSentient(EntityUid uid, IEntityManager entityManager, bool allowMovement = true, bool allowSpeech = true)
  38. {
  39. entityManager.EnsureComponent<MindContainerComponent>(uid);
  40. if (allowMovement)
  41. {
  42. entityManager.EnsureComponent<InputMoverComponent>(uid);
  43. entityManager.EnsureComponent<MobMoverComponent>(uid);
  44. entityManager.EnsureComponent<MovementSpeedModifierComponent>(uid);
  45. }
  46. if (allowSpeech)
  47. {
  48. entityManager.EnsureComponent<SpeechComponent>(uid);
  49. entityManager.EnsureComponent<EmotingComponent>(uid);
  50. }
  51. entityManager.EnsureComponent<ExaminerComponent>(uid);
  52. }
  53. }
  54. }