Example #1
0
 SelectRule(Identifier type, int number, bool optional, ItemFilter filter, RuleElement element)
     : base(element)
 {
     this.filter = filter;
     this.type = type;
     this.number = number;
     this.optional = optional;
 }
Example #2
0
        public static SelectRule New(RuleElement ruleElement, XElement element)
        {
            // Attributes:
            //    requires
            //    spellbook
            //    existing
            //    default
            //    grant
            XAttribute attribute;

            Identifier type = Identifier.Get(element.Attribute(XNames.Type).Value);

            int number = 1;
            attribute = element.Attribute(XNames.Number);
            if (attribute != null) { number = Int32.Parse(attribute.Value); }

            string name = null;
            attribute = element.Attribute(XNames.Name);
            if (attribute != null) { name = attribute.Value; }

            bool optional = false;
            attribute = element.Attribute(XNames.Optional);
            if (attribute != null) { optional = true; }

            ItemFilter filter = null;
            attribute = element.Attribute(XNames.Category);
            if (attribute != null) { filter = ParseCategory(attribute.Value); }

            // Make the name pretty for grouping and tracking purposes.
            if (String.IsNullOrEmpty(name))
            {
                if (ruleElement.Type == Identifier.Level)
                {
                    name = "Level " + ruleElement.Name.ToString(); // "Level 1"
                }
                else
                {
                    name = ruleElement.Name.ToString(); // "Heir of Siberys (level 26)"
                }
            }

            return new SelectRule(type, number, name, optional, filter, ruleElement);
        }
Example #3
0
 public OrFilter(ItemFilter left, ItemFilter right)
 {
     this.left = left;
     this.right = right;
 }
Example #4
0
 public AndFilter(ItemFilter[] filters)
 {
     this.filters = filters;
 }
Example #5
0
        static ItemFilter ParseCategory(string category)
        {
            string[] filters = category.Split(',');
            var itemFilters = new ItemFilter[filters.Length];
            for (int i = 0; i < filters.Length; i++)
            {
                string[] orParts = filters[i].Split('|');
                ItemFilter orFilter = null;
                for (int j = 0; j < orParts.Length; j++)
                {
                    ItemFilter filter;
                    if (orParts[j].StartsWith("$$"))
                    {
                        filter = ParseSpecialCategory(orParts[j]);
                    }
                    else if (orParts[j].StartsWith("!"))
                    {
                        filter = new NotFilter(Identifier.Get(orParts[j].Substring(1)));
                    }
                    else
                    {
                        filter = new CategoryFilter(Identifier.Get(orParts[j]));
                    }

                    if (orFilter == null)
                    {
                        orFilter = filter;
                    }
                    else
                    {
                        orFilter = new OrFilter(orFilter, filter);
                    }
                }

                itemFilters[i] = orFilter;
            }

            if (itemFilters.Length == 1)
            {
                return itemFilters[0];
            }
            else
            {
                return new AndFilter(itemFilters);
            }
        }
Example #6
0
        public static SelectRule New(RuleElement ruleElement, XElement element)
        {
            // Attributes:
            //    name
            //    Level
            //    requires
            //    spellbook
            //    existing
            //    default
            //    grant
            XAttribute attribute;

            Identifier type = Identifier.Get(element.Attribute(XNames.Type).Value);

            int number = 1;
            attribute = element.Attribute(XNames.Number);
            if (attribute != null) { number = Int32.Parse(attribute.Value); }

            ItemFilter filter = null;
            attribute = element.Attribute(XNames.Category);
            if (attribute != null) { filter = ParseCategory(attribute.Value); }

            bool optional = false;
            attribute = element.Attribute(XNames.Optional);
            if (attribute != null) { optional = true; }

            return new SelectRule(type, number, optional, filter, ruleElement);
        }