enjine 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fde1590b396d19e899c2fb1c3a4d84f16696a43f4dc45fe07c8ca9fc6bf8a01c
4
- data.tar.gz: 553667205ce6cb1ab14866e0f0e7cfa2c34102182460e7a09e352cff4adcb9be
3
+ metadata.gz: 242fd476df82923c7f0e3cd8ca58c5fde0bc0b06a92927c687a327b7b9c652e2
4
+ data.tar.gz: 8ff4dfefd1cfe4a565a9d5797424fcf1d46f6e3422dcca839f3593b28225a997
5
5
  SHA512:
6
- metadata.gz: 0c358469569ae3e2fc717e932202be9cf2602011074ed4e17f9a2f5fcf6511260f4270047ffcad69befb15649a4f56a9efeec4bcf27d34a035cb24c87832bf1f
7
- data.tar.gz: 58bb47820eb19f73b97b3cf16d35f50e68eb8d0f20b7d41e32bbda2d11fc5338dda5193159deed98388047bf24efabd9b8428680d4b8b0b3b09508022f3b0a48
6
+ metadata.gz: f0d017430d576d98fecd61959c9cd0ff40d82d517bc4403d3e5382940d970e6f9e7bd0843c188c41e8861768e6fd209efff7556984d12c097b52a725fafaef41
7
+ data.tar.gz: a27e01bf5ff45d2da799a13622a7be2de0dc4d5caeb5827ffe16488562ed82a3941603cff0eaf01d4f2e001221362090227972c35f952f8e77d9f10b84cc9171
data/CHANGELOG.md CHANGED
@@ -8,6 +8,32 @@ change the public API; the stable surface is described in
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [0.6.2] - 2026-11-29
12
+
13
+ ### Added
14
+ - Filters take `color_count` bounds (integers 0-5): "monocolored" `{"color_count": {"equal": 1}}`, "multicolored"
15
+ `{"at_least": 2}`, "colorless" `{"equal": 0}`, for targets, `spell` filters and `each` selectors (CR 105.2a-c).
16
+ - Mana abilities may remove counters from their own source as a cost (`{"remove_counters": {"count": 1, "counter":
17
+ "charge", "self": true}}`: no choice, so CR 605.3a holds; without {T} it can be activated once per counter and
18
+ affordability counts each) and put counters on it (`"add_counters": {"counter": "point", "amount": 1}`, CR 605.1a).
19
+ Either makes a payment that used it irreversible.
20
+ - Copy exceptions take `replace` (`["types", "subtypes", "supertypes"]`): the listed values set the copied ones instead
21
+ of adding to them ("except it's a 6/6 Dinosaur creature", CR 707.9b, 205.1a); without it they still add (CR 205.1b).
22
+ A later copy effect's `replace` wins over earlier additions.
23
+ - Colorless hybrid mana symbols `{C/W}`, `{C/U}`, `{C/B}`, `{C/R}`, `{C/G}` in mana costs: paid with colorless mana or
24
+ the color, the card is that color, mana value 1 per symbol (CR 107.4, 107.4e, 202.2d, 202.3f).
25
+ - `scry` and `surveil` take `to`: each named player does it with their own library, in APNAP order ("target player
26
+ scries X", CR 701.22a, 701.25a, 101.4). It was accepted and ignored before.
27
+
28
+ ### Fixed
29
+ - An activated ability costing "remove N counters from this" (`remove_counters` with `self: true`) and "sacrifice
30
+ this" crashed (KeyError) when the sacrifice came first in the list: costs that take the source away (`sacrifice`,
31
+ `exile_self`) are now paid after the others, in activated abilities, `pay` effects and mana abilities (CR 601.2h,
32
+ 602.2b). A sacrificed source's remembered counters are those it had as it left.
33
+ - A delayed or reflexive triggered ability created by a spell or ability with X read X as 0; it now has the X of what
34
+ created it (CR 107.3n, 603.12).
35
+ - `scry` and `surveil` ignored their `if` condition (CR 608.2c).
36
+
11
37
  ## [0.6.1] - 2026-11-29
12
38
 
13
39
  ### Fixed
@@ -316,7 +342,8 @@ Includes 0.4.0, which was tagged but never published to RubyGems.
316
342
  - `enjine` CLI: hot-seat and random play, `--validate`, `--verify`,
317
343
  `--random-deck`, save and load.
318
344
 
319
- [Unreleased]: https://github.com/thisiscetin/enjine/compare/v0.6.1...HEAD
345
+ [Unreleased]: https://github.com/thisiscetin/enjine/compare/v0.6.2...HEAD
346
+ [0.6.2]: https://github.com/thisiscetin/enjine/compare/v0.6.1...v0.6.2
320
347
  [0.6.1]: https://github.com/thisiscetin/enjine/compare/v0.6.0...v0.6.1
321
348
  [0.6.0]: https://github.com/thisiscetin/enjine/compare/v0.5.0...v0.6.0
322
349
  [0.5.0]: https://github.com/thisiscetin/enjine/compare/v0.4.1...v0.5.0
