예제 #1
0
        private static void ConsoleThread()
        {
            var command = "";

            var pulseTimer = new Timer(e =>
            {
                if (Globals.Initialized)
                {
                    ServerTcp.PreparePulseBroadcast();
                }
            },
                                       null,
                                       TimeSpan.FromSeconds(1),
                                       TimeSpan.FromMilliseconds(25));

            // Recharge systems
            var rechargeTimer = new Timer(e =>
            {
                if (Globals.Initialized)
                {
                    _userService.RechargeSystems();
                }
            },
                                          null,
                                          TimeSpan.FromSeconds(1),
                                          TimeSpan.FromSeconds(1));

            // Try a repop every 30 seconds
            // Remove old loots
            var repopTimer = new Timer(e =>
            {
                if (Globals.Initialized)
                {
                    _mobService.RepopGalaxy();
                }
                if (Globals.Initialized)
                {
                    _itemService.RemoveLoot();
                }
            },
                                       null,
                                       TimeSpan.FromSeconds(1),
                                       TimeSpan.FromMilliseconds(30000));

            // Wander mobs everys 15 seconds
            var wanderTimer = new Timer(e =>
            {
                if (Globals.Initialized)
                {
                    _mobService.WanderMobs();
                }
            },
                                        null,
                                        TimeSpan.FromSeconds(1),
                                        TimeSpan.FromMilliseconds(15000));


            // Save the game every 5 minutes
            var saveTimer = new Timer(e =>
            {
                if (Globals.Initialized)
                {
                    SaveGame();
                }
            },
                                      null,
                                      TimeSpan.FromSeconds(1),
                                      TimeSpan.FromMilliseconds(300000));


            while (command != "end" && command != "e" && command != "exit" && command != "q" && command != "quit")
            {
                command = Console.ReadLine();
                Console.CursorTop--;
                switch (command)
                {
                case "save":
                    SaveGame();
                    break;

                case "":
                    Cnsl.Debug("#");
                    break;

                default:
                    if (command != "end" && command != "e" && command != "exit" && command != "q" && command != "quit")
                    {
                        Cnsl.Debug(@"Unknown Command");
                    }

                    break;
                }
            }

            // Try one last save on exit
            SaveGame();

            pulseTimer.Dispose();
            repopTimer.Dispose();
            wanderTimer.Dispose();
            saveTimer.Dispose();
        }
예제 #2
0
        private static void ConsoleThread()
        {
            var saveTimer = new Timer(e =>
            {
                if (!pause)
                {
                    _gameService.SaveGame(_userService.ActiveUsers.ToList());
                }
                else
                {
                    pause = !pause;
                }
            },
                                      null,
                                      TimeSpan.Zero,
                                      TimeSpan.FromMinutes(5));

            var mobLogicTimer = new Timer(e =>
            {
                _mobService.WanderMobs();
                _mobService.CheckAggro();
                _mobService.DoCombat();
            },
                                          null,
                                          TimeSpan.Zero,
                                          TimeSpan.FromMilliseconds(50));

            var rechargeTimer = new Timer(e =>
            {
                Transactions.Charge(_userService.ActiveUsers.ToList());
            }, null, TimeSpan.Zero, TimeSpan.FromMilliseconds(500));

            var nebulaTimer = new Timer(e =>
            {
                Transactions.GenerateNebulae();
                shd.SendNebulae();
            }, null, TimeSpan.Zero, TimeSpan.FromMinutes(30));

            var pulseTimer = new Timer(e =>
            {
                shd.PreparePulseBroadcast();
                if (Globals.FullData)
                {
                    shd.PrepareStaticBroadcast();
                }
            },
                                       null,
                                       TimeSpan.FromSeconds(1),
                                       TimeSpan.FromMilliseconds(25));

            var repopTimer = new Timer(e => _mobService.RepopGalaxy(),
                                       null,
                                       TimeSpan.Zero,
                                       TimeSpan.FromSeconds(30));

            var debrisTimer = new Timer(e => Transactions.ClearDebris(),
                                        null,
                                        TimeSpan.Zero,
                                        TimeSpan.FromSeconds(15));

            var command = "";

            while (command != "end" && command != "e" && command != "exit" && command != "q" && command != "quit")
            {
                command = Console.ReadLine();

                if (command == "save")
                {
                    Console.SetCursorPosition(0, Console.CursorTop - 1);
                    _gameService.SaveGame(_userService.ActiveUsers.ToList());
                }
                else if (command != "end" && command != "e" && command != "exit" && command != "q" && command != "quit")
                {
                    Console.WriteLine(@"Unknown Command");
                }
            }

            nebulaTimer.Dispose();
            saveTimer.Dispose();
            pulseTimer.Dispose();
            debrisTimer.Dispose();
            repopTimer.Dispose();
            mobLogicTimer.Dispose();
            rechargeTimer.Dispose();
            _gameService.SaveGame(_userService.ActiveUsers.ToList());
        }