enjine 0.3.0 → 0.5.0

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.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +91 -1
  3. data/SUPPORTED.md +34 -26
  4. data/docs/guides/card-data-format.md +143 -1
  5. data/docs/plans/dsl-gaps.md +99 -0
  6. data/docs/reference/abilities.md +46 -13
  7. data/docs/reference/costs.md +23 -6
  8. data/docs/reference/decisions.md +4 -0
  9. data/docs/reference/effects.md +118 -25
  10. data/docs/reference/filters.md +19 -2
  11. data/docs/reference/keywords.md +16 -2
  12. data/docs/reference/triggers.md +28 -7
  13. data/lib/enjine/actions/cast.rb +10 -3
  14. data/lib/enjine/actions/play_land.rb +3 -1
  15. data/lib/enjine/card_definition.rb +19 -3
  16. data/lib/enjine/cli/text.rb +10 -3
  17. data/lib/enjine/decisions/combat.rb +4 -2
  18. data/lib/enjine/decisions/damage_order.rb +18 -0
  19. data/lib/enjine/engine/ability_layers.rb +6 -1
  20. data/lib/enjine/engine/casting/alt_casting.rb +44 -4
  21. data/lib/enjine/engine/casting/cast_choices.rb +13 -1
  22. data/lib/enjine/engine/casting/casting.rb +43 -7
  23. data/lib/enjine/engine/casting/cost_options.rb +3 -1
  24. data/lib/enjine/engine/casting/permissions.rb +27 -23
  25. data/lib/enjine/engine/casting/target_counts.rb +14 -3
  26. data/lib/enjine/engine/casting/waterbend.rb +22 -2
  27. data/lib/enjine/engine/characteristics.rb +32 -14
  28. data/lib/enjine/engine/combat.rb +26 -7
  29. data/lib/enjine/engine/copies.rb +26 -12
  30. data/lib/enjine/engine/damage.rb +51 -1
  31. data/lib/enjine/engine/durations.rb +47 -0
  32. data/lib/enjine/engine/entering.rb +36 -2
  33. data/lib/enjine/engine/face_down.rb +12 -3
  34. data/lib/enjine/engine/faces.rb +16 -2
  35. data/lib/enjine/engine/follow_ups.rb +4 -1
  36. data/lib/enjine/engine/resolution.rb +46 -1
  37. data/lib/enjine/engine/rules.rb +6 -4
  38. data/lib/enjine/engine/state_based_actions.rb +8 -0
  39. data/lib/enjine/engine/triggers.rb +18 -21
  40. data/lib/enjine/engine/turn_history.rb +16 -1
  41. data/lib/enjine/engine/turn_structure.rb +1 -0
  42. data/lib/enjine/engine/zones.rb +23 -4
  43. data/lib/enjine/events.rb +6 -1
  44. data/lib/enjine/frames.rb +2 -2
  45. data/lib/enjine/mana.rb +3 -0
  46. data/lib/enjine/mechanics/abilities/chosen_values.rb +49 -6
  47. data/lib/enjine/mechanics/abilities/damage_replacements.rb +136 -64
  48. data/lib/enjine/mechanics/abilities/double_counters.rb +1 -1
  49. data/lib/enjine/mechanics/abilities/entering_choices.rb +40 -21
  50. data/lib/enjine/mechanics/abilities/play_permissions.rb +52 -19
  51. data/lib/enjine/mechanics/abilities/player_rules.rb +30 -13
  52. data/lib/enjine/mechanics/abilities/replacement_effects.rb +2 -1
  53. data/lib/enjine/mechanics/abilities/static.rb +8 -1
  54. data/lib/enjine/mechanics/card_spec.rb +99 -14
  55. data/lib/enjine/mechanics/costs/base.rb +67 -9
  56. data/lib/enjine/mechanics/costs/behold.rb +21 -5
  57. data/lib/enjine/mechanics/costs/choose_creature_type.rb +43 -0
  58. data/lib/enjine/mechanics/costs/one_of.rb +3 -0
  59. data/lib/enjine/mechanics/costs/pay_life.rb +27 -8
  60. data/lib/enjine/mechanics/costs/remove_counters.rb +8 -5
  61. data/lib/enjine/mechanics/costs/tap.rb +44 -3
  62. data/lib/enjine/mechanics/effects/base.rb +10 -2
  63. data/lib/enjine/mechanics/effects/become.rb +60 -21
  64. data/lib/enjine/mechanics/effects/copy.rb +63 -23
  65. data/lib/enjine/mechanics/effects/counters.rb +8 -2
  66. data/lib/enjine/mechanics/effects/damage.rb +11 -0
  67. data/lib/enjine/mechanics/effects/earthbend.rb +2 -1
  68. data/lib/enjine/mechanics/effects/fight.rb +11 -0
  69. data/lib/enjine/mechanics/effects/gain_control.rb +6 -3
  70. data/lib/enjine/mechanics/effects/library.rb +76 -18
  71. data/lib/enjine/mechanics/effects/pay.rb +7 -4
  72. data/lib/enjine/mechanics/effects/repeat.rb +92 -0
  73. data/lib/enjine/mechanics/effects/return_to_battlefield.rb +25 -6
  74. data/lib/enjine/mechanics/effects/search.rb +34 -6
  75. data/lib/enjine/mechanics/effects/tokens.rb +42 -10
  76. data/lib/enjine/mechanics/filters/base.rb +40 -13
  77. data/lib/enjine/mechanics/filters/exile.rb +27 -0
  78. data/lib/enjine/mechanics/filters/stack.rb +15 -9
  79. data/lib/enjine/mechanics/keywords/alternative_costs.rb +10 -6
  80. data/lib/enjine/mechanics/keywords/cards_have.rb +65 -0
  81. data/lib/enjine/mechanics/keywords/flags.rb +3 -1
  82. data/lib/enjine/mechanics/keywords/hideaway.rb +6 -5
  83. data/lib/enjine/mechanics/keywords/kicker.rb +24 -6
  84. data/lib/enjine/mechanics/keywords/protection.rb +24 -8
  85. data/lib/enjine/mechanics/keywords/riot.rb +13 -10
  86. data/lib/enjine/mechanics/linked.rb +32 -2
  87. data/lib/enjine/mechanics/selector.rb +32 -9
  88. data/lib/enjine/mechanics/triggers/base.rb +14 -3
  89. data/lib/enjine/mechanics/triggers/casting.rb +16 -10
  90. data/lib/enjine/mechanics/triggers/combat.rb +32 -12
  91. data/lib/enjine/mechanics/triggers/keyword_actions.rb +17 -0
  92. data/lib/enjine/mechanics/triggers/tap_and_counters.rb +38 -11
  93. data/lib/enjine/mechanics/triggers/zone_changes.rb +1 -1
  94. data/lib/enjine/mechanics/values.rb +20 -10
  95. data/lib/enjine/mechanics.rb +5 -0
  96. data/lib/enjine/replacements.rb +3 -2
  97. data/lib/enjine/rules_monitor.rb +17 -4
  98. data/lib/enjine/steps.rb +10 -1
  99. data/lib/enjine/version.rb +1 -1
  100. data/lib/enjine/view.rb +1 -1
  101. metadata +7 -1
