optimization please.

iamaldrin08

New member
Joined
Feb 26, 2016
Messages
4
Programming Experience
Beginner
I've made a bluestacks bot, using c#, tessnet2, and autoit.. I need help in optimizing it.. Here's the code..
C#:
using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices; //APIs
using tessnet2;
using AutoItX3Lib;
using System.Threading;
using System.IO;


namespace MinimizeCapture
{


    public partial class Form1 : Form
    {
        #region User32
        [DllImport("user32.dll")]
        static extern int GetWindowText(int hWnd, StringBuilder text, int count); //Copies the text of the specified window's title bar (if it has one) into a buffer


        [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
        static extern System.IntPtr FindWindowByCaption(int ZeroOnly, string lpWindowName);


        IntPtr ip = FindWindowByCaption(0, "BlueStacks App Player"); //Get windows handle


        #endregion




        AutoItX3 au3 = new AutoItX3();
        BackgroundWorker AdvWorker;
        
        public Form1()
        {
            InitializeComponent();
            AdvWorker = new BackgroundWorker();


            // Create a background worker thread that ReportsProgress &
            // SupportsCancellation
            // Hook up the appropriate events.
            AdvWorker.DoWork += new DoWorkEventHandler(AdvWorkerDoWork);
            AdvWorker.ProgressChanged += new ProgressChangedEventHandler
                    (AdvWorkerProgressChanged);
            AdvWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler
                    (AdvWorker_RunWorkerCompleted);
            AdvWorker.WorkerReportsProgress = true;
            AdvWorker.WorkerSupportsCancellation = true;
            
        }


        private void Form1_Load(object sender, EventArgs e)
        {


            #region Collect
            if (cbCollGold.Checked == true || cbCollHonor.Checked == true || cbCollKeys.Checked == true || cbCollRubies.Checked == true || cbCollTicket.Checked == true)
            {
                Funcs.World.Coords.Collect = 1;
            }
            else
            {
                Funcs.World.Coords.Collect = 0;
            }
            #endregion


            #region Formations!
            lblForm1.Location = new Point();
            if (cbFormation.Text == "Basic")
            {
                lblForm1.Location = new Point(88, 96);
                lblForm2.Location = new Point(88, 58);
                lblForm3.Location = new Point(48, 120);
                lblForm4.Location = new Point(48, 77);
                lblForm5.Location = new Point(48, 36);


            }
            else if (cbFormation.Text == "Balanced")
            {
                lblForm1.Location = new Point(88, 114);
                lblForm2.Location = new Point(88, 73);
                lblForm3.Location = new Point(88, 35);
                lblForm4.Location = new Point(48, 93);
                lblForm5.Location = new Point(48, 54);
            }
            else if (cbFormation.Text == "Offensive")
            {
                lblForm1.Location = new Point(88, 69);
                lblForm2.Location = new Point(48, 122);
                lblForm3.Location = new Point(48, 84);
                lblForm4.Location = new Point(48, 52);
                lblForm5.Location = new Point(48, 24);
            }
            else if (cbFormation.Text == "Defensive")
            {
                lblForm1.Location = new Point(88, 135);
                lblForm2.Location = new Point(88, 94);
                lblForm3.Location = new Point(88, 53);
                lblForm4.Location = new Point(88, 12);
                lblForm5.Location = new Point(48, 69);
            }


            if (ip == IntPtr.Zero) // Verify that Bluestacks is a running process.
            {
                MessageBox.Show("Bluestacks is not running.");
                return;
            }
            else
            {
                this.textBoxHandle.Text = ip.ToString(); //Retrieve Window Caption
            }
            #endregion




            Funcs.World.Coords.skill1 = Convert.ToInt16(cbSkill1.Text);
            Funcs.World.Coords.skill2 = Convert.ToInt16(cbSkill2.Text);
            Funcs.World.Coords.skill3 = Convert.ToInt16(cbSkill3.Text);
            Funcs.World.Coords.advskill1 = Convert.ToInt16(cbadvskill1.Text);
            Funcs.World.Coords.advskill2 = Convert.ToInt16(cbadvskill2.Text);
            Funcs.World.Coords.advskill3 = Convert.ToInt16(cbadvskill3.Text);


            Funcs.World.Msgs.path = AppDomain.CurrentDomain.BaseDirectory + "\\tessdata";
            
            if (cbArena.Checked == true)
            {
                Funcs.World.Coords.arena = 1;
            }
            else
            {
                Funcs.World.Coords.arena = 0;
            }
            if (cbAdv.Checked == true)
            {
                Funcs.World.Coords.adv = 1;
            }
            else
            {
                Funcs.World.Coords.adv = 0;
            }
            if (cbRaid.Checked == true)
            {
                Funcs.World.Coords.raid = 1;
            }
            else
            {
                Funcs.World.Coords.raid = 0;
            }
            if (cbTower.Checked == true)
            {
                Funcs.World.Coords.tower = 1;
            }
            else
            {
                Funcs.World.Coords.tower = 0;
            }




        }




        public void buttonSnapHandle_Click(object sender, EventArgs e)
        {








            if (textBox1.Text == "")
            {
                textBox1.Text = "0";
            }
            if (textBox2.Text == "")
            {
                textBox2.Text = "0";
            }
            Funcs.World.Coords.rectx = Convert.ToInt16(textBox1.Text);
            Funcs.World.Coords.recty = Convert.ToInt16(textBox2.Text);
            try
            {


                WindowSnap snap = WindowSnap.GetWindowSnap((IntPtr)ip, true);
                if (snap.Image != null)


                    this.pictureBoxSnap.Image = snap.Image;
            }
            catch { MessageBox.Show("Wrong Handle (note:handle must be entered as decimal (hex is not acceptable)"); }


            #region ImageProc




            //crop image for better reading
            Bitmap original = new Bitmap(this.pictureBoxSnap.Image);
            Rectangle srcRect = new Rectangle(Funcs.World.Coords.rectx, Funcs.World.Coords.recty, 50, 40);
            Bitmap cropped = (Bitmap)original.Clone(srcRect, original.PixelFormat);


            System.Drawing.Bitmap resizedImage = new System.Drawing.Bitmap(256, 256);
            System.Drawing.Graphics.FromImage((System.Drawing.Image)resizedImage).DrawImage(cropped, 0, 0, 256, 256);




            this.pictureBox1.Image = resizedImage;


            //convert image to text
            System.Drawing.Bitmap imagee = new Bitmap(pictureBox1.Image);
            //GET IMAGE FROM FILE


            //CONVERT IMAGE TO TEXT
            tessnet2.Tesseract ocr = new tessnet2.Tesseract();
            ocr.SetVariable("tessedit_char_whitelist", "1234567890ABCDEFGHIJKLMNOQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); // If BIG letters only
            ocr.Init(Funcs.World.Msgs.path, "eng", false);


            //CONVERT IMAGE TO TEXT
            List<tessnet2.Word> res = ocr.DoOCR(imagee, Rectangle.Empty);
            string ocrtext;
            foreach (tessnet2.Word word in res)
            {
                ocrtext = word.Text;
               
                richTextBox1.Text = richTextBox1.Text + word.Text + Environment.NewLine;
            }




            #endregion


        }


        private void checkBoxForceMDI_CheckedChanged(object sender, EventArgs e)
        {
            WindowSnap.ForceMDICapturing = (sender as CheckBox).Checked;
        }




        #region AdvBGworker


       


        void AdvWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            // The background process is complete. We need to inspect
            // our response to see if an error occurred, a cancel was
            // requested or if we completed successfully.  
            if (e.Cancelled)
            {
                listBox1.Items.Add("Task Cancelled.");


            }


            // Check to see if an error occurred in the background process.


            else if (e.Error != null)
            {
                listBox1.Items.Add("Error while performing background operation.");
            }
           // else
           //{
                // Everything completed normally.
           //     listBox1.Items.Add("Task Completed...");
           // }


            //Change the status of the buttons on the UI accordingly
            btnAI.Text = "Start AI";


        }


        /// <summary>
        /// Notification is performed here to the progress bar
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void AdvWorkerProgressChanged(object sender, ProgressChangedEventArgs e)
        {


            // This function fires on the UI thread so it's safe to edit


            // the UI control directly, no funny business with Control.Invoke :)


            // Update the progressBar with the integer supplied to us from the


            // ReportProgress() function.  


            //progressBar1.Value = e.ProgressPercentage;
            //listBox1.Items.Clear();
            listBox1.Items.Add(DateTime.Now.ToString("hh:mm:ss") + ": " + Funcs.World.Msgs.status);
            richTextBox1.Text = Funcs.World.Msgs.ocrtext + ", " + Funcs.World.Coords.rectx + ", " + Funcs.World.Coords.recty;
            if (Funcs.World.Coords.errPage == 1)
            {
                lblKeys.Text = Funcs.World.Msgs.ocrtext;
            }
            else if (Funcs.World.Coords.errPage == 2)
            {
                lblRubies.Text = Funcs.World.Msgs.ocrtext;
            }
            else if (Funcs.World.Coords.errPage == 3)
            {
                lblHonor.Text = Funcs.World.Msgs.ocrtext;
            }
        }
        #endregion


        /// <summary>
        /// Time consuming operations go here </br>
        /// i.e. Database operations,Reporting
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// 
        public void AdvWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            int i = 1;
            Funcs.World.Coords.errPage = 1;
            
            while (!AdvWorker.CancellationPending)
            {
                if (Funcs.World.Coords.errPage <= 3)
                {
                    Funcs.World.Msgs.ocrRead = "1234567890"; //Read numbers only
                }
                else
                {
                    Funcs.World.Msgs.ocrRead = "1234567890ABCDEFGHIJKLMNOQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
                }
                Funcs.World.Coords.bsx = 0;
                Funcs.World.Coords.bsy = 0;
                #region SNAP!
                WindowSnap snap = WindowSnap.GetWindowSnap((IntPtr)ip, true); //take pic




                //crop image for better reading
                Bitmap original = new Bitmap(snap.Image);
                Rectangle srcRect = new Rectangle(Funcs.World.Coords.rectx, Funcs.World.Coords.recty, 50, 40);
                Bitmap cropped = (Bitmap)original.Clone(srcRect, original.PixelFormat);


                //Enlarge cropped pic
                System.Drawing.Bitmap resizedImage = new System.Drawing.Bitmap(256, 256);
                System.Drawing.Graphics.FromImage((System.Drawing.Image)resizedImage).DrawImage(cropped, 0, 0, 256, 256);
                System.Drawing.Bitmap imagee = new Bitmap(resizedImage);
                this.pictureBox1.Image = imagee;
                //CONVERT IMAGE TO TEXT
                tessnet2.Tesseract ocr = new tessnet2.Tesseract();
                ocr.SetVariable("tessedit_char_whitelist", Funcs.World.Msgs.ocrRead); // If BIG letters only
                ocr.Init(Funcs.World.Msgs.path, "eng", false);


                //CONVERT IMAGE TO TEXT
                List<tessnet2.Word> res = ocr.DoOCR(imagee, Rectangle.Empty);


                #endregion


                //Get words from pic
                foreach (tessnet2.Word word in res)
                {


                    #region FixText
                    if (word.Text.Contains("OBB"))
                    {
                        Funcs.World.Msgs.ocrtext = "LOBBY";
                    }
                    else if (word.Text.Contains("Youa"))
                    {
                        Funcs.World.Msgs.ocrtext = "FAIL";
                    }
                    else if (word.Text.Contains("CE"))
                    {
                        Funcs.World.Msgs.ocrtext = "CtowerLobby";
                    }
                    else if (word.Text.Contains("me"))
                    {
                        Funcs.World.Msgs.ocrtext = "Wave1";
                    }
                    else if (word.Text.Contains("KM"))
                    {
                        Funcs.World.Msgs.ocrtext = "Wave1";
                    }
                    else if (word.Text.Contains("Ii"))
                    {
                        Funcs.World.Msgs.ocrtext = "CollectAll";
                    }
                    else if (word.Text.Contains("INI"))
                    {
                        Funcs.World.Msgs.ocrtext = "Inbox";
                    }
                    else if (word.Text.Contains("57")) //Tap to start 770,35
                    {
                        Funcs.World.Msgs.ocrtext = "Version";
                    }
                    else if (word.Text.Contains("SRI"))
                    {
                        Funcs.World.Msgs.ocrtext = "SPECIAL";
                    }
                   
                    else if (word.Text.Contains("Today"))
                    {
                        Funcs.World.Msgs.ocrtext = "Today";
                    }
                    else
                    {
                        Funcs.World.Msgs.ocrtext = word.Text;
                    }
                    #endregion


                  




                    #region ErrorHandling
                    switch (Funcs.World.Msgs.ocrtext)
                    {
                        case "WEEK": //Start up
                            {
                                Funcs.World.Coords.bsx = 830; //Click no
                                Funcs.World.Coords.bsy = 100;
                                Funcs.World.Msgs.status = "Closing offers...";
                                break;
                            }
                        case "Today": //Start up
                            {
                                Funcs.World.Coords.bsx = 750; //Click no
                                Funcs.World.Coords.bsy = 515;
                                Funcs.World.Msgs.status = "Closing offers...";
                                break;
                            }
                        case "SPECIAL": //Start up
                            {
                                Funcs.World.Coords.bsx = 300; //Click no
                                Funcs.World.Coords.bsy = 490;
                                Funcs.World.Msgs.status = "Closing offers...";
                                break;
                            }
                        case "Notice": //Start up
                            {
                                Funcs.World.Coords.bsx = 830; //Click x
                                Funcs.World.Coords.bsy = 30;
                                Funcs.World.Msgs.status = "Closing notice...";
                                break;
                            }
                        case "Version": //Start up Tap to start
                            {
                                Funcs.World.Coords.bsx = 830; //Tap anywhere
                                Funcs.World.Coords.bsy = 30;
                                Funcs.World.Msgs.status = "Start up page...";
                                break;
                            }
                        case "X": //ads
                            {
                                Funcs.World.Coords.bsx = 830; //tap x
                                Funcs.World.Coords.bsy = 600;
                                Funcs.World.Msgs.status = "Start up page...";
                                break;
                            }
                        case "XJ": //ads
                            {
                                Funcs.World.Coords.bsx = 790; //tap x
                                Funcs.World.Coords.bsy = 110;
                                Funcs.World.Msgs.status = "Start up page...";
                                break;
                            }
                        case "OK":
                        case "Disco":
                            {
                                Funcs.World.Msgs.page = "DC"; //Arena lobby
                                Funcs.World.Msgs.status = "OK!";
                                Funcs.World.Coords.bsx = 430;
                                Funcs.World.Coords.bsy = 430; //Click OK


                                break;
                            }
                        case "Wave1":
                            {
                                Funcs.World.Msgs.page = "Wave 1"; //Arena lobby
                                Funcs.World.Msgs.status = "Wave 1!";
                               
                                Funcs.World.Coords.bsx = 0;
                                Funcs.World.Coords.bsy = 0;
                                break;
                            }
                        case "Comn":
                            {
                                Funcs.World.Msgs.page = "Arena Quest"; //Arena lobby
                                Funcs.World.Msgs.status = "Quest done!";
                                Funcs.World.Coords.bsx = 785;
                                Funcs.World.Coords.bsy = 545; //Use rubies


                                break;
                            }


                        case "REC":
                            {
                                Funcs.World.Msgs.page = "PVP Finished!"; //Arena lobby
                                Funcs.World.Coords.bsx = 820;
                                Funcs.World.Coords.bsy = 530; //Click Arena
                                Funcs.World.Msgs.status = "Let's go!";
                                break;
                            }


                        #endregion


                        #region CommonPage




                        case "HEROES":
                            {
                                if (Funcs.World.Coords.adv == 1 || Funcs.World.Coords.tower == 1)
                                {
                                    Funcs.World.Coords.bsx = 750; //Go to adventure/start battle/press ready
                                    Funcs.World.Coords.bsy = 530;
                                    Funcs.World.Msgs.status = "Going to adventure...";
                                }
                                else if (Funcs.World.Coords.arena == 1) //|| Funcs.World.Coords.castlerush == 1)
                                {
                                    Funcs.World.Coords.bsx = 620; //Go to battle
                                    Funcs.World.Coords.bsy = 555;
                                    Funcs.World.Msgs.status = "Going to Arena...";
                                    Funcs.World.Coords.aftrTower = 0;
                                }
                                //  else if (Funcs.World.Coords.Collect == 1) //For mail
                                //  {
                                //      Funcs.World.Coords.bsx = 730; //Click mail
                                //      Funcs.World.Coords.bsy = 50;
                                //      Funcs.World.Msgs.status = "Checking mail...";
                                //      
                                //
                                //  }
                                //after adv = 0


                                break;
                            }
                        case "LOBBY":
                            {
                                if (Funcs.World.Coords.adv == 1)
                                {
                                    //Funcs.World.Msgs.page = "Battle end"; //Tower battle finished
                                    //Funcs.World.Msgs.status = "Going back to celestial tower...";
                                    //Funcs.World.Coords.bsx = 805;
                                    //Funcs.World.Coords.bsy = 430; //Click celestial tower
                                    //Funcs.World.Coords.aftrTower = 1;
                                }
                                if (Funcs.World.Coords.tower == 1)
                                {
                                    Funcs.World.Msgs.page = "Battle end"; //Tower battle finished
                                    Funcs.World.Msgs.status = "Going back to celestial tower...";
                                    Funcs.World.Coords.bsx = 805;
                                    Funcs.World.Coords.bsy = 430; //Click celestial tower
                                    Funcs.World.Coords.aftrTower = 1;
                                }
                                else if (Funcs.World.Coords.arena == 1) //|| Funcs.World.Coords.castlerush == 1)
                                {
                                    Funcs.World.Msgs.page = "Arena end"; //Arena lobby
                                    Funcs.World.Msgs.status = "Going back to lobby...";
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 800, 235); //Quick Start
                                    Funcs.World.Coords.aftrPVP = 1;
                                }


                                break;


                            }
                        case "AD":
                            {
                                if (Funcs.World.Coords.adv == 1)
                                {
                                    Funcs.World.Msgs.page = "Adventure"; //Adventure lobby
                                    Funcs.World.Msgs.status = "Going to the adventure map!";
                                    Funcs.World.Coords.bsx = 200;
                                    Funcs.World.Coords.bsy = 200; //Click Adventure
                                }
                                else if (Funcs.World.Coords.tower == 1)
                                {
                                    Funcs.World.Msgs.page = "Adventure"; //Adventure lobby
                                    Funcs.World.Msgs.status = "Going to the tower!";
                                    Funcs.World.Coords.bsx = 500;
                                    Funcs.World.Coords.bsy = 200; //Click Tower
                                }
                                else if (Funcs.World.Coords.arena == 1)
                                {
                                    Funcs.World.Msgs.page = "Adventure"; //Adventure lobby
                                    Funcs.World.Msgs.status = "Going back to lobby!";
                                    Funcs.World.Coords.bsx = 25;
                                    Funcs.World.Coords.bsy = 50; //Click back
                                }




                                break;
                            }
                        case "MANAG":
                            {
                                if (Funcs.World.Coords.adv == 1)
                                {
                                    //For adv
                                    Funcs.World.Msgs.page = "Manage team and mastery"; //Before battle
                                    Funcs.World.Msgs.status = "Checking team and mastery!";
                                    if (rbAdvTeamA.Checked == true)
                                    {
                                        au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 120, 130); //Team A
                                    }
                                    else if (rbAdvTeamB.Checked == true)
                                    {
                                        au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 220, 130);
                                    }
                                    else if (rbAdvTeamC.Checked == true)
                                    {
                                        au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 320, 130);
                                    }


                                    Funcs.World.Coords.bsx = 330;
                                    Funcs.World.Coords.bsy = 210; //Click Mastery
                                }
                                else if (Funcs.World.Coords.tower == 1)
                                {
                                    //For tower
                                    Funcs.World.Msgs.page = "Manage team and mastery"; //Before battle
                                    Funcs.World.Msgs.status = "Checking team and mastery!";
                                    if (rbTeamA.Checked == true)
                                    {
                                        au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 120, 130); //Team A
                                    }
                                    else if (rbTeamB.Checked == true)
                                    {
                                        au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 220, 130);
                                    }
                                    else if (rbTeamC.Checked == true)
                                    {
                                        au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 320, 130);
                                    }


