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); }
public static StatAliasRule New(RuleElement ruleElement, XElement element) { return(new StatAliasRule( ruleElement, element.Attribute(XNames.Name).Value, element.Attribute(XNames.Alias).Value)); }
public static StatAliasRule New(RuleElement ruleElement, XElement element) { return new StatAliasRule( ruleElement, element.Attribute(XNames.Name).Value, element.Attribute(XNames.Alias).Value); }
public static TextStringRule New(RuleElement ruleElement, XElement element) { return new TextStringRule( ruleElement, element.Attribute(XNames.Name).Value, element.Attribute(XNames.Value).Value); }
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); }
public static TextStringRule New(RuleElement ruleElement, XElement element) { return(new TextStringRule( ruleElement, element.Attribute(XNames.Name).Value, element.Attribute(XNames.Value).Value)); }
public override void Bind(RuleIndex index) { if (this.boundElement == null) { this.boundElement = index.GetElement(this.type, this.elementName); } }
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)); }
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)); }
public static SuggestRule New(RuleElement ruleElement, XElement element) { // Attributes: // name // type return(new SuggestRule(ruleElement)); }
public static SuggestRule New(RuleElement ruleElement, XElement element) { // Attributes: // name // type return new SuggestRule(ruleElement); }
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; }
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); }
public static DropRule New(RuleElement ruleElement, XElement element) { // Attributes: // name // type // select return(new DropRule(ruleElement)); }
public static DropRule New(RuleElement ruleElement, XElement element) { // Attributes: // name // type // select return new DropRule(ruleElement); }
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))); }
public static ReplaceRule New(RuleElement ruleElement, XElement element) { // Attributes: // name // requires // Level // multiclass // optional // power-replace // retrain // powerswap return new ReplaceRule(ruleElement); }
public static ModifyRule New(RuleElement ruleElement, XElement element) { // Attributes: // name // type // Field // value // list-addition // select // requires // die-increase return new ModifyRule(ruleElement); }
public static ModifyRule New(RuleElement ruleElement, XElement element) { // Attributes: // name // type // Field // value // list-addition // select // requires // die-increase return(new ModifyRule(ruleElement)); }
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); }
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(); }
public static ReplaceRule New(RuleElement ruleElement, XElement element) { // Attributes: // name // requires // Level // multiclass // optional // power-replace // retrain // powerswap return(new ReplaceRule(ruleElement)); }
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); }
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)); }
public ConditionalStatAdd(RuleElement element, string condition, StatAddRule rule) : base(element, rule) { this.condition = condition; }
ModifyRule(RuleElement element) : base(element) { }
public WearingStatAdd(RuleElement element, WearingExpression predicate, StatAddRule rule) : base(element, rule) { this.predicate = predicate; }
public StatStatAdd(RuleElement element, string stat, Identifier type, string sourceStat, bool negative) : base(element, stat, type) { this.sourceStat = sourceStat; this.negative = negative; }
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; }
protected DelegatingStatAdd(RuleElement element, StatAddRule rule) : base(element) { this.baseRule = rule; this.baseRule.PropertyChanged += BaseRulePropertyChanged; }
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); } }
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; } } }
public NotWearingStatAdd(RuleElement element, WearingExpression predicate, StatAddRule rule) : base(element, predicate, rule) { }
protected Rule(RuleElement element) { this.element = element; }
public bool TryGetElement(Identifier id, out RuleElement element) { return(this.elements.TryGetValue(id, out element)); }
public bool TryGetElement(Identifier type, Identifier name, out RuleElement element) { // TODO: Accelerate? element = this.elementsByName[name].SingleOrDefault(e => e.Type == type); return(element != null); }
public static Prereq Element(RuleElement element) { return new BoundElementPrereq(element); }
protected StatAddRule(RuleElement element) : base(element) { }
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"); } } }
protected BaseStatAdd(RuleElement element, string stat, Identifier type) : base(element) { this.stat = stat; this.type = type; }
StatAliasRule(RuleElement element, string name, string alias) : base(element) { this.name = name; this.alias = alias; }
public ConstantStatAdd(RuleElement element, string stat, Identifier type, int value) : base(element, stat, type) { this.value = value; }
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); }
TextStringRule(RuleElement element, string name, string value) : base(element) { this.name = name; this.value = value; }
public WearingStatAdd(RuleElement element, WearingExpression predicate, StatAddRule rule) : base(element, rule) { this.predicate = predicate; this.predicate.PropertyChanged += PredicateValueChanged; }
DropRule(RuleElement element) : base(element) { }
protected DelegatingStatAdd(RuleElement element, StatAddRule rule) : base(element) { this.baseRule = rule; }
public AbilityModStatAdd(RuleElement element, string stat, Identifier type, string sourceStat, bool negative) : base(element, stat, type) { this.sourceStat = sourceStat; this.negative = negative; }
SuggestRule(RuleElement element) : base(element) { }
ReplaceRule(RuleElement element) : base(element) { }
GrantRule(RuleElement element, string name, string type) : base(element) { this.name = Identifier.Get(name); this.type = Identifier.Get(type); }