Skip to content

2: The Fireplace DSL

Jerome Leclanche edited this page Jul 17, 2015 · 20 revisions

Action Sequences

Hearthstone defines sequences of actions that can happen at certain times. For example, a Battlecry will happen when a card was played from the hand. A Deathrattle will happen when a card with the DEATHRATTLE tag dies.

Those sequences can be defined in two ways. The recommended way is using the Fireplace DSL. Sequences which are too complex to be implemented using the DSL can be implemented as callables, which return an iterable of actions. An Action Sequence refers to an argument which can be an iterable of actions, or a callable that returns an iterable of actions.

Actions

The full Action reference is available here.

Action sequences are supported in the following card handlers:

  • action: The main action (Battlecry or spell action). Triggers when the card is played from the hand.
  • combo: Same as action, but triggers when at least one more card was played this turn, and the COMBO tag is set on the card.
  • deathrattle: The main death action. Triggers when the card dies, if it has the DEATHRATTLE tag. Can be used in Enchantment cards to attach a deathrattle to a buff (Note: the DEATHRATTLE tag still needs to be set on the buff for it to work).

Card Generators

When generating a card dynamically is needed, such as summoning a random minion of some sort, card generators can declaratively describe how the card should be picked. The base generator is fireplace.actions.RandomCardGenerator. The following generators build on top of it:

  • RandomCard()
  • RandomCollectible()
  • RandomMinion()
  • RandomSpell()
  • RandomWeapon()
  • RandomSparePart()

Each of those generators can take further filters. For example, to give the controller a random Dream Card, you would do:

Give(CONTROLLER, RandomCard(card_class=CardClass.DREAM))

To summon a random legendary minion that costs 5 mana, you would do:

Summon(CONTROLLER, RandomMinion(cost=5, rarity=Rarity.LEGENDARY))

Card Evaluators

When lazily evaluating a certain condition is required for a card's functionality, an Evaluator can be written. An Evaluator implements the evaluate(source, game) method, which returns True or False, depending on its given conditions.

The following Evaluators are implemented:

  • Dead(selector): Returns True if every target matching the selector is dead.
  • Find(selector, count): Returns True if the selector evaluates to at least count entities. count defaults to 1.

An evaluator has an optional "then" clause, and an optional "else" clause. To describe those clauses, use the & (binary and) and | (binary or) operators, respectively. For example, to implement the Kill Command effect:

Find(FRIENDLY_MINIONS + BEAST) & Hit(TARGET, 5) | Hit(TARGET, 3)

Special action: Copy()

The Copy() action is special. It takes a selector as argument, and returns copies of the arguments it's given. It can also be OR'd, in order to provide a fallback when the selector comes up empty:

Summon(CONTROLLER, Copy(RANDOM_ENEMY_MINION) | "CS2_231")

Counters

There is only one Counter currently implemented: Count(). It takes a selector argument and will evaluate to how many matches there are.

For example, to draw a card for every enemy minion:

Draw(CONTROLLER) * Count(ENEMY_MINIONS)

Events

Event listeners can be specified in events. The full Events reference is available here.

Attribute scripts

Attribute scripts are callable functions that take the form func(self, i). self is the card object, and i is the current value of the attribute at the level of the call. They can be used to dynamically increase/decrease certain values or set certain tags.

The following attribute scripts are supported:

  • atk
  • charge
  • cost
  • max_health

Note: When an attribute script that modifies max_health is set on a character, that character will immediately reset all its DAMAGE.