Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a minimum player count #190

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.