Пример #1
0
        private static string ScanArtifactMainStat(Bitmap bm, string gearSlot)
        {
            switch (gearSlot)
            {
            // Flower of Life. Flat HP
            case "flower":
                return(Scraper.Stats["hp"]);

            // Plume of Death. Flat ATK
            case "plume":
                return(Scraper.Stats["atk"]);

            // Otherwise it's either sands, goblet or circlet.
            default:

                Scraper.SetContrast(100.0, ref bm);
                Bitmap n = Scraper.ConvertToGrayscale(bm);
                Scraper.SetThreshold(135, ref n);
                Scraper.SetInvert(ref n);

                // Get Main Stat
                string mainStat = Scraper.AnalyzeText(n).ToLower().Trim();
                n.Dispose();

                // Remove anything not a-z as well as removes spaces/underscores
                mainStat = Regex.Replace(mainStat, @"[\W_0-9]", string.Empty);
                // Replace double characters (ex. aanemodmgbonus). Seemed to be a somewhat common problem.
                mainStat = Regex.Replace(mainStat, "(.)\\1+", "$1");

                if (mainStat == "def" || mainStat == "atk" || mainStat == "hp")
                {
                    mainStat += "%";
                }

                return(Scraper.FindClosestStat(mainStat));
            }
        }
        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);
        }
        public void GatherData()
        {
            // Initize Image Processors
            for (int i = 0; i < maxProcessors; i++)
            {
                Thread processor = new Thread(ImageProcessorWorker)
                {
                    IsBackground = true
                };
                processor.Start();
                ImageProcessors.Add(processor);
            }
            Logger.Debug("Added {ImageProcessors.Count} workers", ImageProcessors.Count);

            Scraper.RestartEngines();

            // Scan Main character Name
            string mainCharacterName = CharacterScraper.ScanMainCharacterName();

            Scraper.AssignTravelerName(mainCharacterName);

            if (Properties.Settings.Default.ScanWeapons)
            {
                Logger.Info("Scanning weapons...");
                // Get Weapons
                Navigation.InventoryScreen();
                Navigation.SelectWeaponInventory();
                try
                {
                    WeaponScraper.ScanWeapons();
                }
                catch (FormatException ex) { UserInterface.AddError(ex.Message); }
                catch (ThreadAbortException) { }
                catch (Exception ex)
                {
                    UserInterface.AddError(ex.Message + "\n" + ex.StackTrace);
                }
                Navigation.MainMenuScreen();
                Logger.Info("Done scanning weapons");
            }

            if (Properties.Settings.Default.ScanArtifacts)
            {
                Logger.Info("Scanning artifacts...");

                // Get Artifacts
                Navigation.InventoryScreen();
                Navigation.SelectArtifactInventory();
                try
                {
                    ArtifactScraper.ScanArtifacts();
                }
                catch (FormatException ex) { UserInterface.AddError(ex.Message); }
                catch (ThreadAbortException) { }
                catch (Exception ex)
                {
                    UserInterface.AddError(ex.Message + "\n" + ex.StackTrace);
                }
                Navigation.MainMenuScreen();
                Logger.Info("Done scanning artifacts");
            }

            workerQueue.Enqueue(new OCRImageCollection(null, "END", 0));

            if (Properties.Settings.Default.ScanCharacters)
            {
                Logger.Info("Scanning characters...");
                // Get characters
                Navigation.CharacterScreen();
                var c = new List <Character>();
                try
                {
                    CharacterScraper.ScanCharacters(ref c);
                }
                catch (ThreadAbortException) { }
                catch (Exception ex)
                {
                    UserInterface.AddError(ex.Message + "\n" + ex.StackTrace);
                }
                Characters = c;
                Navigation.MainMenuScreen();
                Logger.Info("Done scanning characters");
            }

            // Wait for Image Processors to finish
            AwaitProcessors();

            if (Properties.Settings.Default.ScanCharacters)
            {
                // Assign Artifacts to Characters
                if (Properties.Settings.Default.ScanArtifacts)
                {
                    AssignArtifacts();
                }
                if (Properties.Settings.Default.ScanWeapons)
                {
                    AssignWeapons();
                }
            }

            // Scan Character Development Items
            if (Properties.Settings.Default.ScanCharDevItems)
            {
                Logger.Info("Scanning character development materials...");
                // Get Materials
                Navigation.InventoryScreen();
                Navigation.SelectCharacterDevelopmentInventory();
                HashSet <Material> devItems = new HashSet <Material>();
                try
                {
                    MaterialScraper.Scan_Materials(InventorySection.CharacterDevelopmentItems, ref Materials);
                }
                catch (FormatException ex) { UserInterface.AddError(ex.Message); }
                catch (ThreadAbortException) { }
                catch (Exception ex)
                {
                    UserInterface.AddError(ex.Message + "\n" + ex.StackTrace);
                }
                Navigation.MainMenuScreen();
                Logger.Info("Done scanning character development materials");
            }

            // Scan Materials
            if (Properties.Settings.Default.ScanMaterials)
            {
                Logger.Info("Scanning materials...");
                // Get Materials
                Navigation.InventoryScreen();
                Navigation.SelectMaterialInventory();
                HashSet <Material> materials = new HashSet <Material>();
                try
                {
                    MaterialScraper.Scan_Materials(InventorySection.Materials, ref Materials);
                }
                catch (FormatException ex) { UserInterface.AddError(ex.Message); }
                catch (ThreadAbortException) { }
                catch (Exception ex)
                {
                    UserInterface.AddError(ex.Message + "\n" + ex.StackTrace);
                }
                Navigation.MainMenuScreen();
                Logger.Info("Done scanning materials");
            }

            Inventory.AddMaterials(ref Materials);
        }
