/// <summary>
        /// Finds the closest trunk for a climbable tree
        /// </summary>
        /// <param name="trunkColor">color range defining a climbable tree trunk</param>
        /// <param name="trunk">returns a climbable tree trunk if found</param>
        /// <param name="minimumSize">not used</param>
        /// <returns>true if a climbable tree trunk is found</returns>
        private bool FindTreeTrunk(ColorFilter trunkColor, out Blob trunk, int minimumSize = 1, int maximumSize = int.MaxValue)
        {
            trunk = null;
            Screen.ReadWindow();
            bool[,] objectPixels = Vision.ColorFilter(trunkColor);
            Vision.EraseClientUIFromMask(ref objectPixels);
            List <Blob> possibleTrunks = ImageProcessing.FindBlobs(objectPixels, false, MinTreeTrunkSize, MaxTreeTrunkSize);

            if (possibleTrunks.Count == 0)
            {
                return(false);
            }

            trunk = possibleTrunks[0];
            double rectangularity;
            double mostRectangular = Geometry.Rectangularity(trunk);

            for (int i = 1; i < possibleTrunks.Count; i++)
            {
                rectangularity = Geometry.Rectangularity(possibleTrunks[i]);
                if (rectangularity > mostRectangular)
                {
                    trunk           = possibleTrunks[i];
                    mostRectangular = rectangularity;
                }
            }
            return(true);
        }
