Spell05 Card Triggers - Monster-Train-2-Modding-Group/Trainworks-Reloaded GitHub Wiki

Part 5: Card Triggers (Pyre Sharpener)

← Part 4: Dynamic Scaling Spells | Next: Part 6: Conditionals & Card Pools →

So far, all of our spell cards have executed effects when cast by the player. In this lesson, we explore Card Triggers—effects that trigger automatically when specific conditions occur.

We will create Pyre Sharpener, an unplayable card featuring a Reserve trigger. At the end of each turn, if this card is in your hand, it automatically grants your Pyre +3 Attack. You will learn how to make cards unplayable, adding triggers to a card, and how to target the Pyre.


1. Asset Setup

Download the custom card art:

  • Download Art: Save your card art texture as PyreSharpener.png.
  • Save Location: Save it to your mod project under textures/PyreSharpener.png.

2. Complete JSON Definition

In Plugin.cs, add "json/spells/PyreSharpener.json" to your AddMergedJsonFile call. Then create json/spells/PyreSharpener.json and add:

{
  "$schema": "https://github.com/Monster-Train-2-Modding-Group/Trainworks-Reloaded/releases/latest/download/schema.json",
  "cards": [
    {
      "id": "PyreSharpener",
      "cost": 0,
      "cost_type": "unplayable",
      "names": {
        "english": "Pyre Sharpener"
      },
      "rarity": "common",
      "targets_room": false,
      "targetless": false,
      "class": "ClassBanished",
      "card_art": "@PyreSharpenerCardArt",
      "traits": [
        "@PyreSharpenerUnplayable"
      ],
      "triggers": [
        "@BuffThePyreOnUnplayed"
      ],
      "pools": [
        "MegaPool"
      ]
    }
  ],
  "traits": [
    {
      "id": "PyreSharpenerUnplayable",
      "name": "CardTraitUnplayable"
    }
  ],
  "effects": [
    {
      "id": "BuffThePyre",
      "name": "CardEffectBuffDamage",
      "target_mode": "pyre",
      "param_int": 3
    }
  ],
  "card_triggers": [
    {
      "id": "BuffThePyreOnUnplayed",
      "trigger": "on_unplayed_positive",
      "descriptions": {
        "english": "Apply +[effect0.power][attack] to your Pyre."
      },
      "effects": [
        "@BuffThePyre"
      ]
    }
  ],
  "game_objects": [
    {
      "id": "PyreSharpenerCardArt",
      "type": "card_art",
      "extensions": {
        "card_art": {
          "sprite": "@PyreSharpenerSprite"
        }
      }
    }
  ],
  "sprites": [
    {
      "id": "PyreSharpenerSprite",
      "path": "textures/PyreSharpener.png"
    }
  ]
}

3. What’s New in This Recipe

Making a Card Unplayable

Notice two distinct properties work together to handle unplayability:

  1. "cost_type": "unplayable": Hides the Ember cost circle on the card frame. This is visual only and does not mechanically prevent card play.
  2. "name": "CardTraitUnplayable": The functional trait that forbids the player from playing the card.

CardTriggers

Card Triggers exist in their own top-level array alongside traits and effects:

"card_triggers": [
  {
    "id": "BuffThePyreOnUnplayed",
    "trigger": "on_unplayed_positive",
    "descriptions": {
      "english": "Apply +[effect0.power][attack] to your Pyre."
    },
    "effects": [
      "@BuffThePyre"
    ]
  }
]
  • trigger: Defines the card trigger to use Reserve actually has two distinct trigger types:
    • "on_unplayed_positive": Fires at end of turn; styles the card with positive (green) FX around the card.
    • "on_unplayed_negative": Fires at end of turn; styles the card with negative/blight (red) FX around the card.
  • descriptions: Card triggers automatically add themselves into the card's description. Because of this, the card does not need a descriptions field.
    • [effect0.power]: Resolves to the param_int (3) of the trigger's first effect (effect0 -> @BuffThePyre).
    • [attack]: Replaced with the Attack icon.
  • effects: The list of effect IDs that fire when the trigger executes.

Buffing the Pyre

"effects": [
  {
    "id": "BuffThePyre",
    "name": "CardEffectBuffDamage",
    "target_mode": "pyre",
    "param_int": 3
  }
]
  • name: CardEffectBuffDamage applies temporary attack buff directly to enemy units or the Pyre. Never use this effect for friendly units as the attack gained will fall off when the monster is defeated use a CardUpgrade w/ CardEffectAddUpgradeToUnits instead.
  • target_mode: "pyre": This target mode, targets the pyre itself. You don't need to specify target_team with this target mode as there is no enemy pyre.

4. Testing Your Card

  1. Build your mod solution and ensure files are copied to BepInEx/plugins/<YourMod>/.
  2. Launch Monster Train 2 and check the BepInEx console log for clean loading.
  3. Start a battle with Pyre Sharpener in your deck:
    • Confirm the card lacks an Ember cost badge and displays a green Reserve trigger header reading: "Apply +3 Attack to your Pyre."
    • Attempt to drag and cast the card: verify that CardTraitUnplayable prevents it from being played.
    • End your turn while keeping the card in hand: observe the Reserve trigger fire and confirm your Pyre's attack increases by +3.

Next Steps

Now that you know how to build cards with card triggers, head to the final lesson: Part 6: Conditionals & Card Pools (Hymnist Recruit).

⚠️ **GitHub.com Fallback** ⚠️