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,155 @@
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('Exotic Orchard is limited to colors an opponent land could produce', () => {
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const orchard = game.addCard('p1', exoticOrchard(), 'battlefield')
game.addCard('p2', land('Forest', 'G'), 'battlefield')
const green = game.addCard('p1', spell('Green Spell', [], '{G}'), 'hand')
const blue = game.addCard('p1', spell('Blue Spell', [], '{U}'), 'hand')
assert.equal(game.canPlayCard('p1', green.id), true)
assert.equal(game.canPlayCard('p1', blue.id), false)
assert.throws(() => game.castSpell('p1', blue.id), GameError)
assert.equal(orchard.tapped, false)
assert.deepEqual(game.getPlayer('p1').manaPool, { W: 0, U: 0, B: 0, R: 0, G: 0, C: 0 })
game.castSpell('p1', green.id)
assert.equal(orchard.tapped, true)
assert.equal(game.getPlayer('p1').manaPool.G, 0)
})
test('Exotic Orchard adds an opponent land color when activated manually', () => {
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const orchard = game.addCard('p1', exoticOrchard(), 'battlefield')
game.addCard('p2', land('Island', 'U'), 'battlefield')
game.activateAbility('p1', orchard.id, 0)
assert.equal(game.getPlayer('p1').manaPool.U, 1)
assert.equal(game.getPlayer('p1').manaPool.W, 0)
})
test('Exotic Orchard produces nothing without an opponent land', () => {
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const orchard = game.addCard('p1', exoticOrchard(), 'battlefield')
game.activateAbility('p1', orchard.id, 0)
assert.equal(orchard.tapped, true)
assert.deepEqual(game.getPlayer('p1').manaPool, { W: 0, U: 0, B: 0, R: 0, G: 0, C: 0 })
})
test('a mana ability that makes one of several colors uses the chosen color', () => {
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const dual = game.addCard('p1', card('Dual Land', {
typeLine: 'Land',
power: undefined,
toughness: undefined,
abilities: [{
kind: 'activated',
costs: [{ kind: 'tap' }],
effects: [{ op: 'add_mana', player: 'you', mana: { kind: 'symbols', symbols: ['{W}', '{U}'], oneOf: true } }],
optional: false,
text: '{T}: Add {W} or {U}.',
}],
}), 'battlefield')
assert.deepEqual(game.manaColorChoices(dual, 0), ['W', 'U'])
game.activateAbility('p1', dual.id, 0, { manaColor: 'U' })
assert.equal(game.getPlayer('p1').manaPool.U, 1)
assert.equal(game.getPlayer('p1').manaPool.W, 0)
})
test('a mana color the ability cannot make is rejected before tapping', () => {
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const mono = game.addCard('p1', land('Mono Land', 'W'), 'battlefield')
assert.throws(() => game.activateAbility('p1', mono.id, 0, { manaColor: 'G' }), GameError)
assert.equal(mono.tapped, false)
assert.equal(game.getPlayer('p1').manaPool.G, 0)
})
test('an any-color mana source produces the chosen color and offers all five', () => {
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const rainbow = game.addCard('p1', card('Rainbow Land', {
typeLine: 'Land',
power: undefined,
toughness: undefined,
abilities: [{
kind: 'activated',
costs: [{ kind: 'tap' }],
effects: [{ op: 'add_mana', player: 'you', mana: { kind: 'any_color', amount: { kind: 'number', value: 1 }, oneColor: false } }],
optional: false,
text: '{T}: Add one mana of any color.',
}],
}), 'battlefield')
assert.deepEqual(game.manaColorChoices(rainbow, 0), ['W', 'U', 'B', 'R', 'G'])
game.activateAbility('p1', rainbow.id, 0, { manaColor: 'R' })
assert.equal(game.getPlayer('p1').manaPool.R, 1)
})
test('a restricted mana source is used before an unrestricted one', () => {
const rainbow = card('Rainbow Land', {
typeLine: 'Land',
power: undefined,
toughness: undefined,
abilities: [{
kind: 'activated',
costs: [{ kind: 'tap' }],
effects: [{ op: 'add_mana', player: 'you', mana: { kind: 'any_color', amount: { kind: 'number', value: 1 }, oneColor: false } }],
optional: false,
text: '{T}: Add one mana of any color.',
}],
})
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const rainbowLand = game.addCard('p1', rainbow, 'battlefield')
const orchard = game.addCard('p1', exoticOrchard(), 'battlefield')
game.addCard('p2', land('Forest', 'G'), 'battlefield')
const gold = game.addCard('p1', spell('Gold Spell', [], '{G}{U}'), 'hand')
assert.equal(game.canPlayCard('p1', gold.id), true)
game.castSpell('p1', gold.id)
assert.equal(orchard.tapped, true)
assert.equal(rainbowLand.tapped, true)
assert.deepEqual(game.getPlayer('p1').manaPool, { W: 0, U: 0, B: 0, R: 0, G: 0, C: 0 })
})
test('static pump effects apply to matching creatures only', () => {
const anthem = card('Glorious Anthem', {
typeLine: 'Enchantment',
power: undefined,
toughness: undefined,
abilities: [{
kind: 'static',
effects: [{
op: 'pump',
target: { kind: 'object', selector: { controller: 'you', types: ['creature'] }, mode: 'each' },
power: { kind: 'number', value: 1 },
toughness: { kind: 'number', value: 1 },
}],
text: 'Creatures you control get +1/+1.',
}],
})
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const anthemObject = game.addCard('p1', anthem, 'battlefield')
const bear = game.addCard('p1', creature('Grizzly Bears', 2, 2), 'battlefield')
const enemy = game.addCard('p2', creature('Enemy Bear', 2, 2), 'battlefield')
assert.equal(game.getPower(bear), 3)
assert.equal(game.getToughness(bear), 3)
assert.equal(game.getPower(enemy), 2)
assert.equal(game.getPower(anthemObject), 0)
})