Ejemplo n.º 1
0
        private void Start_Click(object sender, EventArgs e)
        {
            if (imageMatchingTask != null && (imageMatchingTask.Status == TaskStatus.Running && matching))
            {
                richTextBox1.Text += "Bot is already Running\n";
                return;
            }
            Toggle(ref matching);
            richTextBox1.Text += "Bot Started\n";
            var webBrowserFlash = Mouse.Flash(webBrowser1);

            imageMatchingTask = Task.Factory.StartNew(() =>
            {
                Bitmap current = null;
                while (true)
                {
                    if (matching == false)
                    {
                        //Toggle(ref matching);
                        break;
                    }

                    try
                    {
                        mainThreadContext.Send(delegate
                        {
                            current = cs.ScreenShot(webBrowser1);
                        }, null);

                        if (mapIsDirty)
                        {
                            while (true)
                            {
                                mainThreadContext.Send(delegate
                                {
                                    richTextBox1.Text += "Trying to find minimap\n";
                                }, null);
                                var result = MatchImages(new Image <Bgr, byte>(current),
                                                         new Image <Bgr, byte>((Bitmap)images["minimap"]), 0.75f);
                                if (result.Item1 == false)
                                {
                                    Thread.Sleep(500);
                                    continue;
                                }

                                miniMapPos = result.Item2;
                                browserMin = new Point(miniMapPos.X + 10, miniMapPos.Y + 30);
                                browserMax = new Point(browserMin.X + 200, browserMin.Y + 200);
                                mapIsDirty = false;
                                break;
                            }
                        }

                        if (LastBotStatus == BotState.Boxing)
                        {
                            var result = MatchImages(new Image <Bgr, byte>(current),
                                                     new Image <Bgr, byte>((Bitmap)images["bonusbox"]), 0.80f);
                            if (result.Item1)
                            {
                                continue;
                            }
                            BotStatus = BotState.Roaming;
                            continue;
                        }

                        foreach (var image in images)
                        {
                            if (image.Key == "minimap")
                            {
                                continue;
                            }

                            var result = MatchImages(new Image <Bgr, byte>(current),
                                                     new Image <Bgr, byte>((Bitmap)image.Value), 0.80f);
                            Console.WriteLine(@"	Image Key : "+ image.Key);

                            if (result.Item1 && image.Key != "bonusbox")
                            {
                                Console.WriteLine("Ignored\n");
                                continue;
                            }

                            if (result.Item1 && image.Key == "bonusbox")
                            {
                                if (LastBotStatus == BotState.Boxing)
                                {
                                    break;
                                }

                                BotStatus = BotState.Boxing;
                                lastBbPos = result.Item2;
                                mainThreadContext.Send(delegate
                                {
                                    richTextBox1.Text += Resources.BotBoxing;
                                }, null);
                                Console.WriteLine("Accepted\n");
                                Mouse.DoMouseLeftClick(webBrowserFlash, new Point(result.Item2.X,
                                                                                  result.Item2.Y));

                                //We have found a bonus box! break the loop so we can search for a new one
                                break;
                            }

                            if (LastBotStatus == BotState.Roaming)
                            {
                                internalRoamingCounter++;
                                if (internalRoamingCounter < resetRoamCounter)
                                {
                                    continue;
                                }
                                internalRoamingCounter = 0;
                            }

                            Console.WriteLine("Nothing Found Roaming\n");
                            BotStatus = BotState.Roaming;
                            mainThreadContext.Send(delegate {
                                richTextBox1.Text += Resources.BotRoaming;
                            }, null);
                            MoveShip(webBrowserFlash);
                        }
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception);
                        break;
                    }
                    Thread.Sleep(100);
                }
            });
        }