Exemplo n.º 1
0
        private NotCondition ConvertXmlNotCondition(XmlNotCondition xmlNotCond, PseudoAttribute pseudo, Attribute attr)
        {
            ICondition innerCond;

            if (xmlNotCond.Keystone != null)
            {
                innerCond = new KeystoneCondition(xmlNotCond.Keystone);
            }
            else if (xmlNotCond.OffHand != null)
            {
                innerCond = new OffHandCondition(xmlNotCond.OffHand);
            }
            else if (xmlNotCond.Tag != null)
            {
                innerCond = new TagCondition(xmlNotCond.Tag);
            }
            else if (xmlNotCond.WeaponClass != null)
            {
                innerCond = new WeaponClassCondition(xmlNotCond.WeaponClass);
            }
            else
            {
                throw new PseudoAttributeDataInvalidException(
                          string.Format(L10n.Message("Empty not condition in attribute {0} in pseudo attribute {1}"), attr.Name, pseudo.Name));
            }
            return(new NotCondition(innerCond));
        }
        /// <summary>
        /// Convertes the given XmlPseudoAttributes into PseudoAttributes.
        /// Does not resolve nesting so there may be duplicates.
        /// </summary>
        private IEnumerable<PseudoAttribute> ConvertFromXml(IEnumerable<XmlPseudoAttribute> xmlPseudoAttributes)
        {
            foreach (var xmlPseudo in xmlPseudoAttributes)
            {
                var pseudo = new PseudoAttribute(xmlPseudo.Name, xmlPseudo.Group);
                _pseudoNameDict[pseudo.Name] = pseudo;

                _nestedPseudosDict[pseudo.Name] = new List<string>();
                foreach (var xmlNestedPseudo in xmlPseudo.PseudoAttributes ?? new XmlNestedPseudoAttribute[0])
                {
                    _nestedPseudosDict[pseudo.Name].Add(xmlNestedPseudo.Name);
                }

                foreach (var xmlAttr in xmlPseudo.Attributes ?? new XmlNestedAttribute[0])
                {
                    var attr = new Attribute(xmlAttr.Name);
                    if (xmlAttr.ConversionMultiplierSpecified)
                    {
                        attr.ConversionMultiplier = (float) xmlAttr.ConversionMultiplier;
                    }
                    pseudo.Attributes.Add(attr);

                    var xmlConditions = xmlAttr.Conditions ?? new XmlAttributeConditions() {Items = new object[0]};
                    for (var i = 0; i < xmlConditions.Items.Length; i++)
                    {
                        ICondition condition;
                        var xmlCondition = xmlConditions.Items[i];
                        switch (xmlConditions.ItemsElementName[i])
                        {
                            case XmlItemsChoiceType.AndComposition:
                                var xmlAndComp = (XmlAndComposition)xmlCondition;
                                var andComp = new AndComposition();
                                if (xmlAndComp.Keystone != null)
                                {
                                    andComp.Conditions.Add(new KeystoneCondition(xmlAndComp.Keystone));
                                }
                                if (xmlAndComp.OffHand != null)
                                {
                                    andComp.Conditions.Add(new OffHandCondition(xmlAndComp.OffHand));
                                }
                                if (xmlAndComp.Tag != null)
                                {
                                    andComp.Conditions.Add(new TagCondition(xmlAndComp.Tag));
                                }
                                if (xmlAndComp.WeaponClass != null)
                                {
                                    andComp.Conditions.Add(new WeaponClassCondition(xmlAndComp.WeaponClass));
                                }

                                if (xmlAndComp.NotCondition != null)
                                {
                                    var xmlNotCond = xmlAndComp.NotCondition;
                                    ICondition innerCond;
                                    if (xmlNotCond.Keystone != null)
                                    {
                                        innerCond = new KeystoneCondition(xmlNotCond.Keystone);
                                    }
                                    else if (xmlNotCond.OffHand != null)
                                    {
                                        innerCond = new OffHandCondition(xmlNotCond.OffHand);
                                    }
                                    else if (xmlNotCond.Tag != null)
                                    {
                                        innerCond = new TagCondition(xmlNotCond.Tag);
                                    }
                                    else if (xmlNotCond.WeaponClass != null)
                                    {
                                        innerCond = new WeaponClassCondition(xmlNotCond.WeaponClass);
                                    }
                                    else
                                    {
                                        throw new PseudoAttributeDataInvalidException(
                                            string.Format(L10n.Message("Empty not condition in attribute {0} in pseudo attribute {1}"), attr.Name, pseudo.Name));
                                    }
                                    andComp.Conditions.Add(new NotCondition(innerCond));
                                }
                                condition = andComp;
                                break;

                            case XmlItemsChoiceType.OffHand:
                                condition = new OffHandCondition(xmlCondition.ToString());
                                break;
                            case XmlItemsChoiceType.Tag:
                                condition = new TagCondition(xmlCondition.ToString());
                                break;
                            case XmlItemsChoiceType.WeaponClass:
                                condition = new WeaponClassCondition(xmlCondition.ToString());
                                break;
                            case XmlItemsChoiceType.Keystone:
                                condition = new KeystoneCondition(xmlCondition.ToString());
                                break;

                            default:
                                throw new PseudoAttributeDataInvalidException(
                                    string.Format(L10n.Message("Unsupported condition type in attribute {0} in pseudo attribute {1}"), attr.Name, pseudo.Name));
                        }
                        attr.Conditions.Add(condition);
                    }
                }

                if (xmlPseudo.Hidden != "True")
                {
                    // If hidden they are only added to _pseudoNameDict and _nestedPseudosDict but not returned.
                    yield return pseudo;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Convertes the given XmlPseudoAttributes into PseudoAttributes.
        /// Does not resolve nesting so there may be duplicates.
        /// </summary>
        private IEnumerable <PseudoAttribute> ConvertFromXml(IEnumerable <XmlPseudoAttribute> xmlPseudoAttributes)
        {
            foreach (var xmlPseudo in xmlPseudoAttributes)
            {
                var pseudo = new PseudoAttribute(xmlPseudo.Name, xmlPseudo.Group);
                _pseudoNameDict[pseudo.Name] = pseudo;

                _nestedPseudosDict[pseudo.Name] = new List <string>();
                foreach (var xmlNestedPseudo in xmlPseudo.PseudoAttributes ?? new XmlNestedPseudoAttribute[0])
                {
                    _nestedPseudosDict[pseudo.Name].Add(xmlNestedPseudo.Name);
                }

                foreach (var xmlAttr in xmlPseudo.Attributes ?? new XmlNestedAttribute[0])
                {
                    var attr = new Attribute(xmlAttr.Name);
                    if (xmlAttr.ConversionMultiplierSpecified)
                    {
                        attr.ConversionMultiplier = (float)xmlAttr.ConversionMultiplier;
                    }
                    pseudo.Attributes.Add(attr);

                    var xmlConditions = xmlAttr.Conditions ?? new XmlAttributeConditions()
                    {
                        Items = new object[0]
                    };
                    for (var i = 0; i < xmlConditions.Items.Length; i++)
                    {
                        ICondition condition;
                        var        xmlCondition = xmlConditions.Items[i];
                        switch (xmlConditions.ItemsElementName[i])
                        {
                        case XmlItemsChoiceType.AndComposition:
                            var xmlAndComp = (XmlAndComposition)xmlCondition;
                            var andComp    = new AndComposition();
                            if (xmlAndComp.Keystone != null)
                            {
                                andComp.Conditions.Add(new KeystoneCondition(xmlAndComp.Keystone));
                            }
                            if (xmlAndComp.OffHand != null)
                            {
                                andComp.Conditions.Add(new OffHandCondition(xmlAndComp.OffHand));
                            }
                            if (xmlAndComp.Tag != null)
                            {
                                andComp.Conditions.Add(new TagCondition(xmlAndComp.Tag));
                            }
                            if (xmlAndComp.WeaponClass != null)
                            {
                                andComp.Conditions.Add(new WeaponClassCondition(xmlAndComp.WeaponClass));
                            }

                            if (xmlAndComp.NotCondition != null)
                            {
                                var notCond = ConvertXmlNotCondition(xmlAndComp.NotCondition, pseudo, attr);
                                andComp.Conditions.Add(notCond);
                            }
                            condition = andComp;
                            break;

                        case XmlItemsChoiceType.Not:
                            condition = ConvertXmlNotCondition((XmlNotCondition)xmlCondition, pseudo, attr);
                            break;

                        case XmlItemsChoiceType.OffHand:
                            condition = new OffHandCondition(xmlCondition.ToString());
                            break;

                        case XmlItemsChoiceType.Tag:
                            condition = new TagCondition(xmlCondition.ToString());
                            break;

                        case XmlItemsChoiceType.WeaponClass:
                            condition = new WeaponClassCondition(xmlCondition.ToString());
                            break;

                        case XmlItemsChoiceType.Keystone:
                            condition = new KeystoneCondition(xmlCondition.ToString());
                            break;

                        default:
                            throw new PseudoAttributeDataInvalidException(
                                      string.Format(L10n.Message("Unsupported condition type in attribute {0} in pseudo attribute {1}"), attr.Name, pseudo.Name));
                        }
                        attr.Conditions.Add(condition);
                    }
                }

                if (xmlPseudo.Hidden != "True")
                {
                    // If hidden they are only added to _pseudoNameDict and _nestedPseudosDict but not returned.
                    yield return(pseudo);
                }
            }
        }
 private NotCondition ConvertXmlNotCondition(XmlNotCondition xmlNotCond, PseudoAttribute pseudo, Attribute attr)
 {
     ICondition innerCond;
     if (xmlNotCond.Keystone != null)
     {
         innerCond = new KeystoneCondition(xmlNotCond.Keystone);
     }
     else if (xmlNotCond.OffHand != null)
     {
         innerCond = new OffHandCondition(xmlNotCond.OffHand);
     }
     else if (xmlNotCond.Tag != null)
     {
         innerCond = new TagCondition(xmlNotCond.Tag);
     }
     else if (xmlNotCond.WeaponClass != null)
     {
         innerCond = new WeaponClassCondition(xmlNotCond.WeaponClass);
     }
     else
     {
         throw new PseudoAttributeDataInvalidException(
             string.Format(L10n.Message("Empty not condition in attribute {0} in pseudo attribute {1}"), attr.Name, pseudo.Name));
     }
     return new NotCondition(innerCond);
 }