Filters

Filters works in a similar way as conditions, and also help determine the targets of an ability.

A filter always has a source array and a destination array (containing either Cards, Characters or Slots), and the function should add the valid targets to the destination array and return it.

The advantage of filters is that they are a bit more flexible than conditions, but are also less performant and more complex (because of array manipulation). Filters also cannot be used for the trigger or for some targets that let the player make a selection. Filters are best used with the All Cards, All Characters or All Slots targets.

In this example, the filter is used to find the character that has the highest hp. The ability target is set to All Characters, which means the source array contains all the cards on the board. And destination array will contain only the cards with the highest attack.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TcgEngine;

[CreateAssetMenu(fileName = "filter", menuName = "TcgEngine/Filter/HighestHP", order = 10)]
public class FilterHighestHP : FilterData
{
    public override List<Card> FilterTargets(Battle data, AbilityData ability, BattleCharacter caster, Card card, List<BattleCharacter> source, List<BattleCharacter> dest)
    {
        //Find highest hp value
        int highest= 0;
        foreach (BattleCharacter character in source)
        {
            int hp = character.GetHP();
            if (hp > highest)
                highest = hp ;
        }

        //Add all highest (more than one card can be targeted)
        foreach (BattleCharacter character in source)
        {
            int hp = character.GetHP();
            if (hp  == highest)
                dest.Add(character);
        }

        return dest; //Return all characters with highest HP
    }
}

Similar to conditions and effects, you need to create a scriptable object from the Create->TcgEngine menu. Filters can be added on the ability data inside the filters_target array.

Last updated