Example #1
0
        RuleIndex(string fileName, XDocument document, ProgressDialog dialog)
        {
            this.name = fileName;
            if (dialog != null) { dialog.SetDescription("Building elements..."); }

            int max = document.Root.Elements().Count();
            int current = 0;

            foreach (XElement element in document.Root.Elements())
            {
                if (dialog != null) { dialog.SetProgress(current++, max); }
                RuleElement re = new RuleElement(element);
                this.elements.Add(re.Id, re);
            }

            current = 0;
            if (dialog != null) { dialog.SetDescription("Binding categories..."); }
            foreach (RuleElement element in this.elements.Values)
            {
                if (dialog != null) { dialog.SetProgress(current++, this.elements.Count); }
                element.BindCategories(this);
            }

            current = 0;
            if (dialog != null) { dialog.SetDescription("Binding rules..."); }
            foreach (RuleElement element in this.elements.Values)
            {
                if (dialog != null) { dialog.SetProgress(current++, this.elements.Count); }
                element.BindRules(this);
            }

            if (dialog != null) { dialog.SetDescription("Reticulating splines..."); }
            this.elementsByName = this.elements.Values.ToLookup(e => e.Name);
            this.elementsByFullName = this.elements.Values.ToLookup(e => e.FullName);
        }
Example #2
0
 public static StatAliasRule New(RuleElement ruleElement, XElement element)
 {
     return(new StatAliasRule(
                ruleElement,
                element.Attribute(XNames.Name).Value,
                element.Attribute(XNames.Alias).Value));
 }
Example #3
0
 public static StatAliasRule New(RuleElement ruleElement, XElement element)
 {
     return new StatAliasRule(
         ruleElement,
         element.Attribute(XNames.Name).Value,
         element.Attribute(XNames.Alias).Value);
 }
Example #4
0
 public static TextStringRule New(RuleElement ruleElement, XElement element)
 {
     return new TextStringRule(
         ruleElement,
         element.Attribute(XNames.Name).Value,
         element.Attribute(XNames.Value).Value);
 }
Example #5
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);
        }
Example #6
0
 public static TextStringRule New(RuleElement ruleElement, XElement element)
 {
     return(new TextStringRule(
                ruleElement,
                element.Attribute(XNames.Name).Value,
                element.Attribute(XNames.Value).Value));
 }
Example #7
0
 public override void Bind(RuleIndex index)
 {
     if (this.boundElement == null)
     {
         this.boundElement = index.GetElement(this.type, this.elementName);
     }
 }
Example #8
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 #9
0
 public static GrantRule New(RuleElement ruleElement, XElement element)
 {
     // TODO: How do we interpret [Dilettante]? It's a hapax legomenon...
     return(new GrantRule(
                ruleElement,
                element.Attribute(XNames.Name).Value,
                element.Attribute(XNames.Type).Value));
 }
Example #10
0
        public static SuggestRule New(RuleElement ruleElement, XElement element)
        {
            // Attributes:
            //  name
            //  type

            return(new SuggestRule(ruleElement));
        }
Example #11
0
        public static SuggestRule New(RuleElement ruleElement, XElement element)
        {
            // Attributes:
            //  name
            //  type

            return new SuggestRule(ruleElement);
        }
Example #12
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 #13
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 #14
0
 public static GrantRule New(RuleElement ruleElement, XElement element)
 {
     // TODO: How do we interpret [Dilettante]? It's a hapax legomenon...
     return new GrantRule(
         ruleElement,
         element.Attribute(XNames.Name).Value,
         element.Attribute(XNames.Type).Value);
 }
Example #15
0
        public static DropRule New(RuleElement ruleElement, XElement element)
        {
            // Attributes:
            //  name
            //  type
            //  select

            return(new DropRule(ruleElement));
        }
Example #16
0
        public static DropRule New(RuleElement ruleElement, XElement element)
        {
            // Attributes:
            //  name
            //  type
            //  select

            return new DropRule(ruleElement);
        }
