/// <summary> /// Returns true if <paramref name="actualAttributeName"/> matches this attribute's name /// (while taking wildcards into account) and evaluates to true given <paramref name="settings"/> /// and the replacements if applicable. /// </summary> /// <param name="settings">The settings to evaluate under. (not null)</param> /// <param name="actualAttributeName">The attribute name to compare <see cref="Name"/> against. (not null)</param> /// <returns> /// True if <paramref name="actualAttributeName"/> matches <see cref="Name"/> and <see cref="ICondition.Evaluate"/> /// returns true. /// </returns> public bool MatchesAndEvaluates(ConditionSettings settings, string actualAttributeName) { if (settings == null) throw new ArgumentNullException("settings"); if (actualAttributeName == null) throw new ArgumentNullException("actualAttributeName"); // If the attribute name has no wildcards, check if it matches the actual name // and evaluate without replacements. if (!WildcardRegex.IsMatch(Name)) return Name == actualAttributeName && Evaluate(settings); var searchRegex = new Regex("^" + WildcardRegex.Replace(Name, "(.*)") + "$"); var match = searchRegex.Match(actualAttributeName); if (!match.Success) return false; var groups = match.Groups; var groupNames = new string[groups.Count - 1]; // The first group is the whole match, we don't want that one. for (int i = 0, j = 1; j < groups.Count; i++, j++) { groupNames[i] = groups[j].Value; } return Evaluate(settings, groupNames); }
/// <summary> /// Returns true iff <see cref="ConditionSettings.Keystones"/> contains <see cref="_keystone"/>. /// </summary> public bool Evaluate(ConditionSettings settings, params string[] replacements) { if (settings == null) throw new ArgumentNullException("settings"); return settings.Keystones.Any(k => k == _keystone); }
public bool Evaluate(ConditionSettings settings, params string[] replacements) { return !_condition.Evaluate(settings, replacements); }
public bool Evaluate(ConditionSettings settings, params string[] replacements) { return Conditions.Count <= 0 || Conditions.Any(c => c.Evaluate(settings, replacements)); }
/// <summary> /// Returns true iff <see cref="ConditionSettings.WeaponClass"/> has the specified /// alias with placeholders replaced by the given replacements. /// </summary> public bool Evaluate(ConditionSettings settings, params string[] replacements) { if (settings == null) throw new ArgumentNullException("settings"); // ReSharper disable once CoVariantArrayConversion // Passing replacements as multiple strings cast to objects is exactly what we want. return settings.WeaponClass.HasAlias(string.Format(_alias, replacements)); }
/// <summary> /// Converts attribute constraints to pseudo attribute constraints with the set Tags, WeaponClass, /// OffHand and check-tagged keystones where possible. /// Str, Int and Dex are not removed from the attribute constraint list but still converted. /// </summary> private void ConverteAttributeToPseudoAttributeConstraints() { var keystones = from id in Tree.GetCheckedNodes() where SkillTree.Skillnodes[id].IsKeyStone select SkillTree.Skillnodes[id].Name; var conditionSettings = new ConditionSettings(Tags, OffHand, keystones.ToArray(), WeaponClass); var convertedConstraints = new List<AttributeConstraint>(); foreach (var attributeConstraint in AttributeConstraints) { var attrName = attributeConstraint.Data; // Select the pseudo attributes and the multiplier for attributes which match the given one and evaluate to true. var pseudos = from pseudo in _pseudoAttributes let matches = (from attr in pseudo.Attributes where attr.MatchesAndEvaluates(conditionSettings, attrName) select attr) where matches.Any() select new { PseudoAttribute = pseudo, Multiplier = matches.First().ConversionMultiplier }; // Add attribute target and weight to the pseudo attributes. var converted = false; foreach (var pseudo in pseudos) { var pseudoAttribute = pseudo.PseudoAttribute; converted = true; if (_addedPseudoAttributes.Contains(pseudoAttribute)) { foreach (var pseudoAttributeConstraint in PseudoAttributeConstraints) { if (pseudoAttributeConstraint.Data == pseudoAttribute) { pseudoAttributeConstraint.TargetValue += attributeConstraint.TargetValue * pseudo.Multiplier; } } } else { _addedPseudoAttributes.Add(pseudoAttribute); PseudoAttributeConstraints.Add(new PseudoAttributeConstraint(pseudoAttribute) { TargetValue = attributeConstraint.TargetValue * pseudo.Multiplier }); } } if (converted && attrName != "+# to Intelligence" && attrName != "+# to Dexterity" && attrName != "+# to Strength") { convertedConstraints.Add(attributeConstraint); } } // Update the attribute constraint related collections. foreach (var convertedConstraint in convertedConstraints) { _addedAttributes.Remove(convertedConstraint.Data); AttributeConstraints.Remove(convertedConstraint); } if (convertedConstraints.Count > 0) { AttributesView.Refresh(); NewAttributeConstraint = convertedConstraints[0]; PseudoAttributesView.Refresh(); PseudoAttributesView.MoveCurrentToFirst(); NewPseudoAttributeConstraint.Data = PseudoAttributesView.CurrentItem as PseudoAttribute; } }