From 28531c8b9eee8fb20ee062f0594b8d24236fc14c Mon Sep 17 00:00:00 2001 From: Just-a-Unity-Dev <67359748+Just-a-Unity-Dev@users.noreply.github.com> Date: Thu, 9 Nov 2023 19:07:58 +0800 Subject: [PATCH] Adds a minimum player count --- .../GameTicking/GameTicker.Lobby.cs | 30 ++++++++++++++++++- Content.Shared/CCVar/CCVars.cs | 10 +++++++ Resources/ConfigPresets/Ekrixi/ekrixi.toml | 5 +++- Resources/Locale/en-US/_ftl/gameticker.ftl | 2 ++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 Resources/Locale/en-US/_ftl/gameticker.ftl diff --git a/Content.Server/GameTicking/GameTicker.Lobby.cs b/Content.Server/GameTicking/GameTicker.Lobby.cs index b7b6a29a5a..4a855c9bcb 100644 --- a/Content.Server/GameTicking/GameTicker.Lobby.cs +++ b/Content.Server/GameTicking/GameTicker.Lobby.cs @@ -6,6 +6,7 @@ using Robust.Shared.Player; using Robust.Shared.Players; using System.Text; +using Content.Shared.CCVar; namespace Content.Server.GameTicking { @@ -27,7 +28,7 @@ public sealed partial class GameTicker private TimeSpan _pauseTime; [ViewVariables] - public new bool Paused { get; set; } + public new bool Paused { get; set; } = true; [ViewVariables] private bool _roundStartCountdownHasNotStartedYetDueToNoPlayers; @@ -164,8 +165,35 @@ public void ToggleReady(IPlayerSession player, bool ready) var status = ready ? PlayerGameStatus.ReadyToPlay : PlayerGameStatus.NotReadyToPlay; _playerGameStatuses[player.UserId] = ready ? PlayerGameStatus.ReadyToPlay : PlayerGameStatus.NotReadyToPlay; RaiseNetworkEvent(GetStatusMsg(player), player.ConnectedClient); + CheckMinPlayers(); // update server info to reflect new ready count UpdateInfoText(); } + + private void CheckMinPlayers() + { + if (RunLevel != GameRunLevel.PreRoundLobby) + return; + + var minPlayers = _configurationManager.GetCVar(CCVars.MinimumPlayers); + if (minPlayers == 0) + { + // Disabled, return. + return; + } + + var readyCount = Readied(); + var needPlayers = minPlayers - readyCount; + PauseStart(needPlayers > 0); + + _chatManager.DispatchServerAnnouncement(Paused + ? Loc.GetString("game-insufficient-players-to-start") + : Loc.GetString("game-sufficient-players-to-start")); + } + + private int Readied() + { + return _playerGameStatuses.Values.Count(x => x == PlayerGameStatus.ReadyToPlay); + } } } diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 3baaa84bd6..5d97d86bad 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -1766,6 +1766,16 @@ public static readonly CVarDef public static readonly CVarDef GenerateFTLPointsRoundstart = CVarDef.Create("ftlpoints.generate_roundstart", false, CVar.ARCHIVE); + /* + * Min players + */ + + /// + /// The minimum amount of players in order to unpause the lobby. + /// + public static readonly CVarDef MinimumPlayers = + CVarDef.Create("minplayers.minimum_players", 0, CVar.ARCHIVE); + /// /// Automatically record full rounds as replays. /// diff --git a/Resources/ConfigPresets/Ekrixi/ekrixi.toml b/Resources/ConfigPresets/Ekrixi/ekrixi.toml index 83ce68fda3..3154104624 100644 --- a/Resources/ConfigPresets/Ekrixi/ekrixi.toml +++ b/Resources/ConfigPresets/Ekrixi/ekrixi.toml @@ -10,9 +10,12 @@ soft_max_players = 50 map = "Nesasio" map_pool = "FTLMapPool" +[minplayers] +minimum_players = 3 + [hub] advertise = false -tags = "region:luna,lang:en,lang" +tags = "region:luna,lang:en" #hub_urls = "https://ekrixi.is-going-to.cyou/hub/" [infolinks] diff --git a/Resources/Locale/en-US/_ftl/gameticker.ftl b/Resources/Locale/en-US/_ftl/gameticker.ftl new file mode 100644 index 0000000000..278e2d01a9 --- /dev/null +++ b/Resources/Locale/en-US/_ftl/gameticker.ftl @@ -0,0 +1,2 @@ +game-insufficient-players-to-start = There are not enough players to start a game, stopping countdown. +game-sufficient-players-to-start = There are enough players to start a game, starting countdown.