Skip to content

Commit

Permalink
Implement AutoTeamBalance configuration. Closes #104
Browse files Browse the repository at this point in the history
  • Loading branch information
kraigher committed Apr 9, 2024
1 parent 317ec35 commit b1cf32e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ When the plugin is first loaded it will create a `retakes_config.json` file in t
| TerroristRatio | The percentage of the total players that should be Terrorists. | 0.45 | 0 | 1 |
| RoundsToScramble | The number of rounds won in a row before the teams are scrambled. | 5 | -1 | 99999 |
| IsScrambleEnabled | Whether to scramble the teams once the RoundsToScramble value is met. | true | false | true |
| AutoTeamBalance | Whether to automatically balance teams. | true | false | true |
| EnableFallbackAllocation | Whether to enable the fallback weapon allocation. You should set this value to false if you're using a standalone weapon allocator. | true | false | true |
| EnableBombsiteAnnouncementVoices | Whether to play the bombsite announcement voices. The volume for these values is client sided `snd_toolvolume`. | true | false | true |
| EnableBombsiteAnnouncementCenter | Whether to display the bombsite in the center announcement box. | true | false | true |
Expand Down
1 change: 1 addition & 0 deletions RetakesPlugin/Modules/Configs/RetakesConfigData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class RetakesConfigData
public float TerroristRatio { get; set; } = 0.45f;
public int RoundsToScramble { get; set; } = 5;
public bool IsScrambleEnabled { get; set; } = true;
public bool AutoTeamBalance { get; set; } = true;
public bool EnableFallbackAllocation { get; set; } = true;
public bool EnableBombsiteAnnouncementVoices { get; set; } = true;
public bool EnableBombsiteAnnouncementCenter { get; set; } = true;
Expand Down
16 changes: 12 additions & 4 deletions RetakesPlugin/Modules/Managers/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ public class GameManager
public readonly QueueManager QueueManager;
private readonly int _consecutiveRoundWinsToScramble;
private readonly bool _isScrambleEnabled;
private readonly bool _autoTeamBalance;

public const int ScoreForKill = 50;
public const int ScoreForAssist = 25;
public const int ScoreForDefuse = 50;

public GameManager(Translator translator, QueueManager queueManager, int? roundsToScramble, bool? isScrambleEnabled)
public GameManager(Translator translator, QueueManager queueManager, int? roundsToScramble, bool? isScrambleEnabled, bool? autoTeamBalance)
{
_translator = translator;
QueueManager = queueManager;
_consecutiveRoundWinsToScramble = roundsToScramble ?? 5;
_isScrambleEnabled = isScrambleEnabled ?? true;
_autoTeamBalance = autoTeamBalance ?? true;
}

private bool _scrambleNextRound;
Expand Down Expand Up @@ -206,7 +208,10 @@ public void OnRoundPreStart(CsTeam winningTeam)
{
case CsTeam.CounterTerrorist:
CounterTerroristRoundWin();
CounterTerroristRoundWinTeamBalance();
if (_autoTeamBalance)
{
CounterTerroristRoundWinTeamBalance();
}
break;

case CsTeam.Terrorist:
Expand All @@ -218,9 +223,12 @@ public void OnRoundPreStart(CsTeam winningTeam)
if (_scrambleNextRound)
{
ScrambleTeams();
}

if (_autoTeamBalance)
{
BalanceTeams();
}

BalanceTeams();
}

private List<CCSPlayerController> GetSortedActivePlayers(CsTeam? team = null)
Expand Down
3 changes: 2 additions & 1 deletion RetakesPlugin/RetakesPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ private void OnMapStart(string mapName)
_retakesConfig?.RetakesConfigData?.ShouldForceEvenTeamsWhenPlayerCountIsMultipleOf10
),
_retakesConfig?.RetakesConfigData?.RoundsToScramble,
_retakesConfig?.RetakesConfigData?.IsScrambleEnabled
_retakesConfig?.RetakesConfigData?.IsScrambleEnabled,
_retakesConfig?.RetakesConfigData?.AutoTeamBalance
);

_breakerManager = new BreakerManager(
Expand Down

0 comments on commit b1cf32e

Please sign in to comment.