Beispiel #1
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();
        }
Beispiel #2
0
 /// <summary>
 /// Takes a screenshot of the game
 /// </summary>
 /// <param name="overwrite">set to true to take a screenshot even if one already exists</param>
 private void ManuallySetScreen(bool overwrite)
 {
     if (overwrite || Screen == null)
     {
         Screen.Value = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow(true));
     }
 }
Beispiel #3
0
        /// <summary>
        /// Finds the next slot that matches a single color filter
        /// </summary>
        /// <param name="emptySlotNumber">Set to a number higher than 1 to find the second, third, etc empty slot.</param>
        /// <returns>The first matching inventory slot scanning left to right then top to bottom. Returns null if no match is found.</returns>
        public Point?FirstColorMatchingSlot(ColorFilter colorFilter, double matchStrictness = 0.1, bool safeTab = true, int emptySlotNumber = 1)
        {
            emptySlotNumber = (int)Numerical.LimitToRange(emptySlotNumber, 1, INVENTORY_CAPACITY);
            if (OpenInventory(safeTab))
            {
                Screen.Value = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow());
            }
            Point?inventorySlot;

            int slotCount = 0;

            for (int slot = 0; slot < INVENTORY_CAPACITY; slot++)
            {
                inventorySlot = InventoryIndexToCoordinates(slot);
                if (SlotMatchesColorFilter(inventorySlot.Value.X, inventorySlot.Value.Y, colorFilter, matchStrictness, false, false))
                {
                    slotCount++;
                    if (slotCount >= emptySlotNumber)
                    {
                        return(inventorySlot);
                    }
                }

                if (BotProgram.StopFlag)
                {
                    return(null);
                }
            }

            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// Waits for the "Enter amount:" prompt to appear over the chat box
        /// </summary>
        /// <param name="timeout">Gives up after the max wait time has elapsed</param>
        /// <returns>true if the prompt appears</returns>
        public static bool WaitForEnterAmount(Process rsClient, int timeout)
        {
            Point     screenSize = ScreenScraper.GetWindowSize(rsClient);
            const int asterisk   = 91235;
            const int left       = 252;
            const int right      = 265;
            int       top        = screenSize.Y - 81;
            int       bottom     = screenSize.Y - 69;

            Color[,] screen;
            Stopwatch watch = new Stopwatch();

            watch.Start();
            long asteriskHash;

            while (watch.ElapsedMilliseconds < timeout)
            {
                if (BotProgram.StopFlag)
                {
                    return(false);
                }

                screen       = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow());
                screen       = ImageProcessing.ScreenPiece(screen, left, right, top, bottom);
                asteriskHash = ImageProcessing.ColorSum(screen);
                if (Numerical.CloseEnough(asterisk, asteriskHash, 0.01))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #5
0
        /// <summary>
        /// Wrapper for ScreenScraper.CaptureWindow
        /// </summary>
        internal bool ReadWindow(bool checkClient = true, bool fastCapture = false)
        {
            if (BotProgram.StopFlag || checkClient && !RSClient.PrepareClient())
            {
                return(false);
            }

            Value = null;

            try
            {
                LastScreenShot = DateTime.Now;
                Bitmap         = ScreenScraper.CaptureWindow(fastCapture);
                Value          = ScreenScraper.GetRGB(Bitmap);
            }
            catch
            {
                return(false);
            }
            finally
            {
                if (Bitmap != null)
                {
                    Bitmap.Dispose();
                }
            }

            return((Value != null) && (Height > 0) && (Width > 0));
        }
        /// <summary>
        /// Waits for the furnace crafting popup to appear
        /// </summary>
        /// <returns>true if the popup is found</returns>
        public bool WaitForPopup(int timeout)
        {
            const int popupTitleHash = 842393;

            Color[,] screen;
            Stopwatch watch = new Stopwatch();

            watch.Start();
            long titleHash;

            int left   = Left + 144;
            int right  = Left + 344;
            int top    = Top + 4;
            int bottom = Top + 23;

            while (watch.ElapsedMilliseconds < timeout)
            {
                if (BotProgram.StopFlag)
                {
                    return(false);
                }

                screen    = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow());
                screen    = ImageProcessing.ScreenPiece(screen, left, right, top, bottom);
                titleHash = ImageProcessing.ColorSum(screen);

                if (Numerical.CloseEnough(popupTitleHash, titleHash, 0.001))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #7
0
        /// <summary>
        /// Set the list of empty inventory slots
        /// </summary>
        public void SetEmptySlots()
        {
            OpenInventory();
            Screen.Value = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow());
            EmptySlots   = new bool[INVENTORY_COLUMNS, INVENTORY_ROWS];

            for (int x = 0; x < INVENTORY_COLUMNS; x++)
            {
                for (int y = 0; y < INVENTORY_ROWS; y++)
                {
                    EmptySlots[x, y] = SlotIsEmpty(x, y, false, false);
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// Determines if the bank screen is currently visible
        /// </summary>
        /// <returns>true if the bank is open</returns>
        public bool NPCContactIsOpen()
        {
            int left   = Left + 182;
            int right  = Left + 316;
            int top    = Top + 12;
            int bottom = Top + 25;

            Color[,] screen;
            screen = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow());
            screen = ImageProcessing.ScreenPiece(screen, left, right, top, bottom);
            double titleMatch = ImageProcessing.FractionalMatch(screen, RGBHSBRangeFactory.BankTitle());

            return(titleMatch > 0.05);
        }
Beispiel #9
0
        /// <summary>
        /// Determines if the bank screen is currently visible
        /// </summary>
        /// <returns>true if the bank is open</returns>
        public bool BankIsOpen()
        {
            const double minTitleMatch = 0.05;
            double       titleMatch;
            int          left   = Left + 162;
            int          right  = Left + 325;
            int          top    = Top + 8;
            int          bottom = Top + 25;

            Color[,] screen;
            screen     = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow());
            screen     = ImageProcessing.ScreenPiece(screen, left, right, top, bottom);
            titleMatch = ImageProcessing.FractionalMatch(screen, RGBHSBRangeFactory.BankTitle());

            return(titleMatch > minTitleMatch);
        }
Beispiel #10
0
        /// <summary>
        /// Determines if a bank slot is occupied by an empty placeholder
        /// </summary>
        /// <param name="screen">image of the entire game screen</param>
        /// <returns></returns>
        public bool SlotIsEmpty(int x, int y, Color[,] screen)
        {
            Rectangle counterOffset = new Rectangle(-16, -17, 8, 11);
            Point     slotLocation  = ItemSlotLocation(x, y).Value;
            int       left          = slotLocation.X + counterOffset.X;
            int       right         = slotLocation.X + counterOffset.X + counterOffset.Width;
            int       top           = slotLocation.Y + counterOffset.Y;
            int       bottom        = slotLocation.Y + counterOffset.Y + counterOffset.Height;

            if (screen == null)
            {
                screen = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow());
            }
            screen = ImageProcessing.ScreenPiece(screen, left, right, top, bottom);
            double slotCounterMatch = ImageProcessing.FractionalMatch(screen, RGBHSBRangeFactory.BankSlotPlaceholderZero());

            return(slotCounterMatch > 0.1);
        }
Beispiel #11
0
        /// <summary>
        /// Wrapper for ScreenScraper.CaptureWindow
        /// </summary>
        public bool ReadWindow(bool fastCapture = false)
        {
            Bitmap screenshot;

            try
            {
                screenshot   = ScreenScraper.CaptureWindow(fastCapture);
                Screen.Value = ScreenScraper.GetRGB(screenshot);
            }
            catch
            {
                return(false);
            }

            bool success = (screenshot != null) && (Screen.Width > 0) && (Screen.Height > 0);

            screenshot.Dispose();
            return(success);
        }
Beispiel #12
0
        /// <summary>
        /// Waits for the right-click popup to appear
        /// </summary>
        /// <param name="timeout"></param>
        /// <returns></returns>
        public virtual bool WaitForPopup(int timeout = 3000, CheckHeight checkHeight = CheckHeight.None)
        {
            Color[,] screen = null;
            Stopwatch watch = new Stopwatch();

            watch.Start();
            while (watch.ElapsedMilliseconds < timeout)
            {
                if (BotProgram.SafeWait(200))
                {
                    return(false);
                }
                screen = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow());
                if (PopupExists(screen) && PopupIsCorrectHeight(screen, checkHeight))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #13
0
        /// <summary>
        /// Determines if the given inventory slot matches a color filter
        /// </summary>
        /// <param name="x">slots away from the leftmost column (0-3) or screen x coordinate</param>
        /// <param name="y">slots away from the topmost column (0-6) or screen y coordinate</param>
        /// <param name="colorFilter">color range to match on</param>
        /// <param name="readScreen">set to true to reread the game screen before checking</param>
        /// <param name="safeTab">set to true to switch to the inventory tab even if it already thinks that it is selected</param>
        /// <returns>true if the slot matches a color filter</returns>
        public bool SlotMatchesColorFilter(int xSlot, int ySlot, ColorFilter colorFilter, double matchStrictness = 0.1, bool readScreen = false, bool safeTab = false)
        {
            int x = xSlot;
            int y = ySlot;

            InventoryToScreen(ref x, ref y);
            if (OpenInventory(safeTab) || readScreen)
            {
                Screen.Value = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow(true));
            }

            int xOffset = (INVENTORY_GAP_X / 2) - 1;
            int yOffset = (INVENTORY_GAP_Y / 2) - 1;
            int left    = x - xOffset;
            int right   = x + xOffset;
            int top     = y - yOffset;
            int bottom  = y + yOffset;

            Color[,] itemIcon = ImageProcessing.ScreenPiece(Screen, left, right, top, bottom);
            double colorMatch = ImageProcessing.FractionalMatch(itemIcon, colorFilter);

            return(colorMatch > matchStrictness);
        }