コード例 #1
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;
        }