Esempio n. 1
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Starting up...");
            PokeTradeBot.SeedChecker = new Z3SeedSearchHandler <PK8>();
            if (args.Length > 1)
            {
                Console.WriteLine("This program does not support command line arguments.");
            }

            if (File.Exists(ConfigPath))
            {
                var lines = File.ReadAllText(ConfigPath);
                var prog  = JsonConvert.DeserializeObject <ProgramConfig>(lines);
                var env   = new PokeBotRunnerImpl(prog.Hub);
                foreach (var bot in prog.Bots)
                {
                    bot.Initialize();
                    AddBot(env, bot);
                }

                LogUtil.Forwarders.Add((msg, ident) => Console.WriteLine($"{ident}: {msg}"));
                env.StartAll();
                Console.WriteLine("Started all bots.");
                Console.WriteLine("Press any key to stop execution and quit.");
                Console.ReadKey();
                env.StopAll();
            }
            else
            {
                Console.WriteLine("Unable to parse config file. Please copy your config from the WinForms project.");
                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
            }
        }
Esempio n. 2
0
        private static void Main(string[] args)
        {
            String ConfigPath;

            Console.WriteLine("Starting up...");
            PokeTradeBot.SeedChecker = new Z3SeedSearchHandler <PK8>();

            if (args.Length > 0)
            {
                ConfigPath = args[0];
            }
            else
            {
                ConfigPath = ConfigFileName;
            }

            if (!File.Exists(ConfigPath))
            {
                var hub = new PokeTradeHubConfig();
                CreateNewConfig(hub);
                hub.Folder.CreateDefaults(WorkingDirectory);
                Console.WriteLine("New Config Generated. Edit the configuration and restart the bot.");
                return;
            }


            var lines = File.ReadAllText(ConfigPath);
            var prog  = JsonConvert.DeserializeObject <ProgramConfig>(lines);
            var env   = new PokeBotRunnerImpl(prog.Hub);

            foreach (var bot in prog.Bots)
            {
                bot.Initialize();
                if (!AddBot(env, bot))
                {
                    Console.WriteLine($"Failed to add bot: {bot.IP}");
                }
            }

            LogUtil.Forwarders.Add((msg, ident) => Console.WriteLine($"{ident}: {msg}"));
            env.StartAll();
            Console.WriteLine("Started all bots.");
            Console.WriteLine("Press any key to stop execution and quit.");
            Console.CancelKeyPress += delegate {
                env.StopAll();
            };

            while (true)
            {
            }
        }
Esempio n. 3
0
        private static void RunBots(ProgramConfig prog)
        {
            var env = new PokeBotRunnerImpl(prog.Hub);

            foreach (var bot in prog.Bots)
            {
                bot.Initialize();
                if (!AddBot(env, bot))
                {
                    Console.WriteLine($"Failed to add bot: {bot}");
                }
            }

            PokeTradeBot.SeedChecker = new Z3SeedSearchHandler <PK8>();
            LogUtil.Forwarders.Add((msg, ident) => Console.WriteLine($"{ident}: {msg}"));
            env.StartAll();
            Console.WriteLine($"Started all bots (Count: {prog.Bots.Length}.");
            Console.WriteLine("Press any key to stop execution and quit. Feel free to minimize this window!");
            Console.ReadKey();
            env.StopAll();
        }
Esempio n. 4
0
        private static bool AddBot(PokeBotRunnerImpl env, PokeBotState cfg)
        {
            if (!cfg.IsValid())
            {
                Console.WriteLine($"{cfg}'s config is not valid.");
                return(false);
            }

            var newbot = env.CreateBotFromConfig(cfg);

            try
            {
                env.Add(newbot);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }

            Console.WriteLine($"Added: {cfg}: {cfg.InitialRoutine}");
            return(true);
        }