Пример #2
0
        /// <summary>
        /// Looks for, picks up, and alchs a drop that matches a ColorRange
        /// </summary>
        /// <param name="screenDropArea"></param>
        /// <param name="referenceColor"></param>
        /// <param name="minimumSize">minimum number of pixels needed to </param>
        /// <returns>True if an item is found, picked up, and alched. May be false if no item is found or if there isn't inventory space to pick it up.</returns>
        private bool FindAndAlch(Color[,] screenDropArea, Point offset, ColorFilter referenceColor, int minimumSize)
        {
            bool[,] matchedPixels = Vision.ColorFilter(screenDropArea, referenceColor);
            Blob biggestBlob = ImageProcessing.BiggestBlob(matchedPixels);

            if (biggestBlob.Size < minimumSize)
            {
                return(false);   //Nothing to grab.
            }

            Point blobCenter = biggestBlob.Center;

            if (AlchAlchables)
            {
                Inventory.GrabAndAlch(blobCenter.X + offset.X, blobCenter.Y + offset.Y);
                Inventory.OpenInventory();
            }
            else
            {
                Inventory.Telegrab(blobCenter.X + offset.X, blobCenter.Y + offset.Y);
                Inventory.OpenInventory();
            }

            return(true);
        }
        /// <summary>
        /// Waits for the player to crawl through the drain pipe
        /// </summary>
        /// <returns>true if verified</returns>
        private bool VerifyPassedDrainPipe()
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();
            List <Blob> drainPipes;

            bool[,] drain;
            Blob lowestBlob;

            while (watch.ElapsedMilliseconds < WAIT_FOR_VERIFICATION && !StopFlag)
            {
                Screen.ReadWindow();
                drain      = Vision.ColorFilter(DrainPipe);
                drainPipes = ImageProcessing.FindBlobs(drain, false, MinDrainPipeSize);
                if (drainPipes.Count > 0)
                {
                    drainPipes.Sort(new BlobVerticalComparer());
                    lowestBlob = drainPipes[drainPipes.Count - 1];
                    if (lowestBlob.Center.Y > Screen.Center.Y)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        /// <summary>
        /// Finds the closest climbable tree
        /// </summary>
        /// <param name="treeColor">color range defining tree branches</param>
        /// <param name="tree">returns the tree blob if founf</param>
        /// <param name="minimumSize">not used</param>
        /// <returns>true if a set of branches is found</returns>
        private bool FindTreeBranches(out Blob tree, Point treeTrunk)
        {
            tree = null;
            Screen.ReadWindow();
            bool[,] objectPixels = Vision.ColorFilter(TreeBranch);
            Vision.EraseClientUIFromMask(ref objectPixels);
            List <Blob> branches = ImageProcessing.FindBlobs(objectPixels, false, MinTreeBranchSize);

            if (branches.Count == 0)
            {
                return(false);
            }

            tree = branches[0];
            double offset;
            double closestOffset = Geometry.DistanceBetweenPoints(treeTrunk, branches[0].GetBottom());

            for (int i = 1; i < branches.Count; i++)
            {
                offset = Geometry.DistanceBetweenPoints(treeTrunk, branches[i].GetBottom());
                if (offset < closestOffset)
                {
                    tree          = branches[i];
                    closestOffset = offset;
                }
            }
            return(true);
        }
Пример #5
0
 /// <summary>
 /// Locates the closest unmined iron ore
 /// </summary>
 /// <param name="ironFilter"></param>
 /// <param name="foundObject"></param>
 /// <param name="minimumSize"></param>
 /// <returns>true if an ore rock is found</returns>
 protected bool LocateUnminedOre(ColorFilter ironFilter, out Blob foundObject, int minimumSize, int maximumSize = int.MaxValue)
 {
     Screen.ReadWindow();
     bool[,] ironBoolArray = Vision.ColorFilter(ironFilter);
     foundObject           = ImageProcessing.ClosestBlob(ironBoolArray, Screen.Center, minimumSize);
     return(foundObject != null);
 }
Пример #6
0
        /// <summary>
        /// Looks for, picks up, and alchs a drop that matches a ColorRange
        /// </summary>
        /// <param name="screenDropArea"></param>
        /// <param name="referenceColor"></param>
        /// <param name="minimumSize">minimum number of pixels needed to </param>
        /// <returns>True if an item is found and telegrabbed. May be false if no item is found or if there isn't inventory space to pick it up.</returns>
        private bool FindAndGrab(Color[,] screenDropArea, Point offset, ColorFilter referenceColor, int minimumSize = 50)
        {
            bool[,] matchedPixels = Vision.ColorFilter(screenDropArea, referenceColor);
            Blob biggestBlob = ImageProcessing.BiggestBlob(matchedPixels);

            if (biggestBlob.Size > minimumSize)
            {
                Point blobCenter = biggestBlob.Center;
                Inventory.Telegrab(blobCenter.X + offset.X, blobCenter.Y + offset.Y);
                Inventory.OpenInventory();
                return(true);
            }
            return(false);
        }
Пример #7
0
        /// <summary>
        /// Locates the closest unmined iron ore
        /// </summary>
        /// <param name="ironFilter"></param>
        /// <param name="foundObject"></param>
        /// <param name="minimumSize"></param>
        /// <returns>true if an ore rock is found</returns>
        protected bool LocateFishingTile(ColorFilter fishFilter, out Blob foundObject, int minimumSize, int maximumSize = int.MaxValue)
        {
            foundObject = new Blob();
            Screen.ReadWindow();
            bool[,] fishBoolArray = Vision.ColorFilter(fishFilter);
            List <Blob> allMatches = ImageProcessing.FindBlobs(fishBoolArray);

            if (allMatches == null || allMatches.Count == 0)
            {
                return(false);
            }
            allMatches.Sort(new BlobProximityComparer(Screen.Center));
            foundObject = Geometry.ClosestBlobToPoint(allMatches, Screen.Center);

            return(foundObject != null);
        }
        /// <summary>
        /// Finds the leftmost drain pipe
        /// </summary>
        /// <param name="drainPipeColor"></param>
        /// <param name="drainPipe"></param>
        /// <param name="minimumSize"></param>
        /// <returns></returns>
        private bool LocateDrainPipe(ColorFilter drainPipeColor, out Blob drainPipe, int minimumSize = 1, int maximumSize = int.MaxValue)
        {
            drainPipe = null;
            Screen.ReadWindow();
            bool[,] drains = Vision.ColorFilter(DrainPipe);
            List <Blob> drainPipes = ImageProcessing.FindBlobs(drains, false, MinDrainPipeSize);

            if (drainPipes.Count == 0)
            {
                return(false);
            }

            drainPipes.Sort(new BlobHorizontalComparer());
            drainPipe = drainPipes[0];
            return(true);
        }
Пример #9
0
        /// <summary>
        /// This method detects whether or not the player is currently still fishing based on the distance of
        /// the closest fishing pole to the center
        ///
        /// </summary>
        /// <returns></returns>
        protected bool IsCurrentlyFishing()
        {
            Screen.ReadWindow();
            bool[,] poleBoolArray = Vision.ColorFilter(FishingPoleFilter);
            Blob closestObject;

            closestObject = ImageProcessing.ClosestBlob(poleBoolArray, Screen.Center, 7);

            if (closestObject != null)
            {
                if (Geometry.DistanceBetweenPoints(closestObject.Center, Screen.Center) <= maxFishingPoleDistance)
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #10
0
        /// <summary>
        /// Finds the possible kebbits.
        /// </summary>
        /// <returns>A list of kebbits in the order that they should be checked.</returns>
        protected List <Kebbit> LocateKebbits()
        {
            Screen.ReadWindow();
            bool[,] blackSpotMatches = Vision.ColorFilter(Kebbit.KebbitBlackSpot);
            Vision.EraseClientUIFromMask(ref blackSpotMatches);
            List <Blob>    blackSpots      = ImageProcessing.FindBlobs(blackSpotMatches, false, 1, Screen.ArtifactArea(0.00002183)); //ex 1-11 (0.000000992-0.00001091)
            List <Cluster> kebbitLocations = ImageProcessing.ClusterBlobs(blackSpots, Screen.ArtifactLength(0.0349));

            List <Kebbit> kebbits = new List <Kebbit>();

            foreach (Cluster kebbitSpots in kebbitLocations)
            {
                kebbits.Add(new Kebbit(Screen, kebbitSpots, Screen.Center));
            }

            return(kebbits);
        }
Пример #11
0
        /// <summary>
        /// Looks for, picks up, and alchs a drop that matches a ColorRange
        /// </summary>
        /// <param name="screenDropArea"></param>
        /// <param name="referenceColor"></param>
        /// <param name="minimumSize">minimum number of pixels needed to </param>
        /// <returns>True if an item is found and telegrabbed. May be false if no item is found or if there isn't inventory space to pick it up.</returns>
        private bool FindAndGrabChaosRune(Color[,] screenDropArea, Point offset, ColorFilter referenceColor, int minimumSize = 50)
        {
            bool[,] matchedPixels = Vision.ColorFilter(screenDropArea, referenceColor);
            List <Blob> chaosRunes = ImageProcessing.FindBlobs(matchedPixels, true);

            for (int i = 0; i < Math.Min(10, chaosRunes.Count); i++)
            {
                if ((chaosRunes[i].Size > minimumSize) && chaosRunes[i].IsCircle(0.4))
                {
                    Point blobCenter = chaosRunes[i].Center;
                    Inventory.Telegrab(blobCenter.X + offset.X, blobCenter.Y + offset.Y);
                    Inventory.OpenInventory();
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// Locates the top of the frame of the middle cargo net of the closest group of three
        /// </summary>
        /// <param name="cargoNetFrameColor">defines the top of a cargo net color</param>
        /// <param name="cargoNet">returns the top of the middle cargo net</param>
        /// <param name="minimumSize">conservative size floor</param>
        /// <returns>true if a set of cargo nets is found</returns>
        private bool LocateMiddleCargoNet(ColorFilter cargoNetFrameColor, out Blob cargoNet, int minimumSize = 1, int maximumSize = int.MaxValue)
        {
            cargoNet = null;
            Screen.ReadWindow();
            bool[,] cargoNetFrame = Vision.ColorFilter(CargoNet);
            Vision.EraseClientUIFromMask(ref cargoNetFrame);
            List <Blob> cargoNetFrames = ImageProcessing.FindBlobs(cargoNetFrame, false, MinCargoNetSize);

            if (cargoNetFrames.Count < 3)
            {
                return(false);
            }
            else
            {
                cargoNetFrames = ClosestFrameSet(cargoNetFrames);
                cargoNet       = MiddleCargoNet(cargoNetFrames);
                return(true);
            }
        }
Пример #13
0
        /// <summary>
        /// Estimates the target's fraction of its maximum hitpoints using OSBuddy's target hitpoints indicator
        /// </summary>
        /// <returns></returns>
        protected double TargetHitpointFraction()
        {
            if (!InCombat())
            {
                return(double.MaxValue);
            }

            Screen.UpdateScreenshot();
            Color[,] targetHitpoints = Vision.ScreenPiece(TARGET_HP_LEFT, TARGET_HP_RIGHT, TARGET_HP_TOP, TARGET_HP_BOTTOM);
            RGBHSBRange greenHPBar = RGBHSBRangeFactory.OSBuddyEnemyHitpointsGreen();

            bool[,] greenHP = Vision.ColorFilter(targetHitpoints, greenHPBar);
            double      greenWidth = ImageProcessing.BiggestBlob(greenHP).Width;
            RGBHSBRange redHPBar   = RGBHSBRangeFactory.OSBuddyEnemyHitpointsRed();

            bool[,] redHP = Vision.ColorFilter(targetHitpoints, redHPBar);
            double redWidth = ImageProcessing.BiggestBlob(redHP).Width;

            return(greenWidth / Numerical.NonZero(greenWidth + redWidth));
        }
Пример #14
0
        /// <summary>
        /// Finds the closest bank booth counter that matches a given color
        /// </summary>
        /// <param name="bankBoothColor">not used</param>
        /// <param name="bankBooth">returns the found bank booth blob</param>
        /// <returns>true if a bank booth is found</returns>
        internal bool LocateBankBooth(ColorFilter bankBoothColor, out Blob bankBooth)
        {
            bankBooth = null;

            if (!Screen.ReadWindow())
            {
                return(false);
            }
            bool[,] bankBooths = Vision.ColorFilter(bankBoothColor);
            List <Blob> potentialBoothBlobs = ImageProcessing.FindBlobs(bankBooths, false, MinBankBoothSize, MaxBankBoothSize);
            List <Blob> booths = new List <Blob>();

            foreach (Blob potentialBooth in potentialBoothBlobs)
            {
                if (Geometry.Rectangularity(potentialBooth) > 0.8)
                {
                    booths.Add(potentialBooth);
                }
            }

            bankBooth = Blob.ClosestBlob(Screen.Center, booths);

            return(bankBooth != null);
        }
Пример #15
0
 /// <summary>
 /// Creates a series of test images to visual how a color filter works
 /// </summary>
 /// <param name="filter">color filter to test</param>
 /// <param name="directory">directory in which to save test images</param>
 /// <param name="name">base name for test images</param>
 /// <param name="readWindow">Set to true to always read the window</param>
 protected void MaskTest(ColorFilter filter, string name = "maskTest", string directory = "C:\\Projects\\Roboport\\test_pictures\\mask_tests\\", bool readWindow = false)
 {
     Screen.MakeSureWindowHasBeenRead();
     bool[,] thing = Vision.ColorFilter(filter);
     DebugUtilities.TestMask(Screen.Bitmap, Screen, filter, thing, directory, name);
 }