Пример #4
0
 public bool HasValidEquippedCharacter()
 {
     return(string.IsNullOrWhiteSpace(EquippedCharacter) || Scraper.IsValidCharacter(EquippedCharacter));
 }
Пример #5
0
 public bool HasValidWeaponName()
 {
     return(Scraper.IsValidWeapon(Name));
 }
        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);
        }
        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;
        }
Пример #8
0
        private static List <SubStat> ScanArtifactSubStats(Bitmap artifactImage, ref string setName)
        {
            Bitmap bm = (Bitmap)artifactImage.Clone();

            Scraper.SetBrightness(-30, ref bm);
            Scraper.SetContrast(85, ref bm);
            var n    = Scraper.ConvertToGrayscale(bm);
            var text = Scraper.AnalyzeText(n, Tesseract.PageSegMode.Auto).ToLower();

            List <string> lines = new List <string>(text.Split('\n'));

            lines.RemoveAll(line => string.IsNullOrWhiteSpace(line));

            var index = lines.FindIndex(line => line.Contains("piece") || line.Contains("set") || line.Contains("2-"));

            if (index >= 0)
            {
                lines.RemoveRange(index, lines.Count - index);
            }

            n.Dispose();
            bm.Dispose();
            SubStat[]             substats = new SubStat[4];
            List <Task <string> > tasks    = new List <Task <string> >();

            for (int i = 0; i < lines.Count; i++)
            {
                int j    = i;
                var task = Task.Factory.StartNew(() =>
                {
                    var line = Regex.Replace(lines[j], @"(?:^[^a-zA-Z]*)", string.Empty).Replace(" ", string.Empty);

                    if (line.Any(char.IsDigit))
                    {
                        SubStat substat = new SubStat();
                        Regex re        = new Regex(@"([\w]+\W*)(\d+.*\d+)");
                        var result      = re.Match(line);
                        var stat        = Regex.Replace(result.Groups[1].Value, @"[^\w]", string.Empty);
                        var value       = result.Groups[2].Value;

                        string name = line.Contains("%") ? stat + "%" : stat;

                        substat.stat = Scraper.FindClosestStat(name) ?? "";

                        // Remove any non digits.
                        value = Regex.Replace(value, @"[^0-9]", string.Empty);

                        var cultureInfo = new CultureInfo("en-US");
                        if (!decimal.TryParse(value, NumberStyles.Number, cultureInfo, out substat.value))
                        {
                            substat.value = -1;
                        }

                        // Need to retain the decimal place for percent boosts
                        if (substat.stat.Contains("_"))
                        {
                            substat.value /= 10;
                        }

                        substats[j] = substat;
                        return(null);
                    }
                    else                     // if (line.Contains(":")) // Sometimes Tesseract wouldn't detect a ':' making this check troublesome
                    {
                        var name = line.Trim().ToLower();

                        name = Regex.Replace(name, @"[^\w]", string.Empty);

                        name = Scraper.FindClosestSetName(name);

                        return(!string.IsNullOrWhiteSpace(name) ? name : null);
                    }
                });
                tasks.Add(task);
            }
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            while (tasks.Count > 0 && stopwatch.Elapsed.TotalSeconds < 10)
            {
                for (int i = 0; i < tasks.Count; i++)
                {
                    Task <string> task = tasks[i];
                    if (!task.IsCompleted)
                    {
                        continue;
                    }
                    setName = string.IsNullOrWhiteSpace(setName) ? task.Result : setName;
                    tasks.Remove(task);
                    break;
                }
            }
            return(substats.ToList());
        }
Пример #9
0
 public bool HasValidElement()
 {
     return(!string.IsNullOrWhiteSpace(Element) && Scraper.IsValidElement(Element));
 }
Пример #10
0
 public bool HasValidName()
 {
     return(!string.IsNullOrWhiteSpace(Name) && Scraper.IsValidCharacter(Name));
 }
Пример #11
0
 public bool HasValidMainStat()
 {
     return(Scraper.IsValidStat(MainStat));
 }
Пример #12
0
 public bool HasValidSetName()
 {
     return(Scraper.IsValidSetName(SetName));
 }
Пример #13
0
 public bool HasValidSlot()
 {
     return(Scraper.IsValidSlot(GearSlot));
 }