Allow admins to change round preset.
This commit is contained in:
@@ -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" />
|
||||
|
||||
10
Content.Server/GameTicking/GamePresets/PresetSandbox.cs
Normal file
10
Content.Server/GameTicking/GamePresets/PresetSandbox.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Content.Server.GameTicking.GamePresets
|
||||
{
|
||||
public sealed class PresetSandbox : GamePreset
|
||||
{
|
||||
public override void Start()
|
||||
{
|
||||
// Nothing yet.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<GameRule> _gameRules = new List<GameRule>();
|
||||
|
||||
[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<PresetTraitor>();
|
||||
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<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());
|
||||
@@ -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<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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,5 +33,7 @@ namespace Content.Server.Interfaces.GameTicking
|
||||
T AddGameRule<T>() where T : GameRule, new();
|
||||
void RemoveGameRule(GameRule rule);
|
||||
IEnumerable<GameRule> ActiveGameRules { get; }
|
||||
|
||||
void SetStartPreset(Type type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,4 +45,5 @@
|
||||
- delete
|
||||
- tp
|
||||
- tpgrid
|
||||
- setgamepreset
|
||||
CanViewVar: true
|
||||
|
||||
Reference in New Issue
Block a user