Ejemplo n.º 1
0
        /// <summary>
        /// Clicks through a specified number of text screens with the space bar.
        /// </summary>
        /// <param name="screenCount">number of text screens to click through</param>
        /// <param name="timeout">max time allowed to wait for each text screen</param>
        /// <returns></returns>
        public bool ClickThroughTextScreens(int screenCount, int timeout)
        {
            Stopwatch watch = new Stopwatch();
            int       screensClicked = 0;
            double    textHash = 0, priorText = 0;

            watch.Start();
            while (screensClicked < screenCount && watch.ElapsedMilliseconds < timeout && !BotProgram.StopFlag)
            {
                textHash = DialogBodyText();
                if (textHash != priorText)
                {
                    priorText = textHash;
                    Keyboard.Space();
                    screensClicked++;
                    BotProgram.SafeWaitPlus(500, 100);
                    watch.Restart();
                }
                else
                {
                    BotProgram.SafeWait(100);
                }
            }

            return(screensClicked == screenCount);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Waits until the player stops moving
        /// </summary>
        /// <param name="timeout">maximum time in milliseconds to wait</param>
        /// <returns>true if player stops moving, false if we give up</returns>
        internal bool WaitDuringPlayerAnimation(int timeout = 180000, double colorStrictness = 0.95, double locationStrictness = 0.99)
        {
            int xOffset = Screen.ArtifactLength(0.06);
            int yOffset = Screen.ArtifactLength(0.06);

            Color[,] pastImage    = null;
            Color[,] presentImage = null;
            Color[,] futureImage  = null;

            Stopwatch watch = new Stopwatch();

            watch.Start();

            while (!ImageProcessing.ImageMatch(pastImage, presentImage, colorStrictness, locationStrictness) ||
                   !ImageProcessing.ImageMatch(presentImage, futureImage, colorStrictness, locationStrictness))
            {
                if (BotProgram.StopFlag || watch.ElapsedMilliseconds >= timeout || BotProgram.SafeWait(100))
                {
                    return(false);   //timeout
                }

                Screen.ReadWindow(true, true);
                pastImage    = presentImage;
                presentImage = futureImage;
                futureImage  = ScreenPiece(Screen.Center.X - xOffset, Screen.Center.X + xOffset, Screen.Center.Y - yOffset, Screen.Center.Y + yOffset);
            }

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Moves the character to a bank icon on the minimap
        /// </summary>
        /// <returns>true if the bank icon is found</returns>
        internal virtual bool MoveToBank(int maxRunTimeToBank = 10000, bool readWindow = true, int minBankIconSize = 4, int randomization = 3, Point?moveTarget = null)
        {
            if (readWindow)
            {
                Screen.ReadWindow();
            }
            if (moveTarget == null)
            {
                moveTarget = new Point(0, 0);
            }

            Point offset;

            bool[,] minimapBankIcon = Minimap.MinimapFilter(RGBHSBRangeFactory.BankIconDollar(), out offset);
            Blob bankBlob = ImageProcessing.BiggestBlob(minimapBankIcon);

            if (bankBlob == null || bankBlob.Size < minBankIconSize)
            {
                return(false);
            }

            Point clickLocation = new Point(offset.X + bankBlob.Center.X + moveTarget.Value.X, offset.Y + bankBlob.Center.Y + moveTarget.Value.Y);

            Mouse.LeftClick(clickLocation.X, clickLocation.Y, randomization);
            BotProgram.SafeWait(maxRunTimeToBank);

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Waits on the client to log in after clicking through the welcome screen
        /// </summary>
        /// <returns>true if the log in is verified, false if we time out waiting</returns>
        public bool ConfirmLogin()
        {
            //Wait for up to 60 seconds
            for (int i = 0; i < 60; i++)
            {
                if (BotProgram.StopFlag)
                {
                    return(false);
                }
                ReadWindow();
                if (IsLoggedIn())
                {
                    return(true);
                }
                else
                {
                    if (BotProgram.StopFlag)
                    {
                        return(false);
                    }
                    BotProgram.SafeWait(1000);
                }
            }

            return(false);   //We timed out waiting.
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Determines if the welcome screen has been reached
        /// </summary>
        /// <returns>true if the welcome screen has been reached, false if not or if the StopFlag is raised</returns>
        public bool ConfirmWelcomeScreen(out Point?clickLocation)
        {
            clickLocation = null;

            //Wait up to 60 seconds
            for (int i = 0; i < 60; i++)
            {
                if (BotProgram.StopFlag)
                {
                    return(false);
                }
                ReadWindow();

                if (IsWelcomeScreen(out clickLocation))
                {
                    return(true);
                }
                else
                {
                    if (BotProgram.StopFlag)
                    {
                        return(false);
                    }
                    BotProgram.SafeWait(1000);
                }
            }
            return(false);   //We timed out waiting.
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Waits for the disappearance of the red flag on the minimap which indicates the target to move to
        /// </summary>
        /// <param name="timeout">maximum time to wait for the red flag to disappear</param>
        /// <returns>true if the red flag disappears</returns>
        public bool WaitDuringMovement(int timeout = 30000, int startupWait = 0)
        {
            const int redFlagMinSize = 20;  //ex 28
            const int redFlagMaxSize = 43;
            Stopwatch watch          = new Stopwatch();

            watch.Start();
            Blob redFlag;

            BotProgram.SafeWait(startupWait);
            while (watch.ElapsedMilliseconds < timeout)
            {
                if (BotProgram.StopFlag)
                {
                    return(false);
                }
                ReadWindow();
                redFlag = LocateObject(RGBHSBRangeFactory.GenericColor(Color.Red), redFlagMinSize, redFlagMaxSize);
                if (redFlag == null)
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Casts telegrab at the specified location on the screen
 /// </summary>
 /// <param name="screen"></param>
 /// <param name="x">x pixel location on the screen</param>
 /// <param name="y">y pixel location on the screen</param>
 public void Telegrab(int x, int y, bool safeTab = true, bool autoWait = true)
 {
     ClickSpellbookStandard(5, 2, safeTab);
     Mouse.LeftClick(x, y, 1);
     if (autoWait)
     {
         BotProgram.SafeWait(5000, 300); //telegrab takes about 5 seconds
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Attempts to teleport to the specified location
        /// </summary>
        /// <param name="location">location to teleport to</param>
        /// <param name="wait">whether to wait for expected teleport duration</param>
        /// <returns>False if the player doesn't have the runes to teleport</returns>
        public bool HoverStandardTeleport(StandardTeleports location, bool wait = true, bool safeTab = false)
        {
            Point spellbookSlot = TeleportToSpellBookSlot(location);

            HoverSpellbookStandard(spellbookSlot.X, spellbookSlot.Y, safeTab);
            if (wait)
            {
                BotProgram.SafeWait(TELEPORT_DURATION);
            }
            return(true);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Uses an amulet of glory to teleport the player
 /// </summary>
 /// <param name="teleportLocation">teleport location from the GloryTeleports enum</param>
 /// <returns>true if successful</returns>
 public bool GloryTeleport(GloryTeleports teleportLocation, bool waitForTeleport = true)
 {
     if (!EquipItemRightClick(1, 1, (int)teleportLocation))
     {
         return(false);
     }
     if (waitForTeleport)
     {
         BotProgram.SafeWait(TELEPORT_DURATION);
     }
     return(true);
 }
Ejemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        private void RunChatScanner()
        {
            while (_scanChat == true && !BotProgram.StopFlag)
            {
                if (Screen.LooksValid() && Screen.IsLoggedIn())
                {
                    ScanChat();
                }

                BotProgram.SafeWait(10000);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Waits for a specified inventory slot to be filled.
        /// </summary>
        /// <param name="nextEmptySlot">The slot that expect to fill.</param>
        /// <param name="maxWaitTime">THe maximum time in milliseconds that we should wait for this slot to be filled.</param>
        /// <returns>True if slot is filled while waiting.</returns>
        public bool WaitForSlotToFill(Point nextEmptySlot, int maxWaitTime)
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();
            while (watch.ElapsedMilliseconds < maxWaitTime && !BotProgram.StopFlag)
            {
                if (!SlotIsEmpty(nextEmptySlot, true, false))
                {
                    return(true);
                }
                BotProgram.SafeWait(50);
            }
            return(false);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Waits for an expected set of text to appear in the textbox
        /// </summary>
        /// <param name="timeout">time in milliseconds to keep trying before giving up</param>
        /// <param name="filter">color filter to match the expected text color</param>
        /// <param name="expectedText">hash of the expected text body</param>
        /// <param name="allowedPixelDifference">maximum allowed deviation from the expected hash value in pixels</param>
        /// <param name="filter">color filter to match the expected text color</param>
        /// <returns>true if matching text appears</returns>
        public bool WaitForExpectedText(double expectedText, int allowedPixelDifference, int timeout)
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();
            while (watch.ElapsedMilliseconds < timeout && !BotProgram.StopFlag)
            {
                Screen.Value = ScreenScraper.ReadWindow(true);
                if (DialogBodyTextMatch(expectedText, allowedPixelDifference))
                {
                    return(true);
                }
                BotProgram.SafeWait(100);
            }
            return(false);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Makes sure that a client is running and starts it if it isn't
        /// </summary>
        /// <param name="forceRestart">Set to true to force a client restart even if the client is already running</param>
        /// <returns>true if client is successfully prepared</returns>
        public bool PrepareClient(bool forceRestart = false)
        {
            if (!forceRestart && ScreenScraper.ProcessExists(Value))
            {
                return(true);
            }

            Process   client    = null;
            Stopwatch longWatch = new Stopwatch();

            longWatch.Start();
            while (longWatch.ElapsedMilliseconds < UnitConversions.HoursToMilliseconds(24) && !BotProgram.StopFlag)
            {
                if (!ScreenScraper.RestartClient(ref client, RunParams.RuneScapeClient, RunParams.ClientFlags))
                {
                    BotProgram.SafeWait(5000);
                    continue;
                }
                //Successful restart
                Value = client;

                Stopwatch watch = new Stopwatch();
                watch.Start();
                //Wait for cient to be visually recognized.
                do
                {
                    BotProgram.SafeWait(UnitConversions.SecondsToMilliseconds(5));
                    if (Screen.ReadWindow(false) && (Screen.IsLoggedOut(false) || Screen.IsLoggedIn(false)))
                    {
                        return(true);
                    }
                }while ((watch.ElapsedMilliseconds < UnitConversions.MinutesToMilliseconds(5)) && !BotProgram.StopFlag);
            }

            if (!BotProgram.StopFlag)
            {
                const string errorMessage = "Client did not start correctly";
                MessageBox.Show(errorMessage);
            }

            Value = null;
            return(false);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Mouses over a single point and left-clicks it if it matches the specified mouseover text color.
        /// </summary>
        /// <param name="mouseover">point to mouse over</param>
        /// <param name="textColor">color of text expected to be in the top-left on mouseover</param>
        /// <param name="click">set to false to hover and check without clicking</param>
        /// <param name="randomization">maximum number of pixels from the center of the blob that it is safe to click</param>
        /// <param name="maxWait">max time to wait before concluding that the mouse over failed</param>
        /// <param name="lagTime">time to wait before checking and clicking after mousing over</param>
        /// <returns>true if a matching object is found and clicked on</returns>
        internal bool MouseOver(Point mouseover, ColorFilter textColor, bool click = true, int randomization = 5, int maxWait = 1000, int lagTime = 250)
        {
            randomization = (int)((Screen.Height / 1000.0) * randomization);
            mouseover     = Probability.GaussianCircle(mouseover, randomization);
            Mouse.Move(mouseover.X, mouseover.Y);
            if (BotProgram.SafeWait(lagTime))
            {
                return(false);
            }

            if (Vision.WaitForMouseOverText(textColor, maxWait))
            {
                if (click)
                {
                    Mouse.LeftClick(mouseover.X, mouseover.Y, 0, 0);
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Opens a tab on the inventory UI if it is not already open
        /// </summary>
        /// <param name="tab">tab to open</param>
        /// <param name="x">x coordinate of the center of the tab</param>
        /// <param name="y">y coordinate of the center of the tab</param>
        /// <param name="safeTab">set to true to click on tab even if it is already believed to be open</param>
        /// <returns>true if the tab is clicked on</returns>
        private bool OpenTab(TabSelect tab, int offsetRight, int offsetBottom, bool safeTab = false)
        {
            if (!safeTab && SelectedTab == tab)
            {
                return(false);
            }
            Point?screenSize = ScreenScraper.GetScreenSize();

            if (screenSize == null)
            {
                return(false);
            }

            int x = screenSize.Value.X - offsetRight;
            int y = screenSize.Value.Y - offsetBottom;

            Mouse.LeftClick(x, y, 10);
            BotProgram.SafeWait(TAB_SWITCH_WAIT);
            SelectedTab = tab;
            return(true);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Clicks a point on the minimap specified by radial coordinates
        /// </summary>
        /// <param name="angle">counterclockwise angle from the right direction in degrees</param>
        /// <param name="radius">fraction of the radius of the minimap to move (0-1)</param>
        /// <param name="waitToArrive">set to true to wait until the player almost reaches the destination before returning</param>
        /// <param name="randomization">maximum allowed randomized deviation from the exact click point</param>
        /// <returns>true if successful</returns>
        public bool MoveToPosition(double angle, double radius, bool waitToArrive, int randomization, int minimumWaitTime = 0, Point?restMouse = null, int timeout = 30000)
        {
            radius = Numerical.LimitToRange(radius, 0, 1);
            Point click = RadialToRectangular(angle, radius);

            Mouse.LeftClick(click.X, click.Y, randomization);
            if (waitToArrive)
            {
                //safe minimum time before we expect the red flag to disappear
                //This is also necessary to ensure that the red flag appears on the minimap before we start looking for it.
                Stopwatch watch = new Stopwatch();
                watch.Start();
                int waitTime = Math.Max(minimumWaitTime, (int)(500 + radius * 2500 - watch.ElapsedMilliseconds));
                if (BotProgram.SafeWait(waitTime))
                {
                    return(false);
                }
                Mouse.Move(restMouse);
                return(WaitDuringMovement(timeout));
            }
            Mouse.Move(restMouse);
            return(true);
        }