示例#1
0
        /// <summary>
        /// OCR the image. Need Prepair OCR first!
        /// </summary>
        /// <param name="source"></param>
        /// <param name="lang"></param>
        /// <returns></returns>
        public static string OcrImage(byte[] source, string lang)
        {
            if (t == null)
            {
                throw new Exception("Run PrepairOcr First!");
            }
            Image <Bgr, byte> img = new Image <Bgr, byte>(new Bitmap(BotCore.Decompress(source)));

            t.SetImage(img);
            return(t.GetUTF8Text());
        }
        private static void DemonStage_Enter()
        {
            int error = 0;

            VCBotScript.image = BotCore.ImageCapture();
            while (!BotCore.RGBComparer(VCBotScript.image, new Point(415, 678), Color.FromArgb(223, 192, 63), 10))
            {
                if (!BotCore.GameIsForeground("com.nubee.valkyriecrusade"))
                {
                    ScriptErrorHandler.Reset("Game close, restarting...");
                    return;
                }
                error++;
                if (error > 10)
                {
                    ScriptErrorHandler.Reset("Event Locate Failed!");
                    BotCore.KillGame("com.nubee.valkyriecrusade");
                    return;
                }
                BotCore.Delay(1000, false);
                VCBotScript.image = BotCore.ImageCapture();
            }
            error = 0;
            Variables.ScriptLog("Demon Realm Event Located", Color.Lime);
            List <Point> BlackListedLocation = new List <Point>();

            Variables.ScriptLog("Fetching stage images", Color.White);
            List <Image> Stage = new List <Image>();

            foreach (var file in Directory.GetFiles("Img\\DemonRealm", "*.png").OrderBy(f => f))
            {
                Stage.Add(Image.FromFile(file));
            }
            Point?p = null;

            while (error < 10 && p == null)
            {
                if (!BotCore.GameIsForeground("com.nubee.valkyriecrusade"))
                {
                    return;
                }
                VCBotScript.image = BotCore.ImageCapture();
                var crop = BotCore.CropImage(VCBotScript.image, new Point(0, 0), new Point(1280, 615));
                Variables.ScriptLog("Trying to find stages to enter", Color.LightSkyBlue);
                Bitmap screen = BotCore.Decompress(crop);
                foreach (var blacklist in BlackListedLocation)
                {
                    using (Graphics grf = Graphics.FromImage(screen))
                    {
                        using (Brush brsh = new SolidBrush(ColorTranslator.FromHtml("#000000")))
                        {
                            grf.FillEllipse(brsh, blacklist.X, blacklist.Y, 5, 5);
                        }
                    }
                }
                foreach (var stage in Stage)
                {
                    for (int x = 0; x < 4; x++)
                    {
                        p = BotCore.FindImage(screen, (Bitmap)stage, false);
                        if (p != null)
                        {
                            if (!BlackListedLocation.Contains(p.Value))
                            {
                                Variables.ScriptLog("Stage found!", Color.Lime);
                                BotCore.SendTap(p.Value);
                                BotCore.Delay(2000, false);
                                BotCore.SendTap(768, 536);
                                BotCore.Delay(5000, false);
                                VCBotScript.image = BotCore.ImageCapture();
                                crop = BotCore.CropImage(VCBotScript.image, new Point(948, 623), new Point(1141, 694));
                                if (BotCore.FindImage(crop, Img.Red_Button, false) != null)
                                {
                                    Variables.ScriptLog("Ops, looks like the stage is not able to enter!", Color.Red);
                                    BlackListedLocation.Add(p.Value);
                                    using (Graphics grf = Graphics.FromImage(screen))
                                    {
                                        using (Brush brsh = new SolidBrush(ColorTranslator.FromHtml("#000000")))
                                        {
                                            grf.FillEllipse(brsh, p.Value.X, p.Value.Y, 5, 5);
                                        }
                                    }
                                    p = null;
                                    continue;
                                }
                                BotCore.SendTap(970, 614);
                                BotCore.Delay(2000, false);
                                BotCore.SendTap(753, 423);
                                break;
                            }
                        }
                    }
                    if (p != null)
                    {
                        break;
                    }
                    else
                    {
                        p = BotCore.FindImage(screen, Img.Boss, true);
                        if (p != null)
                        {
                            Variables.ScriptLog("Boss Stage found!", Color.Lime);
                            if (VCBotScript.runes == 3 && VCBotScript.energy != 5)
                            {
                                VCBotScript.StuckRune();
                                return;
                            }
                            BotCore.SendTap(p.Value);
                            break;
                        }
                    }
                }
                VCBotScript.image = BotCore.ImageCapture();
                Point?p2 = BotCore.FindImage(crop, Img.GreenButton, false);
                if (p2 != null)
                {
                    BotCore.SendTap(p2.Value);
                    BotCore.Delay(1000, false);
                    continue;
                }
                error++;
            }
            if (error > 9)
            {
                Variables.ScriptLog("Looks like we are in the trouble!", Color.Red);
                error = 0;
                BotCore.KillGame("com.nubee.valkyriecrusade");
                ScriptErrorHandler.Reset("Restarting game as unable to detect stages properly!");
            }
            Point?point = null;

            BotCore.Delay(5000, false);
            for (int x = 0; x < 20; x++)
            {
                VCBotScript.image = BotCore.ImageCapture();
                Point?p2 = BotCore.FindImage(VCBotScript.image, Img.GreenButton, false);
                if (p2 != null)
                {
                    BotCore.SendTap(p2.Value);
                    BotCore.Delay(1000, false);
                    continue;
                }
                if (!BotCore.GameIsForeground("com.nubee.valkyriecrusade"))
                {
                    return;
                }
                VCBotScript.image = BotCore.ImageCapture();
                point             = BotCore.FindImage(VCBotScript.image, Img.Red_Button, false);
                if (point != null)
                {
                    break;
                }
                BotCore.Delay(1000, false);
            }
            if (point == null)
            {
                BotCore.KillGame("com.nubee.valkyriecrusade");
                ScriptErrorHandler.Reset("No expected UI is shown, restarting game!");
                return;
            }
            BotCore.SendTap(point.Value);
            PrivateVariable.Battling = true;
            VCBotScript.stop.Start();
        }
        private static void Attack()
        {
            do
            {
                BotCore.Delay(1500);
                VCBotScript.image = BotCore.ImageCapture();
            }while (BotCore.RGBComparer(VCBotScript.image, new Point(400, 400), Color.Black, 10));
            Variables.ScriptLog("Running stage!", Color.Lime);
            int error = 0;

            do
            {
                Random rnd = new Random();
                VCBotScript.image = BotCore.ImageCapture();
                var   crop    = BotCore.CropImage(VCBotScript.image, new Point(420, 360), new Point(855, 430));
                Point?buttons = BotCore.FindImage(crop, Img.GreenButton, false);
                if (buttons != null)
                {
                    ArchwitchEvent.CheckWalkEnergy();
                    if (ArchwitchEvent.CurrentWalkEnergy < 15)
                    {
                        //No energy
                        Variables.ScriptLog("SoulWeapon Event have no energy. Exiting now! ", Color.Yellow);
                        return;
                    }
                    BotCore.SendTap(buttons.Value.X + rnd.Next(430, 845), buttons.Value.Y + rnd.Next(370, 420));
                    BotCore.Delay(2000, 3000);
                    continue;
                }
                buttons = BotCore.FindImage(VCBotScript.image, Img.Return, true);
                if (buttons != null)
                {
                    BotCore.SendTap(buttons.Value);
                    BotCore.Delay(1000, 1500);
                    continue;
                }
                buttons = BotCore.FindImage(VCBotScript.image, Img.Close2, true);
                if (buttons != null)
                {
                    BotCore.SendTap(buttons.Value);
                    BotCore.Delay(1000, 1500);
                    continue;
                }
                buttons = BotCore.FindImage(crop, Img.Red_Button, false);
                if (buttons != null)
                {
                    ArchwitchEvent.CheckBossEnergy();
                    if (ArchwitchEvent.CurrentBossEnergy == 0)
                    {
                        Variables.ScriptLog("SoulWeapon Event have no energy. Exiting now! ", Color.Yellow);
                        return;
                    }
                    BotCore.SendTap(buttons.Value.X + rnd.Next(430, 845), buttons.Value.Y + rnd.Next(370, 420));
                    BotCore.Delay(2000, 3000);
                    PrivateVariable.Battling = true;
                    VCBotScript.Battle();
                    continue;
                }
                buttons = BotCore.FindImage(VCBotScript.image, Img.ShopKeeper, true);
                if (buttons != null)
                {
                    BotCore.SendTap(530, 660);
                    BotCore.Delay(1500);
                    continue;
                }
                if (BotCore.FindImage(VCBotScript.image, Img.SoulWeapon, true) != null)
                {
                    //Stage completed
                    return;
                }
                error++;
                if (error > 30)
                {
                    BotCore.Decompress(VCBotScript.image).Save("Profiles\\Logs\\error.png");
                    UnhandledException = true;
                    Variables.ScriptLog("Unhandled exception. Contact PoH98 for fix!", Color.Red);
                    return;
                }
                else
                {
                    BotCore.Delay(1000, 1500);
                }
            }while (true);
        }