2022-05-25 00:26:57 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Content.Server.Administration;
|
|
|
|
|
|
using Content.Server.GameTicking.Presets;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
using Content.Shared.Administration;
|
2021-02-01 16:49:43 -08:00
|
|
|
|
using Robust.Shared.Console;
|
2022-05-25 00:26:57 +02:00
|
|
|
|
using Robust.Shared.Prototypes;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Server.GameTicking.Commands
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2021-11-29 14:40:10 -06:00
|
|
|
|
[AdminCommand(AdminFlags.Round)]
|
2022-02-16 00:23:23 -07:00
|
|
|
|
sealed class ForcePresetCommand : IConsoleCommand
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2024-05-12 17:34:52 -07:00
|
|
|
|
[Dependency] private readonly IEntityManager _e = default!;
|
|
|
|
|
|
|
2020-12-03 03:40:47 +01:00
|
|
|
|
public string Command => "forcepreset";
|
|
|
|
|
|
public string Description => "Forces a specific game preset to start for the current lobby.";
|
|
|
|
|
|
public string Help => $"Usage: {Command} <preset>";
|
|
|
|
|
|
|
2021-02-01 16:49:43 -08:00
|
|
|
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2024-05-12 17:34:52 -07:00
|
|
|
|
var ticker = _e.System<GameTicker>();
|
2020-12-03 03:40:47 +01:00
|
|
|
|
if (ticker.RunLevel != GameRunLevel.PreRoundLobby)
|
|
|
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
|
shell.WriteLine("This can only be executed while the game is in the pre-round lobby.");
|
2020-12-03 03:40:47 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (args.Length != 1)
|
|
|
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
|
shell.WriteLine("Need exactly one argument.");
|
2020-12-03 03:40:47 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var name = args[0];
|
2021-12-21 21:23:29 +01:00
|
|
|
|
if (!ticker.TryFindGamePreset(name, out var type))
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
|
shell.WriteLine($"No preset exists with name {name}.");
|
2020-12-03 03:40:47 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-21 21:23:29 +01:00
|
|
|
|
ticker.SetGamePreset(type, true);
|
2021-02-01 16:49:43 -08:00
|
|
|
|
shell.WriteLine($"Forced the game to start with preset {name}.");
|
2022-04-15 13:55:38 -05:00
|
|
|
|
ticker.UpdateInfoText();
|
2020-12-03 03:40:47 +01:00
|
|
|
|
}
|
2022-05-25 00:26:57 +02:00
|
|
|
|
|
|
|
|
|
|
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (args.Length == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
var options = IoCManager.Resolve<IPrototypeManager>()
|
|
|
|
|
|
.EnumeratePrototypes<GamePresetPrototype>()
|
|
|
|
|
|
.OrderBy(p => p.ID)
|
|
|
|
|
|
.Select(p => p.ID);
|
|
|
|
|
|
|
|
|
|
|
|
return CompletionResult.FromHintOptions(options, "<preset>");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return CompletionResult.Empty;
|
|
|
|
|
|
}
|
2020-12-03 03:40:47 +01:00
|
|
|
|
}
|
2021-02-14 15:39:24 +01:00
|
|
|
|
}
|