예제 #1
0
    private IEnumerator WaitForAllPlayersLoaded()
    {
        CustomUI.OpenPopup("Incoming connection", "A new player is connecting");
        AppUtil.Instance.PauseGame();
        yield return(new WaitUntil(() => networkPlayers.All(p => p.Value.GetComponent <NetworkPlayerSync>().IsLoaded)));

        AppUtil.Instance.UnpauseGame();
        playersLoaded = null;
        CustomUI.Close();
        newPlayerConnecting = false;
    }
 internal void HideUI()
 {
     CustomUI.Close();
 }
예제 #3
0
    private IEnumerator WaitForInit()
    {
        UUI.UnlockMouse(true);
        TutorialController.movementAllowed = false;

        GamePreferences.Set(Preferences.CommsRadioSpawnMode, false);
        GamePreferences.RegisterToPreferenceUpdated(Preferences.CommsRadioSpawnMode, DisableSpawnMode);

        if (!NetworkManager.IsHost())
        {
            // Create offline save
            Main.Log($"[CLIENT] Creating offline save");
            SingletonBehaviour <NetworkSaveGameManager> .Instance.CreateOfflineBackup();

            CustomUI.OpenPopup("Connecting", "Loading savegame");
            Main.Log($"[CLIENT] Receiving savegame");
            AppUtil.Instance.PauseGame();
            // Check if host is connected if so the savegame should be available to receive
            SingletonBehaviour <NetworkJobsManager> .Instance.PlayerConnect();

            yield return(new WaitUntil(() => networkPlayers.ContainsKey(0) || modMismatched));

            if (modMismatched)
            {
                UUI.UnlockMouse(false);
                TutorialController.movementAllowed = true;
                Main.Log($"Mods Mismatched so disconnecting player");
                CustomUI.Open(CustomUI.ModMismatchScreen, false, false);
                NetworkManager.Disconnect();
                yield break;
            }

            // Wait till spawn is set
            yield return(new WaitUntil(() => spawnData != null));

            AppUtil.Instance.UnpauseGame();
            yield return(new WaitUntil(() => !AppUtil.IsPaused));

            yield return(new WaitForEndOfFrame());

            PlayerManager.TeleportPlayer(spawnData.Position + WorldMover.currentMove, PlayerManager.PlayerTransform.rotation, null, false);
            UUI.UnlockMouse(true);

            // Wait till world is loaded
            yield return(new WaitUntil(() => SingletonBehaviour <TerrainGrid> .Instance.IsInLoadedRegion(PlayerManager.PlayerTransform.position)));

            AppUtil.Instance.PauseGame();
            yield return(new WaitUntil(() => AppUtil.IsPaused));

            // Remove all Cars
            SingletonBehaviour <CarsSaveManager> .Instance.DeleteAllExistingCars();

            // Load Junction data from server that changed since uptime
            Main.Log($"Syncing Junctions");
            SingletonBehaviour <NetworkJunctionManager> .Instance.SyncJunction();

            yield return(new WaitUntil(() => SingletonBehaviour <NetworkJunctionManager> .Instance.IsSynced));

            // Load Turntable data from server that changed since uptime
            Main.Log($"Syncing Turntables");
            SingletonBehaviour <NetworkTurntableManager> .Instance.SyncTurntables();

            yield return(new WaitUntil(() => SingletonBehaviour <NetworkTurntableManager> .Instance.IsSynced));

            // Load Train data from server that changed since uptime
            Main.Log($"Syncing traincars");
            SingletonBehaviour <NetworkTrainManager> .Instance.SendInitCarsRequest();

            yield return(new WaitUntil(() => SingletonBehaviour <NetworkTrainManager> .Instance.IsSynced));

            SingletonBehaviour <NetworkSaveGameManager> .Instance.ResetDebts();

            // Load Job data from server that changed since uptime
            Main.Log($"Syncing jobs");
            SingletonBehaviour <NetworkJobsManager> .Instance.SendJobsRequest();

            yield return(new WaitUntil(() => SingletonBehaviour <NetworkJobsManager> .Instance.IsSynced));

            SingletonBehaviour <NetworkJobsManager> .Instance.OnFinishLoading();

            AppUtil.Instance.UnpauseGame();
            yield return(new WaitUntil(() => !AppUtil.IsPaused));

            yield return(new WaitForEndOfFrame());

            CustomUI.Close();
        }
        else
        {
            Main.Log($"Save should be loaded. Run OnFinishedLoading in NetworkTrainManager");
            SingletonBehaviour <NetworkTrainManager> .Instance.OnFinishedLoading();

            yield return(new WaitUntil(() => SingletonBehaviour <NetworkTrainManager> .Instance.SaveCarsLoaded));

            Main.Log($"Run OnFinishedLoading in NetworkJobsManager");
            SingletonBehaviour <NetworkJobsManager> .Instance.OnFinishLoading();
        }

        SendIsLoaded();
        Main.Log($"Finished loading everything. Unlocking mouse and allow movement");
        UUI.UnlockMouse(false);
        TutorialController.movementAllowed = true;
        IsSynced = true;
        // Move to spawn
    }
    private IEnumerator LoadOfflineSave()
    {
        TutorialController.movementAllowed = false;
        Vector3 vector3_1 = SaveGameManager.data.GetVector3("Player_position").Value;

        //SingletonBehaviour<WorldMover>.Instance.movingEnabled = true;
        AppUtil.Instance.UnpauseGame();
        yield return(new WaitUntil(() => !AppUtil.IsPaused));

        yield return(new WaitForEndOfFrame());

        PlayerManager.TeleportPlayer(vector3_1 + WorldMover.currentMove, PlayerManager.PlayerTransform.rotation, null, false);
        UUI.UnlockMouse(true);
        yield return(new WaitUntil(() => SingletonBehaviour <TerrainGrid> .Instance.IsInLoadedRegion(PlayerManager.PlayerTransform.position)));

        SingletonBehaviour <CarsSaveManager> .Instance.DeleteAllExistingCars();

        yield return(new WaitForSecondsRealtime(1));

        CustomUI.OpenPopup("Disconnecting", "Loading offline save");
        yield return(new WaitUntil(() => CustomUI.currentScreen == CustomUI.PopupUI));

        AppUtil.Instance.PauseGame();
        yield return(new WaitUntil(() => AppUtil.IsPaused));

        CarSpawner.useCarPooling = true;
        bool carsLoadedSuccessfully = false;

        ResetDebts();
        JObject jObject = SaveGameManager.data.GetJObject(SaveGameKeys.Turntables);

        if (jObject != null)
        {
            TurntableRailTrack.SetSaveData(jObject);
        }
        else
        {
            Main.Log("[WARNING] Turntables data not found!");
        }
        jObject = SaveGameManager.data.GetJObject(SaveGameKeys.Junctions);
        if (jObject != null)
        {
            JunctionsSaveManager.Load(jObject);
        }
        else
        {
            Main.Log("[WARNING] Junctions save not found!");
        }

        jObject = SaveGameManager.data.GetJObject(SaveGameKeys.Cars);
        if (jObject != null)
        {
            carsLoadedSuccessfully = SingletonBehaviour <CarsSaveManager> .Instance.Load(jObject);

            if (!carsLoadedSuccessfully)
            {
                Main.Log("[WARNING] Cars not loaded successfully!");
            }
        }
        else
        {
            Main.Log("[WARNING] Cars save not found!");
        }

        if (carsLoadedSuccessfully)
        {
            JobsSaveGameData saveData = SaveGameManager.data.GetObject <JobsSaveGameData>(SaveGameKeys.Jobs, JobSaveManager.serializeSettings);
            if (saveData != null)
            {
                SingletonBehaviour <JobSaveManager> .Instance.LoadJobSaveGameData(saveData);
            }
            else
            {
                Main.Log("[WARNING] Jobs save not found!");
            }
            SingletonBehaviour <JobSaveManager> .Instance.MarkAllNonJobCarsAsUnused();
        }

        jObject = SaveGameManager.data.GetJObject("Debt_deleted_locos");
        if (jObject != null)
        {
            SingletonBehaviour <LocoDebtController> .Instance.LoadDestroyedLocosDebtsSaveData(jObject);

            Main.Log("Loaded destroyed locos debt");
        }
        jObject = SaveGameManager.data.GetJObject("Debt_staged_jobs");
        if (jObject != null)
        {
            SingletonBehaviour <JobDebtController> .Instance.LoadStagedJobsDebtsSaveData(jObject);

            Main.Log("Loaded staged jobs debt");
        }
        jObject = SaveGameManager.data.GetJObject("Debt_jobless_cars");
        if (jObject != null)
        {
            SingletonBehaviour <JobDebtController> .Instance.LoadDeletedJoblessCarDebtsSaveData(jObject);

            Main.Log("Loaded jobless cars debt");
        }
        jObject = SaveGameManager.data.GetJObject("Debt_insurance");
        if (jObject != null)
        {
            SingletonBehaviour <CareerManagerDebtController> .Instance.feeQuota.LoadSaveData(jObject);

            Main.Log("Loaded insurance fee data");
        }

        UUI.UnlockMouse(false);
        CustomUI.Close();
        yield return(new WaitUntil(() => !CustomUI.currentScreen));

        TutorialController.movementAllowed = true;
        SingletonBehaviour <SaveGameManager> .Instance.disableAutosave = false;
        IsOfflineSaveLoaded = true;
    }