This commit is contained in:
2026-11-04 17:10:22 +01:00
parent 9ec486274f
commit c742d0cfa8
40 changed files with 12394 additions and 9414 deletions

View File

@@ -0,0 +1,204 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { Game, GameError } from '../src/game/game.js'
import { compileText } from '../src/effects/compile.js'
import type { Ability, Effect, TokenSpec } from '../src/effects/types.js'
import type { CardDefinition, GameObject } from '../src/game/types.js'
import { card, creature, spell, land, exoticOrchard, setup, tokenMaker, tokenDoubler, makeToken, addMana, roleMaker, shockLand } from './helpers.js'
test('a search that shuffles and puts the chosen card on top leaves it on top', () => {
const bear = creature('Bear', 2, 2)
const elf = creature('Elf', 1, 1)
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const bearObject = game.addCard('p1', bear, 'library')
const elfObject = game.addCard('p1', elf, 'library')
const worldlyTutor = game.addCard('p1', spell('Worldly Tutor', [{
op: 'search',
player: 'you',
selector: { types: ['creature'] },
amount: { kind: 'number', value: 1 },
destination: 'top',
tapped: false,
shuffle: true,
}]), 'hand')
game.castSpell('p1', worldlyTutor.id)
game.resolveStack()
assert.equal(game.pendingSearch?.playerId, 'p1')
game.chooseSearchCard('p1', elfObject.id)
assert.equal(game.getPlayer('p1').library[0], elfObject.id)
assert.ok(game.getPlayer('p1').library.includes(bearObject.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()
game.addCard('p1', land('Forest', 'G'), 'library')
game.addCard('p1', land('Island', 'U'), 'library')
const rampantGrowth = game.addCard('p1', spell('Rampant Growth', [{
op: 'search',
player: 'you',
selector: { types: ['land'], supertypes: ['basic'] },
amount: { kind: 'number', value: 1 },
destination: 'battlefield',
tapped: true,
shuffle: true,
}]), 'hand')
game.castSpell('p1', rampantGrowth.id)
game.autoAdvance()
assert.equal(game.pendingSearch?.playerId, 'p1')
assert.equal(game.priority, 'p1')
})
test('static replacement effects make permanents enter tapped with counters', () => {
const slow = creature('Slow Bear', 2, 2, [{
kind: 'static',
effects: [{ op: 'enters_tapped', target: { kind: 'self' } }],
text: 'This enters tapped.',
}, {
kind: 'static',
effects: [{
op: 'enters_with_counters',
target: { kind: 'self' },
counter: '+1/+1',
amount: { kind: 'number', value: 1 },
}],
text: 'This enters with a +1/+1 counter.',
}])
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const bear = game.addCard('p1', slow, 'hand')
game.castSpell('p1', bear.id)
game.resolveStack()
assert.equal(bear.tapped, true)
assert.equal(bear.counters['+1/+1'], 1)
assert.equal(game.getPower(bear), 3)
assert.equal(game.getToughness(bear), 3)
})
function shockLand(): CardDefinition {
return card('Steam Vents', {
typeLine: 'Land — Island Mountain',
power: undefined,
toughness: undefined,
abilities: [{
kind: 'static',
effects: [{ op: 'enters_tapped', target: { kind: 'self' }, unlessCost: { kind: 'pay_life', amount: { kind: 'number', value: 2 } } }],
text: "As this land enters, you may pay 2 life. If you don't, it enters tapped.",
}, {
kind: 'activated',
costs: [{ kind: 'tap' }],
effects: [{ op: 'add_mana', player: 'you', mana: { kind: 'symbols', symbols: ['{U}', '{R}'], oneOf: true } }],
optional: false,
text: '{T}: Add {U} or {R}.',
}],
})
}
test('a land can pay life to enter untapped or enter tapped', () => {
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const vents = game.addCard('p1', shockLand(), 'hand')
game.playLand('p1', vents.id)
assert.equal(vents.tapped, false)
assert.equal(game.pendingChoice?.what, 'pay_cost')
assert.equal(game.pendingChoice?.amount, 2)
assert.throws(() => game.chooseCostPayment('p2', true), GameError)
game.chooseCostPayment('p1', true)
assert.equal(game.getPlayer('p1').life, 38)
assert.equal(vents.tapped, false)
assert.equal(game.pendingChoice, undefined)
const second = game.addCard('p1', shockLand(), 'hand')
game.moveToZone(second, 'battlefield', { controller: 'p1', silent: false })
assert.equal(game.pendingChoice?.what, 'pay_cost')
game.chooseCostPayment('p1', false)
assert.equal(second.tapped, true)
assert.equal(game.getPlayer('p1').life, 38)
})
test('a choice mana ability adds only the color the spell needs', () => {
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const vents = game.addCard('p1', shockLand(), 'battlefield')
const red = game.addCard('p1', spell('Red Spell', [], '{R}'), 'hand')
game.castSpell('p1', red.id)
assert.equal(vents.tapped, true)
assert.equal(game.getPlayer('p1').manaPool.R, 0)
assert.equal(game.getPlayer('p1').manaPool.U, 0)
})