Skip to content

Commit

Permalink
CyclopsInitialSync fix (again) (#1100)
Browse files Browse the repository at this point in the history
* fix bug

* Review changes

* added public to class

* Review changes
  • Loading branch information
dartasen authored May 16, 2020
1 parent 96560de commit 92c53a3
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions NitroxClient/GameLogic/InitialSync/CyclopsInitialAsyncProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using NitroxClient.GameLogic.InitialSync.Base;
using NitroxClient.MonoBehaviours;
Expand All @@ -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)
Expand All @@ -24,14 +25,16 @@ public CyclopsInitialAsyncProcessor(Vehicles vehicles)

public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
{
this.waitScreenItem = waitScreenItem;
vehicles.VehicleCreated += OnVehicleCreated;
IList<VehicleModel> 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);
Expand All @@ -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");
}
}
}
}

0 comments on commit 92c53a3

Please sign in to comment.