示例#1
0
        /// <summary>
        /// Determines if an object has a specified ability.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="abilityName"></param>
        /// <returns></returns>
        public static bool HasAbility(this IAbilityObject obj, string abilityName, bool includeShared = true)
        {
            IEnumerable <Ability> abils;

            if (includeShared && obj is IOwnableAbilityObject)
            {
                abils = obj.UnstackedAbilities(true).Union(obj.SharedAbilities());
            }
            else
            {
                abils = obj.UnstackedAbilities(true);
            }
            return(abils.Any(abil => abil.Rule != null && abil.Rule.Matches(abilityName)));
        }
示例#2
0
        /// <summary>
        /// All abilities belonging to an object.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static IEnumerable <Ability> Abilities(this IAbilityObject obj, Func <IAbilityObject, bool> sourceFilter = null)
        {
            if (obj == null)
            {
                return(Enumerable.Empty <Ability>());
            }

            if (sourceFilter == null && Galaxy.Current != null && Galaxy.Current.IsAbilityCacheEnabled)
            {
                // use the ability cache
                if (Galaxy.Current.AbilityCache[obj] == null)
                {
                    Galaxy.Current.AbilityCache[obj] = obj.UnstackedAbilities(true, sourceFilter).Stack(obj).ToArray();
                }
                return(Galaxy.Current.AbilityCache[obj]);
            }

            return(obj.UnstackedAbilities(true, sourceFilter).Stack(obj));
        }
示例#3
0
 public static ILookup <Ability, Ability> AbilityTree(this IAbilityObject obj, Func <IAbilityObject, bool> sourceFilter = null)
 {
     return(obj.UnstackedAbilities(true, sourceFilter).StackToTree(obj));
 }