[Feature] Get Ability by Ability Index

Zaddo

Active member
The Generic ability is very versatile. But if you have more than one, then you need to depend on the index order to retrieve the correct ability. Using order for retrieval can easily lead to configuration bugs.

The AbilityIndexParameter would typically be unique for multiple instances of the Generic ability. Having a method in UltimateCharacterLocomotion to retrieve abilities by type and the AbilityIndexParameter would make retrieval more targeted when several abilities of the same type exist.

For example:

C#:
       /// <summary>
        /// Returns the ability of type T with the specified Ability Index.
        /// </summary>
        /// <typeparam name="T">The type of ability to return.</typeparam>
        /// <param name="abilityIndex">The Ability Index</param>
        /// <returns>The ability of type T with the specified index. Can be null.</returns>
        public T GetAbilityByAbilityIndex<T>(int abilityIndex) where T : Ability
        {
            return GetAbility(typeof(T), abilityIndex) as T;
        }

        /// <summary>
        /// Returns the ability of the specified type with the Ability index.
        /// </summary>
        /// <param name="type">The type of ability to return.</param>
        /// <param name="abilityIndex">The Ability Index</param>
        /// <returns>The ability of the specified type with the specified ability index. Can be null.</returns>
        public Ability GetAbilityByAbilityIndex(System.Type type, int abilityIndex)
        {
            var allAbilities = (typeof(ItemAbility).IsAssignableFrom(type) ? m_ItemAbilities : m_Abilities);
            if (allAbilities != null)
            {
                for (int i = 0; i < allAbilities.Length; ++i)
                {
                    if (type.IsInstanceOfType(allAbilities[i]) && (allAbilities[i].AbilityIndexParameter == abilityIndex))
                    {
                        return allAbilities[i];
                    }
                }
            }
            return null;
        }
 
Last edited:
Hi, this looks very similar to what I did here with strings instead of ints : https://www.opsive.com/forum/index.php?threads/get-ability-by-string-reference.9101/

Naturally we agree on the need for an additional GetAbility method that uses a parameter to get a specific one, which may be necessary when we have several abilities of the same type or when using inheritance (like the Crawl ability being identified as Height Change), and also considering the unrealiability of indexes.

Another possibility would be to use the ID system, which is halfway between our two methods, this would definitely deserve a try !
 
Top