1
1
using System . Collections ;
2
+ using System . Collections . Generic ;
2
3
using System . Linq ;
3
4
using NitroxClient . GameLogic . InitialSync . Base ;
4
5
using NitroxClient . MonoBehaviours ;
10
11
11
12
namespace NitroxClient . GameLogic . InitialSync
12
13
{
13
- class CyclopsInitialAsyncProcessor : InitialSyncProcessor
14
+ public class CyclopsInitialAsyncProcessor : InitialSyncProcessor
14
15
{
16
+ private int cyclopsLoaded ;
17
+ private int totalCyclopsToLoad ;
15
18
private readonly Vehicles vehicles ;
16
- private int cyclopsLoaded = 0 ;
17
- private int totalCyclopsToLoad = 0 ;
18
19
private WaitScreen . ManualWaitItem waitScreenItem ;
19
20
20
21
public CyclopsInitialAsyncProcessor ( Vehicles vehicles )
@@ -24,14 +25,16 @@ public CyclopsInitialAsyncProcessor(Vehicles vehicles)
24
25
25
26
public override IEnumerator Process ( InitialPlayerSync packet , WaitScreen . ManualWaitItem waitScreenItem )
26
27
{
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 ;
29
30
30
- totalCyclopsToLoad = packet . Vehicles . Where ( v => v . TechType . Enum ( ) == TechType . Cyclops ) . Count ( ) ;
31
+ this . waitScreenItem = waitScreenItem ;
31
32
32
- foreach ( VehicleModel vehicle in packet . Vehicles )
33
+ if ( totalCyclopsToLoad > 0 )
33
34
{
34
- if ( vehicle . TechType . Enum ( ) == TechType . Cyclops )
35
+ vehicles . VehicleCreated += OnVehicleCreated ;
36
+
37
+ foreach ( VehicleModel vehicle in cyclopses )
35
38
{
36
39
Log . Debug ( $ "Trying to spawn { vehicle } ") ;
37
40
vehicles . CreateVehicle ( vehicle ) ;
@@ -46,14 +49,17 @@ private void OnVehicleCreated(GameObject gameObject)
46
49
cyclopsLoaded ++ ;
47
50
waitScreenItem . SetProgress ( cyclopsLoaded , totalCyclopsToLoad ) ;
48
51
52
+ Log . Debug ( $ "Spawned cyclops { NitroxEntity . GetId ( gameObject ) } ") ;
53
+
49
54
// After all cyclops are created
50
55
if ( cyclopsLoaded == totalCyclopsToLoad )
51
56
{
52
57
vehicles . VehicleCreated -= OnVehicleCreated ;
53
- Log . Debug ( $ "Spawned cyclops { NitroxEntity . GetId ( gameObject ) } ") ;
54
58
}
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
+ }
57
63
}
58
64
}
59
65
}
0 commit comments