kjdskjdsk

This commit is contained in:
2026-10-27 19:14:33 +01:00
parent c962800876
commit bb85881cac
19 changed files with 2355 additions and 185 deletions

View File

@@ -56,6 +56,62 @@ test('search effect keeps destination, tapped, and shuffle', () => {
})
})
test('search can put the chosen card on top of the library', () => {
const [ability] = spell('Search your library for a creature card, reveal it, then shuffle and put the card on top.')
assert.equal(ability.kind, 'spell')
if (ability.kind !== 'spell') return
assert.deepEqual(ability.effects[0], {
op: 'search',
player: 'you',
selector: { types: ['creature'] },
amount: { kind: 'number', value: 1 },
destination: 'top',
tapped: false,
shuffle: true,
})
})
test('a two-card search can split between the battlefield and hand', () => {
const [ability] = spell('Search your library for up to two basic land cards, reveal those cards, put one onto the battlefield tapped and the other into your hand, then shuffle.')
assert.equal(ability.kind, 'spell')
if (ability.kind !== 'spell') return
assert.deepEqual(ability.effects[0], {
op: 'search',
player: 'you',
selector: { types: ['land'], supertypes: ['basic'] },
amount: { kind: 'number', value: 2 },
destination: 'battlefield',
tapped: true,
shuffle: true,
split: { destination: 'hand', tapped: false },
})
})
test('"if you search your library this way, shuffle" keeps the search', () => {
const [ability] = spell('Search your library for a card named Sol Ring, reveal it, and put it into your hand. If you search your library this way, shuffle.')
assert.equal(ability.kind, 'spell')
if (ability.kind !== 'spell') return
assert.deepEqual(ability.effects[0], {
op: 'search',
player: 'you',
selector: { name: 'sol ring', types: [] },
amount: { kind: 'number', value: 1 },
destination: 'hand',
tapped: false,
shuffle: true,
})
})
test('search selectors support an exact mana value', () => {
const [ability] = spell('Search your library for an artifact card with mana value 3, reveal it, put it into your hand, then shuffle.')
assert.equal(ability.kind, 'spell')
if (ability.kind !== 'spell') return
const effect = ability.effects[0]
assert.equal(effect.op, 'search')
if (effect.op !== 'search') return
assert.deepEqual(effect.selector, { types: ['artifact'], manaValue: { atLeast: 3, atMost: 3 } })
})
test('"it" refers to the triggering object when unambiguous', () => {
const [ability] = creature('Whenever another creature enters, put a +1/+1 counter on it.')
assert.equal(ability.kind, 'triggered')
@@ -283,6 +339,53 @@ test('counter-removal costs parse and round-trip through pseudocode', () => {
}])
})
test('hideaway lands exile a card and gate playing it on their condition', () => {
const lands: Array<[string, string, string]> = [
["Clive's Hideaway", `Hideaway 4 (When this land enters, look at the top four cards of your library, exile one face down, then put the rest on the bottom in a random order.)
{T}: Add {C}.
{2}, {T}: You may play the exiled card without paying its mana cost if you control four or more legendary creatures.`, 'you_control'],
['Howltooth Hollow', `Hideaway 4 (When this land enters, look at the top four cards of your library, exile one face down, then put the rest on the bottom in a random order.)
This land enters tapped.
{T}: Add {B}.
{B}, {T}: You may play the exiled card without paying its mana cost if each player has no cards in hand.`, 'cards_in_hand_at_most'],
['Mosswort Bridge', `Hideaway 4 (When this land enters, look at the top four cards of your library, exile one face down, then put the rest on the bottom in a random order.)
This land enters tapped.
{T}: Add {G}.
{G}, {T}: You may play the exiled card without paying its mana cost if creatures you control have total power 10 or greater.`, 'total_power'],
['Shelldock Isle', `Hideaway 4 (When this land enters, look at the top four cards of your library, exile one face down, then put the rest on the bottom in a random order.)
This land enters tapped.
{T}: Add {U}.
{U}, {T}: You may play the exiled card without paying its mana cost if a library has twenty or fewer cards in it.`, 'library_at_most'],
['Spinerock Knoll', `Hideaway 4 (When this land enters, look at the top four cards of your library, exile one face down, then put the rest on the bottom in a random order.)
This land enters tapped.
{T}: Add {R}.
{R}, {T}: You may play the exiled card without paying its mana cost if an opponent was dealt 7 or more damage this turn.`, 'opponent_damaged_this_turn'],
['Windbrisk Heights', `Hideaway 4 (When this land enters, look at the top four cards of your library, exile one face down, then put the rest on the bottom in a random order.)
This land enters tapped.
{T}: Add {W}.
{W}, {T}: You may play the exiled card without paying its mana cost if you attacked with three or more creatures this turn.`, 'attacked_with_creatures'],
]
for (const [name, text, condition] of lands) {
const abilities = compileText(text, name, [], 'Land')
assert.equal(abilities.filter(ability => ability.kind === 'unsupported').length, 0, name)
const hideaway = abilities.find(ability => ability.kind === 'triggered' && ability.effects.some(effect => effect.op === 'hideaway'))
assert.equal(hideaway?.kind, 'triggered', name)
if (hideaway?.kind !== 'triggered') continue
assert.deepEqual(hideaway.effects, [{ op: 'hideaway', amount: { kind: 'number', value: 4 } }], name)
const activated = abilities.at(-1)
assert.equal(activated?.kind, 'activated', name)
if (activated?.kind !== 'activated') continue
const [effect] = activated.effects
assert.equal(effect.op, 'conditional', name)
if (effect.op !== 'conditional') continue
assert.equal(effect.condition.kind, condition, name)
assert.deepEqual(effect.effects, [{ op: 'play_exiled', player: 'you', free: true }], name)
}
})
test('a trigger returns its own card from the graveyard', () => {
const [ability] = creature('When this dies, return this from your graveyard to the battlefield with a finality counter on it.')
assert.equal(ability.kind, 'triggered')
@@ -295,3 +398,152 @@ test('a trigger returns its own card from the graveyard', () => {
counters: { counter: 'finality', amount: { kind: 'number', value: 1 } },
}])
})
test('Commander-batch oracle lines compile to dedicated nodes', () => {
const [free] = spell('If you control a commander, you may cast this without paying its mana cost.')
assert.equal(free.kind, 'alternative_cost')
if (free.kind !== 'alternative_cost') return
assert.deepEqual(free.condition, { kind: 'you_control_commander' })
assert.deepEqual(free.costs, [])
const [overload] = spell('Overload {6}{U}')
assert.deepEqual(overload, { kind: 'overload', cost: '{6}{U}', text: 'Overload {6}{U}' })
const [graves] = creature('When this enters, exile all graveyards.')
assert.equal(graves.kind, 'triggered')
if (graves.kind !== 'triggered') return
assert.deepEqual(graves.effects, [{ op: 'exile_graveyards' }])
const [rest] = creature('If a card or token would be put into a graveyard from anywhere, exile it instead.')
assert.equal(rest.kind, 'static')
if (rest.kind !== 'static') return
assert.deepEqual(rest.effects, [{ op: 'exile_instead_of_graveyard' }])
const [leyline] = creature("If a card would be put into an opponent's graveyard from anywhere, exile it instead.")
assert.equal(leyline.kind, 'static')
if (leyline.kind !== 'static') return
assert.deepEqual(leyline.effects, [{ op: 'exile_instead_of_graveyard', owner: 'opponent' }])
const [thalia] = creature('Noncreature spells cost {1} more to cast.')
assert.equal(thalia.kind, 'static')
if (thalia.kind !== 'static') return
assert.deepEqual(thalia.effects, [{
op: 'cost_increase',
amount: { kind: 'number', value: 1 },
spellType: 'noncreature',
}])
const [linvala] = creature("Activated abilities of creatures your opponents control can't be activated.")
assert.equal(linvala.kind, 'static')
if (linvala.kind !== 'static') return
assert.deepEqual(linvala.effects, [{
op: 'restriction',
target: { kind: 'object', selector: { controller: 'opponent', types: ['creature'] }, mode: 'each' },
rule: 'cant_activate',
}])
const [aven] = creature('If an opponent would search a library, that player searches the top four cards of that library instead.')
assert.equal(aven.kind, 'static')
if (aven.kind !== 'static') return
assert.deepEqual(aven.effects, [{
op: 'search_restriction',
who: 'opponent',
amount: { kind: 'number', value: 4 },
}])
const [field] = compileText(
'Whenever this or another land you control enters, if you control seven or more lands with different names, create a 2/2 black Zombie creature token.',
'Field of the Dead',
[],
'Land',
)
assert.equal(field.kind, 'triggered')
if (field.kind !== 'triggered') return
assert.deepEqual(field.condition, {
kind: 'distinct_names',
selector: { types: ['land'] },
atLeast: 7,
})
})
test('spell cost reductions compile their conditions and mana symbols', () => {
const [bears] = creature('Creature spells you cast cost {1} less to cast.')
assert.equal(bears.kind, 'static')
if (bears.kind !== 'static') return
assert.deepEqual(bears.effects, [{
op: 'cost_reduction',
target: {
kind: 'object',
selector: { controller: 'you', types: ['creature'] },
mode: 'each',
},
amount: { kind: 'number', value: 1 },
}])
const [cantrips] = creature('Instant and sorcery spells cost {2} less to cast.')
assert.equal(cantrips.kind, 'static')
if (cantrips.kind !== 'static') return
assert.deepEqual(cantrips.effects, [{
op: 'cost_reduction',
target: {
kind: 'object',
selector: { match: 'any', types: ['instant', 'sorcery'] },
mode: 'each',
},
amount: { kind: 'number', value: 2 },
}])
const [legendary] = creature('Legendary spells you cast cost {R}{G} less to cast. This effect reduces only the amount of colored mana you pay.')
assert.equal(legendary.kind, 'static')
if (legendary.kind !== 'static') return
assert.deepEqual(legendary.effects, [{
op: 'cost_reduction',
target: {
kind: 'object',
selector: { controller: 'you', supertypes: ['legendary'], types: [] },
mode: 'each',
},
symbols: '{R}{G}',
}])
const [tribal] = creature("Each spell you cast that's a Demon, Horror, or Nightmare costs {1} less to cast.")
assert.equal(tribal.kind, 'static')
if (tribal.kind !== 'static') return
assert.deepEqual(tribal.effects, [{
op: 'cost_reduction',
target: {
kind: 'object',
selector: { controller: 'you', match: 'any', subtypes: ['demon', 'horror', 'nightmare'], types: [] },
mode: 'each',
},
amount: { kind: 'number', value: 1 },
}])
})
test('new abilities, effects and conditions round-trip through pseudocode', () => {
const abilities: Ability[] = [
...spell('If you control a commander, you may cast this without paying its mana cost.'),
...spell('Overload {6}{U}'),
...creature('When this enters, exile all graveyards.'),
...creature('If a card or token would be put into a graveyard from anywhere, exile it instead.'),
...creature("If a card would be put into an opponent's graveyard from anywhere, exile it instead."),
...creature('Noncreature spells cost {1} more to cast.'),
...creature('Creature spells you cast cost {1} less to cast.'),
...creature('Legendary spells you cast cost {R}{G} less to cast.'),
...creature("Each spell you cast that's a Demon, Horror, or Nightmare costs {1} less to cast."),
...creature("Activated abilities of creatures your opponents control can't be activated."),
...creature('If an opponent would search a library, that player searches the top four cards of that library instead.'),
...compileText(
'Whenever this or another land you control enters, if you control seven or more lands with different names, create a 2/2 black Zombie creature token.',
'Field of the Dead',
[],
'Land',
),
]
for (const ability of abilities) {
const pseudo = formatAbility(ability)
const reparsed = parsePseudoCard(`# Test [supported]\n${pseudo}`).abilities[0]
assert.ok(reparsed)
assert.equal(formatAbility(reparsed), pseudo)
}
})

