Conditions and Effects

If you want to create new effects or conditions for your card abilities, you can create a new script that inherits from ConditionData or EffectData, and override one of the functions.


For example, let's create a new ability effect to return all your cards into your deck, shuffle it, and then redraw the same number of cards. Create a new script called EffectRedrawHand.cs with:

using UnityEngine;
using TcgEngine;
using TcgEngine.Gameplay;

[CreateAssetMenu(fileName = "effect", menuName = "TcgEngine/Effect/RedrawHand", order = 10)]
public class EffectRedrawHand : EffectData
    public override void DoEffect(GameLogic logic, AbilityData ability, Card caster, Player target)
        int nb_cards = target.cards_hand.Count;        //Store number of cards in hand
        target.cards_deck.AddRange(target.cards_hand); //Add hand cards to your deck
        target.cards_hand.Clear();                     //Empty hand array
        logic.ShuffleDeck(target.cards_deck);          //Shuffle Deck
        logic.DrawCard(target.player_id, nb_cards );  //Redraw Hand

Notice in the definition of the function, the target is a Player, this means we will need to select a player target (like PlayerSelf or PlayerOpponent) when creating the ability.


Now lets say we want the player to only use this ability if they have at least 3 cards in hand. We can create a condition for it. Create a new script called ConditionHandCount.cs

using UnityEngine;
using TcgEngine;

[CreateAssetMenu(fileName = "condition", menuName = "TcgEngine/Condition/CountHand", order = 10)]
public class ConditionCountHand : ConditionData
    public int value;

    public override bool IsTriggerConditionMet(Game data, AbilityData ability, Card caster)
        Player player = data.GetPlayer(caster.player_id);
        int nb_cards = player.cards_hand.Count;
        return nb_cards >= value;

Data Files

We will now create the data files for the effect we just created. And then Link it to the ability.

In Unity, right click inside a folder, and select Create -> TcgEngine -> Effects, select your new effect, it should be named what you set in the tag [CreateAssetMenu] in your new script.

Do the same thing with your new condition, and set the value to 3.

Now in Resources/Abilities, create a new ability, you can dupplicate an existing one to make it faster with Ctrl-D

Set these settings on the ability

You can now add that ability to any card, this will give the card a new Activated ability that cost 2 mana, that can only be used when you have 3 or more cards in hand, and that will shuffle back your hand into the deck and redraw the same number of cards.

Trigger Condition vs Target Condition

A trigger condition will be checked to know if the ability should trigger or not, while a target condition will be checked to see if a target is valid. If trigger conditions are true, the ability will be resolved (mana/action will be spent, fx will appear). The target condition is checked for each individual target after the ability was already triggered.

For example if you have an ability that you can cast when you have 5 HP or less and that affects ALL blue cards on the board, 5 HP would be a trigger condition, while "is blue" would be a target condition.

When creating a new script, use IsTriggerConditionMet for trigger conditions and use IsTargetConditionMet for target conditions. And place the condition in the appropriate array on the ability. Target conditions can be defined with 3 different types of targets: Card, Player or Slot.

Last updated