@@ -12,10 +12,11 @@ namespace UncomplicatedCustomTeams.API.Features
1212{
1313 public class Team
1414 {
15+ private static readonly System . Random _random = new ( ) ;
1516 /// <summary>
1617 /// Gets a complete list of every custom <see cref="Team"/> registered
1718 /// </summary>
18- public static List < Team > List { get ; } = new ( ) ;
19+ public static List < Team > List { get ; } = [ ] ;
1920
2021 /// <summary>
2122 /// Register a new custom <see cref="Team"/>
@@ -178,21 +179,31 @@ public static void Register(Team team)
178179
179180 public static Team EvaluateSpawn ( WaveType wave )
180181 {
181- List < Team > Teams = [ ] ;
182- foreach ( Team Team in List . Where ( t => t . SpawnConditions . SpawnWave == wave ) )
182+ var eligibleTeams = List . Where ( t => t . SpawnConditions . SpawnWave == wave ) . ToList ( ) ;
183+
184+ if ( ! eligibleTeams . Any ( ) )
183185 {
184- for ( int a = 0 ; a < Team . SpawnChance ; a ++ )
185- Teams . Add ( Team ) ;
186+ return null ;
186187 }
187- LogManager . Debug ( $ "Evaluated team count, found { Teams . Count } /100 elements [{ List . Count ( t => t . SpawnConditions . SpawnWave == wave ) } ]!\n If the number is less than 100 THERE'S A PROBLEM!") ;
188188
189- if ( Teams . Count == 0 )
189+ LogManager . Debug ( $ "Found { eligibleTeams . Count } eligible Custom Team(s) for WaveType '{ wave } '. Evaluating chances independently.") ;
190+
191+ foreach ( var team in eligibleTeams )
190192 {
191- LogManager . Debug ( "No valid team found, returning..." ) ;
192- return null ;
193+ int roll = _random . Next ( 0 , 100 ) ;
194+ if ( roll < team . SpawnChance )
195+ {
196+ LogManager . Debug ( $ "Team '{ team . Name } ' succeeded its spawn roll! (Rolled: { roll } , Needed < { team . SpawnChance } ). Selecting this team.") ;
197+ return team ;
198+ }
199+ else
200+ {
201+ LogManager . Debug ( $ "Team '{ team . Name } ' failed its spawn roll. (Rolled: { roll } , Needed < { team . SpawnChance } ).") ;
202+ }
193203 }
194- int Chance = new System . Random ( ) . Next ( 0 , 99 ) ;
195- return Teams . Count > Chance ? Teams [ Chance ] : null ;
204+
205+ LogManager . Debug ( "No custom team succeeded their spawn roll. returning null..." ) ;
206+ return null ;
196207 }
197208
198209 public class SpawnData
0 commit comments