Why not refactoring the FilterStrategy too?

Is there any particular reason for which Sam didn’t refactor the FilterStrategy too?
I can see an obvious advantage of passing AbilityData to FilterStrategy’s Filter method: be able to identify the caster of this ability, and thus, get any ability more flexible. For instance: abilities could also be used by enemies.

namespace RPG.Abilities
{
    public abstract class FilterStrategy : ScriptableObject
    {
        public abstract IEnumerable<GameObject> Filter(AbilityData abilityData);
    }
}

And then you can do something like:

namespace RPG.Abilities.Targeting
{
    [CreateAssetMenu(menuName = ("RPG/Abilities/Filter/Filter Opponent By Tag"))]
    public class FilterOponnentByTagStrategy : FilterStrategy
    {
        [SerializeField] string player;
        [SerializeField] string enemy;
        public override IEnumerable<GameObject> Filter(AbilityData abilityData)
        {
            string tagToCheck = abilityData.User.CompareTag(player) ? enemy : player;

            foreach (GameObject objectToFilter in abilityData.Targets)
            {
                if (objectToFilter.CompareTag(tagToCheck))
                    yield return objectToFilter;
            }
        }
    }
}

And finally use this filter strategy on any ability. If this ability is casted by an enemy, it will affect only the player and vice-versa.
Obviously, you could go also with a FilterAllyByTagStrategyand, by tweaking a little bit the code above, be able to have a healing group effect for both players and enemies…

Sam didn’t focus on enemies performing abilities (or wearing armor, for that matter). I’ve done something fairly similar in my own strategies.

1 Like

Thank you for all your answers!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms