DockCommand.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using Content.Server.Administration;
  2. using Content.Server.Shuttles.Components;
  3. using Content.Server.Shuttles.Systems;
  4. using Content.Shared.Administration;
  5. using Robust.Shared.Console;
  6. namespace Content.Server.Shuttles.Commands;
  7. [AdminCommand(AdminFlags.Mapping)]
  8. public sealed class DockCommand : IConsoleCommand
  9. {
  10. [Dependency] private readonly IEntityManager _entManager = default!;
  11. public string Command => "dock";
  12. public string Description => Loc.GetString("cmd-dock-desc");
  13. public string Help => Loc.GetString("cmd-dock-help");
  14. public void Execute(IConsoleShell shell, string argStr, string[] args)
  15. {
  16. if (args.Length != 2)
  17. {
  18. shell.WriteError(Loc.GetString("cmd-dock-args"));
  19. return;
  20. }
  21. if (!NetEntity.TryParse(args[0], out var airlock1Net) || !_entManager.TryGetEntity(airlock1Net, out var airlock1))
  22. {
  23. shell.WriteError(Loc.GetString("cmd-dock-invalid", ("entity", args[0])));
  24. return;
  25. }
  26. if (!NetEntity.TryParse(args[1], out var airlock2Net) || !_entManager.TryGetEntity(airlock2Net, out var airlock2))
  27. {
  28. shell.WriteError(Loc.GetString("cmd-dock-invalid", ("entity", args[1])));
  29. return;
  30. }
  31. if (!_entManager.TryGetComponent(airlock1, out DockingComponent? dock1))
  32. {
  33. shell.WriteError(Loc.GetString("cmd-dock-found", ("airlock", airlock1)));
  34. return;
  35. }
  36. if (!_entManager.TryGetComponent(airlock2, out DockingComponent? dock2))
  37. {
  38. shell.WriteError(Loc.GetString("cmd-dock-found", ("airlock", airlock2)));
  39. return;
  40. }
  41. var dockSystem = _entManager.System<DockingSystem>();
  42. dockSystem.Dock((airlock1.Value, dock1), (airlock2.Value, dock2));
  43. if (dock1.DockedWith == airlock2)
  44. {
  45. shell.WriteLine(Loc.GetString("cmd-dock-success"));
  46. }
  47. else
  48. {
  49. shell.WriteError(Loc.GetString("cmd-dock-fail"));
  50. }
  51. }
  52. public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
  53. {
  54. if (args.Length == 1)
  55. {
  56. return CompletionResult.FromOptions(CompletionHelper.Components<DockingComponent>(args[0], _entManager));
  57. }
  58. if (args.Length == 2)
  59. {
  60. return CompletionResult.FromOptions(CompletionHelper.Components<DockingComponent>(args[1], _entManager));
  61. }
  62. return CompletionResult.Empty;
  63. }
  64. }