Skip to content

Commit 92c53a3

Browse files
authored
CyclopsInitialSync fix (again) (#1100)
* fix bug * Review changes * added public to class * Review changes
1 parent 96560de commit 92c53a3

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

NitroxClient/GameLogic/InitialSync/CyclopsInitialAsyncProcessor.cs

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using NitroxClient.GameLogic.InitialSync.Base;
45
using NitroxClient.MonoBehaviours;
@@ -10,11 +11,11 @@
1011

1112
namespace 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

Comments
 (0)