Example #17
0
        RuleIndex(string fileName, XDocument document, ProgressDialog dialog)
        {
            this.name = fileName;
            if (dialog != null)
            {
                dialog.SetDescription("Building elements...");
            }

            int max     = document.Root.Elements().Count();
            int current = 0;

            foreach (XElement element in document.Root.Elements())
            {
                if (dialog != null)
                {
                    dialog.SetProgress(current++, max);
                }
                RuleElement re = new RuleElement(element);
                this.elements.Add(re.Id, re);
            }

            current = 0;
            if (dialog != null)
            {
                dialog.SetDescription("Binding categories...");
            }
            foreach (RuleElement element in this.elements.Values)
            {
                if (dialog != null)
                {
                    dialog.SetProgress(current++, this.elements.Count);
                }
                element.BindCategories(this);
            }

            current = 0;
            if (dialog != null)
            {
                dialog.SetDescription("Binding rules...");
            }
            foreach (RuleElement element in this.elements.Values)
            {
                if (dialog != null)
                {
                    dialog.SetProgress(current++, this.elements.Count);
                }
                element.BindRules(this);
            }

            if (dialog != null)
            {
                dialog.SetDescription("Reticulating splines...");
            }
            this.elementsByName     = this.elements.Values.ToLookup(e => e.Name);
            this.elementsByFullName = this.elements.Values.ToLookup(e => e.FullName);
        }
Example #18
0
            public override IEnumerable <RuleElement> Filter(IEnumerable <RuleElement> elements)
            {
                RuleElement re = GetRuleElement();

                if (re == null)
                {
                    return(Enumerable.Empty <RuleElement>());
                }

                return(elements.Where(e => e.Categories.Contains(re.Id)));
            }
Example #19
0
        public static ReplaceRule New(RuleElement ruleElement, XElement element)
        {
            // Attributes:
            //  name
            //  requires
            //  Level
            //  multiclass
            //  optional
            //  power-replace
            //  retrain
            //  powerswap

            return new ReplaceRule(ruleElement);
        }
Example #20
0
        public static ModifyRule New(RuleElement ruleElement, XElement element)
        {
            // Attributes:
            //  name
            //  type
            //  Field
            //  value
            //  list-addition
            //  select
            //  requires
            //  die-increase

            return new ModifyRule(ruleElement);
        }
Example #21
0
        public static ModifyRule New(RuleElement ruleElement, XElement element)
        {
            // Attributes:
            //  name
            //  type
            //  Field
            //  value
            //  list-addition
            //  select
            //  requires
            //  die-increase

            return(new ModifyRule(ruleElement));
        }
Example #22
0
 public bool Grants(RuleElement element)
 {
     if (element == this)
     {
         return(true);
     }
     foreach (GrantRule grantRule in this.rules.OfType <GrantRule>())
     {
         if (grantRule.Target.Grants(element))
         {
             return(true);
         }
     }
     return(false);
 }
Example #23
0
        public static string ConvertElement(RuleIndex index, RuleElement element)
        {
            var stringWriter = new StringWriter();
            var converter = new Converter(index, stringWriter);

            converter.WriteGlobalPrefix();
            converter.WriteTypePrefix(element.Type);

            converter.WriteGenericRulesElement(element);

            converter.WriteTypeSuffix();
            converter.WriteGlobalSuffix();

            return stringWriter.ToString();
        }
Example #24
0
        public static ReplaceRule New(RuleElement ruleElement, XElement element)
        {
            // Attributes:
            //  name
            //  requires
            //  Level
            //  multiclass
            //  optional
            //  power-replace
            //  retrain
            //  powerswap


            return(new ReplaceRule(ruleElement));
        }
Example #25
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 #26
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));
        }
Example #27
0
 public ConditionalStatAdd(RuleElement element, string condition, StatAddRule rule)
     : base(element, rule)
 {
     this.condition = condition;
 }
Example #28
0
 ModifyRule(RuleElement element) : base(element)
 {
 }
Example #29
0
 public WearingStatAdd(RuleElement element, WearingExpression predicate, StatAddRule rule)
     : base(element, rule)
 {
     this.predicate = predicate;
 }
Example #30
0
 public StatStatAdd(RuleElement element, string stat, Identifier type, string sourceStat, bool negative)
     : base(element, stat, type)
 {
     this.sourceStat = sourceStat;
     this.negative = negative;
 }
