11using System . Collections ;
2+ using System . Collections . Generic ;
23using System . Linq ;
34using NitroxClient . GameLogic . InitialSync . Base ;
45using NitroxClient . MonoBehaviours ;
1011
1112namespace NitroxClient . GameLogic . InitialSync
1213{
13- class CyclopsInitialAsyncProcessor : InitialSyncProcessor
14+ public class CyclopsInitialAsyncProcessor : InitialSyncProcessor
1415 {
16+ private int cyclopsLoaded ;
17+ private int totalCyclopsToLoad ;
1518 private readonly Vehicles vehicles ;
16- private int cyclopsLoaded = 0 ;
17- private int totalCyclopsToLoad = 0 ;
1819 private WaitScreen . ManualWaitItem waitScreenItem ;
1920
2021 public CyclopsInitialAsyncProcessor ( Vehicles vehicles )
@@ -24,14 +25,16 @@ public CyclopsInitialAsyncProcessor(Vehicles vehicles)
2425
2526 public override IEnumerator Process ( InitialPlayerSync packet , WaitScreen . ManualWaitItem waitScreenItem )
2627 {
27- this . waitScreenItem = waitScreenItem ;
28- vehicles . VehicleCreated += OnVehicleCreated ;
28+ IList < VehicleModel > cyclopses = packet . Vehicles . Where ( v => v . TechType . Enum ( ) == TechType . Cyclops ) . ToList ( ) ;
29+ totalCyclopsToLoad = cyclopses . Count ;
2930
30- totalCyclopsToLoad = packet . Vehicles . Where ( v => v . TechType . Enum ( ) == TechType . Cyclops ) . Count ( ) ;
31+ this . waitScreenItem = waitScreenItem ;
3132
32- foreach ( VehicleModel vehicle in packet . Vehicles )
33+ if ( totalCyclopsToLoad > 0 )
3334 {
34- if ( vehicle . TechType . Enum ( ) == TechType . Cyclops )
35+ vehicles . VehicleCreated += OnVehicleCreated ;
36+
37+ foreach ( VehicleModel vehicle in cyclopses )
3538 {
3639 Log . Debug ( $ "Trying to spawn { vehicle } ") ;
3740 vehicles . CreateVehicle ( vehicle ) ;
@@ -46,14 +49,17 @@ private void OnVehicleCreated(GameObject gameObject)
4649 cyclopsLoaded ++ ;
4750 waitScreenItem . SetProgress ( cyclopsLoaded , totalCyclopsToLoad ) ;
4851
52+ Log . Debug ( $ "Spawned cyclops { NitroxEntity . GetId ( gameObject ) } ") ;
53+
4954 // After all cyclops are created
5055 if ( cyclopsLoaded == totalCyclopsToLoad )
5156 {
5257 vehicles . VehicleCreated -= OnVehicleCreated ;
53- Log . Debug ( $ "Spawned cyclops { NitroxEntity . GetId ( gameObject ) } ") ;
5458 }
55-
56- Log . Debug ( $ "We still need to load { totalCyclopsToLoad - cyclopsLoaded } cyclops") ;
59+ else
60+ {
61+ Log . Debug ( $ "We still need to load { totalCyclopsToLoad - cyclopsLoaded } cyclops") ;
62+ }
5763 }
5864 }
5965}
0 commit comments