@@ -224,17 +224,19 @@ Rules: CR 701.3a, CR 701.3b, CR 701.3c, CR 301.5c
224
224
 
225
225
  ## become
226
226
 
227
- Each referenced permanent becomes what the parameters say, for `duration` (end_of_turn, default; until_your_next_turn: until your next turn begins; indefinite: as long as it stays on the battlefield; while_source_on_battlefield: for as long as this effect's source remains on the battlefield; while_you_control_source: for as long as you control it): it has the card `types`, `supertypes` and `subtypes` in addition to its other types (layer 4, "becomes an artifact creature"), its creature types are exactly `creature_types` (layer 4), its colors are `colors` (layer 5), with `loses_abilities: true` it loses all the abilities it had (layer 6; abilities granted later, keyword counters put on it later and this effect's own `keywords` and `abilities` stay, CR 613.7), it has the `keywords` and `abilities` (layer 6: triggered, activated, mana, play_from or additional_land_plays abilities) and its base power and toughness are `base_power_toughness` (layer 7b). A permanent that becomes a creature has its printed power and toughness (a Vehicle's), or 0/0.
227
+ Each referenced permanent becomes what the parameters say, for `duration` (end_of_turn, default; until_your_next_turn: until your next turn begins; indefinite: as long as it stays on the battlefield; while_source_on_battlefield: for as long as this effect's source remains on the battlefield; while_you_control_source: for as long as you control it): it has the card `types`, `supertypes` and `subtypes` in addition to its other types (layer 4, "becomes an artifact creature"; with `set_types` its card types are exactly those first, "it's an enchantment, not a creature", and subtypes of a card type it loses go), its creature types are exactly `creature_types` ([] for "loses all creature types"; `all_creature_types: true` for "all creature types") (layer 4), its colors are `colors` (layer 5), with `loses_abilities: true` it loses all the abilities it had (layer 6; abilities granted later, keyword counters put on it later and this effect's own `keywords` and `abilities` stay, CR 613.7), it has the `keywords` and `abilities` (layer 6: triggered, activated, mana, play_from or additional_land_plays abilities) and its base power and toughness are `base_power_toughness` (layer 7b). A permanent that becomes a creature has its printed power and toughness (a Vehicle's), or 0/0.
228
228
 
229
229
  Rules: CR 611.2a, CR 611.2b, CR 611.2c, CR 613.1d, CR 613.1e, CR 613.1f, CR 613.4b, CR 613.7b, CR 205.1a, CR 205.1b, CR 301.7b, CR 514.2
230
230
 
231
231
  | Parameter | Description |
232
232
  | --- | --- |
233
+ | `set_types` | card types it has instead of its others: artifact, creature, enchantment, land |
233
234
  | `types` | card types it also has: artifact, creature, enchantment, land |
234
235
  | `supertypes` | supertypes it also has ("legendary") |
235
236
  | `subtypes` | subtypes it also has ("in addition to its other types") |
236
- | `creature_types` | list of creature types (replaces the others) |
237
- | `colors` | list of W, U, B, R, G (replaces its colors) |
237
+ | `creature_types` | list of creature types (replaces the others; [] removes them all) |
238
+ | `all_creature_types` | true: it has every creature type |
239
+ | `colors` | list of W, U, B, R, G (replaces its colors), or "chosen": the color chosen earlier while this resolved (choose_color); abilities it grants that say "chosen_color" keep that color |
238
240
  | `loses_abilities` | true: it loses all abilities ("loses all abilities") |
239
241
  | `keywords` | list of keywords it gains |
240
242
  | `base_power_toughness` | {"power": n, "toughness": n} |
@@ -268,7 +270,7 @@ Rules: CR 611.2a, CR 611.2b, CR 611.2c, CR 613.1d, CR 613.1e, CR 613.1f, CR 613.
268
270
 
269
271
  ## become_copy
270
272
 
271
- Each referenced permanent becomes a copy of the (first) object `of` refers to, with the `except` modifications, until end of turn (default) or for as long as it stays on the battlefield (`duration: "permanent"`). It keeps its counters, status and other effects; nothing enters or leaves, so no enter or leave abilities trigger. Several copy effects apply in timestamp order.
273
+ Each referenced permanent becomes a copy of the (first) object `of` refers to, with the `except` modifications, until end of turn (default), until your next turn (`until_your_next_turn`) or for as long as it stays on the battlefield (`duration: "permanent"`). It keeps its counters, status and other effects; nothing enters or leaves, so no enter or leave abilities trigger. Several copy effects apply in timestamp order.
272
274
 
273
275
  Rules: CR 707.2, CR 707.4, CR 613.2a, CR 613.7, CR 611.2a, CR 514.2
274
276
 
@@ -277,7 +279,7 @@ Rules: CR 707.2, CR 707.4, CR 613.2a, CR 613.7, CR 611.2a, CR 514.2
277
279
  | `to` | selector (the permanents that become copies) |
278
280
  | `of` | selector (what they copy) |
279
281
  | `except` | {"legendary": false, "keywords": [...], "types": [...], "subtypes": [...], "supertypes": [...], "name": ..., "power": n, "toughness": n, "colors": [...]} |
280
- | `duration` | end_of_turn | permanent |
282
+ | `duration` | end_of_turn | until_your_next_turn | permanent |
281
283
 
282
284
  ```json
283
285
  {
@@ -390,17 +392,18 @@ Rules: CR 701.68a, CR 701.68b, CR 701.68c
390
392
 
391
393
  ## cast
392
394
 
393
- The controller may cast referenced cards (or card copies) now, while this resolves, paying their costs; timing restrictions don't apply. `to`, `for`, `not_types`, `max_mana_value`, `count`, `exile_instead` and `any_mana_type` work as for `cast_free`.
395
+ The controller may cast referenced cards (or card copies) now, while this resolves, paying their costs; timing restrictions don't apply. `to`, `from`, `for`, `not_types`, `max_mana_value`, `count`, `exile_instead` and `any_mana_type` work as for `cast_free` ("you may cast an artifact spell from your graveyard": `from: "graveyard"`).
394
396
 
395
397
  Rules: CR 608.2g, CR 707.12, CR 707.12a, CR 601.2a, CR 601.2f
396
398
 
397
399
  | Parameter | Description |
398
400
  | --- | --- |
399
401
  | `to` | selector |
402
+ | `from` | hand | graveyard |
400
403
  | `for` | card spec |
401
404
  | `not_types` | list of card types |
402
405
  | `max_mana_value` | amount |
403
- | `count` | 1 or "any" |
406
+ | `count` | integer >= 1 (default 1) or "any" |
404
407
  | `exile_instead` | true or a card spec (as for cast_free) |
405
408
  | `any_mana_type` | boolean: mana of any type can be spent to cast it (CR 609.4b) |
406
409
 
@@ -416,7 +419,7 @@ Rules: CR 608.2g, CR 707.12, CR 707.12a, CR 601.2a, CR 601.2f
416
419
 
417
420
  ## cast_free
418
421
 
419
- The controller may cast referenced cards without paying their mana costs while this resolves. `to` names the cards ({"result": n}), or a player for the cards in their hand (default: your hand). Only cards matching `for`/`not_types` with mana value up to `max_mana_value` (optional amount) that could be cast now (legal targets). `count`: 1 (default) or "any" (any number, one at a time). X is 0 (CR 107.3b). `play: true` ("you may play"): a land among them may be played, on your turn with a land play left (`{type: "play_land"}`). A face-down card is judged face up.
422
+ The controller may cast referenced cards without paying their mana costs while this resolves. `to` names the cards ({"result": n}), or a player for the cards in their hand (default: your hand), or in the zone `from` (hand | graveyard). Only cards matching `for`/`not_types` with mana value up to `max_mana_value` (optional amount) that could be cast now (legal targets). `count`: 1 (default), up to N (an integer), or "any" (any number, one at a time). X is 0 (CR 107.3b). `play: true` ("you may play"): a land among them may be played, on your turn with a land play left (`{type: "play_land"}`). A face-down card is judged face up.
420
423
 
421
424
  Rules: CR 608.2g, CR 118.9, CR 601.2a, CR 107.3b, CR 118.6a, CR 305.2a, CR 305.3, CR 406.3a
422
425
 
@@ -426,7 +429,8 @@ Rules: CR 608.2g, CR 118.9, CR 601.2a, CR 107.3b, CR 118.6a, CR 305.2a, CR 305.3
426
429
  | `for` | card spec |
427
430
  | `not_types` | list of card types |
428
431
  | `max_mana_value` | amount |
429
- | `count` | 1 or "any" |
432
+ | `count` | integer >= 1 (default 1) or "any" |
433
+ | `from` | hand | graveyard |
430
434
  | `play` | boolean |
431
435
  | `exile_instead` | true or a card spec: if a spell cast this way (matching it) would be put into a graveyard, it's exiled instead (CR 614.1a) |
432
436
  | `any_mana_type` | boolean: mana of any type can be spent to cast it (CR 609.4b) |
@@ -443,6 +447,50 @@ Rules: CR 608.2g, CR 118.9, CR 601.2a, CR 107.3b, CR 118.6a, CR 305.2a, CR 305.3
443
447
  }
444
448
  ```
445
449
 
450
+ ## change_target
451
+
452
+ Change the target(s) of each spell or ability on the stack `of` refers to: each target becomes another legal target you choose for that spell; if one can't, none change.
453
+
454
+ Rules: CR 115.7, CR 115.7a, CR 115.7e
455
+
456
+ | Parameter | Description |
457
+ | --- | --- |
458
+ | `of` | selector (spells or abilities on the stack) |
459
+
460
+ ```json
461
+ {
462
+ "change_target": {
463
+ "of": {
464
+ "target": 0
465
+ }
466
+ }
467
+ }
468
+ ```
469
+
470
+ ## choose_card_name
471
+
472
+ The player (`to`, default you) chooses a card name among the cards in the game (`types`: the named card has one of these; `not`: it has none of these); "the chosen name" (`name: "chosen"` in filters) reads it. `remember: "source"`: the source permanent remembers it for its other abilities.
473
+
474
+ Rules: CR 201.4, CR 607.2d, CR 608.2c
475
+
476
+ | Parameter | Description |
477
+ | --- | --- |
478
+ | `types` | list of card types |
479
+ | `not` | list of card types |
480
+ | `remember` | "source" |
481
+ | `to` | player selector (default you) |
482
+
483
+ ```json
484
+ {
485
+ "choose_card_name": {
486
+ "types": [
487
+ "land"
488
+ ],
489
+ "remember": "source"
490
+ }
491
+ }
492
+ ```
493
+
446
494
  ## choose_card_type
447
495
 
448
496
  The player (`to`, default you) chooses a card type; later effects of this spell or ability read it with "types": "chosen".
@@ -728,9 +776,9 @@ Rules: CR 114.1, CR 114.2, CR 114.3, CR 114.4, CR 113.6p
728
776
 
729
777
  ## create_token
730
778
 
731
- 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).
779
+ 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).
732
780
 
