コード例 #1
0
        private static int ScanLevel(ref bool ascended)
        {
            int level = -1;

            var xRef = 1280.0;
            var yRef = 720.0;

            if (Navigation.GetAspectRatio() == new Size(8, 5))
            {
                yRef = 800.0;
            }

            Rectangle region = new RECT(
                Left:   (int)(960 / xRef * Navigation.GetWidth()),
                Top:    (int)(135 / yRef * Navigation.GetHeight()),
                Right:  (int)(1125 / xRef * Navigation.GetWidth()),
                Bottom: (int)(163 / yRef * Navigation.GetHeight()));

            do
            {
                Bitmap bm = Navigation.CaptureRegion(region);

                bm = Scraper.ResizeImage(bm, bm.Width * 2, bm.Height * 2);
                Bitmap n = Scraper.ConvertToGrayscale(bm);
                Scraper.SetInvert(ref n);
                Scraper.SetContrast(30.0, ref bm);

                string text = Scraper.AnalyzeText(n).Trim();

                text = Regex.Replace(text, @"(?![0-9/]).", string.Empty);
                if (text.Contains("/"))
                {
                    var values = text.Split('/');
                    if (int.TryParse(values[0], out level) && int.TryParse(values[1], out int maxLevel))
                    {
                        maxLevel = (int)Math.Round(maxLevel / 10.0, MidpointRounding.AwayFromZero) * 10;
                        ascended = 20 <= level && level < maxLevel;
                        UserInterface.SetCharacter_Level(bm, level, maxLevel);
                        n.Dispose();
                        bm.Dispose();
                        return(level);
                    }
                    n.Dispose();
                    bm.Dispose();
                }
                Navigation.SystemRandomWait(Navigation.Speed.Normal);
            } while (level == -1);

            return(-1);
        }
コード例 #2
0
        public static int ScanMaterialCount(Rectangle rectangle, out Bitmap quantity)
        {
            var region = new RECT(
                Left: rectangle.X,
                Top: (int)(rectangle.Y + (0.8 * rectangle.Height)),                 // Only get the bottom of inventory item
                Right: rectangle.Right,
                Bottom: rectangle.Bottom + 10);

            using (Bitmap bm = Navigation.CaptureRegion(region))
            {
                quantity = (Bitmap)bm.Clone();

                using (Bitmap rescaled = Scraper.ResizeImage(bm, (int)(bm.Width * 3), (int)(bm.Height * 3)))
                {
                    Bitmap copy = (Bitmap)rescaled.Clone();
                    Scraper.SetGamma(0.7, 0.7, 0.7, ref copy);
                    // Image Processing
                    Bitmap n = Scraper.ConvertToGrayscale(copy);
                    Scraper.SetContrast(65, ref n);                     // Setting a high contrast seems to be better than thresholding
                    //Scraper.SetThreshold(165, ref n);

                    string old_text = Scraper.AnalyzeText(n, Tesseract.PageSegMode.SingleWord).Trim().ToLower();

                    // Might be worth it to train some more numbers
                    var cleaned = old_text.Replace("mm", "111").Replace("m", "11").Replace("nn", "11").Replace("n", "1");                     // Tesseract struggles with 1's so close together because of font
                    cleaned = cleaned.Replace("a", "4");
                    cleaned = cleaned.Replace("e", "1");
                    //old_text = old_text.Replace("b", "8");
                    //old_text = old_text.Replace("+", "4");

                    cleaned = Regex.Replace(cleaned, @"[^0-9]", string.Empty);

                    _ = int.TryParse(cleaned, out int count);

                    Debug.WriteLine($"{old_text} -> {cleaned} -> {count}");

                    //if (count > 3000 || count == 0)
                    //{
                    //	//Navigation.DisplayBitmap(n);
                    //}
                    copy.Dispose();
                    n.Dispose();
                    return(count);
                }
            }
        }
コード例 #3
0
        private static int ScanExperience()
        {
            int experience = 0;

            int      xOffset          = 1117;
            int      yOffset          = 151;
            Bitmap   bm               = new Bitmap(90, 10);
            Graphics g                = Graphics.FromImage(bm);
            int      screenLocation_X = Navigation.GetPosition().Left + xOffset;
            int      screenLocation_Y = Navigation.GetPosition().Top + yOffset;

            g.CopyFromScreen(screenLocation_X, screenLocation_Y, 0, 0, bm.Size);

            //Image Operations
            bm = Scraper.ResizeImage(bm, bm.Width * 6, bm.Height * 6);
            //Scraper.ConvertToGrayscale(ref bm);
            //Scraper.SetInvert(ref bm);
            Scraper.SetContrast(30.0, ref bm);

            string text = Scraper.AnalyzeText(bm);

            text = text.Trim();
            text = Regex.Replace(text, @"(?![0-9\s/]).", string.Empty);

            if (Regex.IsMatch(text, "/"))
            {
                string[] temp = text.Split('/');
                experience = Convert.ToInt32(temp[0]);
            }
            else
            {
                Debug.Print("Error: Found " + experience + " instead of experience");
                UserInterface.AddError("Found " + experience + " instead of experience");
            }

            return(experience);
        }
