diff --git a/RetakesPlugin/Modules/Managers/GameManager.cs b/RetakesPlugin/Modules/Managers/GameManager.cs index 69aef75..9a2b96a 100644 --- a/RetakesPlugin/Modules/Managers/GameManager.cs +++ b/RetakesPlugin/Modules/Managers/GameManager.cs @@ -35,6 +35,9 @@ public void ScrambleNextRound(CCSPlayerController? admin = null) private void ScrambleTeams() { + _scrambleNextRound = false; + _consecutiveRoundsWon = 0; + var shuffledActivePlayers = Helpers.Shuffle(QueueManager.ActivePlayers); var newTerrorists = shuffledActivePlayers.Take(QueueManager.GetTargetNumTerrorists()).ToList(); @@ -66,40 +69,35 @@ public void AddScore(CCSPlayerController player, int score) private int _consecutiveRoundsWon; - public void TerroristRoundWin() + private void TerroristRoundWin() { _consecutiveRoundsWon++; - if (_consecutiveRoundsWon == _consecutiveRoundWinsToScramble) + var shouldScrambleNow = _isScrambleEnabled && _consecutiveRoundsWon == _consecutiveRoundWinsToScramble; + var roundsLeftToScramble = _consecutiveRoundWinsToScramble - _consecutiveRoundsWon; + // Almost scramble if 1-2 rounds left to automatic scramble + var shouldAlmostScramble = _isScrambleEnabled && roundsLeftToScramble > 0 && roundsLeftToScramble <= 2; + + if (shouldScrambleNow) { Server.PrintToChatAll( $"{RetakesPlugin.MessagePrefix}{_translator["retakes.teams.scramble", _consecutiveRoundWinsToScramble]}"); - _consecutiveRoundsWon = 0; ScrambleTeams(); } - else if (_consecutiveRoundsWon >= 3) + else if (shouldAlmostScramble) { - if (_isScrambleEnabled) - { - Server.PrintToChatAll( - $"{RetakesPlugin.MessagePrefix}{_translator["retakes.teams.almost_scramble", _consecutiveRoundsWon, _consecutiveRoundWinsToScramble - _consecutiveRoundsWon]}"); - } - else - { - Server.PrintToChatAll( - $"{RetakesPlugin.MessagePrefix}{_translator["retakes.teams.win_streak", _consecutiveRoundsWon]}"); - } + Server.PrintToChatAll( + $"{RetakesPlugin.MessagePrefix}{_translator["retakes.teams.almost_scramble", _consecutiveRoundsWon, roundsLeftToScramble]}"); } - else if (_scrambleNextRound) + else if (_consecutiveRoundsWon >= 3) { - _scrambleNextRound = false; - _consecutiveRoundsWon = 0; - ScrambleTeams(); + Server.PrintToChatAll( + $"{RetakesPlugin.MessagePrefix}{_translator["retakes.teams.win_streak", _consecutiveRoundsWon]}"); } } - public void CounterTerroristRoundWin() + private void CounterTerroristRoundWin() { if (_consecutiveRoundsWon >= 3) { @@ -140,7 +138,7 @@ public void CounterTerroristRoundWin() SetTeams(newTerrorists, newCounterTerrorists); } - public void BalanceTeams() + private void BalanceTeams() { List newTerrorists = new(); List newCounterTerrorists = new(); @@ -198,6 +196,29 @@ public void BalanceTeams() SetTeams(newTerrorists, newCounterTerrorists); } + public void OnRoundPreStart(CsTeam winningTeam) + { + // Handle team swaps during round pre-start. + switch (winningTeam) + { + case CsTeam.CounterTerrorist: + CounterTerroristRoundWin(); + break; + + case CsTeam.Terrorist: + TerroristRoundWin(); + break; + } + + + if (_scrambleNextRound) + { + ScrambleTeams(); + } + + BalanceTeams(); + } + private List GetSortedActivePlayers(CsTeam? team = null) { return QueueManager.ActivePlayers diff --git a/RetakesPlugin/RetakesPlugin.cs b/RetakesPlugin/RetakesPlugin.cs index 91270a4..db0c77c 100644 --- a/RetakesPlugin/RetakesPlugin.cs +++ b/RetakesPlugin/RetakesPlugin.cs @@ -557,23 +557,9 @@ public HookResult OnRoundPreStart(EventRoundPrestart @event, GameEventInfo info) _gameManager.QueueManager.DebugQueues(false); Helpers.Debug($"Updated queues."); - // Handle team swaps during round pre-start. - switch (_lastRoundWinner) - { - case CsTeam.CounterTerrorist: - Helpers.Debug($"Calling CounterTerroristRoundWin()"); - _gameManager.CounterTerroristRoundWin(); - Helpers.Debug($"CounterTerroristRoundWin call complete"); - break; - - case CsTeam.Terrorist: - Helpers.Debug($"Calling TerroristRoundWin()"); - _gameManager.TerroristRoundWin(); - Helpers.Debug($"TerroristRoundWin call complete"); - break; - } - - _gameManager.BalanceTeams(); + Helpers.Debug($"Calling GameManager.OnRoundPreStart({_lastRoundWinner})"); + _gameManager.OnRoundPreStart(_lastRoundWinner); + Helpers.Debug($"GameManager.OnRoundPreStart call complete"); // Set round teams to prevent team changes mid round _gameManager.QueueManager.SetRoundTeams();