예제 #1
0
 public static void Postfix()
 {
     if (GameStarter.AfterStart != null)
     {
         Loger.Log("Client HarmonyPatch Root_Play.SetupForQuickTestPlay()");
         GameStarter.AfterStart();
     }
 }
예제 #2
0
 public static void Postfix()
 {
     if (GameStarter.AfterStart != null)
     {
         Loger.Log("Client HarmonyPatch Game.InitNewGame()");
         GameStarter.AfterStart();
     }
 }
예제 #3
0
        private static void CreatePlayerWorld(ModelInfo serverInfo)
        {
            Loger.Log("Client InitConnected() ExistMap");

            //создать поселение
            GameStarter.SetMapSize        = serverInfo.MapSize;
            GameStarter.SetPlanetCoverage = serverInfo.PlanetCoverage;
            GameStarter.SetSeed           = serverInfo.Seed;
            GameStarter.SetDifficulty     = serverInfo.Difficulty;
            GameStarter.SetScenario       = GetScenarioDefault();
            GameStarter.AfterStart        = CreatePlayerMap;

            GameStarter.GameGeneration(false);

            //выбор места на планете. Код из события завершения выбора параметров планеты Page_CreateWorldParams
            Loger.Log("Client InitConnected() ExistMap1");

            Current.Game          = new Game();
            Current.Game.InitData = new GameInitData();
            Current.Game.Scenario = GameStarter.SetScenario;
            Current.Game.Scenario.PreConfigure();
            Current.Game.storyteller = new Storyteller(StorytellerDefOf.Cassandra
                                                       , GameStarter.SetDifficulty == 0 ? DifficultyDefOf.Easy
                    : DifficultyDefOf.Rough);

            Loger.Log("Client InitConnected() ExistMap2");
            Current.Game.World = WorldGenerator.GenerateWorld(
                GameStarter.SetPlanetCoverage,
                GameStarter.SetSeed,
                GameStarter.SetOverallRainfall,
                GameStarter.SetOverallTemperature,
                OverallPopulation.Little
                );

            Loger.Log("Client InitConnected() ExistMap3");
            //после создания мира запускаем его обработку, загружаем поселения др. игроков
            UpdateWorldController.InitGame();
            UpdateWorld(true);

            Timers.Add(10000, PingServer);

            Loger.Log("Client InitConnected() ExistMap4");
            var form = GetFirstConfigPage();

            Find.WindowStack.Add(form);

            Loger.Log("Client InitConnected() ExistMap5");

            MemoryUtility.UnloadUnusedUnityAssets();

            Loger.Log("Client InitConnected() ExistMap6");
            Find.World.renderer.RegenerateAllLayersNow();

            Loger.Log("Client InitConnected() ExistMap7");
        }
        /// <summary>
        /// После успешной регистрации или входа
        /// </summary>
        ///
        public static void InitConnected()
        {
            Loger.Log("Client InitConnected()");
            Data = new ClientData();
            TimersStop();
            Timers = new WorkTimer();

            var connect    = SessionClient.Get;
            var serverInfo = connect.GetInfo(true);

            My = serverInfo.My;
            ServerTimeDelta = serverInfo.ServerTime - DateTime.UtcNow;

            Loger.Log("Client IsAdmin=" + serverInfo.IsAdmin + " Seed=" + serverInfo.Seed + " ExistMap=" + My.ExistMap);
            //создаем мир, если мы админ
            if (serverInfo.IsAdmin && serverInfo.Seed == "")
            {
                Loger.Log("Client InitConnected() IsAdmin");
                var form = new Dialog_CreateWorld();
                form.PostCloseAction = () =>
                {
                    if (!form.ResultOK)
                    {
                        Disconnected("OCity_SessionCC_MsgCanceledCreateW".Translate());
                        return;
                    }
                    GameStarter.SetMapSize        = int.Parse(form.InputMapSize);
                    GameStarter.SetPlanetCoverage = float.Parse(form.InputPlanetCoverage) / 100f;
                    GameStarter.SetSeed           = form.InputSeed;
                    GameStarter.SetDifficulty     = int.Parse(form.InputDifficulty);
                    GameStarter.SetScenario       = ScenarioDefault;

                    GameStarter.AfterStart = CreatingWorld;
                    GameStarter.GameGeneration();
                };
                Find.WindowStack.Add(form);
                return;
            }

            if (!My.ExistMap)
            {
                Loger.Log("Client InitConnected() ExistMap");

                //создать поселение
                GameStarter.SetMapSize        = serverInfo.MapSize;
                GameStarter.SetPlanetCoverage = serverInfo.PlanetCoverage;
                GameStarter.SetSeed           = serverInfo.Seed;
                GameStarter.SetDifficulty     = serverInfo.Difficulty;
                GameStarter.SetScenario       = ScenarioDefault;

                GameStarter.AfterStart = CreatePlayerMap;

                GameStarter.GameGeneration(false);

                //выбор места на планете. Код из события завершения выбора параметров планеты Page_CreateWorldParams
                Loger.Log("Client InitConnected() ExistMap1");

                Current.Game          = new Game();
                Current.Game.InitData = new GameInitData();
                Current.Game.Scenario = GameStarter.SetScenario;
                Current.Game.Scenario.PreConfigure();
                Current.Game.storyteller = new Storyteller(StorytellerDefOf.Cassandra
                                                           , GameStarter.SetDifficulty == 2 ? DifficultyDefOf.Hard
                        : GameStarter.SetDifficulty == 1 ? DifficultyDefOf.Medium
                        : DifficultyDefOf.VeryEasy);

                Loger.Log("Client InitConnected() ExistMap2");
                Current.Game.World = WorldGenerator.GenerateWorld(
                    GameStarter.SetPlanetCoverage,
                    GameStarter.SetSeed,
                    GameStarter.SetOverallRainfall,
                    GameStarter.SetOverallTemperature);

                Loger.Log("Client InitConnected() ExistMap3");
                //после создания мира запускаем его обработку, загружаем поселения др. игроков
                UpdateWorldController.InitGame();
                UpdateWorld(true);

                Loger.Log("Client InitConnected() ExistMap4");
                var form = GetFirstConfigPage();
                Find.WindowStack.Add(form);

                Loger.Log("Client InitConnected() ExistMap5");

                MemoryUtility.UnloadUnusedUnityAssets();

                Loger.Log("Client InitConnected() ExistMap6");
                Find.World.renderer.RegenerateAllLayersNow();

                Loger.Log("Client InitConnected() ExistMap7");

                return;
            }

            Loger.Log("Client InitConnected() WorldLoad");

            var worldData = connect.WorldLoad();

            File.WriteAllBytes(SaveFullName, worldData.SaveFileData);
            Action loadAction = () => {
                LongEventHandler.QueueLongEvent(delegate {
                    Current.Game = new Game {
                        InitData = new GameInitData {
                            gameToLoad = SaveName
                        }
                    };
                    GameLoades.AfterLoad = () =>
                    {
                        GameLoades.AfterLoad = null;

                        //Непосредственно после загрузки игры
                        InitGame();
                    };

                    /* вместо этого сделал через гармонику
                     * LongEventHandler.ExecuteWhenFinished(() =>
                     * {
                     *  var th = new Thread(() =>
                     *  {
                     *      //не знаю как правильно привязаться к событию окончания загрузки мира
                     *      while (Current.Game == null || Current.Game.World == null || Find.WorldObjects == null)
                     *      {
                     *          Thread.Sleep(100);
                     *          Loger.Log("Sleep(100)");
                     *      }
                     *      Thread.Sleep(100);
                     *      LongEventHandler.QueueLongEvent(delegate
                     *      {
                     *          //Непосредственно после загрузки игры
                     *          InitGame();
                     *      }, "", false, null);
                     *  });
                     *  th.IsBackground = true;
                     *  th.Start();
                     * });
                     */
                }, "Play", "LoadingLongEvent", false, null);
            };

            PreLoadUtility.CheckVersionAndLoad(SaveFullName, ScribeMetaHeaderUtility.ScribeHeaderMode.Map, loadAction);
        }
