AddNPCCommand.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Content.Server.Administration;
  2. using Content.Server.NPC.HTN;
  3. using Content.Shared.Administration;
  4. using Robust.Shared.Console;
  5. namespace Content.Server.NPC.Commands
  6. {
  7. [AdminCommand(AdminFlags.Fun)]
  8. public sealed class AddNPCCommand : IConsoleCommand
  9. {
  10. [Dependency] private readonly IEntityManager _entities = default!;
  11. public string Command => "addnpc";
  12. public string Description => "Add a HTN NPC component with a given root task";
  13. public string Help => "Usage: addnpc <entityId> <rootTask>"
  14. + "\n entityID: Uid of entity to add the AiControllerComponent to. Open its VV menu to find this."
  15. + "\n rootTask: Name of a behaviorset to add to the component on initialize.";
  16. public void Execute(IConsoleShell shell, string argStr, string[] args)
  17. {
  18. if (args.Length != 2)
  19. {
  20. shell.WriteError("Wrong number of args.");
  21. return;
  22. }
  23. var nent = new NetEntity(int.Parse(args[0]));
  24. if (!_entities.TryGetEntity(nent, out var entId))
  25. {
  26. shell.WriteError($"Unable to find entity {nent}");
  27. return;
  28. }
  29. if (_entities.HasComponent<HTNComponent>(entId))
  30. {
  31. shell.WriteError("Entity already has an NPC component.");
  32. return;
  33. }
  34. var comp = _entities.AddComponent<HTNComponent>(entId.Value);
  35. comp.RootTask = new HTNCompoundTask()
  36. {
  37. Task = args[1]
  38. };
  39. shell.WriteLine("AI component added.");
  40. }
  41. }
  42. }