NPCDomainCommand.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Content.Server.Administration;
  2. using Content.Server.NPC.HTN;
  3. using Content.Shared.Administration;
  4. using Robust.Shared.Console;
  5. using Robust.Shared.Prototypes;
  6. namespace Content.Server.NPC.Commands;
  7. /// <summary>
  8. /// Lists out the domain of a particular HTN compound task.
  9. /// </summary>
  10. [AdminCommand(AdminFlags.Debug)]
  11. public sealed class NPCDomainCommand : IConsoleCommand
  12. {
  13. [Dependency] private readonly IEntitySystemManager _sysManager = default!;
  14. [Dependency] private readonly IPrototypeManager _protoManager = default!;
  15. public string Command => "npcdomain";
  16. public string Description => "Lists the domain of a particular HTN compound task";
  17. public string Help => $"{Command} <htncompoundtask>";
  18. public void Execute(IConsoleShell shell, string argStr, string[] args)
  19. {
  20. if (args.Length != 1)
  21. {
  22. shell.WriteError("shell-need-exactly-one-argument");
  23. return;
  24. }
  25. if (!_protoManager.HasIndex<HTNCompoundPrototype>(args[0]))
  26. {
  27. shell.WriteError($"Unable to find HTN compound task for '{args[0]}'");
  28. return;
  29. }
  30. var htnSystem = _sysManager.GetEntitySystem<HTNSystem>();
  31. foreach (var line in htnSystem.GetDomain(new HTNCompoundTask {Task = args[0]}).Split("\n"))
  32. {
  33. shell.WriteLine(line);
  34. }
  35. }
  36. public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
  37. {
  38. if (args.Length > 1)
  39. return CompletionResult.Empty;
  40. return CompletionResult.FromHintOptions(CompletionHelper.PrototypeIDs<HTNCompoundPrototype>(proto: _protoManager), "compound task");
  41. }
  42. }