Example #31
0
        public static StatAddRule New(RuleElement ruleElement, XElement element)
        {
            // TODO: HANDLE:
            //      requires, e.g.: requires="Epic Tier" (this is rather complex)
            //      non-zero
            //      zero
            //      statmin, e.g.: statmin="Dexterity 13"
            //

            string name = element.Attribute(XNames.Name).Value;
            string value = element.Attribute(XNames.Value).Value;

            Identifier type = null;
            XAttribute attribute = element.Attribute(XNames.Type);
            if (attribute != null) { type = Identifier.Get(attribute.Value); }

            StatAddRule rule;

            int constantValue;
            if (Int32.TryParse(value, out constantValue))
            {
                constantValue *= 2;
                if (element.Attribute(XNames.HalfPoint) != null) { constantValue += 1; }
                rule = new ConstantStatAdd(ruleElement, name, type, constantValue);
            }
            else
            {
                bool negative = false;
                if (value[0] == '+')
                {
                    value = value.Substring(1);
                }
                else if (value[0] == '-')
                {
                    negative = true;
                    value = value.Substring(1);
                }

                if (value.StartsWith("ABILITYMOD"))
                {
                    value = value.Substring(11, value.Length - 12);
                    rule = new AbilityModStatAdd(ruleElement, name, type, value, negative);
                }
                else
                {
                    // NOTE: The values that contain ':' are bugged; they don't actually work in cb either.
                    rule = new StatStatAdd(ruleElement, name, type, value, negative);
                }
            }

            attribute = element.Attribute(XNames.Condition);
            if (attribute != null)
            {
                rule = new ConditionalStatAdd(ruleElement, attribute.Value, rule);
            }

            attribute = element.Attribute(XNames.Wearing);
            if (attribute != null)
            {
                rule = new WearingStatAdd(ruleElement, WearingExpression.New(attribute.Value), rule);
            }

            attribute = element.Attribute(XNames.NotWearing);
            if (attribute != null)
            {
                rule = new NotWearingStatAdd(ruleElement, WearingExpression.New(attribute.Value), rule);
            }

            return rule;
        }
Example #32
0
 public ConditionalStatAdd(RuleElement element, string condition, StatAddRule rule)
     : base(element, rule)
 {
     this.condition = condition;
 }
Example #33
0
 protected DelegatingStatAdd(RuleElement element, StatAddRule rule)
     : base(element)
 {
     this.baseRule = rule;
     this.baseRule.PropertyChanged += BaseRulePropertyChanged;
 }
Example #34
0
 public void Grant(RuleElement element)
 {
     int refs;
     if (this.grants.TryGetValue(element, out refs))
     {
         this.grants[element] = refs + 1;
     }
     else
     {
         this.grants.Add(element, 1);
         element.Apply(this);
         MaybeSetInternalProperty(element, element.Type);
     }
 }
Example #35
0
 public void Revoke(RuleElement element)
 {
     int refs;
     if (this.grants.TryGetValue(element, out refs))
     {
         refs = refs - 1;
         if (refs == 0)
         {
             MaybeSetInternalProperty(null, element.Type);
             this.grants.Remove(element);
             element.Revoke(this);
         }
         else
         {
             this.grants[element] = refs;
         }
     }
 }
Example #36
0
 public NotWearingStatAdd(RuleElement element, WearingExpression predicate, StatAddRule rule)
     : base(element, predicate, rule)
 {
 }
Example #37
0
 protected Rule(RuleElement element)
 {
     this.element = element;
 }
Example #38
0
 public bool TryGetElement(Identifier id, out RuleElement element)
 {
     return(this.elements.TryGetValue(id, out element));
 }
Example #39
0
 public bool TryGetElement(Identifier type, Identifier name, out RuleElement element)
 {
     // TODO: Accelerate?
     element = this.elementsByName[name].SingleOrDefault(e => e.Type == type);
     return(element != null);
 }
Example #40
0
 public static Prereq Element(RuleElement element)
 {
     return new BoundElementPrereq(element);
 }
Example #41
0
 protected StatAddRule(RuleElement element)
     : base(element)
 {
 }
Example #42
0
 void MaybeSetInternalProperty(RuleElement element, Identifier type)
 {
     if (type == Identifier.Class)
     {
         this.@class = element;
         Notify("Class");
     }
     else if (type == Identifier.Level)
     {
         int newLevel =
             this.grants.Keys
                 .Where(re => re.Type == Identifier.Level)
                 .Max(re => Int32.Parse(re.Name.ToString()));
         if (newLevel != this.level)
         {
             this.level = newLevel;
             Notify("Level");
         }
     }
 }
Example #43
0
 protected BaseStatAdd(RuleElement element, string stat, Identifier type)
     : base(element)
 {
     this.stat = stat;
     this.type = type;
 }
Example #44
0
 StatAliasRule(RuleElement element, string name, string alias)
     : base(element)
 {
     this.name = name;
     this.alias = alias;
 }
Example #45
0
 public ConstantStatAdd(RuleElement element, string stat, Identifier type, int value)
     : base(element, stat, type)
 {
     this.value = value;
 }