733
- Rules: CR 111.1, CR 111.10, CR 701.7a, CR 704.5d, CR 508.4, CR 506.3b
781
+ Rules: CR 111.1, CR 111.10, CR 701.7a, CR 704.5d, CR 508.4, CR 506.3b, CR 707.2
734
782
 
735
783
  | Parameter | Description |
736
784
  | --- | --- |
@@ -739,6 +787,7 @@ Rules: CR 111.1, CR 111.10, CR 701.7a, CR 704.5d, CR 508.4, CR 506.3b
739
787
  | `tapped` | boolean |
740
788
  | `attacking` | boolean |
741
789
  | `to` | selector (default "you") |
790
+ | `size` | amount: the tokens are N/N |
742
791
 
743
792
  ```json
744
793
  {
@@ -906,9 +955,9 @@ Rules: CR 701.8a
906
955
 
907
956
  ## dig
908
957
 
909
- 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: hideaway).
958
+ 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).
910
959
 
911
- Rules: CR 701.20a, CR 701.20e, CR 401.4, CR 400.7j, CR 406.3, CR 607.2a
960
+ Rules: CR 701.20a, CR 701.20e, CR 401.4, CR 400.7j, CR 406.3, CR 607.2a, CR 702.75a
912
961
 
913
962
  | Parameter | Description |
914
963
  | --- | --- |
@@ -922,6 +971,7 @@ Rules: CR 701.20a, CR 701.20e, CR 401.4, CR 400.7j, CR 406.3, CR 607.2a
922
971
  | `rest` | bottom_random | bottom_any | graveyard |
923
972
  | `face_down` | boolean (put exile) |
924
973
  | `link` | boolean (put exile) |
974
+ | `looker` | "source_controller" (face_down) |
925
975
 
926
976
  ```json
