enjine 0.2.0 → 0.4.1
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 +4 -4
- data/CHANGELOG.md +66 -1
- data/README.md +2 -1
- data/SUPPORTED.md +4 -4
- data/docs/ARCHITECTURE.md +2 -0
- data/docs/DESIGN.md +12 -5
- data/docs/MECHANICS_COVERAGE.md +32 -4
- data/docs/guides/api.md +51 -0
- data/docs/guides/card-data-format.md +58 -1
- data/docs/guides/deck-builder.md +18 -0
- data/docs/plans/commander.md +63 -0
- data/docs/plans/dsl-gaps.md +76 -0
- data/docs/reference/decisions.md +5 -1
- data/docs/reference/effects.md +12 -9
- data/docs/reference/triggers.md +3 -1
- data/lib/enjine/actions/cast.rb +12 -4
- data/lib/enjine/card_definition.rb +39 -3
- data/lib/enjine/cli/text.rb +23 -1
- data/lib/enjine/cli.rb +2 -1
- data/lib/enjine/color_identity.rb +38 -0
- data/lib/enjine/decisions/commander_zone.rb +36 -0
- data/lib/enjine/deck.rb +73 -14
- data/lib/enjine/deck_builder.rb +62 -18
- data/lib/enjine/engine/casting/alt_casting.rb +9 -0
- data/lib/enjine/engine/casting/casting.rb +19 -0
- data/lib/enjine/engine/casting/permissions.rb +19 -14
- data/lib/enjine/engine/characteristics.rb +29 -12
- data/lib/enjine/engine/commander.rb +125 -0
- data/lib/enjine/engine/copies.rb +16 -9
- data/lib/enjine/engine/damage.rb +3 -1
- data/lib/enjine/engine/durations.rb +47 -0
- data/lib/enjine/engine/emblems.rb +1 -1
- data/lib/enjine/engine/faces.rb +2 -0
- data/lib/enjine/engine/pregame.rb +1 -0
- data/lib/enjine/engine/priority.rb +1 -0
- data/lib/enjine/engine/rules.rb +3 -2
- data/lib/enjine/engine/state_based_actions.rb +9 -0
- data/lib/enjine/engine/triggers.rb +16 -9
- data/lib/enjine/engine/zones.rb +19 -2
- data/lib/enjine/events.rb +4 -1
- data/lib/enjine/format.rb +53 -0
- data/lib/enjine/fuzz.rb +17 -0
- data/lib/enjine/game.rb +4 -3
- data/lib/enjine/mechanics/abilities/double_counters.rb +1 -1
- data/lib/enjine/mechanics/abilities/play_permissions.rb +3 -2
- data/lib/enjine/mechanics/abilities/replacement_effects.rb +2 -1
- data/lib/enjine/mechanics/abilities/static.rb +7 -0
- data/lib/enjine/mechanics/card_spec.rb +54 -12
- data/lib/enjine/mechanics/effects/become.rb +35 -13
- data/lib/enjine/mechanics/effects/copy.rb +7 -4
- data/lib/enjine/mechanics/effects/gain_control.rb +6 -3
- data/lib/enjine/mechanics/effects/return_to_battlefield.rb +25 -6
- data/lib/enjine/mechanics/filters/base.rb +19 -2
- data/lib/enjine/mechanics/filters/stack.rb +1 -1
- data/lib/enjine/mechanics/triggers/base.rb +14 -3
- data/lib/enjine/mechanics/triggers/casting.rb +1 -1
- data/lib/enjine/mechanics/triggers/tap_and_counters.rb +21 -5
- data/lib/enjine/mechanics/triggers/zone_changes.rb +1 -1
- data/lib/enjine/mechanics/values.rb +10 -7
- data/lib/enjine/mechanics.rb +5 -0
- data/lib/enjine/player.rb +2 -1
- data/lib/enjine/rules_monitor.rb +29 -3
- data/lib/enjine/setup.rb +10 -4
- data/lib/enjine/snapshot/player_checks.rb +47 -0
- data/lib/enjine/snapshot.rb +4 -1
- data/lib/enjine/state.rb +33 -14
- data/lib/enjine/steps.rb +10 -1
- data/lib/enjine/version.rb +1 -1
- data/lib/enjine/view.rb +18 -1
- data/lib/enjine.rb +2 -0
- metadata +7 -1
data/docs/plans/dsl-gaps.md
CHANGED
|
@@ -1,5 +1,81 @@
|
|
|
1
1
|
# DSL gaps: mechanics missing for FAIL and PARTIAL cards
|
|
2
2
|
|
|
3
|
+
## Ranking of 2026-11-20 (enjine 0.3.0)
|
|
4
|
+
|
|
5
|
+
Source: deckfinder `card_scripts`, all 303 PARTIAL and 60 FAIL scripts (365 cards with the
|
|
6
|
+
"missing" note of each). Every card was tagged by hand with **every** gap its note names, so a card
|
|
7
|
+
counts as made exact only when all of its gaps are closed. The order is greedy: at each step, the change
|
|
8
|
+
that makes the most cards exact per unit of effort (S = 1, M = 2, L = 3+, from a skim of `lib/`).
|
|
9
|
+
|
|
10
|
+
- **Batch 1 done (Unreleased), verified:** `counters_placed by`, filter `owner`, card-spec keywords/
|
|
11
|
+
not_subtypes/power/toughness/layout, and the turn-counted durations. Re-scripted and passing
|
|
12
|
+
`enjine --verify` (10–12 rules-monitored games each): Ant-Man, Exemplar of Light, Inspired Tethermage,
|
|
13
|
+
Knight of Wundagore, Mikey & Leo, The Great Goblin, Charming Prince, Get Out, Northampton Farm,
|
|
14
|
+
The Eagles Are Coming!, Laughing Jasper Flint, Steamcore Scholar, Absorbing Man, Haste Magic, Inti
|
|
15
|
+
(**15 exact**, against the 30 the tag count promised). Still blocked by a second gap: Beast and Kid
|
|
16
|
+
Loki (a live static), Invisible Woman (batching across permanents), Terrasymbiosis (once-each-turn
|
|
17
|
+
may), Boiling Rock Rioter and Starfall Invocation (owner on exiled/destroyed card specs), Clash of
|
|
18
|
+
Elements (the owner decides and is dealt the damage), Iroh (computed enters-with counters), April
|
|
19
|
+
O'Neil and Codie (kindred / prepared spell filters), Hearth Elemental (the graveyard count uses a
|
|
20
|
+
permanent-style filter, not a card spec), Leonardo (play_from has no "during your turn"),
|
|
21
|
+
Evil's Thrall (mana-value comparison condition), Dragonhawk ("still exiled").
|
|
22
|
+
- **Batch 2 done (Unreleased), verified:** `become` `set_types`, `"creature_types": []`,
|
|
23
|
+
`all_creature_types`, `return_to_battlefield` `as`, and `{"triggering": filter}` reading last-known card
|
|
24
|
+
types. Re-scripted and passing `enjine --verify` (seeds 0 and 7): Enduring Courage, Enduring Curiosity,
|
|
25
|
+
Enduring Innocence, Tom, Bert, and William, Kitesail Larcenist, Hydro-Man, Nameless Inversion, Soulstone
|
|
26
|
+
Sanctuary (**8 exact**, of the 10 change 5 promised). Still blocked: The Irencrag (become a named
|
|
27
|
+
Equipment with equip), Brilliance Unleashed (its own return effect, not yet re-scripted with `as`).
|
|
28
|
+
Known gap: layer 4 applies resolved type effects (in timestamp order) before statics that change types,
|
|
29
|
+
whatever their timestamps (CR 613.7a wants one order for both).
|
|
30
|
+
- 81 cards have only a one-off gap (no change below helps them); 284 share at least one listed gap.
|
|
31
|
+
- The first 4 changes (all S) make **30** cards exact; the first 20 make about **95**; the first 30
|
|
32
|
+
about **150**.
|
|
33
|
+
- Notes that look stale (written before 0.2.0, worth re-scripting first, no engine work): The Wind Crystal
|
|
34
|
+
(cost_modifier colors exist), Armor Wars chapter III (`greatest_mana_value`), Fblthp (`library_size`),
|
|
35
|
+
Dina's Guidance (`search_library put: graveyard`), Terror of the Peaks and Bolg of the North (0.2.0
|
|
36
|
+
last-known-information work; check in a game).
|
|
37
|
+
|
|
38
|
+
| # | Change | Effort | Cards made exact | Cumulative effort → exact | Examples |
|
|
39
|
+
|---|---|---|---|---|---|
|
|
40
|
+
| 1 | `counters_placed` `by: you`; a "you put counters on it this turn" filter (CountersChanged carries who put them) | S | 9 | 1 → 9 | Ant-Man, Beast, Exemplar of Light, Inspired Tethermage |
|
|
41
|
+
| 2 | `owner: you/opponent` on permanent filters and selectors ("creature you own") | S | 9 | 2 → 18 | Boiling Rock Rioter, Charming Prince, Clash of Elements, Get Out |
|
|
42
|
+
| 3 | card-spec filters: keyword, Adventure/prepared layout, kindred, non-subtype, power/toughness in `play_from` | S | 6 | 3 → 24 | April O'Neil, Bandit's Talent, Codie, Hearth Elemental |
|
|
43
|
+
| 4 | `until_your_next_turn` / until-your-next-end-step on `become_copy`, `gain_control`, permissions | S | 6 | 4 → 30 | Absorbing Man, Dragonhawk, Evil's Thrall, Haste Magic |
|
|
44
|
+
| 5 | `become` `set_types` (and lose creature types/add supertype/set name); fix the monitor's CR 613.4c recompute | M | 10 | 6 → 40 | Brilliance Unleashed, Enduring Courage, Enduring Curiosity, Enduring Innocence |
|
|
45
|
+
| 6 | cost_modifier: condition, first spell each turn, one-turn effect, keyword or chosen-type spells | M | 6 | 8 → 46 | Arachne, Armor Wars, Don & Raph, Eluge |
|
|
46
|
+
| 7 | last-known counters and combat status of a creature that left; move every counter kind | M | 6 | 10 → 52 | Aerith Gainsborough, Ares, Donatello, Essence Channeler |
|
|
47
|
+
| 8 | "descended this turn" (a permanent card put into your graveyard from anywhere) | S | 3 | 11 → 55 | Corpses of the Lost, Molten Collapse, Stalactite Stalker |
|
|
48
|
+
| 9 | "one or two targets": a minimum target count | S | 3 | 12 → 58 | Atlantis Attacks, Heroes' Hangout, Leonardo's Technique |
|
|
49
|
+
| 10 | must-change form of `choose_new_targets`; single-target stack filter | S | 4 | 13 → 62 | Bolt Bend, Redirect Lightning, Return the Favor, Untimely Malfunction |
|
|
50
|
+
| 11 | offspring keyword (CR 702.175) | S | 3 | 14 → 65 | Coruscation Mage, Iridescent Vinelasher, Starscape Cleric |
|
|
51
|
+
| 12 | attack triggers know whether a player or a planeswalker is attacked | S | 3 | 15 → 68 | Attuma, Garruk, Preacher of the Schism |
|
|
52
|
+
| 13 | `remove_counters` cost from this permanent | S | 3 | 16 → 71 | Drake Hatcher, Flitterwing Nuisance, Leatherhead |
|
|
53
|
+
| 14 | `enters_with_counters` with a condition or computed count for others | M | 6 | 18 → 77 | Dust Animus, Gev, Giada, Myojin of Night's Reach |
|
|
54
|
+
| 15 | `add_mana` `until: end_of_turn` (mana not lost as steps end) | S | 3 | 19 → 80 | Electro, Raphael, The Last Agni Kai |
|
|
55
|
+
| 16 | "you've scried or surveilled this turn" condition | S | 3 | 20 → 83 | Desperate Futurescribe, Proctor of Potential, Surveillance Phantasm |
|
|
56
|
+
| 17 | `deal_damage` with a `source` selector | S | 3 | 21 → 86 | Compel Brutality, Hawkeye's Bow, Ingris Stingerquill |
|
|
57
|
+
| 18 | one-turn / conditional additional land plays as an effect | S | 3 | 22 → 89 | Beorn, Thranduil's Company, Way of the Paradox |
|
|
58
|
+
| 19 | static "that many plus one" counter replacement | S | 3 | 23 → 92 | Doc Samson, Michelangelo, Yoshimaru |
|
|
59
|
+
| 20 | "put into a graveyard from the battlefield / library this turn" filters and amounts | S | 3 | 24 → 95 | Bringer of the Last Gift, Cruel Calculations, Supper for Spiders |
|
|
60
|
+
| 21 | equip: once each turn, creature filter, cost reduction by target, alternative cost | M | 5 | 26 → 100 | Dark Knight's Greatsword, Dragonfire Blade, Kíli the Resourceful, Shredder's Armor |
|
|
61
|
+
| 22 | search destinations: choose per card (hand or graveyard, battlefield and hand), exile | M | 5 | 28 → 105 | Dina's Guidance, Part in Friendship, Roads Go Ever, Town Greeter |
|
|
62
|
+
| 23 | attach to the entering / enchanted / triggering creature without targeting | M | 5 | 30 → 110 | Doc Ock's Tentacles, Quintessential Katana, Super-Soldier Serum, Thorin |
|
|
63
|
+
| 24 | choose a card name; same-name filters across zones | L | 7 | 33 → 117 | Ancestral Anger, Ancient Vendetta, Key to the Side-Door, Maelstrom Pulse |
|
|
64
|
+
| 25 | cost modifiers for activated abilities of other permanents (equip, power-up, plot) | M | 5 | 35 → 122 | Doc Aurlock, Dwarven Mauler, Hulk, Mutagen Man |
|
|
65
|
+
| 26 | costs: put stun/page counter, exile a permanent, return a tapped creature, sacrifice the Aura, computed life, variable count | L | 7 | 38 → 129 | Jessica Jones, Madame Null, Mazemind Tome, Rottenmouth Viper |
|
|
66
|
+
| 27 | attack tax, can't be attacked, max attackers, block-count limits | L | 7 | 41 → 136 | Archangel of Tithes, Dáin, Meltstrider's Resolve, Storm |
|
|
67
|
+
| 28 | simultaneous per-player actions (wheel, mass discard/return/sacrifice) | L | 9 | 45 → 145 | Deadly Brew, Garruk, Raphael's Technique, Rush of Dread |
|
|
68
|
+
| 29 | copy exceptions that add abilities or types | M | 4 | 47 → 149 | Ardyn, Electroduplicate, Face Yourself, Likeness Looter |
|
|
69
|
+
| 30 | "attacks alone" trigger | M | 4 | 49 → 153 | Black Widow, Jiang Yanggu, Luke Cage, Spider-Man Noir |
|
|
70
|
+
|
|
71
|
+
Further down (2–4 cards each): Cases, total-mana-value limits on chosen cards, entering attacking from a
|
|
72
|
+
return or reveal, impending, token-type replacements, draw/life replacements, counter doubling, "once each
|
|
73
|
+
turn" on may-abilities, hone counters, attacks-alone triggers. Large, low-yield: face-down permanents
|
|
74
|
+
(manifest dread, disguise; 4 cards, L), split and Room layouts (3, L), another player choosing (End of the
|
|
75
|
+
Hunt, Taster of Wares; 9 cards but L).
|
|
76
|
+
|
|
77
|
+
## Snapshot of 2026-11-11 (history)
|
|
78
|
+
|
|
3
79
|
Snapshot of 2026-11-11, taken from deckfinder through its MCP connection (`dsl_status scope: all`).
|
|
4
80
|
Of 1,025 cards in scope (the user's collection, decks and imported opponent decklists), 192 are
|
|
5
81
|
DSL FAIL (no script possible yet) and 87 are DSL PARTIAL (a best-effort script that leaves something out).
|
data/docs/reference/decisions.md
CHANGED
|
@@ -40,6 +40,10 @@ While casting/activating: `{type: "count", count: n}` announces how many targets
|
|
|
40
40
|
|
|
41
41
|
While casting/activating a spell or ability with {X} in its cost: `{type: "x", value: n}` announces X (0 up to `max`, the most the available mana could pay for); `{type: "cancel"}` rewinds.
|
|
42
42
|
|
|
43
|
+
## commander_zone
|
|
44
|
+
|
|
45
|
+
Your commander is in a graveyard, exile, hand or library: `{type: "command", object: id}` puts it into the command zone, `{type: "stay", object: id}` leaves it where it is (CR 903.9).
|
|
46
|
+
|
|
43
47
|
## declare_attackers
|
|
44
48
|
|
|
45
49
|
Declare one attacker: `{type: "attack", object: id, target: ref}` (the defending player or one of their planeswalkers), or `{type: "done"}` (withheld while a creature that attacks each combat if able could still attack, CR 508.1d, or while a creature that can't attack alone attacks alone, CR 506.5; then `{type: "withdraw", object: id}` undoes an attack).
|
|
@@ -96,7 +100,7 @@ Untap step: `{type: "untap", object: id}` or `{type: "keep_tapped", object: id}`
|
|
|
96
100
|
|
|
97
101
|
- `activate` — `{type: "activate", object: id, ability: ref}` — start activating an ability (CR 602.2), including planeswalker loyalty abilities (CR 606) and abilities of cards in your hand (cycling, CR 702.29).
|
|
98
102
|
- `activate_mana` — `{type: "activate_mana", object: id, ability: ref}` — activate a mana ability; it resolves immediately (CR 605.3). `mana: "{G}{G}"` names the mana when it is chosen as the ability is activated.
|
|
99
|
-
- `cast` — `{type: "cast", object: id}` — start casting a card from your hand (CR 601.2). `{type: "cast", object: id, via: method}` casts a card from another zone (graveyard, exile, the top of your library) by the permission or alternative cost `via` names, e.g. beam me up (CR 601.3, 702.196). A card outside the game is named `"outside:<card id>"` (CR 400.11b). `{type: "cast", object: id, face: 1}` casts another face of a card in your hand: a modal double-faced card's back face, an Adventure or an Omen (CR 712.8b, 716.3, 721.3). Offered only when timing allows, targets exist and enough mana is available.
|
|
103
|
+
- `cast` — `{type: "cast", object: id}` — start casting a card from your hand (CR 601.2). `{type: "cast", object: id, via: method}` casts a card from another zone (graveyard, exile, the top of your library) by the permission or alternative cost `via` names, e.g. beam me up (CR 601.3, 702.196). In a Commander game `via: "command"` casts your commander from the command zone, its cost including the commander tax (CR 903.8). A card outside the game is named `"outside:<card id>"` (CR 400.11b). `{type: "cast", object: id, face: 1}` casts another face of a card in your hand: a modal double-faced card's back face, an Adventure or an Omen (CR 712.8b, 716.3, 721.3). Offered only when timing allows, targets exist and enough mana is available.
|
|
100
104
|
- `pass` — `{type: "pass"}` — pass priority. When all players pass in succession with an empty stack, the step ends (CR 117.4).
|
|
101
105
|
- `play_land` — `{type: "play_land", object: id}` — special action: your main phase, empty stack, one land per turn plus additional land plays (CR 305.1, 305.2). With `via`: a land from another zone that an effect lets you play. With `face: 1`: a modal double-faced card played with its land back face up (CR 712.9).
|
|
102
106
|
- `special_action` — `{type: "special_action", object: id, ability: ref}` — a special action of a card in your hand: foretell (during your turn, pay {2} and exile it face down, CR 116.2h) or suspend (when you could begin to cast it, pay its suspend cost and exile it with time counters, CR 116.2f) or plot (in your main phase with an empty stack, pay its plot cost and exile it, CR 116.2k).
|
data/docs/reference/effects.md
CHANGED
|
@@ -224,16 +224,18 @@ 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
|
+
| `creature_types` | list of creature types (replaces the others; [] removes them all) |
|
|
238
|
+
| `all_creature_types` | true: it has every creature type |
|
|
237
239
|
| `colors` | list of W, U, B, R, G (replaces its colors) |
|
|
238
240
|
| `loses_abilities` | true: it loses all abilities ("loses all abilities") |
|
|
239
241
|
| `keywords` | list of keywords it gains |
|
|
@@ -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
|
{
|
|
@@ -1327,7 +1329,7 @@ Rules: CR 613.1b, CR 108.4, CR 506.4, CR 302.6, CR 514.2, CR 611.2b
|
|
|
1327
1329
|
| --- | --- |
|
|
1328
1330
|
| `to` | selector (permanents) |
|
|
1329
1331
|
| `gains` | selector (a player; default "you") |
|
|
1330
|
-
| `duration` | permanent | end_of_turn | while_source_on_battlefield | while_source_tapped | while_you_control_source |
|
|
1332
|
+
| `duration` | permanent | end_of_turn | end_of_your_next_turn | while_source_on_battlefield | while_source_tapped | while_you_control_source |
|
|
1331
1333
|
|
|
1332
1334
|
```json
|
|
1333
1335
|
{
|
|
@@ -1609,14 +1611,14 @@ Rules: CR 702.26a, CR 702.26b, CR 702.26d, CR 702.26g, CR 702.26h, CR 502.1, CR
|
|
|
1609
1611
|
|
|
1610
1612
|
## play_permission
|
|
1611
1613
|
|
|
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.
|
|
1614
|
+
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 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.
|
|
1613
1615
|
|
|
1614
1616
|
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
|
|
1615
1617
|
|
|
1616
1618
|
| Parameter | Description |
|
|
1617
1619
|
| --- | --- |
|
|
1618
1620
|
| `to` | selector (usually {"result": n}) |
|
|
1619
|
-
| `duration` | end_of_turn | end_of_your_next_turn | while_exiled |
|
|
1621
|
+
| `duration` | end_of_turn | end_of_your_next_turn | until_your_next_end_step | while_exiled |
|
|
1620
1622
|
| `play` | play | cast |
|
|
1621
1623
|
| `for` | card spec |
|
|
1622
1624
|
| `not_types` | list of card types |
|
|
@@ -1924,9 +1926,9 @@ Rules: CR 101.4, CR 400.7, CR 608.2c
|
|
|
1924
1926
|
|
|
1925
1927
|
## return_to_battlefield
|
|
1926
1928
|
|
|
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.
|
|
1929
|
+
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
1930
|
|
|
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
|
|
1931
|
+
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
1932
|
|
|
1931
1933
|
| Parameter | Description |
|
|
1932
1934
|
| --- | --- |
|
|
@@ -1935,6 +1937,7 @@ Rules: CR 400.7, CR 400.4a, CR 110.2, CR 111.8, CR 603.7c, CR 614.1c, CR 122.6,
|
|
|
1935
1937
|
| `transformed` | boolean |
|
|
1936
1938
|
| `under` | owner | you |
|
|
1937
1939
|
| `counters` | {counter name: n}: it enters with these counters ("with a +1/+1 counter on it") |
|
|
1940
|
+
| `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
1941
|
|
|
1939
1942
|
```json
|
|
1940
1943
|
{
|
data/docs/reference/triggers.md
CHANGED
|
@@ -298,11 +298,13 @@ Rules: CR 122.6, CR 603.2, CR 603.2c
|
|
|
298
298
|
| `subject` | "self" (default) or {"each": filter, ...} |
|
|
299
299
|
| `counter` | counter name |
|
|
300
300
|
| `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) |
|
|
301
|
+
| `by` | you | opponent: only counters that player puts ("whenever you put ...", CR 122.6a; a permanent's controller puts the counters it enters with) |
|
|
301
302
|
|
|
302
303
|
```json
|
|
303
304
|
{
|
|
304
305
|
"counters_placed": {
|
|
305
|
-
"counter": "+1/+1"
|
|
306
|
+
"counter": "+1/+1",
|
|
307
|
+
"by": "you"
|
|
306
308
|
}
|
|
307
309
|
}
|
|
308
310
|
```
|
data/lib/enjine/actions/cast.rb
CHANGED
|
@@ -9,7 +9,8 @@ module Enjine
|
|
|
9
9
|
'`{type: "cast", object: id}` — start casting a card from your hand (CR 601.2). ' \
|
|
10
10
|
'`{type: "cast", object: id, via: method}` casts a card from another zone (graveyard, exile, the top ' \
|
|
11
11
|
"of your library) by the permission or alternative cost `via` names, e.g. beam me up (CR 601.3, " \
|
|
12
|
-
|
|
12
|
+
'702.196). In a Commander game `via: "command"` casts your commander from the command zone, its cost ' \
|
|
13
|
+
"including the commander tax (CR 903.8). A card outside the game is named `\"outside:<card id>\"` (CR 400.11b). " \
|
|
13
14
|
'`{type: "cast", object: id, face: 1}` casts another face of a card in your hand: a modal double-faced ' \
|
|
14
15
|
"card's back face, an Adventure or an Omen (CR 712.8b, 716.3, 721.3). Offered only when timing " \
|
|
15
16
|
"allows, targets exist and enough mana is available."
|
|
@@ -38,12 +39,19 @@ module Enjine
|
|
|
38
39
|
engine.state.battlefield.each do |id|
|
|
39
40
|
add_options(engine, index, id, out) if engine.object(id).controller == index
|
|
40
41
|
end
|
|
41
|
-
engine
|
|
42
|
-
engine.player(index).graveyard.each { add_options(engine, index, it, out) } # CR 113.6m: e.g. "exile this card from your graveyard"
|
|
43
|
-
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) }
|
|
44
43
|
out
|
|
45
44
|
end
|
|
46
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
|
+
|
|
47
55
|
def self.add_options(engine, index, id, out)
|
|
48
56
|
engine.chars(id).activated_abilities.each do |inst|
|
|
49
57
|
out << { type: "activate", object: id, ability: inst.ref } if engine.activatable?(index, id, inst.ref)
|
|
@@ -11,7 +11,8 @@ module Enjine
|
|
|
11
11
|
# Enjine.registry. Anything unknown is reported (with its path) in a single
|
|
12
12
|
# InvalidCardDefinition error.
|
|
13
13
|
class CardDefinition
|
|
14
|
-
KEYS = %w[name mana_cost colors types supertypes subtypes keywords power toughness loyalty abilities rules_text deck_limit
|
|
14
|
+
KEYS = %w[name mana_cost colors types supertypes subtypes keywords power toughness loyalty abilities rules_text deck_limit
|
|
15
|
+
color_identity].freeze
|
|
15
16
|
# Optional catalogue data beside the rules data, never read by the rules: rarity, and the set code and
|
|
16
17
|
# collector number printed on the card ({"set" => "trk", "number" => "12"}).
|
|
17
18
|
PRINT_KEYS = %w[rarity printing].freeze
|
|
@@ -63,6 +64,7 @@ module Enjine
|
|
|
63
64
|
@rules_data = @source
|
|
64
65
|
@source = deep_freeze(@source.merge("rarity" => @rarity, "printing" => @printing).compact) if @rarity || @printing
|
|
65
66
|
@printed_characteristics = Characteristics.printed(self) if errors.empty?
|
|
67
|
+
@color_identity = ColorIdentity.of(self) if face.nil? && errors.empty? # a face has its card's (see #color_identity)
|
|
66
68
|
freeze
|
|
67
69
|
end
|
|
68
70
|
|
|
@@ -79,6 +81,7 @@ module Enjine
|
|
|
79
81
|
@keywords, keyword_modules = read_names(card, "keywords", :keyword, errors)
|
|
80
82
|
@colors = read_colors(card, errors)
|
|
81
83
|
@deck_limit = read_deck_limit(card, errors)
|
|
84
|
+
@declared_color_identity = read_color_identity(card, errors)
|
|
82
85
|
@power, @power_amount = read_pt(card, "power", errors)
|
|
83
86
|
@toughness, @toughness_amount = read_pt(card, "toughness", errors)
|
|
84
87
|
@loyalty = read_stat(card, "loyalty", errors)
|
|
@@ -162,11 +165,24 @@ module Enjine
|
|
|
162
165
|
attr_reader :all_effects
|
|
163
166
|
|
|
164
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?)
|
|
165
175
|
def land? = @land
|
|
166
176
|
def creature? = @creature
|
|
167
177
|
def planeswalker? = @planeswalker
|
|
168
178
|
def deck_limit_exempt? = @deck_limit_exempt
|
|
169
179
|
|
|
180
|
+
# The colors a Commander deck must hold to include this card (CR 903.4), WUBRG-ordered, over every face.
|
|
181
|
+
def color_identity = @front ? @front.color_identity : @color_identity
|
|
182
|
+
|
|
183
|
+
# The identity this face states by hand ("color_identity": ["R"]), nil when derived from its data.
|
|
184
|
+
attr_reader :declared_color_identity
|
|
185
|
+
|
|
170
186
|
# Most copies a constructed deck may hold (CR 100.2a): nil for any number (basic lands, or a card that
|
|
171
187
|
# says "a deck can have any number of cards named ~").
|
|
172
188
|
def deck_limit = @deck_limit_exempt ? nil : (@deck_limit || Deck::MAX_COPIES)
|
|
@@ -199,6 +215,13 @@ module Enjine
|
|
|
199
215
|
|
|
200
216
|
private
|
|
201
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
|
+
|
|
202
225
|
def precompute_predicates
|
|
203
226
|
@land = @types.include?(:land)
|
|
204
227
|
@creature = @types.include?(:creature)
|
|
@@ -210,6 +233,7 @@ module Enjine
|
|
|
210
233
|
@spell_ability = @abilities.find { it.kind == :spell } || aura_spell_ability
|
|
211
234
|
every = @abilities + @nested_instances.map(&:ability)
|
|
212
235
|
@triggered = every.any? { it.kind == :triggered }
|
|
236
|
+
precompute_off_board
|
|
213
237
|
@all_effects = nested(every.flat_map do |ability|
|
|
214
238
|
ability.respond_to?(:modes) && ability.modal? ? ability.modes.flat_map(&:effects) : ability.try_effects
|
|
215
239
|
end).freeze
|
|
@@ -319,6 +343,16 @@ module Enjine
|
|
|
319
343
|
ok ? Mana::COLORS.select { |c| list.map { it.to_s.upcase }.include?(c.to_s) }.freeze : [].freeze
|
|
320
344
|
end
|
|
321
345
|
|
|
346
|
+
# "color_identity": colors W U B R G; states a face's color identity instead of deriving it (CR 903.4).
|
|
347
|
+
def read_color_identity(card, errors)
|
|
348
|
+
return nil unless card.key?("color_identity")
|
|
349
|
+
|
|
350
|
+
list = card["color_identity"]
|
|
351
|
+
ok = list.is_a?(Array) && list.all? { Mana::COLORS.include?(it.to_s.upcase.to_sym) }
|
|
352
|
+
errors << "color_identity: must be a list of W, U, B, R, G" unless ok
|
|
353
|
+
ok ? Mana::COLORS.select { |c| list.map { it.to_s.upcase }.include?(c.to_s) }.freeze : nil
|
|
354
|
+
end
|
|
355
|
+
|
|
322
356
|
# CR 100.2a: "a deck can have any number of cards named ~" is `"deck_limit": "any"`; "up to seven" is 7.
|
|
323
357
|
# Reads the PRINT_KEYS of a whole card; returns the card without them.
|
|
324
358
|
def read_print(card, errors)
|
|
@@ -415,10 +449,12 @@ module Enjine
|
|
|
415
449
|
out["loyalty"] = @loyalty unless @loyalty.nil?
|
|
416
450
|
out["abilities"] = Snapshot.deep_stringify(card["abilities"]) if card["abilities"].is_a?(Array) && !card["abilities"].empty?
|
|
417
451
|
out["rules_text"] = @rules_text if @rules_text
|
|
418
|
-
out
|
|
419
|
-
deep_freeze(out)
|
|
452
|
+
deep_freeze(out.merge!(deck_building_h))
|
|
420
453
|
end
|
|
421
454
|
|
|
455
|
+
# What deck construction reads beyond the card's characteristics (CR 100.2a, 903.4).
|
|
456
|
+
def deck_building_h = { "deck_limit" => @deck_limit, "color_identity" => @declared_color_identity&.map(&:to_s) }.compact
|
|
457
|
+
|
|
422
458
|
# An integer, or the amount of a characteristic-defining ability as given.
|
|
423
459
|
def normalized_stat(card, key) = card[key].is_a?(Hash) ? Snapshot.deep_stringify(card[key]) : instance_variable_get("@#{key}")
|
|
424
460
|
|
data/lib/enjine/cli/text.rb
CHANGED
|
@@ -79,6 +79,7 @@ module Enjine
|
|
|
79
79
|
lines << " Lands: #{lands.empty? ? "-" : lands.map { permanent(it) }.join(", ")}"
|
|
80
80
|
lines << " Permanents: #{"-" if others.empty?}"
|
|
81
81
|
others.each { lines << " #{permanent(it)}" }
|
|
82
|
+
lines.concat(commander_lines(view, player)) if player["commander"]
|
|
82
83
|
lines << " Hand: #{player["hand"].map { card(it) }.join(", ")}" if player["hand"]
|
|
83
84
|
if player["library"]
|
|
84
85
|
lines << " Library (top first): #{player["library"].first(5).map do
|
|
@@ -89,6 +90,23 @@ module Enjine
|
|
|
89
90
|
lines
|
|
90
91
|
end
|
|
91
92
|
|
|
93
|
+
# A Commander game: the commander, where it waits, its tax and the damage it has taken from commanders.
|
|
94
|
+
def commander_lines(view, player)
|
|
95
|
+
waiting = view["command"].select { it["owner"] == player["name"] && it["kind"] != "emblem" }
|
|
96
|
+
damage = player["commander_damage"].map { |name, n| "#{n} from #{name}" }.join(", ")
|
|
97
|
+
[" Commander: #{player["commander"]}#{" [#{waiting.first["id"]}] in the command zone" unless waiting.empty?}" \
|
|
98
|
+
"#{" · tax {#{player["commander_tax"]}}" if player["commander_tax"].positive?}" \
|
|
99
|
+
"#{" · commander damage taken: #{damage}" unless damage.empty?}"]
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# " from the command zone (+{2})" on a cast option of a commander.
|
|
103
|
+
def commander_tax(opt)
|
|
104
|
+
return "" unless opt[:via] == "command"
|
|
105
|
+
|
|
106
|
+
tax = Engine::Commander::TAX * @game.state.players[@game.state.object(opt[:object]).owner].commander_casts.to_i
|
|
107
|
+
" from the command zone#{" (+{#{tax}})" if tax.positive?}"
|
|
108
|
+
end
|
|
109
|
+
|
|
92
110
|
def permanent(obj)
|
|
93
111
|
parts = [obj["name"]]
|
|
94
112
|
parts << "#{obj["power"]}/#{obj["toughness"]}" if obj.key?("power")
|
|
@@ -120,6 +138,7 @@ module Enjine
|
|
|
120
138
|
when "bottom" then " — put #{decision.details["count"]} more on the bottom"
|
|
121
139
|
when "assign_damage" then " — #{name_of(decision.details["attacker"])}: #{decision.details["remaining"]} damage left"
|
|
122
140
|
when "choose_target" then " — target ##{decision.details["index"] + 1}"
|
|
141
|
+
when "commander_zone" then " — #{name_of(decision.details["object"])} (your commander)"
|
|
123
142
|
when "choose_target_count" then " — how many for target ##{decision.details["index"] + 1}"
|
|
124
143
|
else ""
|
|
125
144
|
end
|
|
@@ -132,7 +151,9 @@ module Enjine
|
|
|
132
151
|
case opt[:type]
|
|
133
152
|
when "pass" then "Pass priority"
|
|
134
153
|
when "play_land" then "Play land #{name_of(opt[:object])}"
|
|
135
|
-
when "cast" then "Cast #{name_of(opt[:object])} #{cost_of(opt[:object])}".rstrip
|
|
154
|
+
when "cast" then "Cast #{name_of(opt[:object])} #{cost_of(opt[:object])}#{commander_tax(opt)}".rstrip
|
|
155
|
+
when "command" then "Put #{name_of(opt[:object])} into the command zone"
|
|
156
|
+
when "stay" then "Leave #{name_of(opt[:object])} where it is"
|
|
136
157
|
when "activate" then "Activate #{name_of(opt[:object])}: #{ability_text(opt[:object], opt[:ability])}"
|
|
137
158
|
when "special_action" then "#{ability_text(opt[:object], opt[:ability])}: #{name_of(opt[:object])} (special action)"
|
|
138
159
|
when "activate_mana"
|
|
@@ -260,6 +281,7 @@ module Enjine
|
|
|
260
281
|
when "sba_toughness" then "#{what} dies (0 toughness)"
|
|
261
282
|
when "sba_loyalty" then "#{what} is put into the graveyard (0 loyalty)"
|
|
262
283
|
when "countered" then "#{what} is countered"
|
|
284
|
+
when "commander" then "#{ev["owner"]} puts #{what} into the command zone"
|
|
263
285
|
when "mulligan_bottom" then "#{ev["owner"]} puts #{what} on the bottom of their library (mulligan)"
|
|
264
286
|
else "#{ev["owner"]}'s #{what}: #{ev["from"]} → #{ev["to"]} (#{ev["reason"]})"
|
|
265
287
|
end
|
data/lib/enjine/cli.rb
CHANGED
|
@@ -68,6 +68,7 @@ module Enjine
|
|
|
68
68
|
o.on("--random-deck [SPEC]", "Print a random deck from --pool as JSON, e.g. \"colors=WU seed=7\"") do
|
|
69
69
|
@options[:random_deck] = it
|
|
70
70
|
end
|
|
71
|
+
o.on("--format NAME", "constructed (default) or duel_commander: decks then name a \"commander\"") { @options[:format] = it }
|
|
71
72
|
o.on("--names A,B", Array, "Player names (default alice,bob)") { @options[:names] = it }
|
|
72
73
|
o.on("--validate FILE", "Validate a JSON array of card data blocks; prints a JSON report") { @options[:validate] = it }
|
|
73
74
|
o.on("--verify DIR", "Validate and play-test every card in DIR's JSON files; exit 1 on any problem") do
|
|
@@ -161,7 +162,7 @@ module Enjine
|
|
|
161
162
|
def new_game
|
|
162
163
|
decks = [@options[:deck1], @options[:deck2]].each_with_index.map { |deck, i| deck_for(deck, i) }
|
|
163
164
|
players = @options[:names].zip(decks).map { |name, deck| Player.new(name: name, deck: deck) }
|
|
164
|
-
@setup = Setup.new(*players)
|
|
165
|
+
@setup = Setup.new(*players, format: @options.fetch(:format, Format::CONSTRUCTED))
|
|
165
166
|
@setup.new_game(seed: @options[:seed])
|
|
166
167
|
end
|
|
167
168
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Enjine
|
|
4
|
+
# A card's color identity (CR 903.4): the colors of the mana symbols in its mana cost and rules, plus its
|
|
5
|
+
# color indicator, characteristic-defining colors and the mana its basic land types make (CR 903.5d), over
|
|
6
|
+
# every face of the card (CR 903.4d-e). Reminder text doesn't count (CR 903.4c), and the engine never reads
|
|
7
|
+
# text: the symbols are found in the card's *data* (costs, produced mana, kicker, ...), not in `rules_text`.
|
|
8
|
+
# A face may state its identity by hand with "color_identity" instead, for the odd card the data can't tell.
|
|
9
|
+
module ColorIdentity
|
|
10
|
+
SKIPPED_KEYS = %w[name rules_text rarity printing color_identity].freeze
|
|
11
|
+
BASIC_LAND_COLORS = { plains: :W, island: :U, swamp: :B, mountain: :R, forest: :G }.freeze
|
|
12
|
+
|
|
13
|
+
module_function
|
|
14
|
+
|
|
15
|
+
# WUBRG-ordered colors of a whole card.
|
|
16
|
+
def of(definition)
|
|
17
|
+
colors = definition.faces.flat_map { face_colors(it) }
|
|
18
|
+
Mana::COLORS.select { colors.include?(it) }.freeze
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def face_colors(face)
|
|
22
|
+
face.declared_color_identity || (face.colors + land_colors(face) + symbols(face.source.except("faces")))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# The colors of the mana a basic land type makes (CR 305.6, 903.5d).
|
|
26
|
+
def land_colors(face) = face.subtypes.filter_map { BASIC_LAND_COLORS[it] }
|
|
27
|
+
|
|
28
|
+
# The colors named by every mana symbol in the card's data, hybrid and monocolored hybrid symbols included.
|
|
29
|
+
def symbols(node)
|
|
30
|
+
case node
|
|
31
|
+
when Hash then node.flat_map { |key, value| SKIPPED_KEYS.include?(key) ? [] : symbols(value) }
|
|
32
|
+
when Array then node.flat_map { symbols(it) }
|
|
33
|
+
when String then node.scan(Mana::SYMBOL).flatten.flat_map { it.scan(/[WUBRG]/).map(&:to_sym) }
|
|
34
|
+
else []
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Enjine
|
|
4
|
+
module Decisions
|
|
5
|
+
# CR 903.9: a commander went to a graveyard, exile, hand or library; its owner chooses whether to put it
|
|
6
|
+
# into the command zone instead (Engine::Commander).
|
|
7
|
+
class CommanderZone < Base
|
|
8
|
+
def self.doc
|
|
9
|
+
'Your commander is in a graveyard, exile, hand or library: `{type: "command", object: id}` puts it into ' \
|
|
10
|
+
'the command zone, `{type: "stay", object: id}` leaves it where it is (CR 903.9).'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.options(_engine, pending)
|
|
14
|
+
[{ type: "command", object: pending["object"] }, { type: "stay", object: pending["object"] }]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.submit(engine, _pending, option) = engine.choose_commander_zone!(option[:type] == "command")
|
|
18
|
+
end
|
|
19
|
+
register("commander_zone", CommanderZone)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
module Frames
|
|
23
|
+
# The owner's choice to send a commander back to the command zone (CR 903.9), before priority.
|
|
24
|
+
class CommanderZone < Base
|
|
25
|
+
def self.step(engine, frame) = engine.step_commander_zone!(frame)
|
|
26
|
+
def self.decisions = %w[commander_zone]
|
|
27
|
+
|
|
28
|
+
def self.validate(frame, data, errors)
|
|
29
|
+
errors << "frames: commander_zone object #{frame["object"]} doesn't exist" unless data["objects"].any? do
|
|
30
|
+
it["id"] == frame["object"]
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
register("commander_zone", CommanderZone)
|
|
35
|
+
end
|
|
36
|
+
end
|