View File

@@ -127,6 +127,104 @@ test('permanents can be repositioned by their controller and positions are clear
assert.equal(bear.position, undefined)
})
test('hideaway exiles a card and its linked ability plays it for free once the condition is met', () => {
const hideawayLand = card('Hideaway Test', {
typeLine: 'Land',
abilities: [
{
kind: 'triggered',
event: { kind: 'enters', subject: { kind: 'self' } },
effects: [{ op: 'hideaway', amount: { kind: 'number', value: 4 } }],
optional: false,
text: 'Hideaway 4',
},
{
kind: 'activated',
costs: [],
effects: [{
op: 'conditional',
condition: { kind: 'total_power', controller: 'you', atLeast: 10 },
effects: [{ op: 'play_exiled', player: 'you', free: true }],
}],
optional: false,
text: 'Play the exiled card without paying its mana cost if creatures you control have total power 10 or greater.',
},
],
})
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const hidden = game.addCard('p1', creature('Hidden Bear', 2, 2), 'library')
const library = game.getPlayer('p1').library
library.splice(library.indexOf(hidden.id), 1)
library.unshift(hidden.id)
const land = game.addCard('p1', hideawayLand, 'hand')
game.playLand('p1', land.id)
game.resolveStack()
assert.equal(hidden.zone, 'exile')
assert.deepEqual(land.linkedExile, [hidden.id])
game.activateAbility('p1', land.id, 1)
game.resolveStack()
assert.equal(hidden.zone, 'exile')
game.addCard('p1', creature('Big Bear', 10, 10), 'battlefield')
game.activateAbility('p1', land.id, 1)
game.resolveStack()
assert.equal(hidden.zone, 'battlefield')
assert.ok(game.getPlayer('p1').battlefield.includes(hidden.id))
})
test('playing a card hidden by hideaway uses the land drop', () => {
const hideawayLand = card('Hideaway Land', {
typeLine: 'Land',
abilities: [
{
kind: 'triggered',
event: { kind: 'enters', subject: { kind: 'self' } },
effects: [{ op: 'hideaway', amount: { kind: 'number', value: 1 } }],
optional: false,
text: 'Hideaway 1',
},
{
kind: 'activated',
costs: [],
effects: [{
op: 'conditional',
condition: { kind: 'total_power', controller: 'you', atLeast: 0 },
effects: [{ op: 'play_exiled', player: 'you', free: true }],
}],
optional: false,
text: 'Play the exiled card without paying its mana cost.',
},
],
})
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const hidden = game.addCard('p1', land('Island', 'U'), 'library')
const library = game.getPlayer('p1').library
library.splice(library.indexOf(hidden.id), 1)
library.unshift(hidden.id)
const source = game.addCard('p1', hideawayLand, 'hand')
game.playLand('p1', source.id)
game.resolveStack()
assert.equal(hidden.zone, 'exile')
game.getPlayer('p1').landPlayedThisTurn = true
game.activateAbility('p1', source.id, 1)
game.resolveStack()
assert.equal(hidden.zone, 'exile')
game.getPlayer('p1').landPlayedThisTurn = false
game.activateAbility('p1', source.id, 1)
game.resolveStack()
assert.equal(hidden.zone, 'battlefield')
assert.equal(game.getPlayer('p1').landPlayedThisTurn, true)
})
test('enters triggers from compiled card code fire and resolve through the stack', () => {
const soulWarden = card('Soul Warden', {
typeLine: 'Creature — Human Cleric',
@@ -414,6 +512,69 @@ test('search effects let the player pick among multiple matching cards', () => {
assert.ok(game.getPlayer('p1').library.includes(forestObject.id))
})
test('as-enters creature type choices pause until the controller picks', () => {
const cavern = card('Cavern of Souls', {
typeLine: 'Land',
power: undefined,
toughness: undefined,
abilities: [{
kind: 'static',
effects: [{ op: 'choose', what: 'creature_type' }],
text: 'As this enters, choose a creature type.',
}],
})
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const object = game.addCard('p1', cavern, 'hand')
game.playLand('p1', object.id)
assert.equal(game.pendingChoice?.sourceId, object.id)
assert.equal(game.pendingChoice?.playerId, 'p1')
assert.throws(() => game.pass('p1'), GameError)
assert.throws(() => game.chooseCreatureType('p2', 'Elf'), GameError)
assert.throws(() => game.chooseCreatureType('p1', 'Not A Type'), GameError)
game.chooseCreatureType('p1', 'elf')
assert.equal(object.chosenCreatureType, 'Elf')
assert.equal(game.pendingChoice, undefined)
game.moveToZone(object, 'graveyard')
assert.equal(object.chosenCreatureType, undefined)
game.moveToZone(object, 'battlefield', { silent: false })
assert.equal(game.pendingChoice?.sourceId, object.id)
})
test('a split search sends the first pick to the battlefield and the next to hand', () => {
const forest = land('Forest', 'G')
const island = land('Island', 'U')
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const forestObject = game.addCard('p1', forest, 'library')
const islandObject = game.addCard('p1', island, 'library')
const cultivate = game.addCard('p1', spell('Cultivate', [{
op: 'search',
player: 'you',
selector: { types: ['land'], supertypes: ['basic'] },
amount: { kind: 'number', value: 2 },
destination: 'battlefield',
tapped: true,
shuffle: true,
split: { destination: 'hand', tapped: false },
}]), 'hand')
game.castSpell('p1', cultivate.id)
game.resolveStack()
game.chooseSearchCard('p1', islandObject.id)
assert.equal(game.pendingSearch?.destination, 'hand')
game.chooseSearchCard('p1', forestObject.id)
assert.equal(game.pendingSearch, undefined)
assert.ok(game.getPlayer('p1').battlefield.includes(islandObject.id))
assert.equal(islandObject.tapped, true)
assert.ok(game.getPlayer('p1').hand.includes(forestObject.id))
})
test('autoAdvance stops instead of passing while a search needs a pick', () => {
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
@@ -645,3 +806,427 @@ test('counter-removal costs are paid and fail when counters run out', () => {
assert.throws(() => game.activateAbility('p1', source.id, 0), GameError)
assert.equal(source.counters.spore, 1)
})
test('a free alternative cost needs a commander and skips the mana cost', () => {
const maneuver = card('Flawless Maneuver', {
typeLine: 'Instant',
manaCost: '{2}{W}',
manaValue: 3,
abilities: [
{
kind: 'alternative_cost',
costs: [],
condition: { kind: 'you_control_commander' },
text: 'If you control a commander, you may cast this spell without paying its mana cost.',
},
{
kind: 'spell',
effects: [{
op: 'grant',
target: { kind: 'object', selector: { controller: 'you', types: ['creature'] }, mode: 'each' },
keyword: 'Indestructible',
duration: 'until_end_of_turn',
}],
optional: false,
text: 'Creatures you control gain indestructible until end of turn.',
},
],
})
const game = new Game({
seed: 1,
startingHandSize: 0,
commander: true,
players: [
{ id: 'p1', deck: [card('Filler')], commander: creature('Test Commander', 2, 2) },
{ id: 'p2', deck: [card('Filler')], commander: creature('Other Commander', 2, 2) },
],
})
game.start()
const spell = game.addCard('p1', maneuver, 'hand')
assert.equal(game.canPlayCard('p1', spell.id), false)
assert.throws(() => game.castSpell('p1', spell.id), GameError)
game.moveToZone(game.getPlayer('p1').commanderId!, 'battlefield', { silent: true })
assert.equal(game.canPlayCard('p1', spell.id), true)
game.castSpell('p1', spell.id)
assert.equal(game.stack.length, 1)
assert.deepEqual(game.getPlayer('p1').manaPool, { W: 0, U: 0, B: 0, R: 0, G: 0, C: 0 })
})
test('overload pays the overload cost and widens the spell target', () => {
const rift = card('Cyclonic Rift', {
typeLine: 'Instant',
manaCost: '{U}',
manaValue: 1,
abilities: [
{
kind: 'spell',
effects: [{
op: 'return_to_hand',
target: {
kind: 'object',
selector: { controller: 'opponent', types: ['permanent'], excludeTypes: ['land'] },
mode: 'target',
},
}],
optional: false,
text: "Return target nonland permanent you don't control to its owner's hand.",
},
{ kind: 'overload', cost: '{1}{U}', text: 'Overload {1}{U}' },
],
})
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const island = game.addCard('p1', land('Island', 'U'), 'battlefield')
const wastes = game.addCard('p1', land('Wastes', 'C'), 'battlefield')
const ownCreature = game.addCard('p1', creature('Own Bear', 2, 2), 'battlefield')
const theirCreature = game.addCard('p2', creature('Their Bear', 2, 2), 'battlefield')
const theirArtifact = game.addCard('p2', card('Their Rock', {
typeLine: 'Artifact',
power: undefined,
toughness: undefined,
}), 'battlefield')
const theirLand = game.addCard('p2', land('Forest', 'G'), 'battlefield')
const spell = game.addCard('p1', rift, 'hand')
game.castSpell('p1', spell.id, { overload: true })
assert.equal(island.tapped, true)
assert.equal(wastes.tapped, true)
game.resolveStack()
assert.ok(game.getPlayer('p2').hand.includes(theirCreature.id))
assert.ok(game.getPlayer('p2').hand.includes(theirArtifact.id))
assert.ok(game.getPlayer('p2').battlefield.includes(theirLand.id))
assert.ok(game.getPlayer('p1').battlefield.includes(ownCreature.id))
})
test('a noncreature cost increase taxes spells but not creatures', () => {
const thalia = card('Thalia, Guardian of Thraben', {
typeLine: 'Legendary Creature — Human Soldier',
power: 2,
toughness: 1,
abilities: [{
kind: 'static',
effects: [{ op: 'cost_increase', amount: { kind: 'number', value: 1 }, spellType: 'noncreature' }],
text: 'Noncreature spells cost {1} more to cast.',
}],
})
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
game.addCard('p1', thalia, 'battlefield')
const first = game.addCard('p1', land('Wastes', 'C'), 'battlefield')
const instant = game.addCard('p1', spell('Ponder', [
{ op: 'draw', player: 'you', amount: { kind: 'number', value: 1 } },
], '{1}'), 'hand')
const bears = game.addCard('p1', card('Grizzly Bears', {
typeLine: 'Creature — Bear',
power: 2,
toughness: 2,
manaCost: '{1}',
}), 'hand')
assert.equal(game.canPlayCard('p1', instant.id), false)
assert.equal(game.canPlayCard('p1', bears.id), true)
game.addCard('p1', land('Wastes', 'C'), 'battlefield')
assert.equal(game.canPlayCard('p1', instant.id), true)
game.castSpell('p1', instant.id)
assert.equal(first.tapped, true)
})
test('spell cost reductions match the spell type and controller', () => {
const baral = card('Baral, Chief of Compliance', {
typeLine: 'Legendary Creature — Human Wizard',
power: 1,
toughness: 3,
abilities: [{
kind: 'static',
effects: [{
op: 'cost_reduction',
target: { kind: 'object', selector: { controller: 'you', types: ['instant', 'sorcery'], match: 'any' }, mode: 'each' },
amount: { kind: 'number', value: 1 },
}],
text: 'Instant and sorcery spells you cast cost {1} less to cast.',
}],
})
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
game.addCard('p1', baral, 'battlefield')
const wastes = game.addCard('p1', land('Wastes', 'C'), 'battlefield')
const sorcery = game.addCard('p1', card('Divination', {
typeLine: 'Sorcery',
manaCost: '{2}',
abilities: [{ kind: 'spell', effects: [{ op: 'draw', player: 'you', amount: { kind: 'number', value: 1 } }], optional: false, text: 'Draw a card.' }],
}), 'hand')
const bears = game.addCard('p1', card('Grizzly Bears', {
typeLine: 'Creature — Bear',
power: 2,
toughness: 2,
manaCost: '{2}',
}), 'hand')
assert.equal(game.canPlayCard('p1', sorcery.id), true)
assert.equal(game.canPlayCard('p1', bears.id), false)
game.castSpell('p1', sorcery.id)
assert.equal(wastes.tapped, true)
})
test('a colored cost reduction removes matching pips and nothing else', () => {
const edgewalker = card('Edgewalker', {
typeLine: 'Creature — Human Cleric',
power: 2,
toughness: 2,
abilities: [{
kind: 'static',
effects: [{
op: 'cost_reduction',
target: { kind: 'object', selector: { controller: 'you', types: ['creature'], match: 'any', subtypes: ['cleric', 'soldier'] }, mode: 'each' },
symbols: '{W}{B}',
}],
text: 'Cleric spells you cast cost {W}{B} less to cast.',
}],
})
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
game.addCard('p1', edgewalker, 'battlefield')
game.addCard('p1', land('Plains', 'W'), 'battlefield')
game.addCard('p1', land('Swamp', 'B'), 'battlefield')
const cleric = game.addCard('p1', card('Cleric Test', {
typeLine: 'Creature — Human Cleric',
power: 2,
toughness: 2,
colors: ['W', 'B'],
manaCost: '{1}{W}{B}',
manaValue: 3,
}), 'hand')
const soldier = game.addCard('p1', card('Soldier Test', {
typeLine: 'Creature — Human Soldier',
power: 2,
toughness: 2,
colors: ['W', 'B'],
manaCost: '{1}{W}{B}',
manaValue: 3,
}), 'hand')
const bear = game.addCard('p1', card('Bear Test', {
typeLine: 'Creature — Bear',
power: 2,
toughness: 2,
colors: ['W', 'B'],
manaCost: '{1}{W}{B}',
manaValue: 3,
}), 'hand')
assert.equal(game.canPlayCard('p1', cleric.id), true)
assert.equal(game.canPlayCard('p1', soldier.id), true)
assert.equal(game.canPlayCard('p1', bear.id), false)
game.castSpell('p1', cleric.id)
})
test('Linvala stops only opponents from activating creature abilities', () => {
const linvala = card('Linvala, Keeper of Silence', {
typeLine: 'Legendary Creature — Angel',
power: 3,
toughness: 4,
abilities: [{
kind: 'static',
effects: [{
op: 'restriction',
target: { kind: 'object', selector: { controller: 'opponent', types: ['creature'] }, mode: 'each' },
rule: 'cant_activate',
}],
text: "Activated abilities of creatures your opponents control can't be activated.",
}],
})
const drawAbility = {
kind: 'activated' as const,
costs: [],
effects: [{ op: 'draw' as const, player: 'you' as const, amount: { kind: 'number' as const, value: 1 } }],
optional: false,
text: 'Draw a card.',
}
const game = setup([{ id: 'p1', deck: [card('Filler'), card('Filler')] }, { id: 'p2' }])
game.start()
game.addCard('p1', linvala, 'battlefield')
const own = game.addCard('p1', creature('Own Cleric', 1, 1, [drawAbility]), 'battlefield')
const theirs = game.addCard('p2', creature('Their Cleric', 1, 1, [drawAbility]), 'battlefield')
game.activateAbility('p1', own.id, 0)
assert.equal(game.stack.length, 1)
game.resolveStack()
game.pass('p1')
assert.throws(() => game.activateAbility('p2', theirs.id, 0), /cannot activate/)
})
test('Aven Mindcensor limits an opponent search to the top four cards', () => {
const aven = card('Aven Mindcensor', {
typeLine: 'Creature — Bird Wizard',
power: 2,
toughness: 1,
abilities: [{
kind: 'static',
effects: [{ op: 'search_restriction', who: 'opponent', amount: { kind: 'number', value: 4 } }],
text: 'If an opponent would search a library, that player searches the top four cards of that library instead.',
}],
})
const game = setup([{ id: 'p1' }, { id: 'p2', deck: [] }])
game.start()
game.addCard('p1', aven, 'battlefield')
for (const name of ['Forest', 'Island', 'Mountain', 'Plains', 'Swamp', 'Wastes']) {
game.addCard('p2', land(name, 'C'), 'library')
}
const topFour = game.getPlayer('p2').library.slice(0, 4)
const growth = game.addCard('p2', spell('Rampant Growth', [{
op: 'search',
player: 'you',
selector: { types: ['land'] },
amount: { kind: 'number', value: 1 },
destination: 'battlefield',
shuffle: true,
}]), 'hand')
game.pass('p1')
game.castSpell('p2', growth.id)
game.resolveStack()
assert.deepEqual(
game.searchCandidates('p2').map(object => object.id).sort(),
[...topFour].sort(),
)
})
test('Rest in Peace exiles all graveyards and replaces later graveyard moves', () => {
const rest = card('Rest in Peace', {
typeLine: 'Enchantment',
power: undefined,
toughness: undefined,
abilities: [
{
kind: 'triggered',
event: { kind: 'enters', subject: { kind: 'self' } },
effects: [{ op: 'exile_graveyards' }],
optional: false,
text: 'When this enchantment enters, exile all graveyards.',
},
{
kind: 'static',
effects: [{ op: 'exile_instead_of_graveyard' }],
text: 'If a card or token would be put into a graveyard from anywhere, exile it instead.',
},
],
})
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const oldSpell = game.addCard('p1', spell('Old Spell', []), 'graveyard')
const oldCreature = game.addCard('p2', creature('Old Bear', 2, 2), 'graveyard')
const doomed = game.addCard('p1', creature('Doomed Bear', 2, 2), 'battlefield')
game.addCard('p1', rest, 'battlefield', { silent: false })
game.resolveStack()
assert.ok(game.getPlayer('p1').exile.includes(oldSpell.id))
assert.ok(game.getPlayer('p2').exile.includes(oldCreature.id))
assert.deepEqual(game.getPlayer('p1').graveyard, [])
assert.deepEqual(game.getPlayer('p2').graveyard, [])
game.moveToZone(doomed, 'graveyard')
assert.equal(doomed.zone, 'exile')
assert.ok(game.getPlayer('p1').exile.includes(doomed.id))
})
test("Leyline of the Void exiles only opponents' cards and starts on the battlefield", () => {
const leyline = card('Leyline of the Void', {
typeLine: 'Enchantment',
power: undefined,
toughness: undefined,
abilities: [
{
kind: 'static',
effects: [{ op: 'restriction', target: { kind: 'self' }, rule: 'begin_on_battlefield' }],
text: 'If this card is in your opening hand, you may begin the game with it on the battlefield.',
},
{
kind: 'static',
effects: [{ op: 'exile_instead_of_graveyard', owner: 'opponent' }],
text: "If a card would be put into an opponent's graveyard from anywhere, exile it instead.",
},
],
})
const game = new Game({
seed: 3,
startingHandSize: 0,
players: [{ id: 'p1', deck: [card('Filler')] }, { id: 'p2', deck: [card('Filler')] }],
})
const leylineObject = game.addCard('p1', leyline, 'hand')
game.start()
assert.ok(game.getPlayer('p1').battlefield.includes(leylineObject.id))
assert.ok(!game.getPlayer('p1').hand.includes(leylineObject.id))
const theirs = game.addCard('p2', creature('Their Bear', 2, 2), 'battlefield')
const own = game.addCard('p1', creature('Own Bear', 2, 2), 'battlefield')
game.moveToZone(theirs, 'graveyard')
game.moveToZone(own, 'graveyard')
assert.equal(theirs.zone, 'exile')
assert.equal(own.zone, 'graveyard')
})
test('Field of the Dead makes a Zombie at seven differently named lands', () => {
const field = card('Field of the Dead', {
typeLine: 'Land',
power: undefined,
toughness: undefined,
abilities: [{
kind: 'triggered',
event: {
kind: 'enters',
subject: {
kind: 'object',
selector: { other: true, controller: 'you', types: ['land'] },
mode: 'each',
includeSelf: true,
},
},
condition: { kind: 'distinct_names', selector: { types: ['land'] }, atLeast: 7 },
effects: [{
op: 'create_token',
player: 'you',
amount: { kind: 'number', value: 1 },
token: {
types: ['creature'],
subtypes: ['zombie'],
colors: ['B'],
power: { kind: 'number', value: 2 },
toughness: { kind: 'number', value: 2 },
},
}],
optional: false,
text: 'Whenever this or another land you control enters, if you control seven or more lands with different names, create a 2/2 black Zombie creature token.',
}],
})
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
game.addCard('p1', field, 'battlefield')
for (const name of ['Forest', 'Island', 'Mountain', 'Plains']) {
game.addCard('p1', land(name, 'C'), 'battlefield')
}
game.addCard('p1', land('Swamp', 'C'), 'battlefield', { silent: false })
game.resolveStack()
assert.equal(game.getPlayer('p1').battlefield
.map(id => game.getObject(id)).filter(object => object.isToken).length, 0)
game.addCard('p1', land('Wastes', 'C'), 'battlefield', { silent: false })
game.resolveStack()
const tokens = game.getPlayer('p1').battlefield
.map(id => game.getObject(id)).filter(object => object.isToken)
assert.equal(tokens.length, 1)
assert.equal(tokens[0].definition.typeLine.toLowerCase().includes('zombie'), true)
})