/// <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))); }
/// <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)); }
public static ILookup <Ability, Ability> AbilityTree(this IAbilityObject obj, Func <IAbilityObject, bool> sourceFilter = null) { return(obj.UnstackedAbilities(true, sourceFilter).StackToTree(obj)); }