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 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.º 3
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.º 4
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.º 5
0
        /// <summary>
        /// Chooses the next bot and makes any necessary transitions
        /// </summary>
        /// <returns>true if successful</returns>
        protected virtual bool NextBot()
        {
            if (BotParamsList.Count <= 1)
            {
                return(false);
            }

            int nextBot = BotParamsList.ActiveBot;

            do
            {
                nextBot = RNG.Next(0, BotParamsList.Count);
            } while (nextBot == BotParamsList.ActiveBot);
            BotParamsList.ActiveBot = nextBot;

            if (SelectBotAction())
            {
                CurrentBot = BotRegistry.GetSelectedBot(CurrentRunParams);
                CurrentBot.LogoutWhenDone = true;
            }
            else
            {
                CurrentBot = null;
            }

            return(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Drops all of the items in the inventory
        /// </summary>
        /// <param name="safeTab"></param>
        public void DropInventory(bool safeTab = true, bool onlyDropPreviouslyEmptySlots = true)
        {
            Screen.Value = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow());
            OpenInventory(safeTab);
            int effectiveY;

            Keyboard.ShiftDown();
            for (int x = 0; x < INVENTORY_COLUMNS; x++)
            {
                for (int y = 0; y < INVENTORY_ROWS; y++)
                {
                    effectiveY = (x % 2 == 0) ? y : INVENTORY_ROW_MAX - y;
                    if ((!onlyDropPreviouslyEmptySlots || EmptySlots[x, effectiveY]) && !SlotIsEmpty(x, effectiveY, false, false))
                    {
                        if (BotProgram.StopFlag)
                        {
                            Keyboard.ShiftUp();
                            return;
                        }
                        ClickInventory(x, effectiveY, false);
                        BotProgram.SafeWaitPlus(50, 25);
                    }
                }
            }
            Keyboard.ShiftUp();
        }
Ejemplo n.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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.º 12
0
        /// <summary>
        ///
        /// </summary>
        private void RunChatScanner()
        {
            while (_scanChat == true && !BotProgram.StopFlag)
            {
                if (Screen.LooksValid() && Screen.IsLoggedIn())
                {
                    ScanChat();
                }

                BotProgram.SafeWait(10000);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Clicks on a stationary object
        /// </summary>
        /// <param name="stationaryObject">color filter for the stationary object</param>
        /// <param name="tolerance">maximum allowable distance between two subsequent checks to consider both objects the same object</param>
        /// <param name="afterClickWait">time to wait after clicking on the stationary object</param>
        /// <param name="maxWaitTime">maximum time to wait before giving up</param>
        /// <returns></returns>
        internal bool ClickStationaryObject(ColorFilter stationaryObject, double tolerance, int afterClickWait, int maxWaitTime, int minimumSize)
        {
            Blob foundObject;

            if (Vision.LocateStationaryObject(stationaryObject, out foundObject, tolerance, maxWaitTime, minimumSize))
            {
                Mouse.LeftClick(foundObject.Center.X, foundObject.Center.Y);
                BotProgram.SafeWaitPlus(afterClickWait, 0.2 * afterClickWait);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 14
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.º 15
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.º 16
0
 /// <summary>
 /// Casts a spell on an item in the inventory. Assumes that casting the spell reopens the spellbook.
 /// </summary>
 /// <param name="spellBookX"></param>
 /// <param name="spellBookY"></param>
 /// <param name="castTime">cooldown time of the spell</param>
 /// <param name="x">x inventory or screen coordinate within the inventory</param>
 /// <param name="y">y inventory or screen coordinate within the inventory</param>
 /// <param name="safeTab"></param>
 /// <returns>true if the spell is cast successfully</returns>
 private bool CastInventorySpell(int spellBookX, int spellBookY, int castTime, int x, int y, bool safeTab = true, bool autoWait = true)
 {
     if (ScreenToInventory(ref x, ref y))
     {
         OpenSpellbook(safeTab);
         ClickSpellbookStandard(spellBookX, spellBookY, safeTab);
         SelectedTab = TabSelect.Inventory;
         ClickInventory(x, y, false);
         SelectedTab = TabSelect.Spellbook;
         if (autoWait)
         {
             BotProgram.SafeWaitPlus(castTime, 100);
         }
         return(true);
     }
     return(false);
 }
Ejemplo n.º 17
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.º 18
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.º 19
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.º 20
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);
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Uses an item in the inventory on another item in the inventory
 /// </summary>
 /// <param name="subjectItem">the item to use on another item</param>
 /// <param name="objectItem">the item to be used on</param>
 /// <returns>true if the operation seems to succeed</returns>
 public void UseItemOnItem(Point subjectItem, Point objectItem, bool safeTab = false)
 {
     ClickInventory(subjectItem.X, subjectItem.Y, safeTab);
     BotProgram.SafeWaitPlus(200, 30);
     ClickInventory(objectItem.X, objectItem.Y, false);
 }
Ejemplo n.º 22
0
        public static BotProgram GetSelectedBot(RunParams runParams)
        {
            BotProgram bot = null;

            switch (runParams.BotAction)
            {
            case BotActions.LesserDemon:
                return(new LesserDemon(runParams));

            case BotActions.GoldBracelets:
                return(new GoldBracelets(runParams));

            case BotActions.Cannonballs:
                return(new Cannonballs(runParams));

            case BotActions.NightmareZoneD:
                return(new NightmareZoneD(runParams));

            case BotActions.FletchShortBows:
                return(new Use1On27(runParams, Use14On14.FLETCH_BOW_TIME));

            case BotActions.StringBows:
                return(new Use14On14(runParams, Use14On14.STRING_BOW_TIME));

            case BotActions.MakeUnfinishedPotions:
                return(new UnfinishedPotions(runParams));

            case BotActions.MakePotionsSimple:
                return(new Use14On14(runParams, Herblore.MAKE_UNFINISHED_POTION_TIME));

            case BotActions.MakePotionsFull:
                return(new MakePotionFull(runParams));

            case BotActions.AgilityGnomeStronghold:
                return(new AgilityGnomeStronghold(runParams));

            case BotActions.AgilitySeersVillage:
                return(new AgilitySeersVillage(runParams));

            case BotActions.WillowTrees:
                return(new WillowChopping(runParams));

            case BotActions.TeaStall:
                return(new TeaStall(runParams));

            case BotActions.CutGems:
                return(new Use1On27(runParams, Use1On27.CUT_GEM_TIME));

            case BotActions.EnchantLevel2:
                return(new Enchant(runParams, 2));

            case BotActions.IronOre:
                return(new IronPowerMining(runParams));

            case BotActions.Login:
                return(new LogInToGame(runParams));

            case BotActions.DoNothing:
                return(new DoNothing(runParams));

            case BotActions.ButlerSawmill:
                return(new ButlerSawmill(runParams));

            case BotActions.BarbarianFishing:
                return(new BarbarianFishing(runParams));

            case BotActions.Firemaking:
                return(new Firemaking(runParams));

            case BotActions.KnightOfArdougne:
                return(new KnightOfArdougne(runParams));

            case BotActions.TanHides:
                return(new TanHides(runParams));

            case BotActions.MotherlodeMine:
                return(new MotherlodeMine(runParams));

            case BotActions.NatureRings:
                return(new NatureRings(runParams));

            case BotActions.Serum207:
                return(new Serum207(runParams));

            case BotActions.Falconry:
                return(new Falconry(runParams));

            case BotActions.CleanHerbs:
                return(new ClickAll28(runParams, ClickAll28.HERB_CLEAN_TIME));
            }
            return(bot);
        }