Skip to content

Commit

Permalink
Adds a minimum player count
Browse files Browse the repository at this point in the history
  • Loading branch information
Just-a-Unity-Dev committed Nov 9, 2023
1 parent 40a8f40 commit 28531c8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
30 changes: 29 additions & 1 deletion Content.Server/GameTicking/GameTicker.Lobby.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Robust.Shared.Player;
using Robust.Shared.Players;
using System.Text;
using Content.Shared.CCVar;

namespace Content.Server.GameTicking
{
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
10 changes: 10 additions & 0 deletions Content.Shared/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1766,6 +1766,16 @@ public static readonly CVarDef<float>
public static readonly CVarDef<bool> GenerateFTLPointsRoundstart =
CVarDef.Create("ftlpoints.generate_roundstart", false, CVar.ARCHIVE);

/*
* Min players
*/

/// <summary>
/// The minimum amount of players in order to unpause the lobby.
/// </summary>
public static readonly CVarDef<int> MinimumPlayers =
CVarDef.Create("minplayers.minimum_players", 0, CVar.ARCHIVE);

/// <summary>
/// Automatically record full rounds as replays.
/// </summary>
Expand Down
5 changes: 4 additions & 1 deletion Resources/ConfigPresets/Ekrixi/ekrixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions Resources/Locale/en-US/_ftl/gameticker.ftl
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 28531c8

Please sign in to comment.