/// <summary>
        /// Check some error message that need to restart the game
        /// </summary>
        public static bool ErrorHandle()
        {
            if (Variables.Proc != null)
            {
                try
                {
                    if (BotCore.RGBComparer(new Point(145, 170), Color.Black, 2, VCBotScript.image) && BotCore.RGBComparer(new Point(1000, 355), Color.Black, 2, VCBotScript.image))
                    {
                        if (BotCore.RGBComparer(new Point(410, 285), Color.FromArgb(25, 44, 58), 10, VCBotScript.image) && BotCore.RGBComparer(new Point(400, 430), Color.FromArgb(56, 98, 128), 10, VCBotScript.image))
                        {
                            //Error Messagebox found
                            BotCore.KillGame("com.nubee.valkyriecrusade");
                            Reset("Error message found!");
                            return(true);
                        }
                    }
                }
                catch
                {
                }
                return(false);

                /*try
                 * {
                 *  var crop = Screenshot.CropImage(VCBotScript.image, new Point(350, 180), new Point(980, 515));
                 *  foreach(var error in errorImages)
                 *  {
                 *      BotCore.Delay(100);
                 *      Point? p = BotCore.FindImage(crop, error, false);
                 *      if (p != null)
                 *      {
                 *          BotCore.SendTap(p.Value);
                 *          BotCore.KillGame("com.nubee.valkyriecrusade");
                 *          Reset("Error message found!");
                 *      }
                 *  }
                 * }
                 * catch
                 * {
                 *
                 * }*/
            }
            return(true);
        }