                                    Funcs.World.Coords.bsx = 330;
                                    Funcs.World.Coords.bsy = 210; //Click Mastery
                                }
                                else if (Funcs.World.Coords.arena == 1)
                                {
                                    Funcs.World.Msgs.page = "Adventure"; ////Before battle at the tower
                                    Funcs.World.Msgs.status = "Going back to lobby!";
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                    Thread.Sleep(50);
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                    Thread.Sleep(50);
                                    Funcs.World.Coords.bsx = 25;
                                    Funcs.World.Coords.bsy = 50; //Click back
                                }
                                


                                break;
                            }
                        case "MAS":
                            {


                                if (Funcs.World.Coords.adv == 1)
                                {


                                    //For adv
                                    Funcs.World.Msgs.page = "Checking mastery"; //Before battle
                                    Funcs.World.Msgs.status = "Checking mastery!";
                                    if (rbMastAdv1.Checked == true)
                                    {
                                        au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 600, 130); //Mastery 1
                                    }
                                    else if (rbMastAdv2.Checked == true)
                                    {
                                        au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 650, 130);
                                    }
                                    else if (rbMastAdv3.Checked == true)
                                    {
                                        au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 710, 130);
                                    }
                                    Thread.Sleep(200);
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 800, 130); //Click close
                                    Thread.Sleep(200);
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 750, 530); //Click start
                                    Thread.Sleep(2500);
                                    //Loop when in battle


                                    #region SKILLS


                                    switch (Funcs.World.Coords.advskill1)
                                    {
                                        case 1:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 500, 500); //Click skill 1
                                                break;
                                            }
                                        case 2:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 500, 550); //Click skill 2
                                                break;
                                            }
                                        case 3:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 570, 500); //Click skill 3
                                                break;
                                            }
                                        case 4:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 570, 550); //Click skill 4
                                                break;
                                            }
                                        case 5:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 640, 500); //Click skill 5
                                                break;
                                            }
                                        case 6:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 640, 550); //Click skill 6
                                                break;
                                            }
                                        case 7:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 710, 500); //Click skill 7
                                                break;
                                            }
                                        case 8:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 710, 550); //Click skill 8
                                                break;
                                            }
                                        case 9:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 780, 500); //Click skill 9
                                                break;
                                            }
                                        case 10:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 800, 550); //Click skill 10
                                                break;
                                            }


                                    }
                                    Thread.Sleep(50);
                                    switch (Funcs.World.Coords.advskill2)
                                    {
                                        case 1:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 500, 500); //Click skill 1
                                                break;
                                            }
                                        case 2:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 500, 550); //Click skill 2
                                                break;
                                            }
                                        case 3:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 570, 500); //Click skill 3
                                                break;
                                            }
                                        case 4:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 570, 550); //Click skill 4
                                                break;
                                            }
                                        case 5:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 640, 500); //Click skill 5
                                                break;
                                            }
                                        case 6:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 640, 550); //Click skill 6
                                                break;
                                            }
                                        case 7:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 710, 500); //Click skill 7
                                                break;
                                            }
                                        case 8:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 710, 550); //Click skill 8
                                                break;
                                            }
                                        case 9:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 800, 500); //Click skill 9
                                                break;
                                            }
                                        case 10:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 800, 550); //Click skill 10
                                                break;
                                            }


                                    }
                                    Thread.Sleep(100);
                                    switch (Funcs.World.Coords.advskill3)
                                    {
                                        case 1:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 500, 500); //Click skill 1
                                                break;
                                            }
                                        case 2:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 500, 550); //Click skill 2
                                                break;
                                            }
                                        case 3:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 570, 500); //Click skill 3
                                                break;
                                            }
                                        case 4:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 570, 550); //Click skill 4
                                                break;
                                            }
                                        case 5:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 640, 500); //Click skill 5
                                                break;
                                            }
                                        case 6:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 640, 550); //Click skill 6
                                                break;
                                            }
                                        case 7:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 710, 500); //Click skill 7
                                                break;
                                            }
                                        case 8:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 710, 550); //Click skill 8
                                                break;
                                            }
                                        case 9:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 800, 500); //Click skill 9
                                                break;
                                            }
                                        case 10:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 800, 550); //Click skill 10
                                                break;
                                            }


                                    }
                                    #endregion
                                }
                                else if (Funcs.World.Coords.tower == 1)
                                {


                                    //For tower
                                    Funcs.World.Msgs.page = "Checking mastery"; //Before battle
                                    Funcs.World.Msgs.status = "Checking mastery!";
                                    if (rbMast1.Checked == true)
                                    {
                                        au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 600, 130); //Mastery 1
                                    }
                                    else if (rbMast2.Checked == true)
                                    {
                                        au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 650, 130);
                                    }
                                    else if (rbMast3.Checked == true)
                                    {
                                        au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 710, 130);
                                    }
                                    Thread.Sleep(200);
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 800, 130); //Click close
                                    Thread.Sleep(200);
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 750, 530); //Click start
                                    Thread.Sleep(2500);
                                    //Loop when in battle


                                    #region SKILLS


                                    switch (Funcs.World.Coords.skill1)
                                    {
                                        case 1:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 500, 500); //Click skill 1
                                                break;
                                            }
                                        case 2:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 500, 550); //Click skill 2
                                                break;
                                            }
                                        case 3:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 570, 500); //Click skill 3
                                                break;
                                            }
                                        case 4:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 570, 550); //Click skill 4
                                                break;
                                            }
                                        case 5:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 640, 500); //Click skill 5
                                                break;
                                            }
                                        case 6:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 640, 550); //Click skill 6
                                                break;
                                            }
                                        case 7:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 710, 500); //Click skill 7
                                                break;
                                            }
                                        case 8:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 710, 550); //Click skill 8
                                                break;
                                            }
                                        case 9:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 780, 500); //Click skill 9
                                                break;
                                            }
                                        case 10:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 800, 550); //Click skill 10
                                                break;
                                            }


                                    }
                                    Thread.Sleep(50);
                                    switch (Funcs.World.Coords.skill2)
                                    {
                                        case 1:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 500, 500); //Click skill 1
                                                break;
                                            }
                                        case 2:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 500, 550); //Click skill 2
                                                break;
                                            }
                                        case 3:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 570, 500); //Click skill 3
                                                break;
                                            }
                                        case 4:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 570, 550); //Click skill 4
                                                break;
                                            }
                                        case 5:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 640, 500); //Click skill 5
                                                break;
                                            }
                                        case 6:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 640, 550); //Click skill 6
                                                break;
                                            }
                                        case 7:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 710, 500); //Click skill 7
                                                break;
                                            }
                                        case 8:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 710, 550); //Click skill 8
                                                break;
                                            }
                                        case 9:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 800, 500); //Click skill 9
                                                break;
                                            }
                                        case 10:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 800, 550); //Click skill 10
                                                break;
                                            }


                                    }
                                    Thread.Sleep(100);
                                    switch (Funcs.World.Coords.skill3)
                                    {
                                        case 1:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 500, 500); //Click skill 1
                                                break;
                                            }
                                        case 2:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 500, 550); //Click skill 2
                                                break;
                                            }
                                        case 3:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 570, 500); //Click skill 3
                                                break;
                                            }
                                        case 4:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 570, 550); //Click skill 4
                                                break;
                                            }
                                        case 5:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 640, 500); //Click skill 5
                                                break;
                                            }
                                        case 6:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 640, 550); //Click skill 6
                                                break;
                                            }
                                        case 7:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 710, 500); //Click skill 7
                                                break;
                                            }
                                        case 8:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 710, 550); //Click skill 8
                                                break;
                                            }
                                        case 9:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 800, 500); //Click skill 9
                                                break;
                                            }
                                        case 10:
                                            {
                                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 800, 550); //Click skill 10
                                                break;
                                            }


                                    }
                                    #endregion
                                }
                                else if (Funcs.World.Coords.arena == 1)
                                {
                                    Funcs.World.Msgs.page = "Adventure"; ////Before battle at the tower
                                    Funcs.World.Msgs.status = "Going back to lobby!";
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                    Thread.Sleep(50);
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                    Thread.Sleep(50);
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                    Thread.Sleep(50);
                                    Funcs.World.Coords.bsx = 25;
                                    Funcs.World.Coords.bsy = 50; //Click back
                                }




                                break;
                            }
                        case "UNAB":
                            {


                                Funcs.World.Msgs.status = "No more keys...";
                                Funcs.World.Coords.aftrTower = 1;
                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                Thread.Sleep(300);
                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                Thread.Sleep(300);
                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                Thread.Sleep(300);
                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                Thread.Sleep(300);
                                #region Moving on


                                //move on to next module
                                //set the next module on
                                if (cbAdv.Checked == true)
                                {
                                    Funcs.World.Coords.arena = 0;
                                    Funcs.World.Coords.tower = 0;
                                    Funcs.World.Coords.adv = 1; //next module
                                    Funcs.World.Coords.raid = 0;
                                    Funcs.World.Coords.Collect = 0;
                                }
                                else if (cbRaid.Checked == true)
                                {
                                    Funcs.World.Coords.arena = 0;
                                    Funcs.World.Coords.tower = 0;
                                    Funcs.World.Coords.adv = 0;
                                    Funcs.World.Coords.raid = 1; //next module
                                    Funcs.World.Coords.Collect = 0;
                                }
                                else if (cbArena.Checked == true)
                                {
                                    Funcs.World.Coords.arena = 1; //next module
                                    Funcs.World.Coords.tower = 0;
                                    Funcs.World.Coords.adv = 0;
                                    Funcs.World.Coords.raid = 0;
                                    Funcs.World.Coords.Collect = 0;
                                }
                                else
                                {
                                    Funcs.World.Coords.arena = 0;
                                    Funcs.World.Coords.tower = 0;
                                    Funcs.World.Coords.adv = 0;
                                    Funcs.World.Coords.raid = 0;
                                    Funcs.World.Coords.Collect = 1;//next module
                                }
                                #endregion


                                break;
                            }




                        case "CtowerLobby":
                            {
                                if (Funcs.World.Coords.adv == 1)
                                {
                                    //For adv
                                    Funcs.World.Msgs.page = "Going to the adventure page"; //Going back
                                    Funcs.World.Msgs.status = "Going to the adventure lobby";
                                    Funcs.World.Coords.bsx = 25;
                                    Funcs.World.Coords.bsy = 50; //Go back 1 page
                                }
                                else if (Funcs.World.Coords.tower == 1)
                                {
                                    //For tower
                                    if (rbGold.Checked == true) //Gold chamber selected
                                    {
                                        Funcs.World.Coords.bsx = 330; //Click gold chamber
                                        Funcs.World.Coords.bsy = 150;
                                        Funcs.World.Msgs.status = "Let's go to gold chamber!";
                                    }
                                    else if (rbTower.Checked == true) //Tower floor selected
                                    {
                                        Funcs.World.Coords.bsx = 750; //Go to battle
                                        Funcs.World.Coords.bsy = 550;
                                        Funcs.World.Msgs.status = "Let's fight...!";
                                    }
                                }
                                else if (Funcs.World.Coords.arena == 1)
                                {
                                    Funcs.World.Msgs.page = "Adventure"; ////Before battle at the tower
                                    Funcs.World.Msgs.status = "Going back to lobby!";
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                    Thread.Sleep(50);
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                    Thread.Sleep(50);
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                    Thread.Sleep(50);
                                    Funcs.World.Coords.bsx = 25;
                                    Funcs.World.Coords.bsy = 50; //Click back
                                }
                                break;
                            }


                        case "FAIL":
                            {
                                if (Funcs.World.Coords.arena == 1)
                                {
                                    if (Funcs.World.Coords.usearenarubies <= Convert.ToInt16(numericUpDown1.Value))
                                    {
                                        Funcs.World.Msgs.status = "Gonna use rubies!";
                                        Funcs.World.Coords.bsx = 500;
                                        Funcs.World.Coords.bsy = 430; //Use rubies
                                        Funcs.World.Coords.usearenarubies = Funcs.World.Coords.usearenarubies + 1;
                                    }
                                   
                                    
                                }
                                else
                                {
                                    Funcs.World.Msgs.status = "Going back to lobby...";
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 300, 430);
                                    Thread.Sleep(500);
                                    if (Funcs.World.Coords.aftrPVP == 1)
                                    {
                                        au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 805, 535);


                                    }
                                    else
                                    {
                                        au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                        Thread.Sleep(300);
                                        au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                        Thread.Sleep(300);
                                        au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                        Thread.Sleep(300);


                                        #region Moving on


                                        //move on to next module
                                        //set the next module on


                                        if (cbAdv.Checked == true)
                                        {
                                            Funcs.World.Coords.arena = 0;
                                            Funcs.World.Coords.tower = 0;
                                            Funcs.World.Coords.adv = 1; //next module
                                            Funcs.World.Coords.raid = 0;
                                            Funcs.World.Coords.Collect = 0;
                                        }
                                        else if (cbRaid.Checked == true)
                                        {
                                            Funcs.World.Coords.arena = 0;
                                            Funcs.World.Coords.tower = 0;
                                            Funcs.World.Coords.adv = 0;
                                            Funcs.World.Coords.raid = 1; //next module
                                            Funcs.World.Coords.Collect = 0;
                                        }
                                        else if (cbTower.Checked == true)
                                        {
                                            Funcs.World.Coords.arena = 0;
                                            Funcs.World.Coords.tower = 1; //next module
                                            Funcs.World.Coords.adv = 0;
                                            Funcs.World.Coords.raid = 0;
                                            Funcs.World.Coords.Collect = 0;
                                        }
                                        else
                                        {
                                            Funcs.World.Coords.arena = 0;
                                            Funcs.World.Coords.tower = 0;
                                            Funcs.World.Coords.adv = 0;
                                            Funcs.World.Coords.raid = 0;
                                            Funcs.World.Coords.Collect = 1;//next module
                                        }
                                        #endregion


                                    }
                                   
                                }


                                break;
                            }
                        case "NOT":
                            {
                                Funcs.World.Msgs.page = "Reloading Arena"; //NOTICE, reload arena
                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                Thread.Sleep(300);
                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                Thread.Sleep(300);
                                au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                Thread.Sleep(300);
                                Funcs.World.Msgs.status = "Reloading arena!";
                                break;
                            }
                        case "BA":
                            {
                                if (Funcs.World.Coords.arena == 1)
                                {
                                    Funcs.World.Msgs.page = "Arena Lobby"; //Arena lobby
                                    Funcs.World.Coords.bsx = 220;
                                    Funcs.World.Coords.bsy = 235; //Click Arena
                                    Funcs.World.Msgs.status = "Prepare for PVP!";
                                }
                                else
                                {
                                    Funcs.World.Msgs.status = "Going back to lobby...";
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                    Thread.Sleep(300);
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                    Thread.Sleep(300);
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                    Thread.Sleep(300);
                                }
                                    
                                break;
                            }
                        case "AR":
                            {
                                if (Funcs.World.Coords.arena == 1)
                                {
                                    Funcs.World.Msgs.page = "Arena Lobby"; //Arena lobby
                                    Funcs.World.Coords.bsx = 610;
                                    Funcs.World.Coords.bsy = 540; //Click Ready
                                    Funcs.World.Msgs.status = "Prepare for PVP!";
                                }
                                else
                                {
                                    Funcs.World.Msgs.status = "Going back to lobby...";
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                    Thread.Sleep(300);
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                    Thread.Sleep(300);
                                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                                    Thread.Sleep(300);
                                }
                               
                                break;
                            }
                            #endregion
                    }












                    #region Send/Collect


                    // if (Funcs.World.Coords.SendCollect == 1)
                    // {
                    //     Funcs.World.Coords.arena = 0;
                    //     Funcs.World.Coords.tower = 0;
                    //     Funcs.World.Coords.adv = 0;
                    //     Funcs.World.Coords.raid = 0;
                    //
                    //     switch (Funcs.World.Msgs.ocrtext)
                    //     {
                    //
                    //
                    //         case "Inbox":
                    //             {
                    //
                    //                 if (cbCollHonor.Checked == true)
                    //                 {
                    //                     au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 300, 200); //Click Honor Tab
                    //
                    //                 }
                    //                 if (cbCollKeys.Checked == true)
                    //                 {
                    //                     au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 400, 200);//Click Keys Tab
                    //
                    //                 }
                    //                 if (cbCollGold.Checked == true)
                    //                 {
                    //                     au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 500, 200);//Click Gold Tab
                    //
                    //                 }
                    //                 if (cbCollRubies.Checked == true)
                    //                 {
                    //                     au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 650, 200);//Click Rubies Tab
                    //
                    //                 }
                    //                 if (cbCollTicket.Checked == true)
                    //                 {
                    //                     au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 800, 200); //Click Ticket Tab
                    //
                    //                 }
                    //
                    //                 Funcs.World.Coords.bsx = 750; //Click mail
                    //                 Funcs.World.Coords.bsy = 550;
                    //                 Funcs.World.Msgs.status = "Collecting mail...";
                    //                 break;
                    //             }
                    //         default:
                    //             {
                    //
                    //                 #region Moving on
                    //
                    //                 //move on to next module
                    //                 //set the next module on
                    //                 if (cbTower.Checked == true)
                    //                 {
                    //                     Funcs.World.Coords.arena = 0;
                    //                     Funcs.World.Coords.tower = 1; //next module
                    //                     Funcs.World.Coords.adv = 0;
                    //                     Funcs.World.Coords.raid = 0;
                    //                     Funcs.World.Coords.SendCollect = 0;
                    //                 }
                    //                 else if (cbAdv.Checked == true)
                    //                 {
                    //                     Funcs.World.Coords.arena = 0;
                    //                     Funcs.World.Coords.tower = 0;
                    //                     Funcs.World.Coords.adv = 1; //next module
                    //                     Funcs.World.Coords.raid = 0;
                    //                     Funcs.World.Coords.SendCollect = 0;
                    //                 }
                    //                 else if (cbRaid.Checked == true)
                    //                 {
                    //                     Funcs.World.Coords.arena = 0;
                    //                     Funcs.World.Coords.tower = 0;
                    //                     Funcs.World.Coords.adv = 0;
                    //                     Funcs.World.Coords.raid = 1; //next module
                    //                     Funcs.World.Coords.SendCollect = 0;
                    //                 }
                    //                 else if (cbArena.Checked == true)
                    //                 {
                    //                     Funcs.World.Coords.arena = 1; //next module
                    //                     Funcs.World.Coords.tower = 0;
                    //                     Funcs.World.Coords.adv = 0;
                    //                     Funcs.World.Coords.raid = 0;
                    //                     Funcs.World.Coords.SendCollect = 0;
                    //                 }
                    //                 else
                    //                 {
                    //                     Funcs.World.Coords.arena = 0;
                    //                     Funcs.World.Coords.tower = 0;
                    //                     Funcs.World.Coords.adv = 0;
                    //                     Funcs.World.Coords.raid = 0;
                    //                     Funcs.World.Coords.SendCollect = 1;//next module
                    //                 }
                    //                 #endregion
                    //                 au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, 25, 50);
                    //                 
                    //
                    //                 break;
                    //             }
                    //
                    //     }
                    //
                    // }


                    #endregion


                
                }


                #region Click!


                if (Funcs.World.Msgs.oldstatus != Funcs.World.Msgs.status)
                {
                    AdvWorker.ReportProgress(i);
                    Funcs.World.Msgs.oldstatus = Funcs.World.Msgs.status;


                }
                if (Funcs.World.Coords.bsx != 0)
                {
                    au3.ControlClick("BlueStacks App Player", "", "", "Left", 1, Funcs.World.Coords.bsx, Funcs.World.Coords.bsy);
                }


               Thread.Sleep(100);
                Funcs.World.Coords.errPage = Funcs.World.Coords.errPage + 1;


                #endregion


                #region Search


                


                switch (Funcs.World.Coords.errPage) //Search screen
                {


                    #region Collect
                    case 1:
                        {
                            Funcs.World.Coords.rectx = 60; //Get keys
                            Funcs.World.Coords.recty = 50;
                            break;


                        }
                    case 2:
                        {


                            Funcs.World.Coords.rectx = 370; //Get Rubies
                            Funcs.World.Coords.recty = 50;
                            break;


                        }
                    case 3:
                        {
                            Funcs.World.Coords.rectx = 485; //Get HONOR
                            Funcs.World.Coords.recty = 50;
                            break;


                        }
                    #endregion


                    case 4:
                        {
                            Funcs.World.Coords.rectx = 300; //Disconnected
                            Funcs.World.Coords.recty = 305;
                            break;


                        }






                    #region for Arena
                    case 5:
                        {
                            Funcs.World.Coords.rectx = 295; //Use rubies?
                            Funcs.World.Coords.recty = 200;
                            break;
                        }
                    case 6:
                        {
                            Funcs.World.Coords.rectx = 775; //Check 0 arena keys
                            Funcs.World.Coords.recty = 580;
                            break;
                        }
                    case 7:
                        {
                            Funcs.World.Coords.rectx = 385; //Check 0 arena keys
                            Funcs.World.Coords.recty = 200;
                            break;
                        }


                    case 8:
                        {
                            Funcs.World.Coords.rectx = 15; //Check if lobby
                            Funcs.World.Coords.recty = 600;
                            break;
                        }


                    case 9:
                        {
                            Funcs.World.Coords.rectx = 350; //Check Commander Aragon
                            Funcs.World.Coords.recty = 400;
                            break;
                        }
                    case 10:
                        {
                            Funcs.World.Coords.rectx = 50; //Check 1st page/Arena and Tower
                            Funcs.World.Coords.recty = 50;
                            break;
                        }
                    case 11:
                        {
                            Funcs.World.Coords.rectx = 630; //Check 2nd page
                            Funcs.World.Coords.recty = 140;
                            break;
                        }


                    case 12:
                        {
                            Funcs.World.Coords.rectx = 152; //Check 3rd page
                            Funcs.World.Coords.recty = 150;
                            break;
                        }


                    #endregion


                    #region for Tower


                    case 13:
                        {
                            Funcs.World.Coords.rectx = 130; //Check adventure lobby AD
                            Funcs.World.Coords.recty = 145;
                            break;
                        }


                    case 14:
                        {
                            Funcs.World.Coords.rectx = 290; //Check MANAG 
                            Funcs.World.Coords.recty = 530;
                            break;
                        }
                    case 15:
                        {
                            Funcs.World.Coords.rectx = 50; //Check mastery
                            Funcs.World.Coords.recty = 140;
                            break;
                        }
                    case 16:
                        {
                            Funcs.World.Coords.rectx = 770; //Check Lobby
                            Funcs.World.Coords.recty = 590;
                            break;
                        }
                    case 17:
                        {
                            Funcs.World.Coords.rectx = 490; //Check Wave
                            Funcs.World.Coords.recty = 45;
                            break;
                        }
                    case 18:
                        {
                            Funcs.World.Coords.rectx = 260; //NO more keys UNAB
                            Funcs.World.Coords.recty = 190;
                            break;
                        }


                    #endregion


                    #region Mail


                    case 19:
                        {
                            Funcs.World.Coords.rectx = 800; //Check mail
                            Funcs.World.Coords.recty = 560;
                            break;
                        }
                    case 20:
                        {
                            Funcs.World.Coords.rectx = 430; //Check mail
                            Funcs.World.Coords.recty = 430;
                            break;
                        }


                    #endregion


                    #region Startup


                    case 21:
                        {
                            Funcs.World.Coords.rectx = 410; //Notice - Click X
                            Funcs.World.Coords.recty = 25;
                            break;
                        }
                    case 22:
                        {
                            Funcs.World.Coords.rectx = 800; //X - ads
                            Funcs.World.Coords.recty = 590;
                            break;
                        }
                    case 23:
                        {
                            Funcs.World.Coords.rectx = 770; //version check, tap to start
                            Funcs.World.Coords.recty = 35;
                            break;
                        }
                    case 24:
                        {
                            Funcs.World.Coords.rectx = 25; //Daily rewards - WEEK
                            Funcs.World.Coords.recty = 120;
                            break;
                        }
                    case 25:
                        {
                            Funcs.World.Coords.rectx = 775; //ads
                            Funcs.World.Coords.recty = 510;
                            break;
                        }
                    case 26:
                        {
                            Funcs.World.Coords.rectx = 770; //ads
                            Funcs.World.Coords.recty = 110;
                            break;
                        }
                    case 27:
                        {
                            Funcs.World.Coords.rectx = 210; //Special offers
                            Funcs.World.Coords.recty = 380;
                            break;
                        }
                    #endregion


                    default:
                        {
                            Funcs.World.Coords.errPage = 0;
                            Funcs.World.Msgs.status = "Again!";
                            break;
                        }


                }


                #endregion




            }
            AdvWorker.ReportProgress(0);
        }
             
            


        private void button2_Click(object sender, EventArgs e)
        {
            
            if (btnAI.Text == "Start AI")
            {


                if (ip == IntPtr.Zero) // Verify that Bluestacks is a running process.
                {
                    MessageBox.Show("Bluestacks is not running.");
                    return;
                }
                else
                {
                    this.textBoxHandle.Text = ip.ToString(); //Retrieve Window Caption
                }




                //Change the status of the buttons on the UI accordingly
                //The start button is disabled as soon as the background operation is started
                //The Cancel button is enabled so that the user can stop the operation 
                //at any point of time during the execution
                // Kickoff the worker thread to begin it's DoWork function.




                AdvWorker.RunWorkerAsync();
                btnAI.Text = "Stop AI";
            }
            else if (btnAI.Text == "Stop AI")
            {
                if (AdvWorker.IsBusy)
                {


                    // Notify the worker thread that a cancel has been requested.


                    // The cancel will not actually happen until the thread in the


                    // DoWork checks the m_oWorker.CancellationPending flag. 


                    AdvWorker.CancelAsync();
                    btnAI.Text = "Start AI";
                }
                
            }
        }


        private void cbArena_CheckedChanged(object sender, EventArgs e)
        {
            if (cbArena.Checked == true)
            {
                Funcs.World.Coords.arena = 1;
            }
            else
            {
                Funcs.World.Coords.arena = 0;
            }
        }


        private void cbTower_CheckedChanged(object sender, EventArgs e)
        {
            if (cbTower.Checked == true)
            {
                Funcs.World.Coords.tower = 1;
            }
            else
            {
                Funcs.World.Coords.tower = 0;
            }
        }


        private void cbSkill1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Funcs.World.Coords.skill1 = Convert.ToInt16( cbSkill1.Text);
        }


        private void cbSkill2_SelectedIndexChanged(object sender, EventArgs e)
        {
            Funcs.World.Coords.skill2 = Convert.ToInt16(cbSkill2.Text);
        }


        private void cbSkill3_SelectedIndexChanged(object sender, EventArgs e)
        {
            Funcs.World.Coords.skill3 = Convert.ToInt16(cbSkill3.Text);
        }


        public void cbFormation_SelectedIndexChanged(object sender, EventArgs e)
        {
            lblForm1.Location = new Point();
            if (cbFormation.Text == "Basic")
            {
                lblForm1.Location = new Point(69, 96);
                lblForm2.Location = new Point(69, 58);
                lblForm3.Location = new Point(29, 120);
                lblForm4.Location = new Point(29, 77);
                lblForm5.Location = new Point(29, 36);


            }
            else if (cbFormation.Text == "Balanced")
            {
                lblForm1.Location = new Point(69, 114);
                lblForm2.Location = new Point(69, 73);
                lblForm3.Location = new Point(69, 35);
                lblForm4.Location = new Point(29, 93);
                lblForm5.Location = new Point(29, 54);
            }
            else if (cbFormation.Text == "Offensive")
            {
                lblForm1.Location = new Point(69, 66);
                lblForm2.Location = new Point(29, 108);
                lblForm3.Location = new Point(29, 80);
                lblForm4.Location = new Point(29, 52);
                lblForm5.Location = new Point(29, 24);
            }
            else if (cbFormation.Text == "Defensive")
            {
                lblForm1.Location = new Point(69, 108);
                lblForm2.Location = new Point(69, 80);
                lblForm3.Location = new Point(69, 52);
                lblForm4.Location = new Point(69, 24);
                lblForm5.Location = new Point(29, 66);
            }
        }


        private void cbCollHonor_CheckedChanged(object sender, EventArgs e)
        {
            if (cbCollGold.Checked == true || cbCollHonor.Checked == true || cbCollKeys.Checked == true || cbCollRubies.Checked == true || cbCollTicket.Checked == true)
            {
                Funcs.World.Coords.Collect = 1;
            }
            else
            {
                Funcs.World.Coords.Collect = 0;
            }
        }


        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            
        }


        private void comboBox6_SelectedIndexChanged(object sender, EventArgs e)
        {
            Funcs.World.Coords.advskill1 = Convert.ToInt16(cbadvskill1.Text);
        }


        private void cbadvskill2_SelectedIndexChanged(object sender, EventArgs e)
        {
            Funcs.World.Coords.advskill2 = Convert.ToInt16(cbadvskill2.Text);
        }


        private void cbadvskill3_SelectedIndexChanged(object sender, EventArgs e)
        {
            Funcs.World.Coords.advskill3 = Convert.ToInt16(cbadvskill3.Text);
        }


        private void cbAdv_CheckedChanged(object sender, EventArgs e)
        {
            if (cbAdv.Checked == true)
            {
                Funcs.World.Coords.adv = 1;
            }
            else
            {
                Funcs.World.Coords.adv = 0;
            }
        }


        private void cbRaid_CheckedChanged(object sender, EventArgs e)
        {
            if (cbRaid.Checked == true)
            {
                Funcs.World.Coords.raid = 1;
            }
            else
            {
                Funcs.World.Coords.raid = 0;
            }
        }
    }
}
 
Top Bottom