예제 #1
0
 public XmlItemBase Parse()
 {
     _xml = new XmlItemBase();
     ParseSimpleFields();
     ParseItemClass();
     ParseImplicits();
     ParseRequirements();
     ParseTags();
     ParseProperties();
     return(_xml);
 }
예제 #2
0
        private XmlItemBase PrintoutsToBase(ItemClass itemClass, JToken printouts)
        {
            // name, requirements and implicts; same for all categories
            var implicits = PluralValue <string>(printouts, RdfImplicits).ToArray();
            var item      = new XmlItemBase
            {
                Level           = SingularValue <int>(printouts, RdfLvlReq),
                Dexterity       = SingularValue(printouts, RdfBaseDexReq, 0),
                Intelligence    = SingularValue(printouts, RdfBaseIntReq, 0),
                Strength        = SingularValue(printouts, RdfBaseStrReq, 0),
                Name            = SingularValue <string>(printouts, RdfName),
                DropDisabled    = !SingularBool(printouts, RdfDropEnabled, true),
                InventoryHeight = SingularValue(printouts, RdfInventoryHeight, 1),
                InventoryWidth  = SingularValue(printouts, RdfInventoryWidth, 1),
                MetadataId      = SingularValue <string>(printouts, RdfMetadataId),
                Implicit        = implicits,
                ItemClass       = itemClass,
            };

            // tags and properties
            foreach (var s in PluralValue <string>(printouts, RdfTags))
            {
                Tags tag;
                if (TagsEx.TryParse(s, out tag))
                {
                    item.Tags |= tag;
                }
                else
                {
                    _unknownTags.Add(s);
                }
            }
            // properties; tag specific
            var propBuilder = new PropertyBuilder(printouts);

            if (item.Tags.HasFlag(Tags.Weapon))
            {
                propBuilder.Add("Physical Damage: {0}-{1}", RdfBasePhysMin, RdfBasePhysMax);
                propBuilder.Add("Critical Strike Chance: {0}%", RdfBaseCritChance);
                propBuilder.Add("Attacks per Second: {0}", RdfBaseAttackSpeed);
                propBuilder.Add("Weapon Range: {0}", RdfBaseWeaponRange);
            }
            if (item.Tags.HasFlag(Tags.Armour))
            {
                propBuilder.Add("Chance to Block: {0}%", RdfBaseBlock);
                propBuilder.Add("Armour: {0}", RdfBaseArmour);
                propBuilder.Add("Evasion Rating: {0}", RdfBaseEvasion);
                propBuilder.Add("Energy Shield: {0}", RdfBaseEnergyShield);
            }
            item.Properties = propBuilder.ToArray();
            return(item);
        }
예제 #3
0
        private static IEnumerable <XmlItemBase> ParseTable(HtmlNode table, ItemType itemType)
        {
            // Select the item box in the first cell of each (non-header) row
            foreach (var cell in table.SelectNodes("tr/td[1]//*[contains(@class, 'item-box')]"))
            {
                var itemBox    = WikiUtils.ParseItemBox(cell);
                var statGroups = itemBox.StatGroups;
                var itemBase   = new XmlItemBase
                {
                    ItemType = itemType,
                    Name     = itemBox.TypeLine
                };

                var requirementsGroup =
                    statGroups.FirstOrDefault(stats => stats.Any(s => s.StatsCombined.StartsWith("Requires ") || s.StatsCombined.StartsWith("Drop Level: ")));
                var implicitsGroup =
                    statGroups.FirstOrDefault(stats => stats.All(s => s.Stats.All(t => t.Item2 == WikiStatColor.Mod)));
                var propertiesGroup = statGroups[0] == requirementsGroup ? null : statGroups[0];

                var implicitFrom = 1F;
                var implicitTo   = 1F;
                if (implicitsGroup != null)
                {
                    var implicits = new List <XmlStat>();
                    foreach (var wikiItemStat in implicitsGroup)
                    {
                        implicits.AddRange(ParseImplicit(wikiItemStat));
                    }
                    if (implicits.Any())
                    {
                        implicitFrom += implicits[0].From / 100;
                        implicitTo   += implicits[0].To / 100;
                    }
                    itemBase.Implicit = implicits.ToArray();
                }
                if (propertiesGroup != null)
                {
                    itemBase.Properties = ParseProperties(propertiesGroup, implicitFrom, implicitTo).ToArray();
                }
                if (requirementsGroup != null)
                {
                    ParseRequirements(requirementsGroup, itemBase);
                }
                yield return(itemBase);
            }
        }
