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.

The full Action reference is available here.

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)