Skip to content

Commit

Permalink
Allow admins to change round preset.
Browse files Browse the repository at this point in the history
  • Loading branch information
PJB3005 committed May 15, 2019
1 parent e68a5c8 commit a903ffb
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Content.Server/Content.Server.csproj
Expand Up @@ -142,7 +142,7 @@
<Compile Include="GameObjects\EntitySystems\TemperatureSystem.cs" />
<Compile Include="GameTicking\GamePreset.cs" />
<Compile Include="GameTicking\GamePresets\PresetDeathMatch.cs" />
<Compile Include="GameTicking\GamePresets\PresetTraitor.cs" />
<Compile Include="GameTicking\GamePresets\PresetSandbox.cs" />
<Compile Include="GameTicking\GameRule.cs" />
<Compile Include="GameTicking\GameRules\RuleDeathMatch.cs" />
<Compile Include="GameTicking\GameTicker.cs" />
Expand Down
10 changes: 10 additions & 0 deletions 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.
}
}
}
12 changes: 0 additions & 12 deletions Content.Server/GameTicking/GamePresets/PresetTraitor.cs

This file was deleted.

49 changes: 47 additions & 2 deletions Content.Server/GameTicking/GameTicker.cs
Expand Up @@ -15,13 +15,13 @@
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;
Expand Down Expand Up @@ -81,6 +81,8 @@ private set

[ViewVariables] private readonly List<GameRule> _gameRules = new List<GameRule>();

[ViewVariables] private Type _presetType;

#pragma warning disable 649
[Dependency] private IEntityManager _entityManager;
[Dependency] private IMapManager _mapManager;
Expand Down Expand Up @@ -155,7 +157,7 @@ public void StartRound()
RunLevel = GameRunLevel.InRound;

// TODO: Allow other presets to be selected.
var preset = _dynamicTypeFactory.CreateInstance<PresetTraitor>();
var preset = (GamePreset)_dynamicTypeFactory.CreateInstance(_presetType);
preset.Start();

foreach (var (playerSession, ready) in _playersInLobby.ToList())
Expand Down Expand Up @@ -248,6 +250,15 @@ public void RemoveGameRule(GameRule rule)

public IEnumerable<GameRule> 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());
Expand Down Expand Up @@ -643,4 +654,38 @@ public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
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<IGameTicker>();

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);
}
}
}
2 changes: 2 additions & 0 deletions Content.Server/Interfaces/GameTicking/IGameTicker.cs
Expand Up @@ -33,5 +33,7 @@ public interface IGameTicker
T AddGameRule<T>() where T : GameRule, new();
void RemoveGameRule(GameRule rule);
IEnumerable<GameRule> ActiveGameRules { get; }

void SetStartPreset(Type type);
}
}
1 change: 1 addition & 0 deletions Resources/Groups/groups.yml
Expand Up @@ -45,4 +45,5 @@
- delete
- tp
- tpgrid
- setgamepreset
CanViewVar: true

0 comments on commit a903ffb

Please sign in to comment.