Exemple #2
0
 /// <summary>
 /// Check some error message that need to restart the game
 /// </summary>
 public static void ErrorHandle()
 {
     if (Variables.Proc != null)
     {
         try
         {
             var crop = BotCore.CropImage(VCBotScript.image, new Point(350, 180), new Point(980, 515));
             foreach (var error in errorImages)
             {
                 BotCore.Delay(100);
                 Point?p = BotCore.FindImage(crop, error, false);
                 if (p != null)
                 {
                     BotCore.SendTap(p.Value);
                     BotCore.KillGame("com.nubee.valkyriecrusade");
                     Reset("Error message found!");
                 }
             }
         }
         catch
         {
         }
     }
 }
        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();
        }
 public static void ArchwitchEnter()
 {
     do
     {
         VCBotScript.LocateMainScreen();
     }while (!PrivateVariable.InMainScreen);
     //Enter battle screen
     BotCore.SendTap(170, 630);
     BotCore.Delay(5000, false);
     for (int x = 0; x < 5; x++)
     {
         VCBotScript.image = BotCore.ImageCapture();
         Point?located = BotCore.FindImage(VCBotScript.image, Environment.CurrentDirectory + "\\Img\\LocateEventSwitch.png", true);
         if (located == null)
         {
             x -= 1;
             BotCore.Delay(1000, false);
             if (error > 10)
             {
                 ScriptErrorHandler.Reset("Unable to locate Event Switch screen! Returning main screen!");
                 error = 0;
                 return;
             }
             error++;
             ScriptErrorHandler.ErrorHandle();
             continue;
         }
         else
         {
             break;
         }
     }
     //ArchwitchHunt capture detected, try to get into event
     if (File.Exists("Img\\ArchEvent.png"))
     {
         var point = BotCore.FindImage(VCBotScript.image, "Img\\ArchEvent.png", false);
         if (point != null)
         {
             BotCore.SendTap(point.Value);
             //Enter event
             SwitchStage();
         }
         else
         {
             Variables.ScriptLog("Unable to find ArchEvent.png at event page. Exiting function! ", Color.Red);
         }
     }
     else
     {
         Variables.ScriptLog("ArchEvent.png not found! Exiting function! ", Color.Red);
     }
     //not found, we have to exit now!
     //Our next online time had passed. Online it NOWWWWWW!!!!!
     if (VCBotScript.nextOnline < DateTime.Now)
     {
         do
         {
             VCBotScript.LocateMainScreen();
         }while (!PrivateVariable.InMainScreen);
         VCBotScript.Stuck = false;
     }
     else
     {
         BotCore.KillGame("com.nubee.valkyriecrusade");
     }
     return;
 }
        private static void Attack()
        {
            do
            {
                BotCore.Delay(1500);
                VCBotScript.image = Screenshot.ImageCapture();
            }while (BotCore.RGBComparer(new Point(400, 400), Color.Black, 10, VCBotScript.image));
            Variables.ScriptLog("Running stage!", Color.Lime);
            int error = 0;

            do
            {
                Random rnd = new Random();
                VCBotScript.image = Screenshot.ImageCapture();
                var   crop    = Screenshot.CropImage(VCBotScript.image, new Point(420, 360), new Point(855, 450));
                Point?buttons = BotCore.FindImage(crop, Img.GreenButton, false, 0.9);
                if (buttons != null)
                {
                    ArchwitchEvent.CheckWalkEnergy();
                    if (ArchwitchEvent.CurrentWalkEnergy <= 15 || (ArchwitchEvent.CurrentBossEnergy <= 3 && ArchwitchEvent.FullBossEnergy > 0))
                    {
                        //No energy
                        Variables.ScriptLog("SoulWeapon Event have no energy. Exiting now! ", Color.Yellow);
                        TimeSpan delay = new TimeSpan(0, ((ArchwitchEvent.FullWalkEnergy - ArchwitchEvent.CurrentWalkEnergy) * 5), 0);
                        VCBotScript.nextOnline = DateTime.Now + delay;
                        Variables.ScriptLog("Estimate online time is " + VCBotScript.nextOnline, Color.Lime);
                        BotCore.KillGame(VCBotScript.game);
                        BotCore.Delay(delay);
                        PrivateVariable.Instance.InEventScreen = false;
                        PrivateVariable.Instance.InMainScreen  = false;
                        PrivateVariable.Instance.Battling      = false;
                        PrivateVariable.Instance.InMap         = false;
                        ArchwitchEvent.CurrentBossEnergy       = ArchwitchEvent.FullBossEnergy;
                        ArchwitchEvent.CurrentWalkEnergy       = ArchwitchEvent.FullWalkEnergy;
                        BotCore.StartGame(VCBotScript.game + VCBotScript.activity);
                        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, 0.9);
                if (buttons != null)
                {
                    BotCore.SendTap(buttons.Value);
                    BotCore.Delay(1000, 1500);
                    continue;
                }
                buttons = BotCore.FindImage(VCBotScript.image, Img.Close2, true, 0.9);
                if (buttons != null)
                {
                    BotCore.SendTap(buttons.Value);
                    BotCore.Delay(1000, 1500);
                    continue;
                }
                buttons = BotCore.FindImage(crop, Img.Red_Button, false, 0.87);
                if (buttons != null)
                {
                    ArchwitchEvent.CheckBossEnergy();
                    BotCore.SendTap(buttons.Value.X + rnd.Next(430, 845), buttons.Value.Y + rnd.Next(370, 420));
                    BotCore.Delay(2000, 3000);
                    PrivateVariable.Instance.Battling = true;
                    VCBotScript.Battle();
                    continue;
                }
                buttons = BotCore.FindImage(VCBotScript.image, Img.ShopKeeper, true, 0.9);
                if (buttons != null)
                {
                    BotCore.SendTap(770, 640);
                    Variables.ScriptLog("Shop keeper found! Getting in and see what to buy!", Color.White);
                    BotCore.Delay(3000);
                    VCBotScript.image = Screenshot.ImageCapture();
                    if (BotCore.FindImage(VCBotScript.image, Img.MisteryBox, true, 0.9) != null)
                    {
                        Variables.ScriptLog("Mistory Box found! Purchasing all products!", Color.Lime);
                        BotCore.Delay(10000);
                        for (int x = 0; x < 3; x++)
                        {
                            switch (x)
                            {
                            case 0:
                                Variables.ScriptLog("Purchasing First Item", Color.Wheat);
                                BotCore.SendTap(1030, 220);
                                break;

                            case 1:
                                Variables.ScriptLog("Purchasing Second Item", Color.Wheat);
                                BotCore.SendTap(1030, 390);
                                break;

                            case 2:
                                Variables.ScriptLog("Purchasing Third Item", Color.Wheat);
                                BotCore.SendTap(1030, 550);
                                break;
                            }
                            BotCore.Delay(3000);
                            Point?greenButton;
                            do
                            {
                                BotCore.SendTap(2, 2);
                                BotCore.Delay(300);
                                VCBotScript.image = Screenshot.ImageCapture();
                                greenButton       = BotCore.FindImage(VCBotScript.image, Img.GreenButton, false, 0.9);
                            }while (greenButton == null);
                            BotCore.SendTap(greenButton.Value);
                            for (int y = 0; y < 10; y++)
                            {
                                BotCore.SendTap(2, 2);
                                BotCore.Delay(500);
                            }
                            BotCore.Delay(5000);
                        }
                    }
                    BotCore.SendTap(1110, 875);
                    BotCore.Delay(500);
                    continue;
                }
                if (BotCore.FindImage(VCBotScript.image, Img.ArchwitchHunt, true, 0.9) != null)
                {
                    //Stage completed
                    return;
                }
                error++;
                if (error > 30)
                {
                    Screenshot.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);
        }
        public static void SoulWeaponEnter()
        {
            Variables.ScriptLog("Soul Weapon Event found!", Color.Lime);
            int error = 0;

            //Check if we didnt need to switch stage
            do
            {
                if (!BotCore.GameIsForeground(VCBotScript.game))
                {
                    return;
                }
                VCBotScript.image = Screenshot.ImageCapture();
                if (BotCore.FindImage(VCBotScript.image, Img.SoulArrow, false, 0.9) != null || BotCore.FindImage(Screenshot.CropImage(VCBotScript.image, new Point(445, 355), new Point(815, 430)), Img.Red_Button, false, 0.87) != null)
                {
                    Variables.ScriptLog("Already in a stage, running now...", Color.Lime);
                    Attack();
                }
                PT   = OCR.OcrImage(Screenshot.CropImage(VCBotScript.image, new Point(840, 32), new Point(911, 59)), "en");
                Rank = OCR.OcrImage(Screenshot.CropImage(VCBotScript.image, new Point(854, 74), new Point(911, 92)), "en");
                //Back to 1-1 first before we continue
                BotCore.Delay(1000);
                if (Variables.FindConfig("General", "SoulEv", out string data))
                {
                    if (bool.Parse(data))
                    {
                        var New = BotCore.FindImage(VCBotScript.image, Img.NEW, false, 0.8);
                        if (New != null)
                        {
                            Variables.ScriptLog("Found new stage!", Color.Blue);
                            BotCore.SendTap(New.Value);
                            goto SkipSelectStage;
                        }
                        New = BotCore.FindImage(VCBotScript.image, Img.NEW1, false, 0.8);
                        if (New != null)
                        {
                            Variables.ScriptLog("Found new stage!", Color.Blue);
                            BotCore.SendTap(New.Value);
                            goto SkipSelectStage;
                        }
                        New = BotCore.FindImage(VCBotScript.image, Img.NEW2, false, 0.8);
                        if (New != null)
                        {
                            Variables.ScriptLog("Found new stage!", Color.Blue);
                            BotCore.SendTap(New.Value);
                            goto SkipSelectStage;
                        }
                        New = BotCore.FindImage(VCBotScript.image, Img.NEW3, false, 0.8);
                        if (New != null)
                        {
                            Variables.ScriptLog("Found new stage!", Color.Blue);
                            BotCore.SendTap(New.Value);
                            goto SkipSelectStage;
                        }
                        else
                        {
                            Variables.ScriptLog("New stage not found! Try getting into Boss stage!", Color.Blue);
                            New = BotCore.FindImage(VCBotScript.image, Img.Castle, true, 0.8);
                            if (New != null)
                            {
                                BotCore.SendTap(New.Value);
                                goto SkipSelectStage;
                            }
                            Variables.ScriptLog("No Stage located, force getting into stage!", Color.Red);
                        }
                    }
                }
                BotCore.SendSwipe(500, 440, 1200, 360, 1000);//Why it can't swipe????
                BotCore.Delay(1000);
                switch (VCBotScript.Weapon_Stage)
                {
                case 1.1:
                    BotCore.SendTap(449, 532);
                    break;

                case 1.2:
                    BotCore.SendTap(577, 422);
                    break;

                case 1.3:
                    BotCore.SendTap(692, 277);
                    break;

                case 2.1:
                    BotCore.SendTap(820, 423);
                    break;

                case 2.2:
                    BotCore.SendTap(944, 306);
                    break;

                case 2.3:
                    BotCore.SendTap(1053, 210);
                    break;

                case 3.1:
                    BotCore.SendTap(1191, 310);
                    break;

                //next page
                case 3.2:
                    BotCore.SendSwipe(1191, 310, 670, 310, 3000);
                    BotCore.Delay(1000);
                    BotCore.SendTap(315, 427);
                    break;
                }
SkipSelectStage:
                BotCore.Delay(1000, 1200);
                VCBotScript.image = Screenshot.ImageCapture();
                var point = BotCore.FindImage(VCBotScript.image, Img.GreenButton, false, 0.9);
                if (point != null)
                {
                    BotCore.SendTap(point.Value);
                    BotCore.Delay(1000, 2000);
                    Attack();
                    if (!PrivateVariable.Instance.InEventScreen || BotCore.GameIsForeground(VCBotScript.game))
                    {
                        PrivateVariable.Instance.InEventScreen = false;
                        PrivateVariable.Instance.InMainScreen  = false;
                        return;
                    }
                    error = 0;
                    if (Variables.FindConfig("General", "SoulEv", out data))
                    {
                        if (!bool.Parse(data))
                        {
                            if (VCBotScript.Weapon_Stage < 3.0)
                            {
                                VCBotScript.Weapon_Stage += 0.1;
                                if (VCBotScript.Weapon_Stage % 1 > 0.3)
                                {
                                    VCBotScript.Weapon_Stage += 0.7;
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (error > 9)
                    {
                        BotCore.KillGame("com.nubee.valkyriecrusade");
                        ScriptErrorHandler.Reset("Extreme error happens. Restarting game...");
                        return;
                    }
                    else
                    {
                        Variables.ScriptLog("Something error happens. Unable to get detect expcted UI", Color.Red);
                        BotCore.SendSwipe(395, 365, 1100, 380, 1000);
                        error++;
                    }
                }
            }while (error < 10);
        }