927
977
  {
@@ -1196,9 +1246,9 @@ Rules: CR 608.2n, CR 406.1
1196
1246
 
1197
1247
  ## exile_top
1198
1248
 
1199
- Each referenced player (default: you) exiles the top `amount` cards of their library (face up). Later effects name them with {"result": n}; `link: true` exiles them with the source. `face_down: true` exiles them face down: only the `looker` players (default: you) may look at them.
1249
+ Each referenced player (default: you) exiles the top `amount` cards of their library (face up). Later effects name them with {"result": n}; `link: true` exiles them with the source. `face_down: true` exiles them face down: only the `looker` players (default: you) may look at them. `until` instead of `amount`: exile cards from the top one at a time until {"total_mana_value": N}: those cards have a total mana value of N or more, or {"card": card spec}: a matching card is exiled (or the library is empty).
1200
1250
 
1201
- Rules: CR 406.1, CR 400.7j, CR 607.2a, CR 406.3, CR 406.3a
1251
+ Rules: CR 406.1, CR 400.7j, CR 607.2a, CR 406.3, CR 406.3a, CR 202.3, CR 608.2c
1202
1252
 
1203
1253
  | Parameter | Description |
1204
1254
  | --- | --- |
@@ -1207,6 +1257,7 @@ Rules: CR 406.1, CR 400.7j, CR 607.2a, CR 406.3, CR 406.3a
1207
1257
  | `link` | boolean |
1208
1258
  | `face_down` | boolean |
1209
1259
  | `looker` | selector of players who may look (default "you") |
1260
+ | `until` | {"total_mana_value": amount} | {"card": card spec} |
1210
1261
 
1211
1262
  ```json
1212
1263
  {
@@ -1327,7 +1378,7 @@ Rules: CR 613.1b, CR 108.4, CR 506.4, CR 302.6, CR 514.2, CR 611.2b
1327
1378
  | --- | --- |
1328
1379
  | `to` | selector (permanents) |
1329
1380
  | `gains` | selector (a player; default "you") |
1330
- | `duration` | permanent | end_of_turn | while_source_on_battlefield | while_source_tapped | while_you_control_source |
1381
+ | `duration` | permanent | end_of_turn | end_of_your_next_turn | while_source_on_battlefield | while_source_tapped | while_you_control_source |
1331
1382
 
1332
1383
  ```json
1333
1384
  {
@@ -1609,14 +1660,14 @@ Rules: CR 702.26a, CR 702.26b, CR 702.26d, CR 702.26g, CR 702.26h, CR 502.1, CR
1609
1660
 
1610
1661
  ## play_permission
1611
1662
 
1612
- A player may play (`play: "play"`, default) or cast (`"cast"`) each referenced exiled card matching `for`/`not_types`, paying its costs and following timing rules, for `duration`: end_of_turn (default), end_of_your_next_turn or while_exiled. With `choose: "one_per_owner"` only one chosen card per owner. `to_player`: who may play it, "controller" (default, the effect's controller), "owner" (the card's owner) or a player selector (a face-down card: only someone who may look at it). `cost_increase`: spells cast this way cost that much generic mana more. `any_mana_type: true`: mana of any type can be spent to cast those spells.
1663
+ A player may play (`play: "play"`, default) or cast (`"cast"`) each referenced exiled card matching `for`/`not_types`, paying its costs and following timing rules, for `duration`: end_of_turn (default), end_of_your_next_turn, until_your_next_end_step, while_exiled or while_you_control_source ("for as long as you control this creature"). With `choose: "one_per_owner"` only one chosen card per owner. `to_player`: who may play it, "controller" (default, the effect's controller), "owner" (the card's owner) or a player selector (a face-down card: only someone who may look at it). `cost_increase`: spells cast this way cost that much generic mana more. `any_mana_type: true`: mana of any type can be spent to cast those spells. `during: "your_turn"`: only during your turn. `waterbend: "mana_value"`: cast it by waterbending {X} rather than paying its mana cost, where X is its mana value.
1613
1664
 
1614
- Rules: CR 611.2a, CR 601.3, CR 305.1, CR 400.7, CR 514.2, CR 601.2f, CR 108.3, CR 406.3b, CR 609.4b
1665
+ Rules: CR 611.2a, CR 611.2b, CR 601.3, CR 305.1, CR 400.7, CR 514.2, CR 601.2f, CR 108.3, CR 406.3b, CR 609.4b, CR 118.9, CR 701.67a
1615
1666
 
1616
1667
  | Parameter | Description |
1617
1668
  | --- | --- |
1618
1669
  | `to` | selector (usually {"result": n}) |
1619
- | `duration` | end_of_turn | end_of_your_next_turn | while_exiled |
1670
+ | `duration` | end_of_turn | end_of_your_next_turn | until_your_next_end_step | while_exiled | while_you_control_source |
1620
1671
  | `play` | play | cast |
1621
1672
  | `for` | card spec |
1622
1673
  | `not_types` | list of card types |
@@ -1625,6 +1676,8 @@ Rules: CR 611.2a, CR 601.3, CR 305.1, CR 400.7, CR 514.2, CR 601.2f, CR 108.3, C
1625
1676
  | `cost_increase` | integer >= 1 |
1626
1677
  | `any_mana_type` | boolean |
1627
1678
  | `exile_instead` | true or a card spec: if a spell cast this way (matching it) would be put into a graveyard, it's exiled instead (CR 614.1a) |
1679
+ | `during` | your_turn |
1680
+ | `waterbend` | mana_value |
1628
1681
 
1629
1682
  ```json
1630
1683
  {
@@ -1641,7 +1694,7 @@ Rules: CR 611.2a, CR 601.3, CR 305.1, CR 400.7, CR 514.2, CR 601.2f, CR 108.3, C
1641
1694
 
1642
1695
  Each referenced player (default you) gets `rule` for the `duration`: end_of_turn (default) or until_your_next_turn (until the controller's next turn begins). Rules: hexproof, cant_attack, no_max_hand_size, prevent_all_damage, cant_lose_for_life, cant_cast, cant_cast_except_from_hand, spells_cant_be_countered, abilities_cant_be_countered, cant_gain_life, cant_activate, damage_cant_be_prevented, combat_damage_cant_be_prevented, protection_from_opponents.
1643
1696
 
1644
- Rules: CR 702.11c, CR 115.4, CR 508.1c, CR 402.2, CR 514.1, CR 615.1, CR 615.1a, CR 704.5a, CR 104.3b, CR 701.21a, CR 614.17b, CR 101.2, CR 601.3, CR 701.6a, CR 119.7, CR 602.5, CR 615.12, CR 702.16b, CR 702.16e, CR 702.16k, CR 611.2a, CR 514.2
1697
+ Rules: CR 702.11c, CR 115.4, CR 508.1c, CR 402.2, CR 514.1, CR 615.1, CR 615.1a, CR 704.5a, CR 104.3b, CR 701.21a, CR 614.17b, CR 101.2, CR 601.3, CR 701.6a, CR 119.7, CR 602.5, CR 615.12, CR 702.16b, CR 702.16e, CR 702.16k, CR 506.3, CR 611.2a, CR 514.2
1645
1698
 
1646
1699
  | Parameter | Description |
1647
1700
  | --- | --- |
@@ -1860,7 +1913,7 @@ Rules: CR 122.8
1860
1913
 
1861
1914
  ## remove_counters
1862
1915
 
1863
- Remove up to `amount` counters named `counter` from each referenced permanent.
1916
+ Remove up to `amount` counters named `counter` from each referenced permanent. How many were removed is {"this_way": n} ("remove a bait counter ... If you do, ...").
1864
1917
 
1865
1918
  Rules: CR 122.8
1866
1919
 
@@ -1902,6 +1955,44 @@ Rules: CR 120.6, CR 514.2
1902
1955
  }
1903
1956
  ```
1904
1957
 
1958
+ ## repeat
1959
+
1960
+ Run `effects`, then run them again for as long as `while` (a condition) holds after a pass ("if the exiled card is a land card, repeat this process"). {"result": n} in the list and in `while` names what effect n did during the current pass. At most 100 passes.
1961
+
1962
+ Rules: CR 608.2c, CR 400.7j, CR 104.4b
1963
+
1964
+ | Parameter | Description |
1965
+ | --- | --- |
1966
+ | `effects` | list of effects (one pass) |
1967
+ | `while` | condition, checked after each pass |
1968
+
1969
+ ```json
1970
+ {
1971
+ "repeat": {
1972
+ "effects": [
1973
+ {
1974
+ "mill": {
1975
+ "amount": 1
1976
+ }
1977
+ }
1978
+ ],
1979
+ "while": {
1980
+ "amount": {
1981
+ "count": {
1982
+ "result": 0,
1983
+ "for": {
1984
+ "types": [
1985
+ "land"
1986
+ ]
1987
+ }
1988
+ }
1989
+ },
1990
+ "at_least": 1
1991
+ }
1992
+ }
1993
+ }
1994
+ ```
1995
+
1905
1996
  ## return_choice
1906
1997
 
1907
1998
  Each referenced player (default: you) returns `count` (default 1; "any": any number) permanents they control matching `filter` to their owners' hands, chosen by them in turn order starting with the active player (not targeted); all move at once.
@@ -1924,9 +2015,9 @@ Rules: CR 101.4, CR 400.7, CR 608.2c
1924
2015
 
1925
2016
  ## return_to_battlefield
1926
2017
 
1927
- Put each referenced card that is in exile or a graveyard onto the battlefield under its owner's control (`under: "you"`: under the controller's), tapped if `tapped: true`. A card that is no longer in the zone it was expected in, or isn't a permanent card, stays where it is. `transformed: true`: it enters with its back face up; a card that isn't double-faced, or whose back face isn't a permanent, stays where it is.
2018
+ Put each referenced card that is in exile or a graveyard onto the battlefield under its owner's control (`under: "you"`: under the controller's), tapped if `tapped: true`. A card that is no longer in the zone it was expected in, or isn't a permanent card, stays where it is. `transformed: true`: it enters with its back face up; a card that isn't double-faced, or whose back face isn't a permanent, stays where it is. `as`: what it is as it enters, for as long as it stays (the `become` changes, without abilities): "It's an enchantment. (It's not a creature.)" is `{"set_types": ["enchantment"]}`; abilities that trigger on it entering see it so.
1928
2019
 
1929
- Rules: CR 400.7, CR 400.4a, CR 110.2, CR 111.8, CR 603.7c, CR 614.1c, CR 122.6, CR 712.11a, CR 712.11b
2020
+ Rules: CR 400.7, CR 400.4a, CR 110.2, CR 111.8, CR 603.7c, CR 614.1c, CR 122.6, CR 712.11a, CR 712.11b, CR 205.1a
1930
2021
 
1931
2022
  | Parameter | Description |
1932
2023
  | --- | --- |
@@ -1935,6 +2026,7 @@ Rules: CR 400.7, CR 400.4a, CR 110.2, CR 111.8, CR 603.7c, CR 614.1c, CR 122.6,
1935
2026
  | `transformed` | boolean |
1936
2027
  | `under` | owner | you |
1937
2028
  | `counters` | {counter name: n}: it enters with these counters ("with a +1/+1 counter on it") |
2029
+ | `as` | {set_types, types, supertypes, subtypes, creature_types, all_creature_types, colors, loses_abilities, keywords, base_power_toughness}: as `become`, from the moment it enters |
1938
2030
 
1939
2031
  ```json
1940
2032
  {
@@ -2075,9 +2167,9 @@ Rules: CR 701.22a
2075
2167
 
2076
2168
  ## search_library
2077
2169
 
2078
- 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").
2170
+ 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.
2079
2171
 
2080
- Rules: CR 701.23a, CR 701.23b, CR 701.23d, CR 701.23e, CR 701.20a, CR 701.24a, CR 701.24b, CR 118.12, CR 110.2a
2172
+ Rules: CR 701.23a, CR 701.23b, CR 701.23d, CR 701.23e, CR 701.20a, CR 701.24a, CR 701.24b, CR 118.12, CR 110.2a, CR 614.1a
2081
2173
 
2082
2174
  | Parameter | Description |
2083
2175
  | --- | --- |
@@ -2090,6 +2182,7 @@ Rules: CR 701.23a, CR 701.23b, CR 701.23d, CR 701.23e, CR 701.20a, CR 701.24a, C
2090
2182
  | `searcher` | selector of the searching player (default "you") |
2091
2183
  | `may` | true: the searcher may choose not to search |
2092
2184
  | `different_names` | true: each card found has a different name |
2185
+ | `battlefield_instead` | {"if": condition, "for": card spec} (with put: hand) |
2093
2186
 
2094
2187
  ```json
2095
2188
  {
@@ -42,6 +42,22 @@ Rules: CR 115.1
42
42
  "creature_or_planeswalker"
43
43
  ```
44
44
 
45
+ ## exiled_with
46
+
47
+ A card in exile that one of this object's abilities exiled (linked abilities: "the cards exiled with it"); restrict with `any_of`/`not` for its card types.
48
+
49
+ Rules: CR 607.2a, CR 406.6, CR 115.1
50
+
51
+ ```json
52
+ {
53
+ "exiled_with": {
54
+ "any_of": [
55
+ "creature"
56
+ ]
57
+ }
58
+ }
59
+ ```
60
+
45
61
  ## graveyard_card
46
62
 
47
63
  A card in a graveyard (any player's, in seat order; restrict with `controller` for its owner and `any_of`/`not` for its card types).
@@ -152,15 +168,16 @@ Rules: CR 112.1, CR 115.1
152
168
 
153
169
  ## stack_ability
154
170
 
155
- An activated or triggered ability on the stack. `kind`: "activated" or "triggered" for only one of them; `controller`: you | opponent; `source`: a filter its source matches (e.g. "creature", "artifact").
171
+ An activated or triggered ability on the stack. `kind`: "activated" or "triggered" for only one of them; `controller`: you | opponent; `source`: a filter its source matches (e.g. "creature", "artifact"); `single_target: true`: one with a single target.
156
172
 
157
- Rules: CR 113.1b, CR 115.1, CR 605.3b, CR 113.7
173
+ Rules: CR 113.1b, CR 115.1, CR 605.3b, CR 113.7, CR 115.7
158
174
 
159
175
  | Parameter | Description |
160
176
  | --- | --- |
161
177
  | `kind` | activated | triggered |
162
178
  | `controller` | you | opponent |
163
179
  | `source` | filter |
180
+ | `single_target` | boolean |
164
181
 
165
182
  ```json
166
183
  {
@@ -128,6 +128,20 @@ Rules: CR 701.6a, CR 101.2
128
128
  }
129
129
  ```
130
130
 
131
+ ## cant_become_untapped
132
+
133
+ This permanent can't become untapped: not in its controller's untap step nor by an effect ("untap it" does nothing).
134
+
135
+ Rules: CR 701.26b, CR 502.3, CR 101.2
136
+
137
+ ```json
138
+ {
139
+ "keywords": [
140
+ "cant become untapped"
141
+ ]
142
+ }
143
+ ```
144
+
131
145
  ## cant_block
132
146
 
133
147
  Restriction: this creature can't block.
@@ -508,9 +522,9 @@ Rules: CR 702.17b
508
522
 
509
523
  ## riot
510
524
 
511
- As this permanent enters, its controller chooses an additional +1/+1 counter or haste (an enter_choice: `{type: "option", option: "counter" | "haste"}`).
525
+ As this permanent enters, its controller chooses an additional +1/+1 counter or haste (an enter_choice: `{type: "option", option: "counter" | "haste"}`). Riot granted by a static ability ("Other Spiders you control have riot") is chosen as it enters too, and haste chosen this way stays if it later loses riot.
512
526
 
513
- Rules: CR 702.136a, CR 614.12
527
+ Rules: CR 702.136a, CR 702.136b, CR 614.12
514
528
 
515
529
  ```json
516
530
  {
@@ -89,14 +89,15 @@ Rules: CR 603.2, CR 603.2c
89
89
 
90
90
  ## attacks
91
91
 
92
- The subject is declared as an attacker. `first_time_this_turn: true`: only the first time that creature attacks this turn (later combats of the turn don't trigger it).
92
+ The subject is declared as an attacker. `first_time_this_turn: true`: only the first time that creature attacks this turn (later combats of the turn don't trigger it). `alone: true`: only when it is the only creature declared as an attacker (it triggers as the declaration is complete).
93
93
 
94
- Rules: CR 508.3a, CR 603.2
94
+ Rules: CR 508.3a, CR 603.2, CR 506.5
95
95
 
96
96
  | Parameter | Description |
97
97
  | --- | --- |
98
98
  | `subject` | "self" (default) or {"each": filter, ...} |
99
99
  | `first_time_this_turn` | boolean |
100
+ | `alone` | boolean |
100
101
 
101
102
  ```json
102
103
  {
@@ -198,7 +199,7 @@ Rules: CR 603.2e, CR 701.26a, CR 702.194a
198
199
 
199
200
  The subject becomes the target of a spell or ability (controlled by `by`: opponent | you | any (default), relative to the source's controller). One trigger per matching object targeted.
200
201
 
201
- Rules: CR 115.1, CR 601.2c, CR 603.2, CR 603.2c
202
+ Rules: CR 115.1, CR 115.7, CR 601.2c, CR 603.2, CR 603.2c, CR 707.10
202
203
 
203
204
  | Parameter | Description |
204
205
  | --- | --- |
@@ -262,9 +263,9 @@ Rules: CR 509.3a, CR 509.3b, CR 509.3f, CR 603.2
262
263
 
263
264
  ## cast
264
265
 
265
- A player casts a spell. `controller`: you (default) | opponent | any; `spell`: creature | noncreature | instant_or_sorcery, or any spell filter, e.g. {"spell": {"subtypes": ["saga"]}} or {"one_of": [...]} for "creature or Spacecraft spell"; `name` / `mana_value`: "chosen" (the source's as-it-entered choice); `self: true`: "when you cast this spell" (it functions on the stack). `targets`: only a spell that targets something matching this filter ("self": this permanent), e.g. {"creature": {"controller": "you"}}. `from` / `not_from`: only a spell cast from (not from) that zone: hand | graveyard | exile | library | outside. `single_target: true`: only a spell with exactly one target.
266
+ A player casts a spell. `controller`: you (default) | opponent | any; `spell`: creature | noncreature | instant_or_sorcery, or any spell filter, e.g. {"spell": {"subtypes": ["saga"]}} or {"one_of": [...]} for "creature or Spacecraft spell"; `name` / `mana_value`: "chosen" (the source's as-it-entered choice); `self: true`: "when you cast this spell" (it functions on the stack). `targets`: only a spell that targets something matching this filter ("self": this permanent), e.g. {"creature": {"controller": "you"}}. `from` / `not_from`: only a spell cast from (not from) that zone: hand | graveyard | exile | library | outside. `single_target: true`: only a spell with exactly one target. `owner`: "not_you" only a spell you don't own, "you" only one you own.
266
267
 
267
- Rules: CR 603.2, CR 601.2i, CR 113.6, CR 202.3e, CR 201.4, CR 607.2, CR 115.1, CR 601.2a, CR 601.2c
268
+ Rules: CR 603.2, CR 601.2i, CR 113.6, CR 202.3e, CR 201.4, CR 607.2, CR 115.1, CR 601.2a, CR 601.2c, CR 108.3
268
269
 
269
270
  | Parameter | Description |
270
271
  | --- | --- |
@@ -277,6 +278,7 @@ Rules: CR 603.2, CR 601.2i, CR 113.6, CR 202.3e, CR 201.4, CR 607.2, CR 115.1, C
277
278
  | `from` | zone |
278
279
  | `not_from` | zone |
279
280
  | `single_target` | true |
281
+ | `owner` | you | not_you |
280
282
 
281
283
  ```json
282
284
  {
@@ -289,7 +291,7 @@ Rules: CR 603.2, CR 601.2i, CR 113.6, CR 202.3e, CR 201.4, CR 607.2, CR 115.1, C
289
291
 
290
292
  ## counters_placed
291
293
 
292
- One or more counters (only `counter`, if given) are put on the subject, including the counters it enters the battlefield with. Triggers once per event, however many counters.
294
+ One or more counters (only `counter`, if given) are put on the subject, including the counters it enters the battlefield with. Triggers once per event, however many counters. `nth` (needs `counter`): only when the Nth such counter is put on it (the event that takes it from fewer than N to N or more).
293
295
 
294
296
  Rules: CR 122.6, CR 603.2, CR 603.2c
295
297
 
@@ -298,11 +300,14 @@ Rules: CR 122.6, CR 603.2, CR 603.2c
298
300
  | `subject` | "self" (default) or {"each": filter, ...} |
299
301
  | `counter` | counter name |
300
302
  | `first_time_this_turn` | true: only the first time each turn such counters are put on that permanent (an earlier placement counts even if nothing could trigger then) |
303
+ | `by` | you | opponent: only counters that player puts ("whenever you put ...", CR 122.6a; a permanent's controller puts the counters it enters with) |
304
+ | `nth` | positive integer |
301
305
 
302
306
  ```json
303
307
  {
304
308
  "counters_placed": {
305
- "counter": "+1/+1"
309
+ "counter": "+1/+1",
310
+ "by": "you"
306
311
  }
307
312
  }
308
313
  ```
@@ -534,6 +539,22 @@ Rules: CR 119.9, CR 120.3f
534
539
  }
535
540
  ```
536
541
 
542
+ ## gives_gift
543
+
544
+ A player (`controller`: you (default) | opponent | any) gives a gift: an instant or sorcery spell they control whose gift was promised resolves, or the gift triggered ability (an enters trigger under `{"cast_with": "gift"}`) of a permanent they control resolves.
545
+
546
+ Rules: CR 702.174c, CR 702.174b
547
+
548
+ | Parameter | Description |
549
+ | --- | --- |
550
+ | `controller` | you | opponent | any |
551
+
552
+ ```json
553
+ {
554
+ "gives_gift": {}
555
+ }
556
+ ```
557
+
537
558
  ## leaves_battlefield
538
559
 
539
560
  The subject leaves the battlefield (for any zone, or only `to` that zone). Looks back in time: the permanent is matched as it last existed (types, controller, counters).
@@ -39,12 +39,19 @@ module Enjine
39
39
  engine.state.battlefield.each do |id|
40
40
  add_options(engine, index, id, out) if engine.object(id).controller == index
41
41
  end
42
- engine.player(index).hand.each { add_options(engine, index, it, out) } # CR 602.2: the owner activates
43
- engine.player(index).graveyard.each { add_options(engine, index, it, out) } # CR 113.6m: e.g. "exile this card from your graveyard"
44
- engine.state.exile.each { add_options(engine, index, it, out) if engine.object(it).owner == index } # CR 113.6b
42
+ off_board(engine, index).each { add_options(engine, index, it, out) }
45
43
  out
46
44
  end
47
45
 
46
+ # Cards whose abilities may function off the battlefield (CR 113.6b): the hand (the owner activates, CR 602.2),
47
+ # graveyard ("exile this card from your graveyard", CR 113.6m) and exiled cards `index` owns, less those with
48
+ # no activated ability for their zone.
49
+ def self.off_board(engine, index)
50
+ pl = engine.player(index)
51
+ ids = pl.hand + pl.graveyard + engine.state.exile.select { engine.object(it).owner == index }
52
+ engine.own_abilities_only? ? ids.reject { engine.no_activations_here?(engine.object(it)) } : ids
53
+ end
54
+
48
55
  def self.add_options(engine, index, id, out)
49
56
  engine.chars(id).activated_abilities.each do |inst|
50
57
  out << { type: "activate", object: id, ability: inst.ref } if engine.activatable?(index, id, inst.ref)
@@ -38,7 +38,9 @@ module Enjine
38
38
  # The play_land frame: ask the "as this enters" choice, then put the land onto the battlefield.
39
39
  def self.step(engine, frame)
40
40
  land = engine.candidate_object(frame["player"], frame["object"])
41
- return engine.ask_enter_choice!(frame["object"], frame["player"]) if engine.entering_choice_pending?(land, frame["enter"])
41
+ if engine.entering_choice_pending?(land, frame["enter"])
42
+ return engine.ask_enter_choice!(frame["object"], frame["player"], frame["enter"])
43
+ end
42
44
 
43
45
  enters = engine.enters_from_answer(land, frame)
44
46
  engine.pay_entering_costs!(frame["player"], frame)
@@ -165,6 +165,13 @@ module Enjine
165
165
  attr_reader :all_effects
166
166
 
167
167
  def triggered? = @triggered
168
+ # This face has an ability of its own to be played from outside its owner's hand: "you may cast this card
169
+ # from your graveyard" (CR 113.6e), beam me up (CR 702.196a) or an alternative cost (Engine::Permissions).
170
+ def plays_itself? = @plays_itself
171
+ # The zones this face's activated abilities function from (CR 113.6): [:battlefield], or [:hand] for cycling.
172
+ attr_reader :activation_zones
173
+
174
+ def self.self_play?(ability) = %i[beam_me_up alternative_cost].include?(ability.kind) || (ability.kind == :play_from && ability.self?)
168
175
  def land? = @land
169
176
  def creature? = @creature
170
177
  def planeswalker? = @planeswalker
@@ -208,6 +215,13 @@ module Enjine
208
215
 
209
216
  private
210
217
 
218
+ # What lets this face be used off the battlefield, from all its abilities (keyword abilities and nested ones too).
219
+ def precompute_off_board
220
+ own = @ability_instances.map(&:ability) + @nested_instances.map(&:ability)
221
+ @plays_itself = own.any? { CardDefinition.self_play?(it) }
222
+ @activation_zones = own.filter_map { it.zone if %i[activated loyalty].include?(it.kind) }.uniq.freeze
223
+ end
224
+
211
225
  def precompute_predicates
212
226
  @land = @types.include?(:land)
213
227
  @creature = @types.include?(:creature)
@@ -219,6 +233,7 @@ module Enjine
219
233
  @spell_ability = @abilities.find { it.kind == :spell } || aura_spell_ability
220
234
  every = @abilities + @nested_instances.map(&:ability)
221
235
  @triggered = every.any? { it.kind == :triggered }
236
+ precompute_off_board
222
237
  @all_effects = nested(every.flat_map do |ability|
223
238
  ability.respond_to?(:modes) && ability.modal? ? ability.modes.flat_map(&:effects) : ability.try_effects
224
239
  end).freeze
@@ -317,10 +332,11 @@ module Enjine
317
332
  end.uniq.freeze
318
333
  end
319
334
 
320
- # CR 202.2: a card's colors come from its mana cost, unless it has a color indicator (CR 204) or is a
321
- # token whose creating effect gives its colors (CR 111.4): `"colors": ["G"]` (`[]` for colorless).
335
+ # CR 202.2: a card's colors come from its mana cost (a hybrid symbol is each of its colors, CR 202.2d), unless it
336
+ # has a color indicator (CR 204) or is a token whose creating effect gives its colors (CR 111.4): `"colors": ["G"]`
337
+ # (`[]` for colorless).
322
338
  def read_colors(card, errors)
323
- return (@mana_cost.is_a?(Mana::Cost) ? Mana::COLORS.select { @mana_cost.colored.key?(it) } : []).freeze unless card.key?("colors")
339
+ return (@mana_cost.is_a?(Mana::Cost) ? @mana_cost.colors : []).freeze unless card.key?("colors")
324
340
 
325
341
  list = card["colors"]
326
342
  ok = list.is_a?(Array) && list.all? { Mana::COLORS.include?(it.to_s.upcase.to_sym) }
@@ -139,6 +139,8 @@ module Enjine
139
139
  when "assign_damage" then " — #{name_of(decision.details["attacker"])}: #{decision.details["remaining"]} damage left"
140
140
  when "choose_target" then " — target ##{decision.details["index"] + 1}"
141
141
  when "commander_zone" then " — #{name_of(decision.details["object"])} (your commander)"
142
+ when "damage_order"
143
+ " — damage #{decision.details["hit"].split(">").map { name_of(it) }.join(" → ")}"
142
144
  when "choose_target_count" then " — how many for target ##{decision.details["index"] + 1}"
143
145
  else ""
144
146
  end
@@ -161,22 +163,24 @@ module Enjine
161
163
  when "pay_mana"
162
164
  "Pay {#{opt[:mana]}} from mana pool#{" (restricted)" if opt[:restricted]}#{" (made by an artifact)" if opt[:from]}"
163
165
  when "target" then "Target #{name_of(opt[:target])}"
164
- when "cost" then "Use #{name_of(opt[:object])} to pay the cost"
166
+ when "cost" then opt[:creature_type] ? "Choose #{opt[:creature_type]}" : "Use #{name_of(opt[:object])} to pay the cost"
165
167
  when "behold" then "Behold #{name_of(opt[:object])}"
166
168
  when "pay" then opt[:cost] ? "Pay: #{opt[:cost]}" : "Pay"
167
169
  when "cost_option" then @game.pending_decision.details["costs"][opt[:option]]
168
170
  when "cancel" then "Cancel (rewind this cast/activation)"
169
- when "attack" then "Attack #{name_of(opt[:target])} with #{name_of(opt[:object])}"
171
+ when "attack" then "Attack #{name_of(opt[:target])}#{" with #{name_of(opt[:object])}" if opt[:object]}"
170
172
  when "block" then "Block #{name_of(opt[:attacker])} with #{name_of(opt[:object])}"
171
173
  when "assign" then "Assign 1 damage to #{name_of(opt[:object])}"
172
174
  when "done" then "Done"
173
175
  when "source" then "Choose #{name_of(opt[:object])} as the source"
176
+ when "order" then "Apply #{opt[:steps].join(", then ")} (#{opt[:amount]} damage)"
174
177
  when "devour" then "Devour #{name_of(opt[:object])}"
175
178
  when "discard", "bottom", "find" then "#{opt[:type].capitalize} #{name_of(opt[:object])}"
176
179
  when "keep" then "Keep hand"
177
180
  when "call" then "Call #{opt[:call]}"
178
181
  when "mulligan" then "Mulligan"
179
182
  when "play", "draw" then "#{opt[:type].capitalize} first"
183
+ when "card_name", "name" then "Name #{opt[:card_name] || opt[:name]}"
180
184
  else opt.inspect
181
185
  end
182
186
  end
@@ -234,6 +238,7 @@ module Enjine
234
238
  when "trigger_removed" then "#{card_name(ev["card"])}'s triggered ability is removed (#{ev["reason"]})"
235
239
  when "ability_countered" then "#{card_name(ev["card"])}'s ability is countered"
236
240
  when "spell_copied" then "#{ev["player"]} copies #{card_name(ev["card"])}#{targets(ev["targets"])}"
241
+ when "targets_changed" then "#{name_of(ev["object"])} has new targets: #{ev["targets"].map { name_of(it) }.join(", ")}"
237
242
  when "x_announced" then "#{ev["player"]} announces X = #{ev["value"]}"
238
243
  when "payment_finished" then "#{ev["player"]} #{ev["outcome"]}"
239
244
  when "attached" then "#{name_of(ev["object"])} is attached to #{name_of(ev["to"])}"
@@ -258,7 +263,9 @@ module Enjine
258
263
  when "speed_changed" then "#{ev["player"]}: speed #{ev["from"]} → #{ev["to"]}"
259
264
  when "coin_flipped"
260
265
  "#{ev["player"]} flips #{ev["heads"] ? "heads" : "tails"}#{{ true => " and wins", false => " and loses" }[ev["won"]]}"
261
- when "keyword_action" then "#{ev["player"]} #{ev["action"].to_s.tr("_", " ")}#{" #{ev["amount"]}" if ev["amount"]}"
266
+ when "keyword_action"
267
+ verb = ev["action"] == "give_gift" ? "gives a gift" : ev["action"].to_s.tr("_", " ")
268
+ "#{ev["player"]} #{verb}#{" #{ev["amount"]}" if ev["amount"]}"
262
269
  else "#{ev["type"]}: #{ev.except("type")}"
263
270
  end
264
271
  end