コード例 #1
0
        private void reset(CommandArgs args)
        {
            if (args.Parameters.Count != 0)
            {
                int second = int.Parse(args.Parameters[0]);
                for (int i = 0; i < second; i++)
                {
                    TShock.Utils.Broadcast("服务器即将重置,倒计时:" + (second - i), Color.Red);
                    Thread.Sleep(1000);
                }
            }
            //Kick all players
            status = Status.Cleaning;
            Main.WorldFileMetadata = null;
            foreach (var player in TShock.Players)
            {
                if (player != null)
                //player.Kick("服务器正在重置,请稍后进入", true);
                {
                    //TShock.Utils.Kick(player, "服务器正在重置,请稍后进入", true);
                    player.Disconnect("服务器正在重置,请稍后进入");
                }
            }

            //Reset World Map
            Main.gameMenu = true;
            //Main.serverGenLock = true;
            generationProgress = new GenerationProgress();
            Task task = WorldGen.CreateNewWorld(generationProgress);

            status = Status.Generating;

            while (!task.IsCompleted)//Main.serverGenLock)
            {
                TShock.Log.ConsoleInfo(GetProgress());
                Thread.Sleep(100);
            }
            //Reload world map
            status    = Status.Cleaning;
            Main.rand = new UnifiedRandom((int)DateTime.Now.Ticks);
            WorldFile.LoadWorld(false);
            Main.dayTime    = WorldFile._tempDayTime;
            Main.time       = WorldFile._tempTime;
            Main.raining    = WorldFile._tempRaining;
            Main.rainTime   = WorldFile._tempRainTime;
            Main.maxRaining = WorldFile._tempMaxRain;
            Main.cloudAlpha = WorldFile._tempMaxRain;
            Main.moonPhase  = WorldFile._tempMoonPhase;
            Main.bloodMoon  = WorldFile._tempBloodMoon;
            Main.eclipse    = WorldFile._tempEclipse;

            //Reset player data
            TShock.DB.Query("DELETE FROM tsCharacter", Array.Empty <object>());

            //Reset status to playing
            Main.gameMenu      = false;
            generationProgress = null;
            status             = Status.Available;
        }
コード例 #2
0
        private void OnNpcKilled(NpcKilledEventArgs args)
        {
            if (args.npc.type != NPCID.MoonLordCore)
            {
                return;
            }
            if (--Count > 0)
            {
                TShock.Utils.Broadcast($"离重置地图还需要击败{Count}次月球领主", 0, 255, 255);
                return;
            }

            //Kick all players
            status = Status.Cleaning;
            Main.WorldFileMetadata = null;
            foreach (var player in TShock.Players)
            {
                if (player != null)
                //player.Kick("服务器正在重置,请稍后进入", true);
                {
                    //TShock.Utils.Kick(player, "服务器正在重置,请稍后进入", true);
                    player.Disconnect("服务器正在重置,请稍后进入,重置进度:");
                }
            }

            //Reset World Map
            Main.gameMenu = true;
            //Main.serverGenLock = true;
            Main.autoGen       = true;
            generationProgress = new GenerationProgress();
            WorldGen.CreateNewWorld(generationProgress);
            status = Status.Generating;

            while (Main.autoGen) //Main.serverGenLock)
            {
                TShock.Log.ConsoleInfo(GetProgress());
                Thread.Sleep(100);
            }

            //Reload world map
            status    = Status.Cleaning;
            Main.rand = new UnifiedRandom((int)DateTime.Now.Ticks);
            WorldFile.LoadWorld(false);
            Main.dayTime    = WorldFile._tempDayTime;
            Main.time       = WorldFile._tempTime;
            Main.raining    = WorldFile._tempRaining;
            Main.rainTime   = WorldFile._tempRainTime;
            Main.maxRaining = WorldFile._tempMaxRain;
            Main.cloudAlpha = WorldFile._tempMaxRain;
            Main.moonPhase  = WorldFile._tempMoonPhase;
            Main.bloodMoon  = WorldFile._tempBloodMoon;
            Main.eclipse    = WorldFile._tempEclipse;

            //Reset player data
            TShock.DB.Query("DELETE FROM tsCharacter", Array.Empty <object>());

            //Reset status to playing
            Main.gameMenu      = false;
            generationProgress = null;
            status             = Status.Available;
        }