예제 #1
0
        private IList <Weapon> ProcessContent(string content, WeaponType weaponType)
        {
            int currentPosition = 0;

            var weapons = new List <Weapon>();

            while (currentPosition < content.Length)
            {
                Markup weaponImageMarkup = HtmlUtils.Until(content, ref currentPosition, m => m.Name == "img" && m.Classes.Contains("wp_img") && m.Properties.ContainsKey("src") && m.Properties["src"].StartsWith("http://s.mhwg.org/images/weapon2/w"));
                if (weaponImageMarkup == null)
                {
                    break;
                }

                // === rarity =========================================================

                string weaponRarityImageUrl = weaponImageMarkup.Properties["src"];
                int    rarity = TryGetRarity(weaponRarityImageUrl);

                // === name =========================================================

                int closingTdIndex = content.IndexOf("</td>", currentPosition);
                if (closingTdIndex < 0)
                {
                    throw BadFormat($"Missing closing 'td' for weapon name at position {currentPosition}");
                }

                string weaponNameContent = content.Substring(currentPosition, closingTdIndex - currentPosition);

                string weaponName = GetWeaponName(weaponNameContent);
                if (weaponName == null)
                {
                    throw BadFormat($"Could not determine weapon name at position {currentPosition}");
                }

                // === attack =========================================================

                Markup attackMarkup = HtmlUtils.Until(content, ref currentPosition, m => m.Name == "td" && m.Classes.Contains("b"));
                if (attackMarkup == null)
                {
                    throw BadFormat($"Could not find attack markup for weapon '{weaponName}'");
                }

                int    attack;
                string attackStringValue = HtmlUtils.GetMarkupContent(content, attackMarkup);
                if (int.TryParse(attackStringValue, out attack) == false)
                {
                    throw BadFormat($"Invalid attack numeric value '{(attackStringValue ?? "(null)")}' for weapon '{weaponName}'");
                }

                // === element + misc =========================================================

                Markup weaponElementMarkup = HtmlUtils.Until(content, ref currentPosition, m => m.Name == "td" && m.Classes.Length > 0);
                if (weaponElementMarkup == null)
                {
                    throw BadFormat($"Could not find element markup for weapon '{weaponName}'");
                }

                closingTdIndex = content.IndexOf("</td>", currentPosition);
                if (closingTdIndex < 0)
                {
                    throw BadFormat($"Missing closing 'td' of element for weapon '{weaponName}'");
                }

                string weaponElementContent = content.Substring(currentPosition, closingTdIndex - currentPosition);

                TryGetWeaponElement(weaponName, weaponElementContent, out int affinity, out int defense, out ElementInfo[] elementInfo, out EldersealLevel eldersealLevel);