Example #1
0
 /// <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));
 }
Example #2
0
 /// <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)));
 }
Example #3
0
        /// <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));
        }
Example #4
0
 public bool Evaluate(ConditionSettings settings, params string[] replacements)
 {
     return(!_condition.Evaluate(settings, replacements));
 }
Example #5
0
 public bool Evaluate(ConditionSettings settings, params string[] replacements)
 {
     return(Conditions.Count <= 0 || Conditions.Any(c => c.Evaluate(settings, replacements)));
 }