data/SUPPORTED.md CHANGED
@@ -132,7 +132,7 @@ Rules version: Comprehensive Rules effective 2026-11-06.
132
132
  | [`double_tokens`](docs/reference/abilities.md#double_tokens) | 614.1a, 614.5, 111.1, 616.1 | While this permanent is on the battlefield, if tokens would be created under its controller's control, twice that many of those tokens are created instead. Several apply one after another (two make four times as many). |
133
133
  | [`draw_replacement`](docs/reference/abilities.md#draw_replacement) | 614.11, 614.11a, 614.5, 121.2, 616.1 | While this permanent is on the battlefield, each time its controller would draw a card, they draw `amount` cards instead (even with an empty library). The draws it makes aren't replaced by it again, but another such effect applies to each of them. |
134
134
  | [`enchant`](docs/reference/abilities.md#enchant) | 702.5a, 115.1b, 303.4a | The Aura's enchant ability: a target filter for what its spell targets and what the Aura may be attached to, e.g. "creature" or {"permanent": {"any_of": ["artifact", "creature"]}}. Only Auras have it. |
135
- | [`enter_as_copy`](docs/reference/abilities.md#enter_as_copy) | 707.5, 707.9b, 614.1c, 614.12 | As this permanent enters, its controller may choose a permanent on the battlefield matching `of`; it enters as a copy of that permanent (its copiable values, with the `except` modifications) and its enter abilities trigger. `with_counters: true`: it also enters with the counters the copied permanent has. Choosing none: it enters as itself. |
135
+ | [`enter_as_copy`](docs/reference/abilities.md#enter_as_copy) | 707.5, 707.9b, 205.1a, 614.1c, 614.12 | As this permanent enters, its controller may choose a permanent on the battlefield matching `of`; it enters as a copy of that permanent (its copiable values, with the `except` modifications) and its enter abilities trigger. `with_counters: true`: it also enters with the counters the copied permanent has. Choosing none: it enters as itself. |
136
136
  | [`enters_attacking`](docs/reference/abilities.md#enters_attacking) | 614.1c, 508.4, 506.4 | While this permanent's controller controls an attacking creature, permanents matching `affects` enter the battlefield tapped and attacking (the defending player). They never "attacked", so attack triggers don't see them. |
137
137
  | [`enters_prepared`](docs/reference/abilities.md#enters_prepared) | 723.3a, 614.1c | This permanent enters the battlefield prepared (it needs a prepare spell, see `layout: "prepare"`). |
138
138
  | [`enters_tapped`](docs/reference/abilities.md#enters_tapped) | 614.1c, 614.12 | This permanent enters the battlefield tapped (a self-replacement effect). |
@@ -159,7 +159,7 @@ Rules version: Comprehensive Rules effective 2026-11-06.
159
159
  | [`life_gain_replacement`](docs/reference/abilities.md#life_gain_replacement) | 614.1a, 614.5, 616.1, 119.10 | While this permanent is on the battlefield, each time `player` (you (default) | opponent | any, relative to its controller) would gain life, instead: `multiply` (2 = "twice that much"), `plus` an amount ("that much life plus 1"), or `lose: true` ("that player loses that much life instead"). Each applies once to an event; the affected player's best order is used: losing instead first, then adding, then multiplying. Gaining 0 life is no event (nothing applies). |
160
160
  | [`look_at_top`](docs/reference/abilities.md#look_at_top) | 401.5, 604.1 | While this permanent is on the battlefield, its controller sees the top card of their library (the `library_top` of their view). |
161
161
  | [`loyalty`](docs/reference/abilities.md#loyalty) | 606.3, 606.4, 606.5, 602.2b | A loyalty ability. Its cost adds (positive) or removes (negative) loyalty counters and is paid on activation. Sorcery speed, and only one loyalty ability per planeswalker per turn. |
162
- | [`mana`](docs/reference/abilities.md#mana) | 605.1a, 605.3a, 605.3b, 106.1a, 106.4, 106.6, 607.2d, 602.5b | An activated mana ability: pay the cost, add the mana to your mana pool immediately. It does not use the stack and can be activated whenever you have priority. `produce`: the fixed mana (`amount` times). Or `color`: `amount` mana (default 1) of one color you choose as you activate it (`"any_one"`) or in any combination of colors (`"any"`); `colors` limits the choice. `"chosen"`: of the color chosen as this entered (choose_color). `spend_only` restricts how the mana can be spent. `only_if`: "Activate only if ...". `limit: "once_each_turn"`: "Activate only once each turn." |
162
+ | [`mana`](docs/reference/abilities.md#mana) | 605.1a, 605.3a, 605.3b, 106.1a, 106.4, 106.6, 607.2d, 602.5b, 122.1 | An activated mana ability: pay the cost, add the mana to your mana pool immediately. It does not use the stack and can be activated whenever you have priority. `produce`: the fixed mana (`amount` times). Or `color`: `amount` mana (default 1) of one color you choose as you activate it (`"any_one"`) or in any combination of colors (`"any"`); `colors` limits the choice. `"chosen"`: of the color chosen as this entered (choose_color). `spend_only` restricts how the mana can be spent. `only_if`: "Activate only if ...". `limit: "once_each_turn"`: "Activate only once each turn." `add_counters`: it also puts counters on its own source ("Add {C}. Put a point counter on this"). |
163
163
  | [`max_speed`](docs/reference/abilities.md#max_speed) | 702.178a, 702.178b, 702.179e, 113.6c | While your speed is 4 (max speed), this object has `keywords` and `abilities` (any kind: activated, triggered, static, mana; an ability with a graveyard cost works from your graveyard). |
164
164
  | [`may_not_untap`](docs/reference/abilities.md#may_not_untap) | 502.3, 604.1 | Its controller may choose not to untap it during their untap step (decision `untap_choice`, asked only while it's tapped). |
165
165
  | [`mayhem`](docs/reference/abilities.md#mayhem) | 702.187a, 702.187b, 702.187c, 118.9, 601.2b, 601.2f, 601.2h, 305.1 | Mayhem: as long as you discarded this card this turn, you may cast it from your graveyard by paying `cost` rather than its mana cost. Without `cost` (`"mayhem"`), you may play it from your graveyard (a land too) if you discarded it this turn. Cast option `via: "alt:<ref>"`. |
@@ -261,7 +261,7 @@ Rules version: Comprehensive Rules effective 2026-11-06.
261
261
  | [`mana`](docs/reference/costs.md#mana) | 601.2g, 601.2h, 602.2b | Pay mana as part of an activation. Paid during the activation by spending mana from your pool, tapping sources one at a time. |
262
262
  | [`one_of`](docs/reference/costs.md#one_of) | 118.3, 601.2b, 601.2f, 602.2b, 118.12 | Pay one of the listed costs (two or more), chosen as the spell or ability is cast or activated (the `choose_cost_option` decision) or, for `pay` and ward, as it is paid. A cost that can't be paid can't be chosen. |
263
263
  | [`pay_life`](docs/reference/costs.md#pay_life) | 119.4, 119.4b, 118.3b, 601.2b, 107.3a, 702.21a | Pay that much life (you lose it). Only possible while your life total is at least that much. `"X"` pays the X announced for the spell or ability (at most your life total); it may be a spell's additional cost. An amount (e.g. {"power": "self"}, "pay life equal to its power") is computed as the cost is paid. |
264
- | [`remove_counters`](docs/reference/costs.md#remove_counters) | 602.2b, 601.2h, 118.3, 122.1 | Remove `count` counters (of kind `counter`, or any kind) from among permanents you control matching `filter` (default creature), one counter per choice. Removed as it becomes cast. `self: true`: only from this permanent ("Remove two counters from Ghost-Spider"). |
264
+ | [`remove_counters`](docs/reference/costs.md#remove_counters) | 602.2b, 601.2h, 118.3, 122.1, 605.3a | Remove `count` counters (of kind `counter`, or any kind) from among permanents you control matching `filter` (default creature), one counter per choice. Removed as it becomes cast. `self: true`: only from this permanent ("Remove two counters from Ghost-Spider"). With `self: true` and a `counter` kind it needs no choice, so a mana ability may have it ("Remove a charge counter from this: Add one mana of any color"). |
265
265
  | [`sacrifice`](docs/reference/costs.md#sacrifice) | 701.21a, 602.2b, 118.3 | Sacrifice the permanent the ability belongs to (it goes to its owner's graveyard). |
266
266
  | [`sacrifice_permanent`](docs/reference/costs.md#sacrifice_permanent) | 701.21a, 601.2h, 602.2b, 118.3, 608.2h | Sacrifice `count` permanents you control matching `filter` (`other: true`: not the source). Chosen while casting or activating, sacrificed as it becomes cast; the sacrificed permanent's last known types and subtypes are remembered (condition `sacrificed`), and its power, toughness and mana value (amount `sacrificed`). |
267
267
  | [`tap`](docs/reference/costs.md#tap) | 107.5, 602.5a, 602.2b, 607.1a, 302.6 | {T} — tap the permanent the ability belongs to. Requires it to be untapped. `{"tap": "granter"}` instead taps the permanent whose static ability granted this ability ("Tap Fishing Pole"; not {T}, so summoning sickness doesn't matter). |
@@ -308,11 +308,11 @@ Rules version: Comprehensive Rules effective 2026-11-06.
308
308
  | [`counter_unless_pays`](docs/reference/effects.md#counter_unless_pays) | 701.6a, 118.12a, 605.3a, 701.67a | Counter each referenced spell or ability unless its controller pays `mana` (or `waterbend`s that cost, CR 701.67a, or pays the list of costs `cost`) as this resolves (they choose, and pay like any cost; mana abilities allowed). |
309
309
  | [`create_emblem`](docs/reference/effects.md#create_emblem) | 114.1, 114.2, 114.3, 114.4, 113.6p | Each referenced player (default you) gets an emblem with the `abilities` (triggered, static or player_rule abilities). An emblem is in the command zone for the rest of the game; its abilities work there, and "this emblem" is the source of what they do. |
310
310
  | [`create_token`](docs/reference/effects.md#create_token) | 111.1, 111.10, 701.7a, 704.5d, 508.4, 506.3b, 707.2 | Create `amount` tokens under the referenced player's control (default: you). `token` is a predefined token name (Treasure, Clue, Food) or an inline card definition. `tapped: true` creates them tapped; `attacking: true` attacking (only for the attacking player during combat, CR 506.3b); when the defending player controls a planeswalker, the controller chooses for each token whether it attacks that player or one of their planeswalkers (CR 508.4). `size` (an amount, fixed as the effect starts) makes them N/N ("an X/X Spirit token, where X is ..."; part of their copiable values). |
311
- | [`create_token_copy`](docs/reference/effects.md#create_token_copy) | 707.2, 707.8, 707.9a, 707.9b, 111.1, 614.1c | For each object `of` refers to (a permanent, a card in any zone, or the source with "self"), the referenced players (default: you) each create `amount` tokens that are copies of it: its copiable values (its card as modified by other copy effects, not counters, status or other effects), with the `except` modifications. The tokens are the effect's result, for later effects such as granting haste or a delayed sacrifice. |
311
+ | [`create_token_copy`](docs/reference/effects.md#create_token_copy) | 707.2, 707.8, 707.9a, 707.9b, 205.1a, 205.1b, 111.1, 614.1c | For each object `of` refers to (a permanent, a card in any zone, or the source with "self"), the referenced players (default: you) each create `amount` tokens that are copies of it: its copiable values (its card as modified by other copy effects, not counters, status or other effects), with the `except` modifications. The tokens are the effect's result, for later effects such as granting haste or a delayed sacrifice. |
312
312
  | [`damage_replacement`](docs/reference/effects.md#damage_replacement) | 614.1a, 611.2a, 611.2c, 616.1 | For the `duration` (end_of_turn by default, or until_your_next_turn), damage that would be dealt to the referenced players and permanents (`to`, fixed as it resolves; with `permanents: true` also the permanents a referenced player controls as the damage is dealt) is changed: `multiply` (2 = "double that damage") or `plus` an amount (computed as it resolves). `combat`: combat | noncombat only. Doubling applies before adding. |
313
313
  | [`damage_unpreventable`](docs/reference/effects.md#damage_unpreventable) | 615.12, 611.2a | Until end of turn, damage (`combat`: combat | noncombat only) can't be prevented. |
314
314
  | [`deal_damage`](docs/reference/effects.md#deal_damage) | 120.3a, 120.3c, 120.3e, 120.6, 120.4a, 120.10 | Deal `amount` damage to each referenced creature, planeswalker or player. Damage to a player causes life loss; to a planeswalker removes loyalty counters; to a creature is marked until cleanup. {"this_way": n} naming it is the excess damage it dealt (beyond lethal damage, or a planeswalker's loyalty). |
315
- | [`delayed_trigger`](docs/reference/effects.md#delayed_trigger) | 603.7a, 603.7b, 603.7c, 603.7d, 603.7e | Creates a delayed triggered ability with the controller and source of the resolving spell or ability. It triggers only once, the next time `when` happens (e.g. {"step_begins": {"step": "end", "whose": "each"}} for the next end step). Its `effects` may use {"result": n} for what earlier effects of the creating list moved or created (n below its position); those objects are affected only if they are still where they were put. Its own effects are numbered on from there. |
315
+ | [`delayed_trigger`](docs/reference/effects.md#delayed_trigger) | 603.7a, 603.7b, 603.7c, 603.7d, 603.7e, 107.3n | Creates a delayed triggered ability with the controller and source of the resolving spell or ability. It triggers only once, the next time `when` happens (e.g. {"step_begins": {"step": "end", "whose": "each"}} for the next end step). Its `effects` may use {"result": n} for what earlier effects of the creating list moved or created (n below its position); those objects are affected only if they are still where they were put. Its own effects are numbered on from there. |
316
316
  | [`destroy`](docs/reference/effects.md#destroy) | 701.8a | Destroy each referenced permanent (it goes to its owner's graveyard). |
317
317
  | [`dig`](docs/reference/effects.md#dig) | 701.20a, 701.20e, 401.4, 400.7j, 406.3, 607.2a, 702.75a | Look at the top `amount` cards of your library (`reveal: "all"`: reveal them). Take `count` (default 1; "all": every matching card, no choice; "any": any number) cards matching `for` and put them into `put` (`tapped` onto the battlefield); `optional`: you may take fewer. `reveal: "chosen"` reveals the cards taken. The rest go to `rest`: "bottom_random" (default), "bottom_any" (in an order you choose) or "graveyard". `put: "exile"` takes `face_down: true` (only you may look at them) and `link: true` (exiled with the source, CR 607.2a); `looker: "source_controller"`: whoever controls the source may look at them instead of you (hideaway, CR 702.75a). |
318
318
  | [`discard`](docs/reference/effects.md#discard) | 701.9a, 701.9b | Each referenced player discards `amount` cards of their choice (default: you). `random: true`: the cards are chosen at random (the game's random number generator), with no decision. `hand: true`: each discards their whole hand at once ("discard your hand"; how many is its amount {"this_way": n}). |
@@ -359,7 +359,7 @@ Rules version: Comprehensive Rules effective 2026-11-06.
359
359
  | [`pump`](docs/reference/effects.md#pump) | 611.2a, 611.2c, 613.4c, 514.2, 500.1 | Each referenced creature gets +power/+toughness until end of turn (`duration: "until_your_next_turn"`: until its controller's next turn begins). The set of affected creatures is locked in when the effect starts. |
360
360
  | [`put_in_library`](docs/reference/effects.md#put_in_library) | 401.4, 400.7, 608.2b | Put each referenced permanent, or card in a graveyard or exile, into its owner's library: on the `top` or `bottom`, or (`owner_choice`) where its owner chooses. |
361
361
  | [`recruit`](docs/reference/effects.md#recruit) | 701.70a | Each referenced player (default: you) recruits: draws a card, then discards a card; if a nonland card was discarded, they create a 1/1 white Human Soldier creature token. |
362
- | [`reflexive_trigger`](docs/reference/effects.md#reflexive_trigger) | 603.12, 603.12a, 603.7d, 603.7e, 603.3d | Creates a reflexive triggered ability ("when you do, ...") that triggers immediately, with the controller and source of the resolving spell or ability. Its `targets` are chosen as it's put on the stack; its `effects` may name the results of earlier effects of the creating list ({"result": n} / {"this_way": n} with n below its position) and their own, numbered on from there. With `if`, it triggers only when the condition holds ("when excess damage is dealt this way"). |
362
+ | [`reflexive_trigger`](docs/reference/effects.md#reflexive_trigger) | 603.12, 603.12a, 603.7d, 603.7e, 603.3d, 107.3n | Creates a reflexive triggered ability ("when you do, ...") that triggers immediately, with the controller and source of the resolving spell or ability. Its `targets` are chosen as it's put on the stack; its `effects` may name the results of earlier effects of the creating list ({"result": n} / {"this_way": n} with n below its position) and their own, numbered on from there. With `if`, it triggers only when the condition holds ("when excess damage is dealt this way"). |
363
363
  | [`remove_all_counters`](docs/reference/effects.md#remove_all_counters) | 122.8, 122.1 | Remove every counter named `counter` (every counter, if no `counter` is given) from each referenced permanent or player ("you lose all poison counters"). |
364
364
  | [`remove_counters`](docs/reference/effects.md#remove_counters) | 122.8, 122.1 | Remove up to `amount` counters named `counter` from each referenced permanent or player (poison, experience, ...). How many were removed is {"this_way": n} ("remove a bait counter ... If you do, ..."). |
365
365
  | [`remove_damage`](docs/reference/effects.md#remove_damage) | 120.6, 514.2 | Remove all damage marked on each referenced permanent. |
@@ -371,7 +371,7 @@ Rules version: Comprehensive Rules effective 2026-11-06.
371
371
  | [`roll_dice`](docs/reference/effects.md#roll_dice) | 706.1, 706.1a, 706.2, 706.3a, 608.2c | You roll `amount` dice (default 1) with `sides` sides (default 6). The total of the results is this effect's amount: {"this_way": n} in later effects and conditions (a results table is effects with an `if` on it). |
372
372
  | [`sacrifice`](docs/reference/effects.md#sacrifice) | 701.21a | The controller sacrifices each referenced permanent they control (it goes to its owner's graveyard; it isn't destroyed, so indestructible doesn't stop it). |
373
373
  | [`sacrifice_choice`](docs/reference/effects.md#sacrifice_choice) | 701.21a, 101.4, 118.3 | Each referenced player (default: you) sacrifices `count` (default 1; "any": any number) permanents they control matching `filter`, chosen by them in turn order starting with the active player; all are sacrificed at once. The `filter`'s `controller` and `other` restrictions are relative to the effect's controller and source. |
374
- | [`scry`](docs/reference/effects.md#scry) | 701.22a | Look at the top `amount` cards of your library; put any number on the bottom and the rest on top in any order. |
374
+ | [`scry`](docs/reference/effects.md#scry) | 701.22a, 101.4 | Look at the top `amount` cards of your library; put any number on the bottom and the rest on top in any order. `to`: who scries (default "you"; e.g. {"target": 0} for "target player scries"), each in turn. |
375
375
  | [`search_library`](docs/reference/effects.md#search_library) | 701.23a, 701.23b, 701.23d, 701.23e, 701.20a, 701.24a, 701.24b, 118.12, 110.2a, 614.1a | Search your library for up to `count` cards matching `for`, then put them into your hand (or onto the battlefield, tapped if `tapped`, with `counters`; or into your graveyard) and shuffle. `put: library_top`: shuffle, then put the found card (one) on top. Computed bounds in `for` are worked out as the effect resolves. With a stated quality you may find fewer (or none); a search for just "a card" must find one if it can. `reveal` shows the found cards to every player. `searcher` names another player who searches their own library (e.g. {"controller_of": {"target": 0}}); `may: true` lets the searcher decline (then nothing is shuffled). `different_names: true`: the cards found must all have different names ("basic land cards with different names"). `battlefield_instead`: {"if": condition, "for": card spec}: a found card matching `for` goes onto the battlefield instead of into your hand while the condition holds. |
376
376
  | [`set_base_power_toughness`](docs/reference/effects.md#set_base_power_toughness) | 613.4b, 611.2a, 611.2b, 611.2c | Each referenced creature's base power and toughness become `power`/`toughness` (layer 7b; counters and pumps still apply), until end of turn or, with `duration: "indefinite"`, for as long as it stays on the battlefield. |
377
377
  | [`set_creature_types`](docs/reference/effects.md#set_creature_types) | 205.1a, 613.1d, 611.2c, 514.2 | Until end of turn, each referenced creature's creature types are exactly `types` (its other subtypes, such as artifact types, stay). The affected set is locked in. |
@@ -380,7 +380,7 @@ Rules version: Comprehensive Rules effective 2026-11-06.
380
380
  | [`shuffle_library`](docs/reference/effects.md#shuffle_library) | 701.24a | Each referenced player shuffles their library (default: you). |
381
381
  | [`skip_turns`](docs/reference/effects.md#skip_turns) | 614.1b, 614.10, 614.10a | Each referenced player skips their next `amount` turns (extra turns included): each of those turns doesn't happen, and the next player in turn order takes theirs. Several skips add up. |
382
382
  | [`solve`](docs/reference/effects.md#solve) | 720.3a, 720.3b | Each referenced permanent (default: this one) becomes solved if it isn't (a designation it keeps until it leaves the battlefield). Usually written through `to_solve`. |
383
- | [`surveil`](docs/reference/effects.md#surveil) | 701.25a | Look at the top `amount` cards of your library; put any number into your graveyard and the rest on top in any order. |
383
+ | [`surveil`](docs/reference/effects.md#surveil) | 701.25a, 101.4 | Look at the top `amount` cards of your library; put any number into your graveyard and the rest on top in any order. `to`: who surveils (default "you"), each in turn. |
384
384
  | [`suspend`](docs/reference/effects.md#suspend) | 702.62a, 702.62b, 406.1 | Exile each referenced card or spell with `amount` time counters on it; if it doesn't have suspend, it gains suspend (keyword `suspend`) while it stays exiled. |
385
385
  | [`tap`](docs/reference/effects.md#tap) | 701.26a | Tap each referenced permanent. |
386
386
  | [`transform`](docs/reference/effects.md#transform) | 701.27a, 701.27c, 701.27d, 701.27e, 701.27g, 712.15 | Transform each referenced permanent (default: this one): turn it over so its other face is up. It stays the same object, and effects on it keep applying. Nothing happens to a permanent that isn't a double-faced card or token, or whose other face is an instant or sorcery. An ability of the permanent transforms it only if it hasn't transformed since the ability was put on the stack. |
@@ -50,7 +50,7 @@ Tips:
50
50
  | --- | --- | --- | --- |
51
51
  | `name` | yes | string | Unique (a card with faces: see 4.17). Its slug becomes the card id: `"Jace, the Mind Sculptor"` → `jace_the_mind_sculptor`. Two different definitions with the same name in one game raise `CatalogConflict`. |
52
52
  | `types` | yes | list | Card types, lowercase: `land`, `creature`, `artifact`, `enchantment`, `planeswalker`, `instant`, `sorcery`. A card can have several (`["artifact", "creature"]`). |
53
- | `mana_cost` | castable cards | string | `"{2}{W}{W}"`. Symbols: `{N}` generic, `{W}{U}{B}{R}{G}`, `{C}`, `{X}` (announced while casting; use the amount `"x"` in effects, see 4.7). Lands must **not** have one. A card without one can't be cast. Two-color hybrid `{R/G}` is supported (paid with either color, CR 107.4e), and so is monocolored hybrid `{2/B}` (one black mana or two mana of any type; mana value 2, CR 202.3f); Phyrexian and `{S}` are not yet. |
53
+ | `mana_cost` | castable cards | string | `"{2}{W}{W}"`. Symbols: `{N}` generic, `{W}{U}{B}{R}{G}`, `{C}`, `{X}` (announced while casting; use the amount `"x"` in effects, see 4.7). Lands must **not** have one. A card without one can't be cast. Two-color hybrid `{R/G}` is supported (paid with either color, CR 107.4e), and so are monocolored hybrid `{2/B}` (one black mana or two mana of any type; mana value 2, CR 202.3f) and colorless hybrid `{C/W}` (one colorless or one white mana; the card is white, mana value 1 for the symbol, CR 107.4, 202.2d); Phyrexian and `{S}` are not yet. |
54
54
  | `supertypes` | no | list | `basic` (exempt from the 4-copy rule). `legendary` and `snow`: not yet. |
55
55
  | `subtypes` | no | list | Lowercase, spaces become `_`: `["human", "wizard"]`. Free-form labels, except the basic land types `plains island swamp mountain forest`, which grant their mana ability automatically (CR 305.6) and are valid only on lands. |
56
56
  | `keywords` | no | list | Keyword abilities, lowercase: see `SUPPORTED.md` → *Keyword abilities*. A keyword listed twice is one instance (redundant, CR 702.2f), except where each instance triggers separately: `cascade`, `storm`, `extort` and `increment` get one ability per listing ("cascade, cascade" is `["cascade", "cascade"]`, CR 702.85c). |
@@ -103,6 +103,8 @@ pool, so tap other sources first:
103
103
  | "{T}: Add X mana of any one color, where X is …" | `"color": "any_one", "amount": <amount>` |
104
104
  | "As this land enters, choose a color. {T}: Add one mana of the chosen color." | `{ "choose_color": {} }`, `{ "mana": { "cost": ["tap"], "color": "chosen" } }` (also on `add_mana`, CR 607.2d) |
105
105
  | "{T}, Pay 1 life: Add one mana of any color." | `{ "mana": { "cost": ["tap", { "pay_life": 1 }], "color": "any_one" } }` |
106
+ | "{T}, Remove a charge counter from this: Add one mana of any color." | `{ "mana": { "cost": ["tap", { "remove_counters": { "count": 1, "counter": "charge", "self": true } }], "color": "any_one" } }` (only `self: true` with a named `counter`: no choice; without {T} it may be activated once per counter) |
107
+ | "{T}: Add {C}. Put a point counter on this." | `{ "mana": { "cost": ["tap"], "produce": "{C}", "add_counters": { "counter": "point", "amount": 1 } } }` (`amount` defaults to 1; using it during a payment makes the payment irreversible) |
106
108
  | "{T}: Add {C}. Spend this mana only to cast artifact spells or activate abilities of artifacts." | `{ "mana": { "cost": ["tap"], "produce": "{C}", "spend_only": { "spells": { "types": ["artifact"] }, "abilities": { "types": ["artifact"] } } } }` |
107
109
 
108
110
  ```json
@@ -159,7 +161,9 @@ takes `spend_only` too ("Add {C}{C}. Spend this mana only to cast spells.").
159
161
  - `cost`: costs before the colon. `"tap"` is `{T}`; `{ "mana": "{1}{R}" }` is a mana
160
162
  cost; `"sacrifice"` sacrifices this permanent and `"exile_self"` exiles it; `{ "sacrifice_permanent": { "filter": "creature", "other": true } }`,
161
163
  `{ "tap_permanents": { "count": 3, "filter": ... } }` and `{ "remove_counters": { "count": 3 } }` are chosen while
162
- activating; `"exile_self_from_graveyard"` / `"bottom_self_from_graveyard"` make it a graveyard ability. `{Q}` is
164
+ activating (from this permanent only: `"self": true`; "Remove three quest counters from this and sacrifice it" is
165
+ `[{ "remove_counters": { "count": 3, "counter": "quest", "self": true } }, "sacrifice"]` in either order: costs that
166
+ take the permanent away are paid last, CR 601.2h); `"exile_self_from_graveyard"` / `"bottom_self_from_graveyard"` make it a graveyard ability. `{Q}` is
163
167
  not supported yet. More costs (each also usable in a spell's `additional_cost`):
164
168
 
165
169
  | Oracle words | Cost |
@@ -253,6 +257,7 @@ have '[−2]: …'" is `{ "static": { "affects": { "each": "planeswalker", "cont
253
257
  | "noncreature spell" | `{ "spell": { "not": ["creature"] } }` |
254
258
 
255
259
  | "with flying", "with flying or reach", "without flying" | `{ "creature": { "keywords": ["flying"] } }`, `{ "creature": { "keywords": ["flying", "reach"] } }`, `{ "creature": { "not_keywords": ["flying"] } }` (current keywords: granted ones count, CR 702.1) |
260
+ | "monocolored", "multicolored", "colorless" (CR 105.2a-c) | `{ "permanent": { "color_count": { "equal": 1 } } }`, `{ "color_count": { "at_least": 2 } }`, `{ "color_count": { "equal": 0 } }` (integer bounds 0-5; any filter: `creature`, `spell`, a static's `affects.each`) |
256
261
  | "of the chosen color / creature type / card type", "not of the chosen type" | `{ "creature": { "subtypes": "chosen" } }`, `{ "spell": { "colors": "chosen" } }`, `{ "permanent": { "types": "chosen" } }`, `{ "creature": { "not_subtypes": "chosen" } }` (see 4.15) |
257
262
 
258
263
  **Card specs.** Effects that look at cards in any zone (graveyard, hand, library, exile; `for`,
@@ -266,7 +271,7 @@ whose qualities must all match:
266
271
  | "a non-Avatar creature card" | `{ "types": ["creature"], "not_subtypes": ["avatar"] }` |
267
272
  | "a creature card with flying" | `{ "types": ["creature"], "keywords": ["flying"] }` (any listed keyword) |
268
273
  | "with mana value 3 or less", "with power or toughness 1 or less" | `{ "mana_value": { "at_most": 3 } }`, `{ "any_of": [{ "power": { "at_most": 1 } }, { "toughness": { "at_most": 1 } }] }` |
269
- | "a black card", "a monocolored card" | `{ "colors": ["B"] }`, `{ "color_count": { "equal": 1 } }` |
274
+ | "a black card", "a monocolored card" | `{ "colors": ["B"] }`, `{ "color_count": { "equal": 1 } }` (also in target and `each` filters, below) |
270
275
  | "a card that has an Adventure" | `{ "layout": "adventure" }` (any card layout: adventure, omen, prepare, transform, modal, meld) |
271
276
  | "an instant or sorcery card" | `{ "any_of": [{ "types": ["instant"] }, { "types": ["sorcery"] }] }` |
272
277
 
@@ -314,6 +319,8 @@ is a flicker ("exile …, then return it to the battlefield under its owner's co
314
319
  is "… at the beginning of the next end step". It triggers once, with the controller
315
320
  and source of what created it; a remembered object that has changed zones is not
316
321
  affected (CR 603.7c).
322
+ - A delayed or reflexive trigger reads the X of the spell or ability that created it: `"x"` in its effects is that
323
+ X (CR 107.3n, 603.12), e.g. "when you cast your next instant or sorcery spell this turn, copy that spell X times".
317
324
  - `{ "was_cast": true }` as a triggered ability's `if` is "if you cast it" (CR 603.4).
318
325
 
319
326
  ### 4.5b More trigger shapes
@@ -652,6 +659,7 @@ Generic shapes (N, [quality] and [zone] stand for whatever the card says):
652
659
 
653
660
  | Shape | Data |
654
661
  | --- | --- |
662
+ | "target player scries N", "each player surveils N" | `{ "scry": { "amount": N, "to": { "target": 0 } } }`, `{ "surveil": { "amount": N, "to": { "each": "player" } } }` (each named player in turn, APNAP order; default `"you"`) |
655
663
  | look at the top N; you may reveal a [quality] card among them and put it into your hand; the rest go to the bottom in a random order | `{ "dig": { "amount": N, "for": spec, "optional": true, "reveal": "chosen", "put": "hand" } }` |
656
664
  | look at the top N; one goes to your hand, the rest to your graveyard | `{ "dig": { "amount": N, "rest": "graveyard" } }` |
657
665
  | reveal the top N; every [quality] card goes onto the battlefield tapped | `{ "dig": { "amount": N, "reveal": "all", "for": spec, "count": "all", "put": "battlefield", "tapped": true } }` |
@@ -712,7 +720,12 @@ copies with `of` (a selector; `"self"` is the source in any zone, even a card th
712
720
  exiled itself from a graveyard to pay the cost) and takes the same `except` object for
713
721
  "except …" (CR 707.9a-b), which a copy of the copy keeps:
714
722
  `{ "legendary": false, "keywords": ["menace"], "types": [...], "subtypes": [...],
715
- "supertypes": [...], "name": "…", "power": 1, "toughness": 1, "colors": [] }`.
723
+ "supertypes": [...], "name": "…", "power": 1, "toughness": 1, "colors": [], "replace": [...] }`.
724
+ `types`, `subtypes` and `supertypes` are **added** to the copied ones ("except it's an artifact in addition
725
+ to its other types", CR 205.1b). List them in `replace` when the text **sets** them instead ("except it's a
726
+ 6/6 green Dinosaur creature": `{ "types": ["creature"], "subtypes": ["dinosaur"], "colors": ["G"], "power": 6,
727
+ "toughness": 6, "replace": ["types", "subtypes"] }`, CR 707.9b, 205.1a). Set subtypes replace the creature
728
+ types; other subtypes (Equipment, Vehicle) stay unless `types` is set too.
716
729
 
717
730
  | Oracle words | Data |
718
731
  | --- | --- |
@@ -742,12 +742,12 @@ Rules: CR 702.5a, CR 115.1b, CR 303.4a
742
742
 
743
743
  As this permanent enters, its controller may choose a permanent on the battlefield matching `of`; it enters as a copy of that permanent (its copiable values, with the `except` modifications) and its enter abilities trigger. `with_counters: true`: it also enters with the counters the copied permanent has. Choosing none: it enters as itself.
744
744
 
745
- Rules: CR 707.5, CR 707.9b, CR 614.1c, CR 614.12
745
+ Rules: CR 707.5, CR 707.9b, CR 205.1a, CR 614.1c, CR 614.12
746
746
 
747
747
  | Parameter | Description |
748
748
  | --- | --- |
749
749
  | `of` | filter (the permanents it may copy) |
750
- | `except` | {"legendary": false, "keywords": [...], "types": [...], "subtypes": [...], "supertypes": [...], "name": ..., "power": n, "toughness": n, "colors": [...]} |
750
+ | `except` | {"legendary": false, "keywords": [...], "types": [...], "subtypes": [...], "supertypes": [...], "name": ..., "power": n, "toughness": n, "colors": [...], "replace": ["types" | "subtypes" | "supertypes"]} |
751
751
  | `with_counters` | boolean |
752
752
 
753
753
  ```json
@@ -1264,9 +1264,9 @@ Rules: CR 606.3, CR 606.4, CR 606.5, CR 602.2b
1264
1264
 
1265
1265
  ## mana
1266
1266
 
1267
- An activated mana ability: pay the cost, add the mana to your mana pool immediately. It does not use the stack and can be activated whenever you have priority. `produce`: the fixed mana (`amount` times). Or `color`: `amount` mana (default 1) of one color you choose as you activate it (`"any_one"`) or in any combination of colors (`"any"`); `colors` limits the choice. `"chosen"`: of the color chosen as this entered (choose_color). `spend_only` restricts how the mana can be spent. `only_if`: "Activate only if ...". `limit: "once_each_turn"`: "Activate only once each turn."
1267
+ An activated mana ability: pay the cost, add the mana to your mana pool immediately. It does not use the stack and can be activated whenever you have priority. `produce`: the fixed mana (`amount` times). Or `color`: `amount` mana (default 1) of one color you choose as you activate it (`"any_one"`) or in any combination of colors (`"any"`); `colors` limits the choice. `"chosen"`: of the color chosen as this entered (choose_color). `spend_only` restricts how the mana can be spent. `only_if`: "Activate only if ...". `limit: "once_each_turn"`: "Activate only once each turn." `add_counters`: it also puts counters on its own source ("Add {C}. Put a point counter on this").
1268
1268
 
1269
- Rules: CR 605.1a, CR 605.3a, CR 605.3b, CR 106.1a, CR 106.4, CR 106.6, CR 607.2d, CR 602.5b
1269
+ Rules: CR 605.1a, CR 605.3a, CR 605.3b, CR 106.1a, CR 106.4, CR 106.6, CR 607.2d, CR 602.5b, CR 122.1
1270
1270
 
1271
1271
  | Parameter | Description |
1272
1272
  | --- | --- |
@@ -1278,6 +1278,7 @@ Rules: CR 605.1a, CR 605.3a, CR 605.3b, CR 106.1a, CR 106.4, CR 106.6, CR 607.2d
1278
1278
  | `spend_only` | {"spells": card spec, "abilities": card spec, "from" | "not_from": zone} |
1279
1279
  | `only_if` | condition: it can be activated only while it holds (CR 602.5b) |
1280
1280
  | `limit` | "once_each_turn" (CR 602.5b) |
1281
+ | `add_counters` | {"counter": name, "amount": integer (default 1)}: put on this permanent |
1281
1282
 
1282
1283
  ```json
1283
1284
  {
@@ -284,9 +284,9 @@ Rules: CR 119.4, CR 119.4b, CR 118.3b, CR 601.2b, CR 107.3a, CR 702.21a
284
284
 
285
285
  ## remove_counters
286
286
 
287
- Remove `count` counters (of kind `counter`, or any kind) from among permanents you control matching `filter` (default creature), one counter per choice. Removed as it becomes cast. `self: true`: only from this permanent ("Remove two counters from Ghost-Spider").
287
+ Remove `count` counters (of kind `counter`, or any kind) from among permanents you control matching `filter` (default creature), one counter per choice. Removed as it becomes cast. `self: true`: only from this permanent ("Remove two counters from Ghost-Spider"). With `self: true` and a `counter` kind it needs no choice, so a mana ability may have it ("Remove a charge counter from this: Add one mana of any color").
288
288
 
289
- Rules: CR 602.2b, CR 601.2h, CR 118.3, CR 122.1
289
+ Rules: CR 602.2b, CR 601.2h, CR 118.3, CR 122.1, CR 605.3a
290
290
 
291
291
  | Parameter | Description |
292
292
  | --- | --- |
@@ -278,7 +278,7 @@ Rules: CR 707.2, CR 707.4, CR 613.2a, CR 613.7, CR 611.2a, CR 514.2
278
278
  | --- | --- |
279
279
  | `to` | selector (the permanents that become copies) |
280
280
  | `of` | selector (what they copy) |
281
- | `except` | {"legendary": false, "keywords": [...], "types": [...], "subtypes": [...], "supertypes": [...], "name": ..., "power": n, "toughness": n, "colors": [...]} |
281
+ | `except` | {"legendary": false, "keywords": [...], "types": [...], "subtypes": [...], "supertypes": [...], "name": ..., "power": n, "toughness": n, "colors": [...], "replace": ["types" | "subtypes" | "supertypes"]} |
282
282
  | `duration` | end_of_turn | until_your_next_turn | permanent |
283
283
 
284
284
  ```json
@@ -688,7 +688,7 @@ Rules: CR 707.10, CR 707.10a, CR 707.10b, CR 707.10c, CR 707.10f, CR 608.3f
688
688
  | `amount` | amount (default 1) |
689
689
  | `new_targets` | boolean |
690
690
  | `to` | selector (default "you") |
691
- | `except` | {"legendary": false, "keywords": [...], "types": [...], "subtypes": [...], "supertypes": [...], "name": ..., "power": n, "toughness": n, "colors": [...]} |
691
+ | `except` | {"legendary": false, "keywords": [...], "types": [...], "subtypes": [...], "supertypes": [...], "name": ..., "power": n, "toughness": n, "colors": [...], "replace": ["types" | "subtypes" | "supertypes"]} |
692
692
 
693
693
  ```json
694
694
  {
@@ -829,14 +829,14 @@ Rules: CR 111.1, CR 111.10, CR 701.7a, CR 704.5d, CR 508.4, CR 506.3b, CR 707.2
829
829
 
830
830
  For each object `of` refers to (a permanent, a card in any zone, or the source with "self"), the referenced players (default: you) each create `amount` tokens that are copies of it: its copiable values (its card as modified by other copy effects, not counters, status or other effects), with the `except` modifications. The tokens are the effect's result, for later effects such as granting haste or a delayed sacrifice.
831
831
 
832
- Rules: CR 707.2, CR 707.8, CR 707.9a, CR 707.9b, CR 111.1, CR 614.1c
832
+ Rules: CR 707.2, CR 707.8, CR 707.9a, CR 707.9b, CR 205.1a, CR 205.1b, CR 111.1, CR 614.1c
833
833
 
834
834
  | Parameter | Description |
835
835
  | --- | --- |
836
836
  | `of` | selector (what to copy) |
837
837
  | `amount` | amount (default 1) |
838
838
  | `tapped` | boolean |
839
- | `except` | {"legendary": false, "keywords": [...], "types": [...], "subtypes": [...], "supertypes": [...], "name": ..., "power": n, "toughness": n, "colors": [...]} |
839
+ | `except` | {"legendary": false, "keywords": [...], "types": [...], "subtypes": [...], "supertypes": [...], "name": ..., "power": n, "toughness": n, "colors": [...], "replace": ["types" | "subtypes" | "supertypes"]} |
840
840
  | `to` | selector (default "you") |
841
841
 
842
842
  ```json
@@ -920,7 +920,7 @@ Rules: CR 120.3a, CR 120.3c, CR 120.3e, CR 120.6, CR 120.4a, CR 120.10
920
920
 
921
921
  Creates a delayed triggered ability with the controller and source of the resolving spell or ability. It triggers only once, the next time `when` happens (e.g. {"step_begins": {"step": "end", "whose": "each"}} for the next end step). Its `effects` may use {"result": n} for what earlier effects of the creating list moved or created (n below its position); those objects are affected only if they are still where they were put. Its own effects are numbered on from there.
922
922
 
923
- Rules: CR 603.7a, CR 603.7b, CR 603.7c, CR 603.7d, CR 603.7e
923
+ Rules: CR 603.7a, CR 603.7b, CR 603.7c, CR 603.7d, CR 603.7e, CR 107.3n
924
924
 
925
925
  | Parameter | Description |
926
926
  | --- | --- |
@@ -1927,7 +1927,7 @@ Rules: CR 701.70a
1927
1927
 
1928
1928
  Creates a reflexive triggered ability ("when you do, ...") that triggers immediately, with the controller and source of the resolving spell or ability. Its `targets` are chosen as it's put on the stack; its `effects` may name the results of earlier effects of the creating list ({"result": n} / {"this_way": n} with n below its position) and their own, numbered on from there. With `if`, it triggers only when the condition holds ("when excess damage is dealt this way").
1929
1929
 
1930
- Rules: CR 603.12, CR 603.12a, CR 603.7d, CR 603.7e, CR 603.3d
1930
+ Rules: CR 603.12, CR 603.12a, CR 603.7d, CR 603.7e, CR 603.3d, CR 107.3n
1931
1931
 
1932
1932
  | Parameter | Description |
1933
1933
  | --- | --- |
@@ -2216,13 +2216,14 @@ Rules: CR 701.21a, CR 101.4, CR 118.3
2216
2216
 
2217
2217
  ## scry
2218
2218
 
2219
- Look at the top `amount` cards of your library; put any number on the bottom and the rest on top in any order.
2219
+ Look at the top `amount` cards of your library; put any number on the bottom and the rest on top in any order. `to`: who scries (default "you"; e.g. {"target": 0} for "target player scries"), each in turn.
2220
2220
 
2221
- Rules: CR 701.22a
2221
+ Rules: CR 701.22a, CR 101.4
2222
2222
 
2223
2223
  | Parameter | Description |
2224
2224
  | --- | --- |
2225
2225
  | `amount` | integer |
2226
+ | `to` | selector of players (default you) |
2226
2227
 
2227
2228
  ```json
2228
2229
  {
@@ -2410,13 +2411,14 @@ Rules: CR 720.3a, CR 720.3b
2410
2411
 
2411
2412
  ## surveil
2412
2413
 
2413
- Look at the top `amount` cards of your library; put any number into your graveyard and the rest on top in any order.
2414
+ Look at the top `amount` cards of your library; put any number into your graveyard and the rest on top in any order. `to`: who surveils (default "you"), each in turn.
2414
2415
 
2415
- Rules: CR 701.25a
2416
+ Rules: CR 701.25a, CR 101.4
2416
2417
 
2417
2418
  | Parameter | Description |
2418
2419
  | --- | --- |
2419
2420
  | `amount` | integer |
2421
+ | `to` | selector of players (default you) |
2420
2422
 
2421
2423
  ```json
2422
2424
  {
@@ -308,17 +308,24 @@ module Enjine
308
308
  targets: obj.targets.flatten, during_resolution: ctx["no_priority"] == true)
309
309
  end
310
310
 
311
- # The non-mana costs (CR 602.2b): its own ({T}, sacrifice it, exile it from the graveyard), then
312
- # the chosen ones (sacrifice another creature, remove counters). A source sacrificed or exiled as a cost is
313
- # remembered as it last existed (its counters, CR 608.2h).
311
+ # The non-mana costs (CR 602.2b): its own ({T}, exile it from the graveyard), the chosen ones (sacrifice
312
+ # another creature, remove counters) and a loyalty cost, then last the costs that take the source off the
313
+ # battlefield (sacrifice it, exile it). Costs may be paid in any order (CR 601.2h); this is the order in which
314
+ # all of them can be paid ("Remove three quest counters from this and sacrifice it"). A source sacrificed or
315
+ # exiled as a cost is remembered as it last existed (its counters, CR 608.2h).
314
316
  def pay_ability_costs!(ctx, obj)
315
317
  source = object(ctx["source"])
316
318
  ability = chars(source).ability(ctx["ability"])
317
- obj.memory["source_counters"] = source.counters.dup if ability.costs.any? { Mechanics::Costs::LEAVING_SELF.include?(it.class) }
318
- frame_costs(ctx).reject(&:mana?).each { it.pay!(self, source) } # the chosen option of a one_of (CR 601.2b)
319
+ leaving, staying = frame_costs(ctx).reject(&:mana?).partition { Mechanics::Costs.leaving_self?(it) }
320
+ staying.each { it.pay!(self, source) } # the chosen option of a one_of (CR 601.2b)
319
321
  pay_chosen_costs!(ctx)
320
- return unless ability.kind == :loyalty
322
+ pay_loyalty_cost!(ctx, source, ability) if ability.kind == :loyalty
323
+ obj.memory["source_counters"] = source.counters.dup if ability.costs.any? { Mechanics::Costs.leaving_self?(it) }
324
+ leaving.each { it.pay!(self, source) }
325
+ end
321
326
 
327
+ # CR 606.4: a loyalty ability's cost puts or removes loyalty counters.
328
+ def pay_loyalty_cost!(ctx, source, ability)
322
329
  source.loyalty_turn = state.turn
323
330
  cost = ability.x_loyalty? ? -ctx["x"].to_i : ability.loyalty_cost
324
331
  cost.negative? ? remove_counters!(source, "loyalty", -cost) : add_counters!(source, "loyalty", cost)
@@ -179,10 +179,8 @@ module Enjine
179
179
  end
180
180
  end
181
181
 
182
- # A mana ability whose costs include more than {T} and mana (a sacrifice, life, a discard) can't be undone.
183
- def irreversible_mana_ability?(id, ref)
184
- chars(id).ability(ref).costs.any? { !it.is_a?(Mechanics::Costs::Tap) && !it.is_a?(Mechanics::Costs::TapGranter) && !it.mana? }
185
- end
182
+ # A mana ability that can't be undone (Abilities::ManaAbility#irreversible?).
183
+ def irreversible_mana_ability?(id, ref) = chars(id).ability(ref).irreversible?
186
184
 
187
185
  def reserved_for_cost?(frame, id, ref)
188
186
  return true if id == payment_excluded_source(frame)
@@ -213,7 +211,8 @@ module Enjine
213
211
  produced.each { pool[it] += 1 }
214
212
  end
215
213
  used = [id, tapped_granter(option[:ability], ability)].compact
216
- payable_with?(frame, remaining_cost(frame["remaining"]), pool, payment_reserved(frame) + used, restricted: rest)
214
+ later = units_after_activating(id, option[:ability], ability) # ManaSources: it may be activated again
215
+ payable_with?(frame, remaining_cost(frame["remaining"]), pool, payment_reserved(frame) + used, restricted: rest, extra: later)
217
216
  end
218
217
 
219
218
  # CR 605.3: activating a mana ability while paying. One whose costs include more than {T} (a
@@ -232,13 +231,13 @@ module Enjine
232
231
 
233
232
  # Whether `cost` can be paid from `pool` (and the `restricted` pool) plus the player's untapped
234
233
  # sources, minus `excluded` and a source the ability taps for its own cost, for the payment `frame`.
235
- def payable_with?(frame, cost, pool, excluded, restricted:)
234
+ def payable_with?(frame, cost, pool, excluded, restricted:, extra: [])
236
235
  return true if cost.mana_value.zero?
237
236
 
238
237
  index = frame["player"]
239
238
  excluded = [*excluded, payment_excluded_source(frame)].compact
240
239
  purpose = payment_purpose(frame)
241
- units = pool_units(index, pool, purpose, restricted) + source_units(index, excluded, purpose) +
240
+ units = extra + pool_units(index, pool, purpose, restricted) + source_units(index, excluded, purpose) +
242
241
  convoke_units(index, purpose, excluded) + # CR 702.51a (Engine::AltCasting)
243
242
  waterbend_units(index, purpose, excluded) # CR 701.67a (Engine::Waterbending)
244
243
  covers?(cost, units)
@@ -41,14 +41,18 @@ module Enjine
41
41
  # What a copy of `obj` gets: [card id, exceptions] (CR 707.2, 707.3).
42
42
  def copiable_values(obj) = [obj.card, copy_exceptions(obj) || {}]
43
43
 
44
- # 707.9b: exceptions of a later copy effect apply on top of those it copied.
44
+ # 707.9b: exceptions of a later copy effect apply on top of those it copied. A list the later one sets
45
+ # (`replace`, CR 205.1a) replaces the earlier list; otherwise the lists add up (CR 205.1b).
45
46
  def self.merge_except(old, new)
46
47
  old ||= {}
47
- merged = old.merge(new.except("keywords", "types", "subtypes", "supertypes"))
48
+ merged = old.merge(new.except("keywords", "types", "subtypes", "supertypes", "replace"))
49
+ setting = Array(new["replace"])
48
50
  %w[keywords types subtypes supertypes].each do |key|
49
- list = Array(old[key]) | Array(new[key])
51
+ list = setting.include?(key) ? Array(new[key]) : Array(old[key]) | Array(new[key])
50
52
  merged[key] = list unless list.empty?
51
53
  end
54
+ replace = Array(old["replace"]) | setting
55
+ merged["replace"] = replace unless replace.empty?
52
56
  merged
53
57
  end
54
58
 
@@ -56,10 +60,13 @@ module Enjine
56
60
  def self.apply_exceptions(chars, except)
57
61
  attrs = {}
58
62
  attrs[:name] = except["name"] if except["name"]
59
- attrs[:supertypes] = chars.supertypes | sym(except["supertypes"])
63
+ setting = Array(except["replace"]) # CR 205.1a: set, not added (CR 205.1b)
64
+ attrs[:supertypes] = setting.include?("supertypes") ? sym(except["supertypes"]) : chars.supertypes | sym(except["supertypes"])
60
65
  attrs[:supertypes] -= [:legendary] if except["legendary"] == false
61
- attrs[:types] = chars.types | sym(except["types"])
62
- attrs[:subtypes] = chars.subtypes | sym(except["subtypes"])
66
+ attrs[:types] = setting.include?("types") ? sym(except["types"]) : chars.types | sym(except["types"])
67
+ attrs[:subtypes] = if setting.include?("subtypes") then set_subtypes(chars, except, setting)
68
+ else chars.subtypes | sym(except["subtypes"])
69
+ end
63
70
  attrs[:keywords] = chars.keywords | sym(except["keywords"])
64
71
  attrs[:colors] = sym(except["colors"]) if except["colors"]
65
72
  attrs[:power] = except["power"] if except.key?("power")
@@ -69,6 +76,13 @@ module Enjine
69
76
 
70
77
  def self.sym(list) = Array(list).map(&:to_sym)
71
78
 
79
+ # CR 205.1a: setting creature types replaces only the creature types; the other subtypes stay unless the card
80
+ # types are set too (a subtype goes with its card type: "a 6/6 Dinosaur creature" is no Equipment any more).
81
+ def self.set_subtypes(chars, except, setting)
82
+ kept = setting.include?("types") ? [] : chars.subtypes - Mechanics::Keywords::Changeling::CREATURE_TYPES
83
+ kept | sym(except["subtypes"])
84
+ end
85
+
72
86
  # ---- making copies ---------------------------------------------------------------------------
73
87
 
74
88
  # CR 707.8, 111.1: a token that's a copy of [card, except], created under `controller`'s control.
@@ -50,6 +50,7 @@ module Enjine
50
50
  # whose ability costs mana isn't counted (it converts pool mana, CR 605.3a).
51
51
  def source_units(index, excluded, purpose = nil)
52
52
  by_source = Hash.new { |h, k| h[k] = [] }
53
+ repeats = {}
53
54
  all_mana_sources(index).each do |id, ref|
54
55
  next if excluded.include?(id)
55
56
 
@@ -59,11 +60,25 @@ module Enjine
59
60
 
60
61
  # Abilities that tap the permanent granting them (CR 602.2b) make mana once among them all.
61
62
  by_source[granter ? "granter:#{granter}" : id].concat(ability.outcomes(self, object(id)))
63
+ # CR 605.3a: one without {T} whose costs only remove counters from it can be activated again
64
+ repeats[id] = [repeats.fetch(id, 1), ability.repeats(object(id), mana_ability_costs(ref, ability))].max unless granter
65
+ end
66
+ units = by_source.flat_map do |key, options|
67
+ Array.new(options.map(&:size).max.to_i * repeats.fetch(key, 1)) { options.flatten.uniq }
62
68
  end
63
- units = by_source.values.flat_map { |options| Array.new(options.map(&:size).max) { options.flatten.uniq } }
64
69
  as_any_type(units, purpose)
65
70
  end
66
71
 
72
+ # A mana ability without {T} that removes counters from its source can be activated again after this activation
73
+ # (ManaAbility#repeats, CR 605.3a): the units of mana those later activations could add.
74
+ def units_after_activating(id, ref, ability)
75
+ left = ability.repeats(object(id), mana_ability_costs(ref, ability)) - 1
76
+ return [] unless left.positive? && ability.spend_only.nil?
77
+
78
+ outcomes = ability.outcomes(self, object(id))
79
+ Array.new(left * outcomes.map(&:size).max.to_i) { outcomes.flatten.uniq }
80
+ end
81
+
67
82
  # Bipartite matching (augmenting paths): can every colored or hybrid symbol (the list of types
68
83
  # that can pay it) get its own unit?
69
84
  def match_colored(symbols, units)
@@ -141,9 +156,18 @@ module Enjine
141
156
  from = mana_provenance(id) # before a cost sacrifices it (a Treasure)
142
157
  record_activation!("source" => id, "ability" => ability_ref) if ability.per_turn
143
158
  pay_from_pool!(index, ability.mana_cost, id) if ability.mana_cost
144
- mana_ability_costs(ability_ref, ability).each { |cost| cost.pay!(self, obj) }
159
+ Mechanics::Costs.payment_order(mana_ability_costs(ability_ref, ability)).map(&:first).each do |cost| # CR 601.2h
160
+ cost.respond_to?(:pay_at_once!) ? cost.pay_at_once!(self, obj) : cost.pay!(self, obj)
161
+ end
145
162
  produced = chosen || ability.outcomes(self, obj).first # CR 605.3b: a fixed amount is counted as it resolves
146
163
  add_mana!(index, produced, id, restriction: ability.spend_only&.data, from: from)
164
+ add_mana_ability_counters!(index, obj, ability)
165
+ end
166
+
167
+ # "Add {C}. Put a point counter on this" (CR 605.1a, 122.1): the counters go on the source if it's still there.
168
+ def add_mana_ability_counters!(index, obj, ability)
169
+ kind, amount = ability.add_counters
170
+ add_counters!(obj, kind, amount, by_player: index) if kind && state.battlefield.include?(obj.id)
147
171
  end
148
172
 
149
173
  # Whether the mana in the pool (unrestricted) can pay `cost` (a mana ability's mana cost, CR 605.3a).
@@ -94,7 +94,10 @@ module Enjine
94
94
  ids = sources.map(&:first)
95
95
  helpers = state.battlefield.count { |id| (obj = object(id)).controller == index && !obj.tapped && !ids.include?(id) }
96
96
  pl.mana_pool.sum { |_, n| [n, 0].max } + pl.restricted_mana.size + (2 * helpers) +
97
- sources.sum { |id, ref| chars(id).ability(ref).outcomes(self, object(id)).map(&:size).max.to_i }
97
+ sources.sum do |id, ref| # one without {T} may be activated again (ManaAbility#repeats, CR 605.3a)
98
+ ability = chars(id).ability(ref)
99
+ ability.outcomes(self, object(id)).map(&:size).max.to_i * ability.repeats(object(id), mana_ability_costs(ref, ability))
100
+ end
98
101
  end
99
102
  end
100
103
 
@@ -105,7 +105,7 @@ module Enjine
105
105
  def repeats?(entry) = (entry["turn"] && !entry["once"]) || entry["game"] == true
106
106
 
107
107
  def delayed_memory(entry, facts)
108
- { "results" => entry["results"], "watched" => entry["watched"], "triggering" => facts }.compact
108
+ { "results" => entry["results"], "watched" => entry["watched"], "triggering" => facts, "x" => entry["x"] }.compact
109
109
  end
110
110
 
111
111
  # CR 603.7d-e: its source and controller are those of the spell or ability that created it.
@@ -367,7 +367,7 @@ module Enjine
367
367
  obj.source = trigger["source"]
368
368
  obj.ability = trigger["ability"]
369
369
  obj.memory = Snapshot.deep_copy(trigger.fetch("memory", {})).merge("trigger_id" => trigger["id"])
370
- obj.x = entered_x(trigger)
370
+ obj.x = trigger.dig("memory", "x") || entered_x(trigger) # CR 107.3n: a delayed trigger's X (Effects::DelayedTrigger)
371
371
  state.stack.unshift(obj.id)
372
372
  start_casting!(trigger["controller"], obj.id, "trigger", source: trigger["source"], ability: trigger["ability"])
373
373
  end
data/lib/enjine/mana.rb CHANGED
@@ -65,7 +65,7 @@ module Enjine
65
65
  end
66
66
  end
67
67
 
68
- HYBRID = %r{\A([WUBRG2])/([WUBRG])\z}
68
+ HYBRID = %r{\A([WUBRG2C])/([WUBRG])\z}
69
69
 
70
70
  # A monocolored hybrid symbol such as {2/B} (CR 107.4e); its first component is the generic "2".
71
71
  def self.mono_hybrid?(symbol) = symbol.first.to_s == "2"
@@ -107,9 +107,10 @@ module Enjine
107
107
  Cost.new(generic: generic, colored: colored.freeze, x_symbols: x, hybrid: hybrid.compact.freeze)
108
108
  end
109
109
 
110
- # A hybrid symbol (CR 107.4e), kept in its printed order: two-color such as {R/G} ([:R, :G]) or
111
- # monocolored such as {2/B} ([:"2", :B]: one black mana or two mana of any type). Phyrexian symbols
112
- # aren't supported (they are "unsupported mana symbol"s).
110
+ # A hybrid symbol (CR 107.4, 107.4e), kept in its printed order: two-color such as {R/G} ([:R, :G]),
111
+ # monocolored such as {2/B} ([:"2", :B]: one black mana or two mana of any type) or colorless such as {C/W}
112
+ # ([:C, :W]: one colorless or one white mana; it is white, CR 202.2d, and counts 1 for mana value, CR 202.3f).
113
+ # Phyrexian symbols aren't supported (they are "unsupported mana symbol"s).
113
114
  def self.hybrid_symbol(sym, errors, path)
114
115
  pair = HYBRID.match(sym).captures.map(&:to_sym)
115
116
  return pair.freeze if pair.uniq.size == 2
@@ -17,7 +17,7 @@ module Enjine
17
17
  "`except` modifications) and its enter abilities trigger. `with_counters: true`: it " \
18
18
  "also enters with the counters the copied permanent has. Choosing none: it enters as " \
19
19
  "itself.",
20
- rules: %w[707.5 707.9b 614.1c 614.12],
20
+ rules: %w[707.5 707.9b 205.1a 614.1c 614.12],
21
21
  params: { "of" => "filter (the permanents it may copy)", "except" => Mechanics::CopyExcept::PARAM,
22
22
  "with_counters" => "boolean" },
23
23
  example: { "enter_as_copy" => { "of" => { "permanent" => { "any_of" => %w[artifact creature] } },
@@ -77,21 +77,23 @@ module Enjine
77
77
  "(`\"any_one\"`) or in any combination of colors (`\"any\"`); `colors` limits " \
78
78
  "the choice. `\"chosen\"`: of the color chosen as this entered (choose_color). " \
79
79
  "`spend_only` restricts how the mana can be spent. `only_if`: \"Activate only if ...\". " \
80
- "`limit: \"once_each_turn\"`: \"Activate only once each turn.\"",
81
- rules: %w[605.1a 605.3a 605.3b 106.1a 106.4 106.6 607.2d 602.5b],
80
+ "`limit: \"once_each_turn\"`: \"Activate only once each turn.\" `add_counters`: it also " \
81
+ "puts counters on its own source (\"Add {C}. Put a point counter on this\").",
82
+ rules: %w[605.1a 605.3a 605.3b 106.1a 106.4 106.6 607.2d 602.5b 122.1],
82
83
  params: { "cost" => "list of costs (e.g. [\"tap\"])",
83
84
  "produce" => "mana symbols added, e.g. \"{G}\" or \"{C}{C}\"",
84
85
  "amount" => "amount (default 1; with produce: how many times)",
85
86
  "color" => CHOICES.join(" | "), "colors" => "list of colors to choose from (default all five)",
86
87
  "spend_only" => "{\"spells\": card spec, \"abilities\": card spec, \"from\" | \"not_from\": zone}",
87
88
  "only_if" => "condition: it can be activated only while it holds (CR 602.5b)",
88
- "limit" => "\"once_each_turn\" (CR 602.5b)" },
89
+ "limit" => "\"once_each_turn\" (CR 602.5b)",
90
+ "add_counters" => "{\"counter\": name, \"amount\": integer (default 1)}: put on this permanent" },
89
91
  example: { "mana" => { "cost" => ["tap"], "produce" => "{C}" } }
90
92
 
91
93
  attr_reader :costs, :produce, :color, :colors, :amount, :spend_only
92
94
 
93
95
  def self.build(params, errors, path, **)
94
- Mechanics.check_keys(params, %w[cost produce amount color colors spend_only only_if limit], errors, path)
96
+ Mechanics.check_keys(params, %w[cost produce amount color colors spend_only only_if limit add_counters], errors, path)
95
97
  costs = build_costs(Mechanics.fetch_param(params, :cost), errors, path)
96
98
  raw = Mechanics.fetch_param(params, :produce)
97
99
  color = Mechanics.fetch_param(params, :color)
@@ -106,7 +108,24 @@ module Enjine
106
108
  only_if = raw_if && Condition.build(raw_if, errors, "#{path}.only_if")
107
109
  new(costs.compact.freeze, produce, color: color, colors: build_colors(params, color, errors, path),
108
110
  amount: amount, spend_only: spend_only, only_if: only_if,
109
- per_turn: build_limit(params, errors, path))
111
+ per_turn: build_limit(params, errors, path),
112
+ add_counters: build_add_counters(params, errors, path))
113
+ end
114
+
115
+ # "Put a point counter on this" as part of the effect (CR 605.1a: a mana ability may do more than add mana):
116
+ # [counter, amount] or nil.
117
+ def self.build_add_counters(params, errors, path)
118
+ raw = Mechanics.fetch_param(params, :add_counters)
119
+ return nil if raw.nil?
120
+
121
+ amount = raw.is_a?(Hash) ? raw.fetch("amount", 1) : nil
122
+ if raw.is_a?(Hash) && (raw.keys - %w[counter amount]).empty? && raw["counter"].is_a?(String) &&
123
+ !Counters.error(raw["counter"]) && amount.is_a?(Integer) && amount.positive?
124
+ return [raw["counter"], amount].freeze
125
+ end
126
+
127
+ errors << "#{path}.add_counters: must be {\"counter\": counter name, \"amount\": integer >= 1}"
128
+ nil
110
129
  end
111
130
 
112
131
  # CR 605.3a: a mana ability is paid for and resolves at once, so none of its costs can wait for a
@@ -129,7 +148,10 @@ module Enjine
129
148
  end
130
149
  end
131
150
 
151
+ # "Remove a charge counter from this" needs no choice (Costs::RemoveCounters#at_once?).
132
152
  def self.choosing_cost?(cost)
153
+ return false if cost.respond_to?(:at_once?) && cost.at_once?
154
+
133
155
  cost.respond_to?(:choices_needed) || (cost.respond_to?(:x?) && cost.x?) ||
134
156
  (cost.respond_to?(:mana_cost) && cost.mana_cost.hybrid.any? { Mana.mono_hybrid?(it) })
135
157
  end
@@ -153,8 +175,10 @@ module Enjine
153
175
  COLORS
154
176
  end
155
177
 
156
- def initialize(costs, produce, color: nil, colors: COLORS, amount: nil, spend_only: nil, only_if: nil, per_turn: nil)
178
+ def initialize(costs, produce, color: nil, colors: COLORS, amount: nil, spend_only: nil, only_if: nil, per_turn: nil,
179
+ add_counters: nil)
157
180
  super()
181
+ @add_counters = add_counters
158
182
  @per_turn = per_turn
159
183
  @costs = costs
160
184
  @produce = produce
@@ -182,6 +206,23 @@ module Enjine
182
206
  bound.all? { |c| c.payable?(engine, object) } && (mana_cost.nil? || engine.pool_covers?(object.controller, mana_cost))
183
207
  end
184
208
 
209
+ # [counter, amount] it puts on its source as it resolves, or nil.
210
+ attr_reader :add_counters
211
+
212
+ # One whose costs include more than {T} and mana (a sacrifice, life, a discard, removing counters) or that puts
213
+ # counters on its source can't be undone (CR 734.1 rewinds only tapping and mana).
214
+ def irreversible?
215
+ !add_counters.nil? || costs.any? { !it.is_a?(Costs::Tap) && !it.is_a?(Costs::TapGranter) && !it.mana? }
216
+ end
217
+
218
+ # How many times it could be activated in a row now, for affordability: once, unless every cost is removing
219
+ # counters from it (no {T}, CR 605.3a), then as many times as the counters last.
220
+ def repeats(object, bound = costs)
221
+ return 1 if bound.empty? || !bound.all? { it.respond_to?(:at_once?) && it.at_once? }
222
+
223
+ bound.map { it.times_payable(object) }.min
224
+ end
225
+
185
226
  # How many times it may be activated each turn (nil: no limit, CR 602.5b); kept by Engine#record_activation!.
186
227
  attr_reader :per_turn
187
228
 
@@ -222,6 +263,7 @@ module Enjine
222
263
  "#{" (#{colors.join("/")})" unless colors == COLORS}"
223
264
  end
224
265
  "#{costs.join(", ")}: #{what}.#{" #{spend_only.to_s.capitalize}." if spend_only}" \
266
+ "#{" Put #{add_counters[1]} #{add_counters[0]} counter(s) on this." if add_counters}" \
225
267
  "#{" Activate only if #{@only_if}." if @only_if}#{" Activate only once each turn." if per_turn}"
226
268
  end
227
269
  end
@@ -5,11 +5,20 @@ module Enjine
5
5
  # The exceptions of a copy effect (CR 707.9a-b), e.g. {"legendary": false} ("except it isn't
6
6
  # legendary") or {"keywords": ["menace"]} ("except it has menace"). They become part of the copy's
7
7
  # copiable values, so a copy of the copy has them too (CR 707.2). See Engine::Copies.
8
+ #
9
+ # Types, subtypes and supertypes are added to the copied ones ("in addition to its other types", CR 205.1b).
10
+ # `replace` lists those that instead replace the copied values ("except it's a 4/4 Dragon creature": the
11
+ # creature type and card type are set, CR 707.9b, 205.1a): {"types": ["creature"], "subtypes": ["dragon"],
12
+ # "replace": ["types", "subtypes"]}. Set subtypes replace the creature types; other subtypes stay unless the
13
+ # types are set too.
8
14
  module CopyExcept
9
- KEYS = %w[legendary keywords types subtypes supertypes name power toughness colors].freeze
15
+ KEYS = %w[legendary keywords types subtypes supertypes name power toughness colors replace].freeze
16
+ # The lists `replace` may name (CR 205.1a: an effect that sets a card type, subtype or supertype).
17
+ REPLACEABLE = %w[types subtypes supertypes].freeze
10
18
  LISTS = { "keywords" => :keyword, "types" => :type, "supertypes" => :supertype }.freeze
11
19
  PARAM = "{\"legendary\": false, \"keywords\": [...], \"types\": [...], \"subtypes\": [...], " \
12
- "\"supertypes\": [...], \"name\": ..., \"power\": n, \"toughness\": n, \"colors\": [...]}"
20
+ "\"supertypes\": [...], \"name\": ..., \"power\": n, \"toughness\": n, \"colors\": [...], " \
21
+ "\"replace\": [\"types\" | \"subtypes\" | \"supertypes\"]}"
13
22
 
14
23
  module_function
15
24
 
@@ -26,6 +35,7 @@ module Enjine
26
35
  out["subtypes"] = subtypes(raw["subtypes"], errors, "#{path}.subtypes") if raw.key?("subtypes")
27
36
  values(raw, out, errors, path)
28
37
  out["colors"] = colors(raw["colors"], errors, "#{path}.colors") if raw.key?("colors")
38
+ out["replace"] = replace(raw, errors, "#{path}.replace") if raw.key?("replace")
29
39
  out.freeze
30
40
  end
31
41
 
@@ -41,6 +51,14 @@ module Enjine
41
51
  end
42
52
  end
43
53
 
54
+ # CR 205.1a: the listed values are set, replacing the copied ones; each must be given in the exceptions.
55
+ def replace(raw, errors, path)
56
+ list = raw["replace"]
57
+ ok = list.is_a?(Array) && !list.empty? && list.uniq == list && list.all? { REPLACEABLE.include?(it) && raw.key?(it) }
58
+ errors << "#{path}: must list some of #{REPLACEABLE.join(", ")}, each also given in the exceptions" unless ok
59
+ ok ? list.map(&:to_s).freeze : [].freeze
60
+ end
61
+
44
62
  def names(list, category, errors, path)
45
63
  ok = list.is_a?(Array) && !list.empty? && list.all? { Enjine.registry.fetch(category, it.to_s.downcase.tr(" -", "__")) }
46
64
  errors << "#{path}: must be a non-empty list of #{category}s (#{Enjine.registry.names(category).join(", ")})" unless ok
@@ -65,7 +83,9 @@ module Enjine
65
83
  bits = []
66
84
  bits << "not legendary" if except["legendary"] == false
67
85
  %w[name power toughness].each { bits << "#{it} #{except[it]}" if except.key?(it) }
68
- %w[keywords types subtypes supertypes colors].each { bits << "#{it} #{except[it].join("/")}" if except[it] }
86
+ %w[keywords types subtypes supertypes colors].each do |key|
87
+ bits << "#{"only " if except["replace"]&.include?(key)}#{key} #{except[key].join("/")}" if except[key]
88
+ end
69
89
  " (except #{bits.join(", ")})"
70
90
  end
71
91
  end
@@ -10,8 +10,9 @@ module Enjine
10
10
  description: "Remove `count` counters (of kind `counter`, or any kind) from among permanents you " \
11
11
  "control matching `filter` (default creature), one counter per choice. Removed as " \
12
12
  "it becomes cast. `self: true`: only from this permanent (\"Remove two counters from " \
13
- "Ghost-Spider\").",
14
- rules: %w[602.2b 601.2h 118.3 122.1],
13
+ "Ghost-Spider\"). With `self: true` and a `counter` kind it needs no choice, so a mana " \
14
+ "ability may have it (\"Remove a charge counter from this: Add one mana of any color\").",
15
+ rules: %w[602.2b 601.2h 118.3 122.1 605.3a],
15
16
  params: { "count" => "integer", "filter" => "filter (default creature)", "counter" => "counter name (optional)",
16
17
  "self" => "true: from this permanent only" },
17
18
  example: { "remove_counters" => { "count" => 3 } }
@@ -47,6 +48,15 @@ module Enjine
47
48
  entries.each { engine.remove_counters!(engine.object(it["object"]), it["counter"], 1) }
48
49
  end
49
50
 
51
+ # "Remove a charge counter from this" names both the permanent and the kind, so paying it needs no choice: a
52
+ # mana ability may have it (CR 605.3a), and pays it at once with #pay_at_once!.
53
+ def at_once? = @self && !@counter.nil?
54
+
55
+ def pay_at_once!(engine, object) = engine.remove_counters!(object, @counter, count)
56
+
57
+ # How many times it could be paid now (a mana ability without {T} may be activated again, CR 605.3a).
58
+ def times_payable(object) = object.counters.fetch(@counter, 0) / count
59
+
50
60
  def to_s = "Remove #{count} #{"#{@counter} " if @counter}counters from #{@self ? "this" : "among #{what}s you control"}"
51
61
  end
52
62
  end
@@ -50,6 +50,13 @@ module Enjine
50
50
  # The costs that take the permanent itself off the battlefield (CR 113.6m: not from another zone).
51
51
  LEAVING_SELF = [SacrificeSelf, ExileSelf].freeze
52
52
 
53
+ # Whether paying `cost` takes the source itself off the battlefield: such costs are paid after the others
54
+ # (CR 601.2h: any order), so a cost that needs the permanent (remove counters from it) is paid while it's there.
55
+ def self.leaving_self?(cost) = LEAVING_SELF.include?(cost.class)
56
+
57
+ # `costs` in an order in which all of them can be paid: those that take the source away last (stable).
58
+ def self.payment_order(costs) = costs.each_with_index.sort_by { |cost, i| [leaving_self?(cost) ? 1 : 0, i] }
59
+
53
60
  # "Sacrifice a creature" / "Sacrifice another creature or artifact" as a cost (CR 701.21a, 601.2h).
54
61
  # The permanent is chosen while casting and sacrificed as the spell or ability becomes cast; what
55
62
  # it was (types, subtypes, power) is kept for "if you sacrificed a Klingon this way" (CR 608.2h).
@@ -95,7 +95,7 @@ module Enjine
95
95
  "not counters, status or other effects), with the `except` modifications. The tokens " \
96
96
  "are the effect's result, for later effects such as granting haste or a delayed " \
97
97
  "sacrifice.",
98
- rules: %w[707.2 707.8 707.9a 707.9b 111.1 614.1c],
98
+ rules: %w[707.2 707.8 707.9a 707.9b 205.1a 205.1b 111.1 614.1c],
99
99
  params: { "of" => "selector (what to copy)", "amount" => "amount (default 1)", "tapped" => "boolean",
100
100
  "except" => CopyExcept::PARAM, "to" => "selector (default \"you\")" },
101
101
  example: { "create_token_copy" => { "of" => { "target" => 0 }, "except" => { "legendary" => false } } }
@@ -13,7 +13,7 @@ module Enjine
13
13
  "`effects` may use {\"result\": n} for what earlier effects of the creating list moved or " \
14
14
  "created (n below its position); those objects are affected only if they are still " \
15
15
  "where they were put. Its own effects are numbered on from there.",
16
- rules: %w[603.7a 603.7b 603.7c 603.7d 603.7e],
16
+ rules: %w[603.7a 603.7b 603.7c 603.7d 603.7e 107.3n],
17
17
  params: { "when" => "a trigger condition", "effects" => "list of effects",
18
18
  "watch" => "selector resolved now (e.g. {\"target\": 0}): the objects its trigger subject " \
19
19
  "\"watched\" and its effects' selector \"watched\" mean (\"when that creature dies\")",
@@ -32,6 +32,10 @@ module Enjine
32
32
  # created ability's own effects are numbered right after them (StackAbility.parse_effects).
33
33
  def self.linked(values, count, blank) = Array.new(count) { values&.[](it) || blank }
34
34
 
35
+ # The X announced for the resolving spell or ability that creates a delayed or reflexive trigger (CR 107.3n,
36
+ # 603.12: reflexive triggers follow the delayed-trigger rules), or nil when it had none.
37
+ def self.creating_x(engine, ctx) = engine.find_object(ctx.object)&.x
38
+
35
39
  def setup(params, errors, path)
36
40
  @ref = "delayed:#{path}"
37
41
  raw = Mechanics.fetch_param(params, :when)
@@ -57,6 +61,8 @@ module Enjine
57
61
  entry["watched"] = @watch.resolve(engine, ctx) if @watch
58
62
  entry["turn"] = engine.state.turn if @this_turn
59
63
  entry["once"] = true if @this_turn == "once" # CR 603.7b: the next time only, and only this turn
64
+ x = DelayedTrigger.creating_x(engine, ctx)
65
+ entry["x"] = x if x # CR 107.3n: its X is the X of the spell or ability that created it
60
66
  engine.create_delayed_trigger!(entry)
61
67
  end
62
68
  end
@@ -72,7 +78,7 @@ module Enjine
72
78
  "of the creating list ({\"result\": n} / {\"this_way\": n} with n below its position) and " \
73
79
  "their own, numbered on from there. With `if`, it triggers only when the condition holds " \
74
80
  "(\"when excess damage is dealt this way\").",
75
- rules: %w[603.12 603.12a 603.7d 603.7e 603.3d],
81
+ rules: %w[603.12 603.12a 603.7d 603.7e 603.3d 107.3n],
76
82
  params: { "targets" => "list of target filters", "effects" => "list of effects", "if" => "condition",
77
83
  "divide" => "amount divided among the targets as it's put on the stack (CR 601.2d)" },
78
84
  example: { "reflexive_trigger" => { "targets" => ["any_target"],
@@ -112,6 +118,7 @@ module Enjine
112
118
  engine.queue_pending_trigger!(source, nil, { "results" => results,
113
119
  "amounts" => DelayedTrigger.linked(ctx.amounts, @results_count, 0),
114
120
  "triggering" => memory["triggering"]&.dup,
121
+ "x" => DelayedTrigger.creating_x(engine, ctx),
115
122
  "departed" => engine.departed_snapshot }.compact)
116
123
  end
117
124
  end
@@ -104,7 +104,7 @@ module Enjine
104
104
  engine.begin_payment!(payer_obj.controller, mana, ctx.object, waterbend: bend.positive? ? bend : nil)
105
105
  return :wait
106
106
  end
107
- variant.each_with_index do |cost, i|
107
+ Costs.payment_order(variant).each do |cost, i| # the source leaves last (CR 601.2h)
108
108
  next if cost.mana?
109
109
 
110
110
  if cost.respond_to?(:choices_needed) # a chosen creature type was "paid" as it was chosen
@@ -4,13 +4,35 @@ module Enjine
4
4
  module Mechanics
5
5
  module Effects
6
6
  # Scry N / surveil N (CR 701.22, 701.25): look at the top N, put each on the top or away
7
- # (bottom / graveyard), then order the ones kept on top.
7
+ # (bottom / graveyard), then order the ones kept on top. `to` names who does it ("target player scries 2"):
8
+ # each of them in turn, in APNAP order (CR 101.4), with their own library.
8
9
  class LookAtTop < ChoiceEffect
9
10
  def self.default_to = "you"
10
11
  def self.away = raise(NotImplementedError)
11
12
 
12
13
  def run(engine, ctx, locals)
13
- index = ctx.controller
14
+ return :done unless locals.key?("amount") || condition.nil? || condition.true?(engine, ctx) # CR 608.2c, once
15
+
16
+ players = locals["players"] || who(engine, ctx)
17
+ locals["players"] = players unless players == [ctx.controller] # only "you": nothing to remember
18
+ while (turn = locals.fetch("turn", 0)) < players.size
19
+ return :wait if run_for(engine, ctx, locals, players[turn]) == :wait
20
+ break if players.size == 1
21
+
22
+ locals["turn"] = turn + 1
23
+ locals.delete("seen")
24
+ locals.delete("answers")
25
+ end
26
+ :done
27
+ end
28
+
29
+ # The players it names, in APNAP order (CR 101.4).
30
+ def who(engine, ctx)
31
+ named = players(engine, ctx).uniq
32
+ engine.turn_order_from_active.select { named.include?(it) }
33
+ end
34
+
35
+ def run_for(engine, ctx, locals, index)
14
36
  locals["amount"] ||= amount_for(engine, ctx)
15
37
  seen = (locals["seen"] ||= engine.player(index).library.first(locals["amount"]))
16
38
  decided = answers(locals).reject { it["type"] == "order" }
@@ -43,8 +65,10 @@ module Enjine
43
65
  # Scry N (CR 701.22).
44
66
  class Scry < LookAtTop
45
67
  primitive :effect, :scry, description: "Look at the top `amount` cards of your library; put any number on the " \
46
- "bottom and the rest on top in any order.",
47
- rules: %w[701.22a], params: { "amount" => "integer" }, example: { "scry" => { "amount" => 2 } }
68
+ "bottom and the rest on top in any order. `to`: who scries (default " \
69
+ "\"you\"; e.g. {\"target\": 0} for \"target player scries\"), each in turn.",
70
+ rules: %w[701.22a 101.4], params: { "amount" => "integer", "to" => "selector of players (default you)" },
71
+ example: { "scry" => { "amount" => 2 } }
48
72
  def self.away = "bottom"
49
73
 
50
74
  def place(engine, index, tops, bottoms)
@@ -57,8 +81,10 @@ module Enjine
57
81
  # Surveil N (CR 701.25).
58
82
  class Surveil < LookAtTop
59
83
  primitive :effect, :surveil, description: "Look at the top `amount` cards of your library; put any number into " \
60
- "your graveyard and the rest on top in any order.",
61
- rules: %w[701.25a], params: { "amount" => "integer" },
84
+ "your graveyard and the rest on top in any order. `to`: who " \
85
+ "surveils (default \"you\"), each in turn.",
86
+ rules: %w[701.25a 101.4],
87
+ params: { "amount" => "integer", "to" => "selector of players (default you)" },
62
88
  example: { "surveil" => { "amount" => 2 } }
63
89
  def self.away = "graveyard"
64
90
 
@@ -107,6 +107,8 @@ module Enjine
107
107
  # {"creature": {"saddled": true}} saddled this turn (CR 702.171b)
108
108
  # {"creature": {"entered_this_turn": true}} entered the battlefield this turn
109
109
  # {"spell": {"single_target": true}} a spell with a single target (CR 115.7)
110
+ # {"creature": {"color_count": {"equal": 1}}} monocolored (1), multicolored ({"at_least": 2}), colorless (0)
111
+ # (CR 105.2a-c); fixed integer bounds, matched like a color
110
112
  class Restricted
111
113
  TYPES = %w[artifact battle creature enchantment kindred land planeswalker instant sorcery].freeze
112
114
  BOOLEANS = %w[other attacking blocking tapped token modified transformed prepared saddled entered_this_turn
@@ -115,7 +117,7 @@ module Enjine
115
117
  TYPE_LISTS = %w[not any_of types].freeze
116
118
  NAME_LISTS = %w[subtypes not_subtypes supertypes not_supertypes attached_subtypes].freeze
117
119
  KEYWORD_LISTS = %w[keywords not_keywords].freeze
118
- KEYS = (%w[controller owner counters colors name] + BOOLEANS + RANGES + TYPE_LISTS + NAME_LISTS + KEYWORD_LISTS).freeze
120
+ KEYS = (%w[controller owner counters colors color_count name] + BOOLEANS + RANGES + TYPE_LISTS + NAME_LISTS + KEYWORD_LISTS).freeze
119
121
  # Lists that may be "chosen": the choice remembered under that memory key (CR 607.2d). "name" is only
120
122
  # "chosen" ("with the chosen name", CR 201.4).
121
123
  CHOSEN = { "colors" => "chosen_color", "types" => "chosen_card_type", "not" => "chosen_card_type",
@@ -147,7 +149,7 @@ module Enjine
147
149
  errors << "#{path}.colors: must be a non-empty list of W, U, B, R, G (any of them) or \"chosen\""
148
150
  end
149
151
  errors << "#{path}.name: must be \"chosen\"" unless [nil, "chosen"].include?(params["name"])
150
- new(base, params, ranges)
152
+ new(base, params, ranges, color_count(params, errors, path))
151
153
  end
152
154
 
153
155
  def self.validate_lists(params, errors, path)
@@ -196,12 +198,27 @@ module Enjine
196
198
  range.to_h { |key, n| [key, Amount.build(n, errors, "#{path}.#{key}", targets_count: 0, min: -1_000)] }
197
199
  end
198
200
 
201
+ # "Monocolored" / "multicolored" / "colorless" (CR 105.2a-c): bounds on the number of colors, fixed integers
202
+ # so the layer pass can match them (a characteristic, CR 105.2, not a live value).
203
+ def self.color_count(params, errors, path)
204
+ range = params["color_count"]
205
+ return nil if range.nil?
206
+
207
+ ok = range.is_a?(Hash) && !range.empty? && (range.keys - BOUNDS).empty? &&
208
+ range.values.all? { it.is_a?(Integer) && it.between?(0, 5) }
209
+ return range.transform_keys(&:to_s).freeze if ok
210
+
211
+ errors << "#{path}.color_count: must be {\"at_least\": n}, {\"at_most\": n} and/or {\"equal\": n} (n: 0-5)"
212
+ nil
213
+ end
214
+
199
215
  def self.build_ranges(params, errors, path)
200
216
  RANGES.filter_map { |key| [key, validate_range(params[key], errors, "#{path}.#{key}")] if params.key?(key) }.to_h
201
217
  end
202
218
 
203
- def initialize(base, params, ranges = {})
219
+ def initialize(base, params, ranges = {}, color_count = nil)
204
220
  @base = base
221
+ @color_count = color_count
205
222
  @controller = params["controller"]
206
223
  @other = params["other"] == true
207
224
  @params = params
@@ -263,7 +280,7 @@ module Enjine
263
280
  words.concat(chosen_words)
264
281
  words << (@lists["any_of"].empty? ? base.primitive_name.tr("_", " ") : @lists["any_of"].join(" or "))
265
282
  words.concat(ownership_words)
266
- words.concat(@ranges.map { |key, range| "with #{key.tr("_", " ")} #{range_words(range)}" })
283
+ words.concat(range_list_words)
267
284
  words << "with a #{@lists["attached_subtypes"].join(" or ")} attached" unless @lists["attached_subtypes"].empty?
268
285
  (words + [counter_words, ("with a single target" if @params["single_target"])] + keyword_words).compact.join(" ")
269
286
  end
@@ -285,6 +302,11 @@ module Enjine
285
302
  { "you" => "you own", "opponent" => "an opponent owns" }[@params["owner"]]]
286
303
  end
287
304
 
305
+ def range_list_words
306
+ words = @ranges.map { |key, range| "with #{key.tr("_", " ")} #{range_words(range)}" }
307
+ @color_count ? words << "with number of colors #{range_words(@color_count)}" : words
308
+ end
309
+
288
310
  def range_words(range) = range.map { |k, n| format(RANGE_WORDS.fetch(k), n) }.join(" and ")
289
311
 
290
312
  def chosen_words = @chosen.keys.map { "#{"non-" if it.start_with?("not")}chosen-#{it.delete_prefix("not_")}" }
@@ -343,6 +365,7 @@ module Enjine
343
365
  return false if c.subtypes.intersect?(@lists["not_subtypes"]) || c.supertypes.intersect?(@lists["not_supertypes"])
344
366
  return false unless (@lists["supertypes"] - c.supertypes).empty?
345
367
  return false if @colors && !c.colors.intersect?(@colors) # CR 105.2
368
+ return false if @color_count && !in_range?(c.colors.size, @color_count) # CR 105.2a-c
346
369
  return false unless keywords_ok?(c.keywords)
347
370
  return false if !@params["token"].nil? && facts.token != @params["token"]
348
371
  return false if @params["modified"] == false && Counters.any?(facts.counters)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Enjine
4
- VERSION = "0.6.1"
4
+ VERSION = "0.6.2"
5
5
  # Comprehensive Rules document this engine follows.
6
6
  RULES_VERSION = "2026-11-06"
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enjine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehmet Cetin