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

Force even teams config #91

Merged
merged 2 commits into from
Mar 24, 2024
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
3 changes: 2 additions & 1 deletion RetakesPlugin/Modules/Configs/RetakesConfigData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class RetakesConfigData
{
public static int CurrentVersion = 6;
public static int CurrentVersion = 7;

public int Version { get; set; } = CurrentVersion;
public int MaxPlayers { get; set; } = 9;
Expand All @@ -17,4 +17,5 @@ public class RetakesConfigData
public bool IsAutoPlantEnabled { get; set; } = true;
public string QueuePriorityFlag { get; set; } = "@css/vip";
public bool IsDebugMode { get; set; } = false;
public bool ShouldForceEvenTeamsWhenPlayerCountIsMultipleOf10 { get; set; } = true;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm aware this is the longest config property... IN THE WORLD 🙃

}
16 changes: 11 additions & 5 deletions RetakesPlugin/Modules/Managers/QueueManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,29 @@ public class QueueManager
private readonly int _maxRetakesPlayers;
private readonly float _terroristRatio;
private readonly string _queuePriorityFlag;
private readonly bool _shouldForceEvenTeamsWhenPlayerCountIsMultipleOf10;

public HashSet<CCSPlayerController> QueuePlayers = new();
public HashSet<CCSPlayerController> ActivePlayers = new();

public QueueManager(Translator translator, int? retakesMaxPlayers, float? retakesTerroristRatio,
string? queuePriorityFlag)
{
public QueueManager(
Translator translator,
int? retakesMaxPlayers,
float? retakesTerroristRatio,
string? queuePriorityFlag,
bool? shouldForceEvenTeamsWhenPlayerCountIsMultipleOf10
) {
_translator = translator;
_maxRetakesPlayers = retakesMaxPlayers ?? 9;
_terroristRatio = retakesTerroristRatio ?? 0.45f;
_queuePriorityFlag = queuePriorityFlag ?? "@css/vip";
_shouldForceEvenTeamsWhenPlayerCountIsMultipleOf10 = shouldForceEvenTeamsWhenPlayerCountIsMultipleOf10 ?? true;
}

public int GetTargetNumTerrorists()
{
// TODO: Add a config option for this logic
var ratio = (ActivePlayers.Count > 9 ? 0.5 : _terroristRatio) * ActivePlayers.Count;
var shouldForceEvenTeams = _shouldForceEvenTeamsWhenPlayerCountIsMultipleOf10 && ActivePlayers.Count % 10 == 0;
var ratio = (shouldForceEvenTeams ? 0.5 : _terroristRatio) * ActivePlayers.Count;
var numTerrorists = (int)Math.Round(ratio);

// Ensure at least one terrorist if the calculated number is zero
Expand Down
5 changes: 3 additions & 2 deletions RetakesPlugin/RetakesPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace RetakesPlugin;
[MinimumApiVersion(180)]
public class RetakesPlugin : BasePlugin
{
private const string Version = "1.4.1";
private const string Version = "1.4.2";

#region Plugin info
public override string ModuleName => "Retakes Plugin";
Expand Down Expand Up @@ -480,7 +480,8 @@ private void OnMapStart(string mapName)
_translator,
_retakesConfig?.RetakesConfigData?.MaxPlayers,
_retakesConfig?.RetakesConfigData?.TerroristRatio,
_retakesConfig?.RetakesConfigData?.QueuePriorityFlag
_retakesConfig?.RetakesConfigData?.QueuePriorityFlag,
_retakesConfig?.RetakesConfigData?.ShouldForceEvenTeamsWhenPlayerCountIsMultipleOf10
),
_retakesConfig?.RetakesConfigData?.RoundsToScramble,
_retakesConfig?.RetakesConfigData?.IsScrambleEnabled
Expand Down
Loading