Example #46
0
        public static StatAddRule New(RuleElement ruleElement, XElement element)
        {
            // TODO: HANDLE:
            //      requires, e.g.: requires="Epic Tier" (this is rather complex)
            //      non-zero
            //      zero
            //      statmin, e.g.: statmin="Dexterity 13"
            //

            string name  = element.Attribute(XNames.Name).Value;
            string value = element.Attribute(XNames.Value).Value;

            Identifier type      = null;
            XAttribute attribute = element.Attribute(XNames.Type);

            if (attribute != null)
            {
                type = Identifier.Get(attribute.Value);
            }


            StatAddRule rule;

            int constantValue;

            if (Int32.TryParse(value, out constantValue))
            {
                constantValue *= 2;
                if (element.Attribute(XNames.HalfPoint) != null)
                {
                    constantValue += 1;
                }
                rule = new ConstantStatAdd(ruleElement, name, type, constantValue);
            }
            else
            {
                bool negative = false;
                if (value[0] == '+')
                {
                    value = value.Substring(1);
                }
                else if (value[0] == '-')
                {
                    negative = true;
                    value    = value.Substring(1);
                }

                if (value.StartsWith("ABILITYMOD"))
                {
                    value = value.Substring(11, value.Length - 12);
                    rule  = new AbilityModStatAdd(ruleElement, name, type, value, negative);
                }
                else
                {
                    // NOTE: The values that contain ':' are bugged; they don't actually work in cb either.
                    rule = new StatStatAdd(ruleElement, name, type, value, negative);
                }
            }

            attribute = element.Attribute(XNames.Condition);
            if (attribute != null)
            {
                rule = new ConditionalStatAdd(ruleElement, attribute.Value, rule);
            }

            attribute = element.Attribute(XNames.Wearing);
            if (attribute != null)
            {
                rule = new WearingStatAdd(ruleElement, WearingExpression.New(attribute.Value), rule);
            }

            attribute = element.Attribute(XNames.NotWearing);
            if (attribute != null)
            {
                rule = new NotWearingStatAdd(ruleElement, WearingExpression.New(attribute.Value), rule);
            }

            return(rule);
        }
Example #47
0
 public NotWearingStatAdd(RuleElement element, WearingExpression predicate, StatAddRule rule)
     : base(element, predicate, rule)
 {
 }
Example #48
0
 TextStringRule(RuleElement element, string name, string value)
     : base(element)
 {
     this.name  = name;
     this.value = value;
 }
Example #49
0
 public WearingStatAdd(RuleElement element, WearingExpression predicate, StatAddRule rule)
     : base(element, rule)
 {
     this.predicate = predicate;
     this.predicate.PropertyChanged += PredicateValueChanged;
 }
Example #50
0
 StatAliasRule(RuleElement element, string name, string alias)
     : base(element)
 {
     this.name  = name;
     this.alias = alias;
 }
Example #51
0
 protected DelegatingStatAdd(RuleElement element, StatAddRule rule)
     : base(element)
 {
     this.baseRule = rule;
     this.baseRule.PropertyChanged += BaseRulePropertyChanged;
 }
Example #52
0
 DropRule(RuleElement element) : base(element)
 {
 }
Example #53
0
 public WearingStatAdd(RuleElement element, WearingExpression predicate, StatAddRule rule)
     : base(element, rule)
 {
     this.predicate = predicate;
     this.predicate.PropertyChanged += PredicateValueChanged;
 }
Example #54
0
 protected DelegatingStatAdd(RuleElement element, StatAddRule rule)
     : base(element)
 {
     this.baseRule = rule;
 }
Example #55
0
 public AbilityModStatAdd(RuleElement element, string stat, Identifier type, string sourceStat, bool negative)
     : base(element, stat, type)
 {
     this.sourceStat = sourceStat;
     this.negative   = negative;
 }
Example #56
0
 SuggestRule(RuleElement element) : base(element)
 {
 }
Example #57
0
 ReplaceRule(RuleElement element) : base(element)
 {
 }
Example #58
0
 TextStringRule(RuleElement element, string name, string value)
     : base(element)
 {
     this.name = name;
     this.value = value;
 }
Example #59
0
 ModifyRule(RuleElement element)
     : base(element)
 {
 }
Example #60
0
 GrantRule(RuleElement element, string name, string type)
     : base(element)
 {
     this.name = Identifier.Get(name);
     this.type = Identifier.Get(type);
 }