diff --git a/Content.Server/Content.Server.csproj b/Content.Server/Content.Server.csproj index 6eb2763531..8495a115da 100644 --- a/Content.Server/Content.Server.csproj +++ b/Content.Server/Content.Server.csproj @@ -142,7 +142,7 @@ - + diff --git a/Content.Server/GameTicking/GamePresets/PresetSandbox.cs b/Content.Server/GameTicking/GamePresets/PresetSandbox.cs new file mode 100644 index 0000000000..fa9d4ae76b --- /dev/null +++ b/Content.Server/GameTicking/GamePresets/PresetSandbox.cs @@ -0,0 +1,10 @@ +namespace Content.Server.GameTicking.GamePresets +{ + public sealed class PresetSandbox : GamePreset + { + public override void Start() + { + // Nothing yet. + } + } +} diff --git a/Content.Server/GameTicking/GamePresets/PresetTraitor.cs b/Content.Server/GameTicking/GamePresets/PresetTraitor.cs deleted file mode 100644 index 787cf8a146..0000000000 --- a/Content.Server/GameTicking/GamePresets/PresetTraitor.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Robust.Shared.Log; - -namespace Content.Server.GameTicking.GamePresets -{ - public class PresetTraitor : GamePreset - { - public override void Start() - { - Logger.DebugS("ticker.preset", "Current preset is traitor."); - } - } -} diff --git a/Content.Server/GameTicking/GameTicker.cs b/Content.Server/GameTicking/GameTicker.cs index 5b98912752..34554700ee 100644 --- a/Content.Server/GameTicking/GameTicker.cs +++ b/Content.Server/GameTicking/GameTicker.cs @@ -15,13 +15,13 @@ using Robust.Server.Interfaces.Maps; using Robust.Server.Interfaces.Player; using Robust.Server.Player; using Robust.Shared.Configuration; -using Robust.Shared.Console; using Robust.Shared.Enums; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.Configuration; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Map; using Robust.Shared.Interfaces.Network; +using Robust.Shared.Interfaces.Reflection; using Robust.Shared.Interfaces.Timing; using Robust.Shared.IoC; using Robust.Shared.Log; @@ -81,6 +81,8 @@ namespace Content.Server.GameTicking [ViewVariables] private readonly List _gameRules = new List(); + [ViewVariables] private Type _presetType; + #pragma warning disable 649 [Dependency] private IEntityManager _entityManager; [Dependency] private IMapManager _mapManager; @@ -155,7 +157,7 @@ namespace Content.Server.GameTicking RunLevel = GameRunLevel.InRound; // TODO: Allow other presets to be selected. - var preset = _dynamicTypeFactory.CreateInstance(); + var preset = (GamePreset)_dynamicTypeFactory.CreateInstance(_presetType); preset.Start(); foreach (var (playerSession, ready) in _playersInLobby.ToList()) @@ -248,6 +250,15 @@ namespace Content.Server.GameTicking public IEnumerable ActiveGameRules => _gameRules; + public void SetStartPreset(Type type) + { + if (!typeof(GamePreset).IsAssignableFrom(type)) + { + throw new ArgumentException("type must inherit GamePreset"); + } + _presetType = type; + } + private IEntity _spawnPlayerMob() { var entity = _entityManager.ForceSpawnEntityAt(PlayerPrototypeName, _getLateJoinSpawnPoint()); @@ -643,4 +654,38 @@ namespace Content.Server.GameTicking ticker.ToggleReady(player, bool.Parse(args[0])); } } + + class SetGamePresetCommand : IClientCommand + { + public string Command => "setgamepreset"; + public string Description => ""; + public string Help => ""; + + public void Execute(IConsoleShell shell, IPlayerSession player, string[] args) + { + if (args.Length != 1) + { + shell.SendText(player, "Need exactly one argument."); + return; + } + + var ticker = IoCManager.Resolve(); + + Type presetType; + switch (args[0]) + { + case "DeathMatch": + presetType = typeof(PresetDeathMatch); + break; + case "Sandbox": + presetType = typeof(PresetSandbox); + break; + default: + shell.SendText(player, "That is not a valid game preset!"); + return; + } + + ticker.SetStartPreset(presetType); + } + } } diff --git a/Content.Server/Interfaces/GameTicking/IGameTicker.cs b/Content.Server/Interfaces/GameTicking/IGameTicker.cs index ba737643c4..cf879f7c32 100644 --- a/Content.Server/Interfaces/GameTicking/IGameTicker.cs +++ b/Content.Server/Interfaces/GameTicking/IGameTicker.cs @@ -33,5 +33,7 @@ namespace Content.Server.Interfaces.GameTicking T AddGameRule() where T : GameRule, new(); void RemoveGameRule(GameRule rule); IEnumerable ActiveGameRules { get; } + + void SetStartPreset(Type type); } } diff --git a/Resources/Groups/groups.yml b/Resources/Groups/groups.yml index 1df54bd807..1fb9205555 100644 --- a/Resources/Groups/groups.yml +++ b/Resources/Groups/groups.yml @@ -45,4 +45,5 @@ - delete - tp - tpgrid + - setgamepreset CanViewVar: true