예제 #5
0
        /// <summary>
        /// После успешной регистрации или входа
        /// </summary>
        public static void InitConnected()
        {
            try
            {
                Loger.Log("Client InitConnected()");
                Data = new ClientData();
                TimersStop();
                Timers         = new WorkTimer();
                TimerReconnect = new WorkTimer();

                var connect    = SessionClient.Get;
                var serverInfo = connect.GetInfo(ServerInfoType.Full);
                ServerTimeDelta = serverInfo.ServerTime - DateTime.UtcNow;
                SetFullInfo(serverInfo);

                Loger.Log("Client ServerName=" + serverInfo.ServerName);
                Loger.Log("Client ServerVersion=" + serverInfo.VersionInfo + " (" + serverInfo.VersionNum + ")");
                Loger.Log("Client IsAdmin=" + serverInfo.IsAdmin
                          + " Seed=" + serverInfo.Seed
                          + " NeedCreateWorld=" + serverInfo.NeedCreateWorld
                          + " DelaySaveGame=" + Data.DelaySaveGame
                          + " DisableDevMode=" + Data.DisableDevMode);
                Loger.Log("Client Grants=" + serverInfo.My.Grants.ToString());

                if (serverInfo.IsModsWhitelisted && !CheckFiles())
                {
                    var msg = "OCity_SessionCC_FilesUpdated".Translate();
                    //Не все файлы прошли проверку, надо инициировать перезагрузку всех модов
                    Disconnected(msg, () => ModsConfig.RestartFromChangedMods());
                    return;
                }

                if (MainHelper.VersionNum < serverInfo.VersionNum)
                {
                    Disconnected("OCity_SessionCC_Client_UpdateNeeded".Translate() + serverInfo.VersionInfo);
                    return;
                }

                //создаем мир, если мы админ
                if (serverInfo.IsAdmin && serverInfo.Seed == "")
                {
                    Loger.Log("Client InitConnected() IsAdmin");
                    var form = new Dialog_CreateWorld();
                    form.PostCloseAction = () =>
                    {
                        if (!form.ResultOK)
                        {
                            Disconnected("OCity_SessionCC_MsgCanceledCreateW".Translate());
                            return;
                        }

                        GameStarter.SetMapSize        = int.Parse(form.InputMapSize);
                        GameStarter.SetPlanetCoverage = float.Parse(form.InputPlanetCoverage) / 100f;
                        GameStarter.SetSeed           = form.InputSeed;
                        GameStarter.SetDifficulty     = int.Parse(form.InputDifficulty);
                        GameStarter.SetScenario       = GetScenarioDefault();

                        GameStarter.AfterStart = CreatingServerWorld;
                        GameStarter.GameGeneration();
                    };

                    Find.WindowStack.Add(form);
                    return;
                }

                if (serverInfo.NeedCreateWorld)
                {
                    CreatePlayerWorld(serverInfo);
                    return;
                }

                LoadPlayerWorld();
            }
            catch (Exception ext)
            {
                Loger.Log("Exception InitConnected: " + ext.ToString());
            }
        }