private static int ScanMora()
        {
            var region = new Rectangle(
                x: (int)(125 / 1280.0 * Navigation.GetWidth()),
                y: (int)(665 / 720.0 * Navigation.GetHeight()),
                width: (int)(300 / 1280.0 * Navigation.GetWidth()),
                height: (int)(30 / 720.0 * Navigation.GetHeight()));

            if (Navigation.GetAspectRatio() == new Size(8, 5))
            {
                region.Y = (int)(740 / 800.0 * Navigation.GetHeight());
            }

            using (var screenshot = Navigation.CaptureRegion(region))
            {
                string mora = ParseMoraFromScreenshot(screenshot);

                if (int.TryParse(mora, out int count))
                {
                    UserInterface.ResetCharacterDisplay();
                    UserInterface.SetMora(screenshot, count);
                }
                else
                {
                    UserInterface.SetNavigation_Image(screenshot);
                    UserInterface.AddError("Unable to parse mora count");
                    screenshot.Save("./logging/materials/mora.png");
                }
                return(count);
            }
        }
Example #2
0
        private static int ScanArtifactCount()
        {
            //Find artifact count
            var region = new Rectangle(
                x: (int)(1030 / 1280.0 * Navigation.GetWidth()),
                y: (int)(20 / 720.0 * Navigation.GetHeight()),
                width: (int)(175 / 1280.0 * Navigation.GetWidth()),
                height: (int)(25 / 720.0 * Navigation.GetHeight()));

            using (Bitmap countBitmap = Navigation.CaptureRegion(region))
            {
                UserInterface.SetNavigation_Image(countBitmap);

                Bitmap n = Scraper.ConvertToGrayscale(countBitmap);
                Scraper.SetContrast(60.0, ref n);
                Scraper.SetInvert(ref n);

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

                // Remove any non-numeric and '/' characters
                text = Regex.Replace(text, @"[^0-9/]", string.Empty);

                if (string.IsNullOrWhiteSpace(text))
                {
                    countBitmap.Save($"./logging/artifacts/ArtifactCount.png");
                    Navigation.CaptureWindow().Save($"./logging/artifacts/ArtifactWindow_{Navigation.GetWidth()}x{Navigation.GetHeight()}.png");
                    throw new FormatException("Unable to locate artifact count.");
                }

                int count;

                // Check for slash
                if (Regex.IsMatch(text, "/"))
                {
                    count = int.Parse(text.Split('/')[0]);
                }
                else if (Regex.Matches(text, "1500").Count == 1)                 // Remove the inventory limit from number
                {
                    text  = text.Replace("1500", string.Empty);
                    count = int.Parse(text);
                }
                else                 // Extreme worst case
                {
                    count = 1500;
                    Logger.Debug("Defaulted to 1500 for artifact count");
                }

                return(count);
            }
        }
        public static string ScanMainCharacterName()
        {
            var xReference = 1280.0;
            var yReference = 720.0;

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

            RECT region = new RECT(
                Left:   (int)(185 / xReference * Navigation.GetWidth()),
                Top:    (int)(26 / yReference * Navigation.GetHeight()),
                Right:  (int)(460 / xReference * Navigation.GetWidth()),
                Bottom: (int)(60 / yReference * Navigation.GetHeight()));

            Bitmap nameBitmap = Navigation.CaptureRegion(region);

            //Image Operations
            Scraper.SetGamma(0.2, 0.2, 0.2, ref nameBitmap);
            Scraper.SetInvert(ref nameBitmap);
            Bitmap n = Scraper.ConvertToGrayscale(nameBitmap);

            UserInterface.SetNavigation_Image(nameBitmap);

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

            if (text != "")
            {
                // Only keep a-Z and 0-9
                text = Regex.Replace(text, @"[\W_]", string.Empty).ToLower();

                // Only keep text up until first space
                text = Regex.Replace(text, @"\s+\w*", string.Empty);

                UserInterface.SetMainCharacterName(text);
            }
            else
            {
                UserInterface.AddError(text);
            }
            n.Dispose();
            nameBitmap.Dispose();
            return(text);
        }