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, Players 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 Players or All Slots targets.

In this example, the filter is used to find the card that has the highest attack. The ability target is set to All Cards Boards, 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/HighestAttack", order = 10)]
public class FilterHighestAttack : FilterData
{
    public override List<Card> FilterTargets(Game data, AbilityData ability, Card caster, List<Card> source, List<Card> dest)
    {
        //Find highest attack value
        int highest= 0;
        foreach (Card card in source)
        {
            int attack= card.GetAttack();
            if (attack > highest)
                highest= attack;
        }

        //Add all highest (more than one card can be targeted)
        foreach (Card card in source)
        {
            int attack = card.GetAttack();
            if (attack == highest)
                dest.Add(card);
        }

        return dest; //Return all cards with highest attack
    }
}

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