예제 #1
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);
        }
예제 #2
0
        /// <summary>
        /// Finds the closest bank booth in the Port Phasmatys bank
        /// </summary>
        /// <returns>True if the bank booths are found</returns>
        internal bool LocateBankBoothPhasmatys(out Blob bankBooth)
        {
            bankBooth = null;
            const int    numberOfBankBooths         = 6;
            const double minBoothWidthToHeightRatio = 2.3667;   //ex 2.6667
            const double maxBoothWidthToHeightRatio = 3.1333;   //ex 2.8333
            int          left   = Screen.Center.X - Screen.ArtifactLength(0.5);
            int          right  = Screen.Center.X + Screen.ArtifactLength(0.3);
            int          top    = Screen.Center.Y - Screen.ArtifactLength(0.15);
            int          bottom = Screen.Center.Y + Screen.ArtifactLength(0.2);

            Screen.ReadWindow();
            Point offset;

            bool[,] bankBooths = Vision.ColorFilterPiece(RGBHSBRangeFactory.BankBoothPhasmatys(), left, right, top, bottom, out offset);
            List <Blob> boothBlobs         = new List <Blob>();
            List <Blob> possibleBoothBlobs = ImageProcessing.FindBlobs(bankBooths, false, MinBankBoothSize, MaxBankBoothSize);  //list of blobs from biggest to smallest

            possibleBoothBlobs.Sort(new BlobProximityComparer(Screen.Center));
            double widthToHeightRatio, rectangularity;

            //Remove blobs that aren't bank booths
            foreach (Blob possibleBooth in possibleBoothBlobs)
            {
                widthToHeightRatio = (possibleBooth.Width / (double)possibleBooth.Height);
                rectangularity     = Geometry.Rectangularity(possibleBooth);
                if (Numerical.WithinBounds(widthToHeightRatio, minBoothWidthToHeightRatio, maxBoothWidthToHeightRatio) && rectangularity > 0.75)
                {
                    boothBlobs.Add(possibleBooth);
                }
            }

            if (boothBlobs.Count != numberOfBankBooths)
            {
                return(false);   //We either failed to locate all of the booths or identified something that was not actually a booth.
            }

            //Reduce the blob list to the bank booths
            boothBlobs.Sort(new BlobHorizontalComparer()); //sort from left to right
            boothBlobs.RemoveAt(3);                        //remove the unusable booths without tellers
            boothBlobs.RemoveAt(0);
            bankBooth = Blob.ClosestBlob(new Point(Screen.Center.X - left, Screen.Center.Y - top), boothBlobs);
            bankBooth.ShiftPixels(offset.X, offset.Y);
            return(true);
        }