# 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.

### Effects

For example, let's create a new card 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(BattleLogic logic, AbilityData ability, BattleCharacter character, Card card, BattleCharacter 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, nb_cards );  //Redraw Hand
    }
}
```

Notice in the definition of the function, the target is a BattleCharacter, this means we will need to select a character target (like CharacterSelf or AllCharacters) when creating the ability.

### Conditions

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(Battle data, AbilityData ability, BattleCharacter character, Card card)
    {
        int nb_cards = character.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.

![](https://content.gitbook.com/content/2BYzsHAHUc7rwKMRx0iT/blobs/rB7krGGzOzA277jtO6eG/CreateEffect.png)

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

![](https://content.gitbook.com/content/2BYzsHAHUc7rwKMRx0iT/blobs/fGNYM6o5quYvNO0SgjWi/hand_card.png)

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

Set these settings on the ability

![](https://2996529479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2BYzsHAHUc7rwKMRx0iT%2Fuploads%2F0JZhyGy4YSguiqw7PWsY%2Fredraw_hand.png?alt=media\&token=95d5362a-326b-4c23-be94-e4a3126bba12)

You can now add that ability to any card, this will give the card a new ability that when played, if you have 3 or more cards in hand, 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. &#x20;

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.
