From 913b4d97a1aa380547e9610f7adc7b8eb9fefa48 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Sat, 8 Feb 2020 21:23:37 +0100 Subject: [PATCH] Allow more lobby parameters to be configured. --- Content.IntegrationTests/DummyGameTicker.cs | 4 +++ Content.Server/GameTicking/GameTicker.cs | 27 ++++++++++++++----- .../GameTicking/GameTickerCommands.cs | 16 +---------- .../Interfaces/GameTicking/IGameTicker.cs | 1 + Content.Server/Sandbox/SandboxManager.cs | 2 ++ 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/Content.IntegrationTests/DummyGameTicker.cs b/Content.IntegrationTests/DummyGameTicker.cs index f3ffbe05d3..5732e413ea 100644 --- a/Content.IntegrationTests/DummyGameTicker.cs +++ b/Content.IntegrationTests/DummyGameTicker.cs @@ -68,5 +68,9 @@ namespace Content.IntegrationTests public void SetStartPreset(Type type) { } + + public void SetStartPreset(string type) + { + } } } diff --git a/Content.Server/GameTicking/GameTicker.cs b/Content.Server/GameTicking/GameTicker.cs index 30e839fd53..1d41f0a132 100644 --- a/Content.Server/GameTicking/GameTicker.cs +++ b/Content.Server/GameTicking/GameTicker.cs @@ -48,9 +48,6 @@ namespace Content.Server.GameTicking private const string ObserverPrototypeName = "MobObserver"; private const string MapFile = "Maps/stationstation.yml"; - // Seconds. - private const float LobbyDuration = 20; - [ViewVariables] private readonly List _gameRules = new List(); [ViewVariables] private readonly List _manifest = new List(); @@ -86,11 +83,17 @@ namespace Content.Server.GameTicking public event Action OnRunLevelChanged; + private TimeSpan LobbyDuration => + TimeSpan.FromSeconds(_configurationManager.GetCVar("game.lobbyduration")); + public void Initialize() { DebugTools.Assert(!_initialized); _configurationManager.RegisterCVar("game.lobbyenabled", false, CVar.ARCHIVE); + _configurationManager.RegisterCVar("game.lobbyduration", 20, CVar.ARCHIVE); + _configurationManager.RegisterCVar("game.defaultpreset", "Sandbox", CVar.ARCHIVE); + _playerManager.PlayerStatusChanged += _handlePlayerStatusChanged; _netManager.RegisterNetMessage(nameof(MsgTickerJoinLobby)); @@ -98,6 +101,8 @@ namespace Content.Server.GameTicking _netManager.RegisterNetMessage(nameof(MsgTickerLobbyStatus)); _netManager.RegisterNetMessage(nameof(MsgTickerLobbyInfo)); + SetStartPreset(_configurationManager.GetCVar("game.defaultpreset")); + RestartRound(); _initialized = true; @@ -131,7 +136,7 @@ namespace Content.Server.GameTicking if (_playerManager.PlayerCount == 0) _roundStartCountdownHasNotStartedYetDueToNoPlayers = true; else - _roundStartTimeUtc = DateTime.UtcNow + TimeSpan.FromSeconds(LobbyDuration); + _roundStartTimeUtc = DateTime.UtcNow + LobbyDuration; _sendStatusToAll(); } @@ -258,6 +263,14 @@ namespace Content.Server.GameTicking UpdateInfoText(); } + public void SetStartPreset(string type) => + SetStartPreset(type switch + { + "Sandbox" => typeof(PresetSandbox), + "DeathMatch" => typeof(PresetDeathMatch), + _ => throw new NotSupportedException() + }); + private IEntity _spawnPlayerMob(Job job, bool lateJoin = true) { GridCoordinates coordinates = lateJoin ? _getLateJoinSpawnPoint() : _getJobSpawnPoint(job.Prototype.ID); @@ -272,6 +285,7 @@ namespace Content.Server.GameTicking inventory.Equip(slot, equipmentEntity.GetComponent()); } } + return entity; } @@ -313,7 +327,8 @@ namespace Content.Server.GameTicking foreach (var entity in _entityManager.GetEntities(new TypeEntityQuery(typeof(SpawnPointComponent)))) { var point = entity.GetComponent(); - if (point.SpawnType == SpawnPointType.Job && point.Job.ID == jobId) possiblePoints.Add(entity.Transform.GridPosition); + if (point.SpawnType == SpawnPointType.Job && point.Job.ID == jobId) + possiblePoints.Add(entity.Transform.GridPosition); } if (possiblePoints.Count != 0) location = _robustRandom.Pick(possiblePoints); @@ -388,7 +403,7 @@ namespace Content.Server.GameTicking if (LobbyEnabled && _roundStartCountdownHasNotStartedYetDueToNoPlayers) { _roundStartCountdownHasNotStartedYetDueToNoPlayers = false; - _roundStartTimeUtc = DateTime.UtcNow + TimeSpan.FromSeconds(LobbyDuration); + _roundStartTimeUtc = DateTime.UtcNow + LobbyDuration; } break; diff --git a/Content.Server/GameTicking/GameTickerCommands.cs b/Content.Server/GameTicking/GameTickerCommands.cs index a249fb7f7c..3308b1f922 100644 --- a/Content.Server/GameTicking/GameTickerCommands.cs +++ b/Content.Server/GameTicking/GameTickerCommands.cs @@ -190,21 +190,7 @@ namespace Content.Server.GameTicking 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); + ticker.SetStartPreset(args[0]); } } } diff --git a/Content.Server/Interfaces/GameTicking/IGameTicker.cs b/Content.Server/Interfaces/GameTicking/IGameTicker.cs index 894d2baebe..e3754e1a7d 100644 --- a/Content.Server/Interfaces/GameTicking/IGameTicker.cs +++ b/Content.Server/Interfaces/GameTicking/IGameTicker.cs @@ -33,5 +33,6 @@ namespace Content.Server.Interfaces.GameTicking IEnumerable ActiveGameRules { get; } void SetStartPreset(Type type); + void SetStartPreset(string type); } } diff --git a/Content.Server/Sandbox/SandboxManager.cs b/Content.Server/Sandbox/SandboxManager.cs index 384c176060..ca77a92f74 100644 --- a/Content.Server/Sandbox/SandboxManager.cs +++ b/Content.Server/Sandbox/SandboxManager.cs @@ -8,6 +8,7 @@ using Robust.Server.Player; using Robust.Shared.Enums; using Robust.Shared.Interfaces.Network; using Robust.Shared.IoC; +using Robust.Shared.ViewVariables; namespace Content.Server.Sandbox { @@ -23,6 +24,7 @@ namespace Content.Server.Sandbox private bool _isSandboxEnabled; + [ViewVariables(VVAccess.ReadWrite)] public bool IsSandboxEnabled { get => _isSandboxEnabled;