ForcePresetCommand.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.Linq;
  2. using Content.Server.Administration;
  3. using Content.Server.GameTicking.Presets;
  4. using Content.Shared.Administration;
  5. using Robust.Shared.Console;
  6. using Robust.Shared.Prototypes;
  7. namespace Content.Server.GameTicking.Commands
  8. {
  9. [AdminCommand(AdminFlags.Round)]
  10. sealed class ForcePresetCommand : IConsoleCommand
  11. {
  12. [Dependency] private readonly IEntityManager _e = default!;
  13. public string Command => "forcepreset";
  14. public string Description => "Forces a specific game preset to start for the current lobby.";
  15. public string Help => $"Usage: {Command} <preset>";
  16. public void Execute(IConsoleShell shell, string argStr, string[] args)
  17. {
  18. var ticker = _e.System<GameTicker>();
  19. if (ticker.RunLevel != GameRunLevel.PreRoundLobby)
  20. {
  21. shell.WriteLine("This can only be executed while the game is in the pre-round lobby.");
  22. return;
  23. }
  24. if (args.Length != 1)
  25. {
  26. shell.WriteLine("Need exactly one argument.");
  27. return;
  28. }
  29. var name = args[0];
  30. if (!ticker.TryFindGamePreset(name, out var type))
  31. {
  32. shell.WriteLine($"No preset exists with name {name}.");
  33. return;
  34. }
  35. ticker.SetGamePreset(type, true);
  36. shell.WriteLine($"Forced the game to start with preset {name}.");
  37. ticker.UpdateInfoText();
  38. }
  39. public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
  40. {
  41. if (args.Length == 1)
  42. {
  43. var options = IoCManager.Resolve<IPrototypeManager>()
  44. .EnumeratePrototypes<GamePresetPrototype>()
  45. .OrderBy(p => p.ID)
  46. .Select(p => p.ID);
  47. return CompletionResult.FromHintOptions(options, "<preset>");
  48. }
  49. return CompletionResult.Empty;
  50. }
  51. }
  52. }