コード例 #4
0
        private static int[] ScanTalents(string name)
        {
            int[] talents = { -1, -1, -1 };

            int specialOffset = 0;

            // Check if character has a movement talent like
            // Mona or Ayaka
            if (name.Contains("Mona") || name.Contains("Ayaka"))
            {
                specialOffset = 1;
            }

            var xRef = 1280.0;
            var yRef = 720.0;

            if (Navigation.GetAspectRatio() == new Size(8, 5))
            {
                yRef = 800.0;
            }

            Rectangle region = new RECT(
                Left:   (int)(160 / xRef * Navigation.GetWidth()),
                Top:    (int)(116 / yRef * Navigation.GetHeight()),
                Right:  (int)(225 / xRef * Navigation.GetWidth()),
                Bottom: (int)(141 / yRef * Navigation.GetHeight()));

            for (int i = 0; i < 3; i++)
            {
                // Change y-offset for talent clicking
                int yOffset = (int)(110 / yRef * Navigation.GetHeight()) + (i + ((i == 2) ? specialOffset : 0)) * (int)(60 / yRef * Navigation.GetHeight());

                Navigation.SetCursorPos(Navigation.GetPosition().Left + (int)(1130 / xRef * Navigation.GetWidth()), Navigation.GetPosition().Top + yOffset);
                Navigation.Click();
                Navigation.Speed speed = i == 0 ? Navigation.Speed.Normal : Navigation.Speed.Fast;
                Navigation.SystemRandomWait(speed);

                while (talents[i] < 1 || talents[i] > 15)
                {
                    Bitmap talentLevel = Navigation.CaptureRegion(region);

                    talentLevel = Scraper.ResizeImage(talentLevel, talentLevel.Width * 2, talentLevel.Height * 2);

                    Bitmap n = Scraper.ConvertToGrayscale(talentLevel);
                    Scraper.SetContrast(60, ref n);
                    Scraper.SetInvert(ref n);

                    string text = Scraper.AnalyzeText(n).Trim();
                    text = Regex.Replace(text, @"\D", string.Empty);

                    if (int.TryParse(text, out int level))
                    {
                        if (level >= 1 && level <= 15)
                        {
                            talents[i] = level;
                            UserInterface.SetCharacter_Talent(talentLevel, text, i);
                        }
                    }

                    n.Dispose();
                    talentLevel.Dispose();
                }
            }

            Navigation.sim.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.ESCAPE);
            return(talents);
        }
コード例 #5
0
        private static void ScanNameAndElement(ref string name, ref string element)
        {
            int       attempts    = 0;
            int       maxAttempts = 75;
            Rectangle region      = new RECT(
                Left:   (int)(85 / 1280.0 * Navigation.GetWidth()),
                Top:    (int)(10 / 720.0 * Navigation.GetHeight()),
                Right:  (int)(305 / 1280.0 * Navigation.GetWidth()),
                Bottom: (int)(55 / 720.0 * Navigation.GetHeight()));

            do
            {
                Navigation.SystemRandomWait(Navigation.Speed.Fast);
                using (Bitmap bm = Navigation.CaptureRegion(region))
                {
                    Bitmap n = Scraper.ConvertToGrayscale(bm);
                    Scraper.SetThreshold(110, ref n);
                    Scraper.SetInvert(ref n);

                    n = Scraper.ResizeImage(n, n.Width * 2, n.Height * 2);
                    string block = Scraper.AnalyzeText(n, Tesseract.PageSegMode.Auto).ToLower().Trim();
                    string line  = Scraper.AnalyzeText(n, Tesseract.PageSegMode.SingleLine).ToLower().Trim();

                    // Characters with wrapped names will not have a slash
                    string nameAndElement = line.Contains("/") ? line : block;

                    if (nameAndElement.Contains("/"))
                    {
                        var split = nameAndElement.Split('/');

                        // Search for element and character name in block

                        // Long name characters might look like
                        // <Element>   <First Name>
                        // /           <Last Name>
                        element = !split[0].Contains(" ") ? Scraper.FindElementByName(split[0].Trim()) : Scraper.FindElementByName(split[0].Split(' ')[0].Trim());

                        // Find character based on string after /
                        // Long name characters might search by their last name only but it'll still work.
                        name = Scraper.FindClosestCharacterName(Regex.Replace(split[1], @"[\W]", string.Empty));
                        if (name == "Traveler")
                        {
                            foreach (var item in from item in Scraper.Characters
                                     where item.Value["GOOD"].ToString() == "Traveler"
                                     select item)
                            {
                                name = item.Key;
                            }
                        }
                    }
                    n.Dispose();

                    if (!string.IsNullOrWhiteSpace(name) && !string.IsNullOrWhiteSpace(element))
                    {
                        UserInterface.SetCharacter_NameAndElement(bm, name, element);
                        return;
                    }
                }
                attempts++;
                Navigation.SystemRandomWait(Navigation.Speed.Normal);
            } while ((string.IsNullOrWhiteSpace(name) || string.IsNullOrEmpty(element)) && (attempts < maxAttempts));
            name    = null;
            element = null;
        }