Exemplo n.º 1
0
        /// <summary>
        /// Determines if the current
        /// </summary>
        /// /// <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 the text matches the expected hash</returns>
        public bool DialogBodyTextMatch(double expectedText, int allowedPixelDifference)
        {
            double match     = DialogBodyText();
            double tolerance = (allowedPixelDifference + 0.5) * PixelSize;  //use an extra half pixel to avoid rounding errors

            return(Numerical.WithinRange(expectedText, match, tolerance));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines if the absorption shield is at least 900 and therefore close to maximum
        /// </summary>
        /// <returns>true is the absorption shield has a value of 900-999 (999 is max value but 1000+ would break this method if made possible)</returns>
        protected bool AbsorptionShieldIsHigh()
        {
            int left   = 20;
            int right  = 31;
            int top    = 25;
            int bottom = 59;

            double hundredsPlaceWhite = Vision.FractionalMatchPiece(RGBHSBRangeFactory.White(), left, right, top, bottom);

            return(Numerical.WithinRange(hundredsPlaceWhite, 0.1476, 0.0005));    //TODO determine good values for range
        }
Exemplo n.º 3
0
        /// <summary>
        /// Eats a bite of rock cake if hitpoints are above 1
        /// </summary>
        /// <returns>true if a bite of rock cake is taken</returns>
        protected bool Hitpoints()
        {
            if (TimeSinceLastOverload < overloadDrainTime || Numerical.CloseEnough(overloadBoostTime, TimeSinceLastOverload, 0.02))
            {
                return(false);   //an overload might be taking effect or wearing off
            }

            const double    oneHitpoint       = 0.035714285714285712;
            RectangleBounds hitpoints         = Minimap.HitpointsDigitsArea();
            double          redHitpointsMatch = Vision.FractionalMatchPiece(HitpointsRed, hitpoints.Left, hitpoints.Right, hitpoints.Top, hitpoints.Bottom);

            if (Numerical.WithinRange(redHitpointsMatch, oneHitpoint, 0.01 * oneHitpoint) || (Minimap.Hitpoints() > 0.25))
            {
                return(false);   //hitpoints are already at 1 or an overload has just worn off and hitpoints are no longer red
            }

            Inventory.RightClickInventoryOption(0, 0, 1, false);   //guzzle rock cake
            SafeWaitPlus(1000, 250);
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Determines if the client is logged out
        /// </summary>
        /// <returns>true if we are verifiably logged out</returns>
        public bool IsLoggedOut(bool readWindow = false)
        {
            if (readWindow && !ReadWindow())
            {
                RunParams.LoggedIn = false;
                return(false);
            }

            Color color;
            Point loginOffset = LoginScreenOffset();
            int   height      = Height;
            int   top         = loginOffset.Y;
            int   centerX     = Center.X + loginOffset.X;
            int   checkRow    = Math.Min(Math.Max(0, height - 1), loginOffset.Y + ScreenScraper.LOGIN_WINDOW_HEIGHT + 1); //1 pixel below where the bottom of the login window should be
            int   xOffset     = (ScreenScraper.LOGIN_WINDOW_WIDTH / 2) + 2;
            int   blackPixels = 0;
            int   totalPixels = 0;

            for (int x = centerX - xOffset; x < centerX + xOffset; x++)
            {
                //check bottom of login box
                color        = Value[x, checkRow];
                blackPixels += ImageProcessing.ColorsAreEqual(color, Color.Black) ? 1 : 0;
                totalPixels++;
            }
            for (int y = top; y < checkRow; y++)  //check sides
            {
                //check left of login box
                color        = Value[centerX - xOffset, y];
                blackPixels += ImageProcessing.ColorsAreEqual(color, Color.Black) ? 1 : 0;
                totalPixels++;

                //check right of login box
                color        = Value[centerX + xOffset, y];
                blackPixels += ImageProcessing.ColorsAreEqual(color, Color.Black) ? 1 : 0;
                totalPixels++;
            }
            //assume we are logged out if a majority off the border pixels are perfectly black
            if ((blackPixels / ((double)totalPixels)) < 0.25)
            {
                return(false);
            }

            //Check for "Welcome to RuneScape" yellow text. We are probably logged out at this point.
            int topWelcome    = top + 241;
            int bottomWelcome = topWelcome + 13;
            int leftWelcome   = Center.X - 75;
            int rightWelcome  = leftWelcome + 146;

            bool[,] welcomeText = ImageProcessing.ColorFilterPiece(Value, RGBHSBRangeFactory.Yellow(), leftWelcome, rightWelcome, topWelcome, bottomWelcome);
            double welcomeMatch = ImageProcessing.FractionalMatch(welcomeText);

            if (!Numerical.WithinRange(welcomeMatch, 0.23275, 0.01)) //ex 0.23275
            {
                //Check for the "Enter your username/email & password." text.
                leftWelcome   = Center.X - 140;
                rightWelcome  = leftWelcome + 280;
                topWelcome    = top + 206;
                bottomWelcome = topWelcome + 10;
                welcomeText   = ImageProcessing.ColorFilterPiece(Value, RGBHSBRangeFactory.Yellow(), leftWelcome, rightWelcome, topWelcome, bottomWelcome);
                welcomeMatch  = ImageProcessing.FractionalMatch(welcomeText);

                if (!Numerical.WithinRange(welcomeMatch, 0.25234, 0.01)) //ex. 0.2523
                {
                    return(false);                                       //Could not find the welcome text or the enter text.
                }
            }

            RunParams.LoggedIn = false;
            return(true);
        }
Exemplo n.º 5
0
 public void WithinRangeTest(double test, double target, double offsetRange, bool close)
 {
     Assert.AreEqual(Numerical.WithinRange(target, test, offsetRange), close);
 }