@@ -35,6 +35,9 @@ public void ScrambleNextRound(CCSPlayerController? admin = null)
35
35
36
36
private void ScrambleTeams ( )
37
37
{
38
+ _scrambleNextRound = false ;
39
+ _consecutiveRoundsWon = 0 ;
40
+
38
41
var shuffledActivePlayers = Helpers . Shuffle ( QueueManager . ActivePlayers ) ;
39
42
40
43
var newTerrorists = shuffledActivePlayers . Take ( QueueManager . GetTargetNumTerrorists ( ) ) . ToList ( ) ;
@@ -66,40 +69,35 @@ public void AddScore(CCSPlayerController player, int score)
66
69
67
70
private int _consecutiveRoundsWon ;
68
71
69
- public void TerroristRoundWin ( )
72
+ private void TerroristRoundWin ( )
70
73
{
71
74
_consecutiveRoundsWon ++ ;
72
75
73
- if ( _consecutiveRoundsWon == _consecutiveRoundWinsToScramble )
76
+ var shouldScrambleNow = _isScrambleEnabled && _consecutiveRoundsWon == _consecutiveRoundWinsToScramble ;
77
+ var roundsLeftToScramble = _consecutiveRoundWinsToScramble - _consecutiveRoundsWon ;
78
+ // Almost scramble if 1-2 rounds left to automatic scramble
79
+ var shouldAlmostScramble = _isScrambleEnabled && roundsLeftToScramble > 0 && roundsLeftToScramble <= 2 ;
80
+
81
+ if ( shouldScrambleNow )
74
82
{
75
83
Server . PrintToChatAll (
76
84
$ "{ RetakesPlugin . MessagePrefix } { _translator [ "retakes.teams.scramble" , _consecutiveRoundWinsToScramble ] } ") ;
77
85
78
- _consecutiveRoundsWon = 0 ;
79
86
ScrambleTeams ( ) ;
80
87
}
81
- else if ( _consecutiveRoundsWon >= 3 )
88
+ else if ( shouldAlmostScramble )
82
89
{
83
- if ( _isScrambleEnabled )
84
- {
85
- Server . PrintToChatAll (
86
- $ "{ RetakesPlugin . MessagePrefix } { _translator [ "retakes.teams.almost_scramble" , _consecutiveRoundsWon , _consecutiveRoundWinsToScramble - _consecutiveRoundsWon ] } ") ;
87
- }
88
- else
89
- {
90
- Server . PrintToChatAll (
91
- $ "{ RetakesPlugin . MessagePrefix } { _translator [ "retakes.teams.win_streak" , _consecutiveRoundsWon ] } ") ;
92
- }
90
+ Server . PrintToChatAll (
91
+ $ "{ RetakesPlugin . MessagePrefix } { _translator [ "retakes.teams.almost_scramble" , _consecutiveRoundsWon , roundsLeftToScramble ] } ") ;
93
92
}
94
- else if ( _scrambleNextRound )
93
+ else if ( _consecutiveRoundsWon >= 3 )
95
94
{
96
- _scrambleNextRound = false ;
97
- _consecutiveRoundsWon = 0 ;
98
- ScrambleTeams ( ) ;
95
+ Server . PrintToChatAll (
96
+ $ "{ RetakesPlugin . MessagePrefix } { _translator [ "retakes.teams.win_streak" , _consecutiveRoundsWon ] } ") ;
99
97
}
100
98
}
101
99
102
- public void CounterTerroristRoundWin ( )
100
+ private void CounterTerroristRoundWin ( )
103
101
{
104
102
if ( _consecutiveRoundsWon >= 3 )
105
103
{
@@ -140,7 +138,7 @@ public void CounterTerroristRoundWin()
140
138
SetTeams ( newTerrorists , newCounterTerrorists ) ;
141
139
}
142
140
143
- public void BalanceTeams ( )
141
+ private void BalanceTeams ( )
144
142
{
145
143
List < CCSPlayerController > newTerrorists = new ( ) ;
146
144
List < CCSPlayerController > newCounterTerrorists = new ( ) ;
@@ -198,6 +196,29 @@ public void BalanceTeams()
198
196
SetTeams ( newTerrorists , newCounterTerrorists ) ;
199
197
}
200
198
199
+ public void OnRoundPreStart ( CsTeam winningTeam )
200
+ {
201
+ // Handle team swaps during round pre-start.
202
+ switch ( winningTeam )
203
+ {
204
+ case CsTeam . CounterTerrorist :
205
+ CounterTerroristRoundWin ( ) ;
206
+ break ;
207
+
208
+ case CsTeam . Terrorist :
209
+ TerroristRoundWin ( ) ;
210
+ break ;
211
+ }
212
+
213
+
214
+ if ( _scrambleNextRound )
215
+ {
216
+ ScrambleTeams ( ) ;
217
+ }
218
+
219
+ BalanceTeams ( ) ;
220
+ }
221
+
201
222
private List < CCSPlayerController > GetSortedActivePlayers ( CsTeam ? team = null )
202
223
{
203
224
return QueueManager . ActivePlayers
0 commit comments