StationCommand.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System.Diagnostics;
  2. using System.Linq;
  3. using Content.Server.Administration;
  4. using Content.Server.Cargo.Systems;
  5. using Content.Server.Station.Components;
  6. using Content.Server.Station.Systems;
  7. using Content.Shared.Administration;
  8. using Robust.Shared.Toolshed;
  9. using Robust.Shared.Toolshed.Errors;
  10. using Robust.Shared.Toolshed.Syntax;
  11. using Robust.Shared.Utility;
  12. namespace Content.Server.Station.Commands;
  13. [ToolshedCommand, AdminCommand(AdminFlags.Admin)]
  14. public sealed class StationsCommand : ToolshedCommand
  15. {
  16. private StationSystem? _station;
  17. private CargoSystem? _cargo;
  18. [CommandImplementation("list")]
  19. public IEnumerable<EntityUid> List()
  20. {
  21. _station ??= GetSys<StationSystem>();
  22. return _station.GetStationsSet();
  23. }
  24. [CommandImplementation("get")]
  25. public EntityUid Get(IInvocationContext ctx)
  26. {
  27. _station ??= GetSys<StationSystem>();
  28. var set = _station.GetStationsSet();
  29. if (set.Count > 1 || set.Count == 0)
  30. ctx.ReportError(new OnlyOneStationsError());
  31. return set.FirstOrDefault();
  32. }
  33. [CommandImplementation("getowningstation")]
  34. public IEnumerable<EntityUid?> GetOwningStation([PipedArgument] IEnumerable<EntityUid> input)
  35. => input.Select(GetOwningStation);
  36. [CommandImplementation("getowningstation")]
  37. public EntityUid? GetOwningStation([PipedArgument] EntityUid input)
  38. {
  39. _station ??= GetSys<StationSystem>();
  40. return _station.GetOwningStation(input);
  41. }
  42. [CommandImplementation("largestgrid")]
  43. public EntityUid? LargestGrid([PipedArgument] EntityUid input)
  44. {
  45. _station ??= GetSys<StationSystem>();
  46. return _station.GetLargestGrid(Comp<StationDataComponent>(input));
  47. }
  48. [CommandImplementation("largestgrid")]
  49. public IEnumerable<EntityUid?> LargestGrid([PipedArgument] IEnumerable<EntityUid> input)
  50. => input.Select(LargestGrid);
  51. [CommandImplementation("grids")]
  52. public IEnumerable<EntityUid> Grids([PipedArgument] EntityUid input)
  53. => Comp<StationDataComponent>(input).Grids;
  54. [CommandImplementation("grids")]
  55. public IEnumerable<EntityUid> Grids([PipedArgument] IEnumerable<EntityUid> input)
  56. => input.SelectMany(Grids);
  57. [CommandImplementation("config")]
  58. public StationConfig? Config([PipedArgument] EntityUid input)
  59. => Comp<StationDataComponent>(input).StationConfig;
  60. [CommandImplementation("config")]
  61. public IEnumerable<StationConfig?> Config([PipedArgument] IEnumerable<EntityUid> input)
  62. => input.Select(Config);
  63. [CommandImplementation("addgrid")]
  64. public void AddGrid([PipedArgument] EntityUid input, EntityUid grid)
  65. {
  66. _station ??= GetSys<StationSystem>();
  67. _station.AddGridToStation(input, grid);
  68. }
  69. [CommandImplementation("rmgrid")]
  70. public void RmGrid([PipedArgument] EntityUid input, EntityUid grid)
  71. {
  72. _station ??= GetSys<StationSystem>();
  73. _station.RemoveGridFromStation(input, grid);
  74. }
  75. [CommandImplementation("rename")]
  76. public void Rename([PipedArgument] EntityUid input, string name)
  77. {
  78. _station ??= GetSys<StationSystem>();
  79. _station.RenameStation(input, name);
  80. }
  81. [CommandImplementation("rerollBounties")]
  82. public void RerollBounties([PipedArgument] EntityUid input)
  83. {
  84. _cargo ??= GetSys<CargoSystem>();
  85. _cargo.RerollBountyDatabase(input);
  86. }
  87. }
  88. public record struct OnlyOneStationsError : IConError
  89. {
  90. public FormattedMessage DescribeInner()
  91. {
  92. return FormattedMessage.FromMarkupOrThrow("This command doesn't function if there is more than one or no stations, explicitly specify a station with the ent command or similar.");
  93. }
  94. public string? Expression { get; set; }
  95. public Vector2i? IssueSpan { get; set; }
  96. public StackTrace? Trace { get; set; }
  97. }