예제 #4
0
        private static XmlItemBase PrintoutsToBase(ItemCategory category, JToken printouts)
        {
            // name, requirements and implicts; same for all categories
            var implicits = PluralValue <string>(printouts, RdfImplicits)
                            .SelectMany(WikiStatTextUtils.ConvertStatText).ToArray();
            var item = new XmlItemBase
            {
                Level           = SingularValue <int>(printouts, RdfLvlReq),
                Dexterity       = SingularValue(printouts, RdfBaseDexReq, 0),
                Intelligence    = SingularValue(printouts, RdfBaseIntReq, 0),
                Strength        = SingularValue(printouts, RdfBaseStrReq, 0),
                Name            = SingularValue <string>(printouts, RdfName),
                DropDisabled    = !SingularBool(printouts, RdfDropEnabled, true),
                InventoryHeight = SingularValue(printouts, RdfInventoryHeight, 1),
                InventoryWidth  = SingularValue(printouts, RdfInventoryWidth, 1),
                MetadataId      = SingularValue <string>(printouts, RdfMetadataId),
                Implicit        = implicits,
            };
            // properties; category specific
            var propBuilder = new PropertyBuilder(printouts);

            switch (category)
            {
            case ItemCategory.Weapon:
                propBuilder.Add("Physical Damage", RdfBasePhysMin, RdfBasePhysMax);
                propBuilder.Add("Critical Strike Chance %", RdfBaseCritChance);
                propBuilder.Add("Attacks per Second", RdfBaseAttackSpeed);
                propBuilder.Add("Weapon Range", RdfBaseWeaponRange);
                break;

            case ItemCategory.Armour:
                propBuilder.Add("Chance to Block %", RdfBaseBlock);
                propBuilder.Add("Armour", RdfBaseArmour);
                propBuilder.Add("Evasion Rating", RdfBaseEvasion);
                propBuilder.Add("Energy Shield", RdfBaseEnergyShield);
                break;

            case ItemCategory.Other:
                break;
            }
            item.Properties = propBuilder.ToArray();
            return(item);
        }
예제 #5
0
        private static ItemType TypeFromItem(XmlItemBase item, ItemGroup group)
        {
            ItemType ret;
            var      type = group.ToString();

            // If there is a type with the same name as the group, take that
            if (Enum.TryParse(type, out ret))
            {
                return(ret);
            }

            // Each jewel base has its own type.
            if (Enum.TryParse(item.Name.Replace(" Jewel", "Jewel"), out ret))
            {
                return(ret);
            }

            // Types of armour groups.
            if (item.Strength > 0)
            {
                type += "Armour";
            }
            if (item.Dexterity > 0)
            {
                type += "Evasion";
            }
            if (item.Intelligence > 0)
            {
                type += "EnergyShield";
            }
            // Special case for when all of Str, Dex and Int are 0
            if (type == group.ToString())
            {
                type += "ArmourEvasionEnergyShield";
            }
            if (!Enum.TryParse(type, out ret))
            {
                throw new ArgumentException($"Type {type} parsed from the given base item and group does not exist");
            }
            return(ret);
        }
예제 #6
0
        private static void ParseRequirements(IEnumerable <WikiItemStat> requirements, XmlItemBase itemBase)
        {
            var requirementLine =
                requirements.Select(s => s.StatsCombined).FirstOrDefault(s => s.StartsWith("Requires "));

            if (requirementLine == null)
            {
                return;
            }

            int i;

            if (TryParseFirstMatchToInt(LevelRegex, requirementLine, out i))
            {
                itemBase.Level = i;
            }
            if (TryParseFirstMatchToInt(StrRegex, requirementLine, out i))
            {
                itemBase.Strength = i;
            }
            if (TryParseFirstMatchToInt(DexRegex, requirementLine, out i))
            {
                itemBase.Dexterity = i;
            }
            if (TryParseFirstMatchToInt(IntRegex, requirementLine, out i))
            {
                itemBase.Intelligence = i;
            }
        }