コード例 #1
0
        /// <summary>
        /// Gets an ability value.
        /// If the stacking rule in the mod is DoNotStack, an arbitrary matching ability will be chosen.
        /// If there are no values, null will be returned.
        /// </summary>
        /// <param name="name">The name of the ability.</param>
        /// <param name="obj">The object from which to get the value.</param>
        /// <param name="index">The ability value index (usually 1 or 2).</param>
        /// <param name="filter">A filter for the abilities. For instance, you might want to filter by the ability grouping rule's value.</param>
        /// <returns>The ability value.</returns>
        public static string GetAbilityValue(this IAbilityObject obj, string name, int index = 1, bool includeShared = true, bool includeEmpireCommon = true, Func <Ability, bool> filter = null)
        {
            if (obj == null)
            {
                return(null);
            }

            var abils = obj.Abilities();

            if (includeShared)
            {
                abils = abils.Union(obj.SharedAbilities());
            }
            if (includeEmpireCommon)
            {
                abils = abils.Union(obj.EmpireCommonAbilities());
            }

            abils = abils.Where(a => a.Rule != null && a.Rule.Matches(name) && a.Rule.CanTarget(obj.AbilityTarget) && (filter == null || filter(a)));
            abils = abils.Stack(obj);
            if (!abils.Any())
            {
                return(null);
            }
            return(abils.First().Values[index - 1]);
        }
コード例 #2
0
        /// <summary>
        /// Gets any abilities that can be activated.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static IDictionary <Ability, IAbilityObject> ActivatableAbilities(this IAbilityObject o)
        {
            if (o is Vehicle)
            {
                return(((Vehicle)o).ActivatableAbilities());
            }
            if (o is Planet)
            {
                return(((Planet)o).ActivatableAbilities());
            }

            var dict = new Dictionary <Ability, IAbilityObject>();

            foreach (var a in o.Abilities())
            {
                if (a.Rule.IsActivatable)
                {
                    dict.Add(a, o);
                }
            }
            return(dict);
        }