diff --git a/NitroxClient/GameLogic/InitialSync/CyclopsInitialAsyncProcessor.cs b/NitroxClient/GameLogic/InitialSync/CyclopsInitialAsyncProcessor.cs index a588aa2653..30d9aea15d 100644 --- a/NitroxClient/GameLogic/InitialSync/CyclopsInitialAsyncProcessor.cs +++ b/NitroxClient/GameLogic/InitialSync/CyclopsInitialAsyncProcessor.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.Collections.Generic; using System.Linq; using NitroxClient.GameLogic.InitialSync.Base; using NitroxClient.MonoBehaviours; @@ -10,11 +11,11 @@ namespace NitroxClient.GameLogic.InitialSync { - class CyclopsInitialAsyncProcessor : InitialSyncProcessor + public class CyclopsInitialAsyncProcessor : InitialSyncProcessor { + private int cyclopsLoaded; + private int totalCyclopsToLoad; private readonly Vehicles vehicles; - private int cyclopsLoaded = 0; - private int totalCyclopsToLoad = 0; private WaitScreen.ManualWaitItem waitScreenItem; public CyclopsInitialAsyncProcessor(Vehicles vehicles) @@ -24,14 +25,16 @@ public CyclopsInitialAsyncProcessor(Vehicles vehicles) public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem) { - this.waitScreenItem = waitScreenItem; - vehicles.VehicleCreated += OnVehicleCreated; + IList cyclopses = packet.Vehicles.Where(v => v.TechType.Enum() == TechType.Cyclops).ToList(); + totalCyclopsToLoad = cyclopses.Count; - totalCyclopsToLoad = packet.Vehicles.Where(v => v.TechType.Enum() == TechType.Cyclops).Count(); + this.waitScreenItem = waitScreenItem; - foreach (VehicleModel vehicle in packet.Vehicles) + if (totalCyclopsToLoad > 0) { - if (vehicle.TechType.Enum() == TechType.Cyclops) + vehicles.VehicleCreated += OnVehicleCreated; + + foreach (VehicleModel vehicle in cyclopses) { Log.Debug($"Trying to spawn {vehicle}"); vehicles.CreateVehicle(vehicle); @@ -46,14 +49,17 @@ private void OnVehicleCreated(GameObject gameObject) cyclopsLoaded++; waitScreenItem.SetProgress(cyclopsLoaded, totalCyclopsToLoad); + Log.Debug($"Spawned cyclops {NitroxEntity.GetId(gameObject)}"); + // After all cyclops are created if (cyclopsLoaded == totalCyclopsToLoad) { vehicles.VehicleCreated -= OnVehicleCreated; - Log.Debug($"Spawned cyclops {NitroxEntity.GetId(gameObject)}"); } - - Log.Debug($"We still need to load {totalCyclopsToLoad - cyclopsLoaded} cyclops"); + else + { + Log.Debug($"We still need to load {totalCyclopsToLoad - cyclopsLoaded} cyclops"); + } } } }