Fa triggers malament

This commit is contained in:
2026-10-29 20:30:29 +01:00
parent bc05b63083
commit 9ec486274f
16 changed files with 2287 additions and 128 deletions

View File

@@ -84,6 +84,46 @@ Deck
assert.match(result.errors.join(' '), /exactly 100/)
})
test('a commander identity mana source only offers colors in the identity', () => {
const game = new Game({
seed: 1,
startingHandSize: 0,
commander: true,
players: [
{ id: 'p1', deck: [basicLand('Forest')], commander: commanderDefinition('Test Commander', { colors: ['U', 'R'], colorIdentity: ['U', 'R'] }) },
{ id: 'p2', deck: [basicLand('Forest')], commander: commanderDefinition('Other Commander') },
],
})
game.start()
const tower = game.addCard('p1', {
oracleId: 'command-tower',
name: 'Command Tower',
typeLine: 'Land',
abilities: [{
kind: 'activated',
costs: [{ kind: 'tap' }],
effects: [{
op: 'add_mana',
player: 'you',
mana: {
kind: 'any_color',
amount: { kind: 'number', value: 1 },
oneColor: false,
restriction: "commander's color identity",
},
}],
optional: false,
text: "{T}: Add one mana of any color in your commander's color identity.",
}],
}, 'battlefield')
assert.deepEqual(game.manaColorChoices(tower, 0), ['U', 'R'])
assert.throws(() => game.activateAbility('p1', tower.id, 0, { manaColor: 'G' }), /cannot produce/)
assert.equal(tower.tapped, false)
game.activateAbility('p1', tower.id, 0, { manaColor: 'R' })
assert.equal(game.getPlayer('p1').manaPool.R, 1)
})
test('a commander starts in the command zone, pays tax, and returns there from the graveyard', () => {
const commander = commanderDefinition('Test Commander')
const game = new Game({
@@ -91,8 +131,8 @@ test('a commander starts in the command zone, pays tax, and returns there from t
startingHandSize: 0,
commander: true,
players: [
{ id: 'p1', deck: [], commander },
{ id: 'p2', deck: [], commander: commanderDefinition('Other Commander') },
{ id: 'p1', deck: [basicLand('Forest')], commander },
{ id: 'p2', deck: [basicLand('Forest')], commander: commanderDefinition('Other Commander') },
],
})
game.start()
@@ -138,8 +178,8 @@ test('twenty-one commander damage loses the game', () => {
startingHandSize: 0,
commander: true,
players: [
{ id: 'p1', deck: [], commander },
{ id: 'p2', deck: [], commander: commanderDefinition('Other Commander') },
{ id: 'p1', deck: [basicLand('Forest')], commander },
{ id: 'p2', deck: [basicLand('Forest')], commander: commanderDefinition('Other Commander') },
],
})
game.start()

View File

@@ -175,6 +175,24 @@ test('static anthem', () => {
assert.equal(target.selector.controller, 'you')
})
test('negative colors become an excluded color filter', () => {
const [ability] = spell('Destroy target nonblack creature.')
assert.equal(ability.kind, 'spell')
if (ability.kind !== 'spell') return
assert.deepEqual(ability.effects[0], {
op: 'destroy',
target: {
kind: 'object',
selector: { types: ['creature'], excludeColors: ['B'] },
mode: 'target',
},
})
const source = formatAbility(ability)
assert.match(source, /withoutColor\('black'\)/)
assert.equal(formatAbility(parseCardSource(`export default [${source}]`).abilities[0]), source)
})
test('enters-with-counters is a static replacement effect', () => {
const [ability] = creature('This creature enters with X +1/+1 counters on it.')
assert.equal(ability.kind, 'static')
@@ -234,6 +252,36 @@ test('token copy of the triggering nontoken Dragon loses legendary', () => {
)
})
test('token-doubling replacement lines compile and round-trip', () => {
const cases: Array<[string, object]> = [
[
'If an effect would create one or more tokens under your control, it creates twice that many of those tokens instead.',
{ op: 'token_multiplier', multiplier: 2, who: 'you' },
],
[
'If one or more tokens would be created under your control, twice that many of those tokens are created instead.',
{ op: 'token_multiplier', multiplier: 2, who: 'you' },
],
[
'If one or more tokens would be created, twice that many of those tokens are created instead.',
{ op: 'token_multiplier', multiplier: 2, who: 'each_player' },
],
[
'If one or more creature tokens would be created under your control, three times that many of those tokens are created instead.',
{ op: 'token_multiplier', multiplier: 3, who: 'you', creatureOnly: true },
],
]
for (const [text, expected] of cases) {
const [ability] = creature(text)
assert.equal(ability.kind, 'static')
if (ability.kind !== 'static') return
assert.deepEqual(ability.effects[0], expected)
const source = formatAbility(ability)
assert.equal(formatAbility(parseCardSource(`export default [${source}]`).abilities[0]), source)
}
})
test('all effects are typed', () => {
const [ability] = spell('Draw two cards, then discard a card.')
assert.equal(ability.kind, 'spell')
@@ -577,3 +625,24 @@ test('new abilities, effects and conditions round-trip through card source', ()
assert.equal(formatAbility(reparsed), source)
}
})
test('Role token creation compiles with the attachment target', () => {
for (const role of ['Cursed', 'Monster', 'Royal', 'Sorcerer', 'Virtuous', 'Wicked', 'Young Hero']) {
const [ability] = spell(`Create a ${role} Role token attached to target creature you control.`)
assert.equal(ability.kind, 'spell')
if (ability.kind !== 'spell') return
const effect = ability.effects[0]
assert.equal(effect.op, 'create_token')
if (effect.op !== 'create_token') return
assert.equal(effect.token.name, role)
assert.deepEqual(effect.token.subtypes, ['aura', 'role'])
assert.deepEqual(effect.attachTo, {
kind: 'object',
selector: { controller: 'you', types: ['creature'] },
mode: 'target',
})
const source = formatAbility(ability)
assert.equal(formatAbility(parseCardSource(`export default [${source}]`).abilities[0]), source)
}
})

View File

@@ -1,8 +1,8 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { Game, GameError } from '../src/game/game.js'
import type { Ability, Effect } from '../src/effects/types.js'
import type { CardDefinition } from '../src/game/types.js'
import type { Ability, Effect, TokenSpec } from '../src/effects/types.js'
import type { CardDefinition, GameObject } from '../src/game/types.js'
function card(name: string, overrides: Partial<CardDefinition> = {}): CardDefinition {
return {
@@ -72,6 +72,71 @@ function setup(players: { id: string; deck?: CardDefinition[]; life?: number }[]
return game
}
function tokenMaker(name: string, token: TokenSpec): CardDefinition {
return card(name, {
typeLine: 'Artifact',
abilities: [{
kind: 'activated',
costs: [{ kind: 'tap' }],
effects: [{ op: 'create_token', player: 'you', amount: { kind: 'number', value: 1 }, token }],
optional: false,
text: '{T}: Create a token.',
}],
})
}
function tokenDoubler(
name: string,
multiplier: number,
who: 'you' | 'each_player' = 'you',
creatureOnly = false,
): CardDefinition {
return card(name, {
typeLine: 'Enchantment',
abilities: [{
kind: 'static',
effects: [{ op: 'token_multiplier', multiplier, who, ...(creatureOnly ? { creatureOnly: true } : {}) }],
text: 'Token replacement.',
}],
})
}
function makeToken(game: Game, token: TokenSpec, playerId = 'p1'): GameObject {
const maker = game.addCard(playerId, tokenMaker('Token Maker', token), 'battlefield')
game.activateAbility(playerId, maker.id, 0)
game.resolveStack()
const tokens = game.getPlayer(playerId).battlefield
.map(id => game.getObject(id))
.filter(object => object.isToken)
return tokens[tokens.length - 1]
}
function addMana(game: Game, ...symbols: string[]): void {
for (const symbol of symbols) {
const source = game.addCard('p1', land('Mana Land', symbol), 'battlefield')
game.activateAbility('p1', source.id, 0)
}
}
function roleMaker(name: string): CardDefinition {
return card(`${name} Role Maker`, {
typeLine: 'Enchantment',
abilities: [{
kind: 'activated',
costs: [{ kind: 'tap' }],
effects: [{
op: 'create_token',
player: 'you',
amount: { kind: 'number', value: 1 },
token: { name, types: ['enchantment'], subtypes: ['aura', 'role'], colors: [] },
attachTo: { kind: 'object', selector: { types: ['creature'], controller: 'you' }, mode: 'target' },
}],
optional: false,
text: `{T}: Create a ${name} Role token attached to target creature you control.`,
}],
})
}
test('turns start at the first main phase, draw opening hands, and pass to the next player', () => {
const forest = land('Forest', 'G')
const game = new Game({
@@ -90,8 +155,8 @@ test('turns start at the first main phase, draw opening hands, and pass to the n
assert.equal(game.step, 'main')
assert.equal(game.priority, 'p1')
assert.equal(game.getPlayer('p1').life, 40)
assert.equal(game.getPlayer('p1').hand.length, 7)
assert.equal(game.getPlayer('p1').library.length, 3)
assert.equal(game.getPlayer('p1').hand.length, 8)
assert.equal(game.getPlayer('p1').library.length, 2)
game.endTurn('p1')
@@ -143,7 +208,7 @@ test('mulligans draw a new seven and bottom one more card each time', () => {
assert.equal(game.status, 'active')
assert.equal(game.turn, 1)
assert.equal(game.step, 'main')
assert.equal(game.getPlayer('p1').hand.length, 5)
assert.equal(game.getPlayer('p1').hand.length, 6)
})
test('passing priority twice advances from the main phase into combat', () => {
@@ -223,6 +288,9 @@ test('hideaway exiles a card and its linked ability plays it for free once the c
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const hidden = game.addCard('p1', creature('Hidden Bear', 2, 2), 'library')
for (const name of ['Filler One', 'Filler Two', 'Filler Three']) {
game.addCard('p1', creature(name, 1, 1), 'library')
}
const library = game.getPlayer('p1').library
library.splice(library.indexOf(hidden.id), 1)
library.unshift(hidden.id)
@@ -231,8 +299,22 @@ test('hideaway exiles a card and its linked ability plays it for free once the c
game.playLand('p1', land.id)
game.resolveStack()
assert.equal(game.pendingChoice?.what, 'hideaway')
assert.equal(game.pendingChoice?.playerId, 'p1')
assert.equal(game.pendingChoice?.cardIds?.length, 4)
assert.ok(game.pendingChoice?.cardIds?.includes(hidden.id))
assert.throws(() => game.chooseHideawayCard('p2', hidden.id), GameError)
const looked = [...game.getPlayer('p1').library.slice(0, 4)]
game.chooseHideawayCard('p1', hidden.id)
assert.equal(game.pendingChoice, undefined)
assert.equal(hidden.zone, 'exile')
assert.equal(hidden.faceDown, true)
assert.deepEqual(land.linkedExile, [hidden.id])
assert.deepEqual(
game.getPlayer('p1').library.slice(-3).sort(),
looked.filter(id => id !== hidden.id).sort(),
)
game.activateAbility('p1', land.id, 1)
game.resolveStack()
@@ -243,6 +325,7 @@ test('hideaway exiles a card and its linked ability plays it for free once the c
game.resolveStack()
assert.equal(hidden.zone, 'battlefield')
assert.equal(hidden.faceDown, undefined)
assert.ok(game.getPlayer('p1').battlefield.includes(hidden.id))
})
@@ -281,6 +364,7 @@ test('playing a card hidden by hideaway uses the land drop', () => {
game.playLand('p1', source.id)
game.resolveStack()
assert.equal(hidden.zone, 'exile')
assert.equal(hidden.faceDown, true)
game.getPlayer('p1').landPlayedThisTurn = true
game.activateAbility('p1', source.id, 1)
@@ -399,6 +483,59 @@ test('Exotic Orchard produces nothing without an opponent land', () => {
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',
@@ -475,6 +612,58 @@ test('temporary pump effects expire at end of turn', () => {
assert.equal(game.getPower(bear), 2)
})
test('the engine exposes legal creature targets for a card', () => {
const game = setup([{ id: 'p1', deck: Array.from({ length: 3 }, () => card('Filler')) }, { id: 'p2', deck: Array.from({ length: 3 }, () => card('Filler')) }])
game.start()
const bear = game.addCard('p2', creature('Grizzly Bears', 2, 2), 'battlefield')
const growth = game.addCard('p1', spell('Giant Growth', [{
op: 'pump',
target: { kind: 'object', selector: { types: ['creature'] }, mode: 'target' },
power: { kind: 'number', value: 3 },
toughness: { kind: 'number', value: 3 },
duration: 'until_end_of_turn',
}]), 'hand')
assert.deepEqual(game.legalTargetsForCard('p1', growth.id), [{ kind: 'object', id: bear.id }])
})
test('excluded colors filter legal targets', () => {
const game = setup([{ id: 'p1', deck: Array.from({ length: 3 }, () => card('Filler')) }, { id: 'p2', deck: Array.from({ length: 3 }, () => card('Filler')) }])
game.start()
game.addCard('p2', card('Black Bear', { typeLine: 'Creature — Bear', colors: ['B'], power: 2, toughness: 2 }), 'battlefield')
const green = game.addCard('p2', card('Green Bear', { typeLine: 'Creature — Bear', colors: ['G'], power: 2, toughness: 2 }), 'battlefield')
const doomBlade = game.addCard('p1', spell('Doom Blade', [{
op: 'destroy',
target: { kind: 'object', selector: { types: ['creature'], excludeColors: ['B'] }, mode: 'target' },
}]), 'hand')
assert.deepEqual(game.legalTargetsForCard('p1', doomBlade.id), [{ kind: 'object', id: green.id }])
})
test('the engine exposes legal targets for an activated ability', () => {
const game = setup([{ id: 'p1', deck: Array.from({ length: 3 }, () => card('Filler')) }, { id: 'p2', deck: Array.from({ length: 3 }, () => card('Filler')) }])
game.start()
const bear = game.addCard('p2', creature('Grizzly Bears', 2, 2), 'battlefield')
const pinger = game.addCard('p1', card('Pinger', {
typeLine: 'Creature — Test',
power: 1,
toughness: 1,
abilities: [{
kind: 'activated',
costs: [],
optional: false,
text: '{T}: This creature deals 1 damage to target creature an opponent controls.',
effects: [{
op: 'damage',
target: { kind: 'object', selector: { controller: 'opponent', types: ['creature'] }, mode: 'target' },
amount: { kind: 'number', value: 1 },
}],
}],
}), 'battlefield')
assert.deepEqual(game.legalTargetsForAbility('p1', pinger.id, 0), [{ kind: 'object', id: bear.id }])
})
test('"until the end of your next turn" lasts through the controller next turn', () => {
const game = setup([{ id: 'p1', deck: Array.from({ length: 3 }, () => card('Filler')) }, { id: 'p2', deck: Array.from({ length: 3 }, () => card('Filler')) }])
game.start()
@@ -590,6 +779,86 @@ test('activated abilities create tokens that enter the battlefield', () => {
assert.equal(game.getPower(tokens[0]), 1)
})
test('token doublers stack and only apply to their controller', () => {
const goblin: TokenSpec = {
types: ['creature'],
subtypes: ['goblin'],
colors: ['R'],
power: { kind: 'number', value: 1 },
toughness: { kind: 'number', value: 1 },
}
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const p1Maker = game.addCard('p1', tokenMaker('P1 Maker', goblin), 'battlefield')
game.addCard('p1', tokenDoubler('Parallel Lives', 2), 'battlefield')
game.addCard('p1', tokenDoubler('Anointed Procession', 2), 'battlefield')
const p2Maker = game.addCard('p2', tokenMaker('P2 Maker', goblin), 'battlefield')
game.addCard('p2', tokenDoubler('Adrix and Nev', 2), 'battlefield')
const tokensOf = (playerId: string): number => game.getPlayer(playerId).battlefield
.map(id => game.getObject(id)).filter(object => object.isToken).length
game.activateAbility('p1', p1Maker.id, 0)
game.resolveStack()
assert.equal(tokensOf('p1'), 4)
assert.equal(tokensOf('p2'), 0)
game.endTurn('p1')
game.activateAbility('p2', p2Maker.id, 0)
game.resolveStack()
assert.equal(tokensOf('p2'), 2)
})
test('Primal Vigor doubles tokens for every player', () => {
const goblin: TokenSpec = {
types: ['creature'],
subtypes: ['goblin'],
colors: ['R'],
power: { kind: 'number', value: 1 },
toughness: { kind: 'number', value: 1 },
}
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const p1Maker = game.addCard('p1', tokenMaker('P1 Maker', goblin), 'battlefield')
game.addCard('p1', tokenDoubler('Primal Vigor', 2, 'each_player'), 'battlefield')
const p2Maker = game.addCard('p2', tokenMaker('P2 Maker', goblin), 'battlefield')
const tokensOf = (playerId: string): number => game.getPlayer(playerId).battlefield
.map(id => game.getObject(id)).filter(object => object.isToken).length
game.activateAbility('p1', p1Maker.id, 0)
game.resolveStack()
assert.equal(tokensOf('p1'), 2)
game.endTurn('p1')
game.activateAbility('p2', p2Maker.id, 0)
game.resolveStack()
assert.equal(tokensOf('p2'), 2)
})
test('Ojer Taq triples creature tokens but not other tokens', () => {
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const creatureMaker = game.addCard('p1', tokenMaker('Creature Maker', {
types: ['creature'],
subtypes: ['goblin'],
colors: ['R'],
power: { kind: 'number', value: 1 },
toughness: { kind: 'number', value: 1 },
}), 'battlefield')
const treasureMaker = game.addCard('p1', tokenMaker('Treasure Maker', {
types: ['artifact'], subtypes: ['treasure'], colors: [],
}), 'battlefield')
game.addCard('p1', tokenDoubler('Ojer Taq', 3, 'you', true), 'battlefield')
game.activateAbility('p1', creatureMaker.id, 0)
game.resolveStack()
game.activateAbility('p1', treasureMaker.id, 0)
game.resolveStack()
const tokens = game.getPlayer('p1').battlefield.map(id => game.getObject(id)).filter(object => object.isToken)
assert.equal(tokens.filter(object => object.definition.typeLine.toLowerCase().includes('creature')).length, 3)
assert.equal(tokens.filter(object => object.definition.typeLine.toLowerCase().includes('treasure')).length, 1)
})
test('search effects find cards in the library and put them onto the battlefield tapped', () => {
const forest = land('Forest', 'G')
const game = setup([{ id: 'p1' }, { id: 'p2' }])
@@ -648,6 +917,33 @@ test('search effects let the player pick among multiple matching cards', () => {
assert.ok(game.getPlayer('p1').library.includes(forestObject.id))
})
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',
@@ -1031,7 +1327,7 @@ test('counter-removal costs are paid and fail when counters run out', () => {
game.activateAbility('p1', source.id, 0)
game.resolveStack()
assert.equal(source.counters.spore, 1)
assert.equal(game.getPlayer('p1').hand.length, 1)
assert.equal(game.getPlayer('p1').hand.length, 2)
assert.throws(() => game.activateAbility('p1', source.id, 0), GameError)
assert.equal(source.counters.spore, 1)
@@ -1460,3 +1756,186 @@ test('Field of the Dead makes a Zombie at seven differently named lands', () =>
assert.equal(tokens.length, 1)
assert.equal(tokens[0].definition.typeLine.toLowerCase().includes('zombie'), true)
})
test('predefined Treasure, Gold, Powerstone, Heartwood, and Vibranium tokens produce mana', () => {
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const treasure = makeToken(game, { types: ['artifact'], subtypes: ['treasure'], colors: [] })
assert.equal(treasure.definition.name, 'Treasure')
game.activateAbility('p1', treasure.id, 0, { manaColor: 'G' })
assert.equal(game.getPlayer('p1').manaPool.G, 1)
assert.equal(treasure.zone, 'graveyard')
const gold = makeToken(game, { types: ['artifact'], subtypes: ['gold'], colors: [] })
game.activateAbility('p1', gold.id, 0, { manaColor: 'R' })
assert.equal(game.getPlayer('p1').manaPool.R, 1)
const powerstone = makeToken(game, { types: ['artifact'], subtypes: ['powerstone'], colors: [] })
game.activateAbility('p1', powerstone.id, 0)
assert.equal(game.getPlayer('p1').manaPool.C, 1)
const heartwood = makeToken(game, { types: ['artifact'], subtypes: ['heartwood'], colors: [] })
game.activateAbility('p1', heartwood.id, 0, { manaColor: 'G' })
assert.equal(game.getPlayer('p1').manaPool.G, 2)
const vibranium = makeToken(game, { types: ['artifact'], subtypes: ['vibranium'], colors: [] })
assert.equal(game.hasKeyword(vibranium, 'Indestructible'), true)
game.activateAbility('p1', vibranium.id, 0)
assert.equal(game.getPlayer('p1').manaPool.C, 2)
})
test('predefined Food, Clue, Blood, and Shard tokens sacrifice for their effects', () => {
const game = setup([{
id: 'p1',
deck: Array.from({ length: 6 }, (_, index) => card(`Filler ${index}`)),
}, { id: 'p2' }])
game.start()
const food = makeToken(game, { types: ['artifact'], subtypes: ['food'], colors: [] })
addMana(game, 'G', 'G')
game.activateAbility('p1', food.id, 0)
game.resolveStack()
assert.equal(game.getPlayer('p1').life, 43)
assert.equal(food.zone, 'graveyard')
game.addCard('p1', card('Discard Fodder'), 'hand')
const discard = game.getObject(game.getPlayer('p1').hand[0])
const handAfterFood = game.getPlayer('p1').hand.length
const blood = makeToken(game, { types: ['artifact'], subtypes: ['blood'], colors: [] })
addMana(game, 'G')
game.activateAbility('p1', blood.id, 0)
game.resolveStack()
assert.equal(discard.zone, 'graveyard')
assert.equal(game.getPlayer('p1').hand.length, handAfterFood)
const clue = makeToken(game, { types: ['artifact'], subtypes: ['clue'], colors: [] })
addMana(game, 'G', 'G')
game.activateAbility('p1', clue.id, 0)
game.resolveStack()
assert.equal(game.getPlayer('p1').hand.length, handAfterFood + 1)
const shard = makeToken(game, { types: ['enchantment'], subtypes: ['shard'], colors: [] })
addMana(game, 'G', 'G')
game.activateAbility('p1', shard.id, 0)
game.resolveStack()
assert.equal(game.getPlayer('p1').hand.length, handAfterFood + 2)
})
test('Walker and Incubator tokens use their predefined characteristics', () => {
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const walker = makeToken(game, { types: ['artifact'], subtypes: ['walker'], colors: [] })
assert.equal(walker.definition.name, 'Walker')
assert.equal(game.getPower(walker), 2)
assert.equal(game.getToughness(walker), 2)
assert.deepEqual(walker.definition.colors, ['B'])
const maker = game.addCard('p1', card('Incubator Maker', {
typeLine: 'Artifact',
abilities: [{
kind: 'activated',
costs: [{ kind: 'tap' }],
effects: [{ op: 'keyword_action', action: 'incubate', amount: { kind: 'number', value: 2 } }],
optional: false,
text: '{T}: Incubate 2.',
}],
}), 'battlefield')
game.activateAbility('p1', maker.id, 0)
game.resolveStack()
const incubator = game.getPlayer('p1').battlefield
.map(id => game.getObject(id))
.find(object => object.isToken && object.definition.name === 'Incubator')
assert.ok(incubator)
assert.equal(incubator.counters['+1/+1'], 2)
addMana(game, 'G', 'G')
game.activateAbility('p1', incubator.id, 0)
game.resolveStack()
assert.equal(incubator.definition.name, 'Phyrexian')
assert.equal(game.getPower(incubator), 2)
assert.equal(game.getToughness(incubator), 2)
})
test('predefined Map, Lander, and Mutagen tokens use their activated abilities', () => {
const mapGame = setup([{ id: 'p1', deck: [card('Filler')] }, { id: 'p2' }])
mapGame.start()
const topCard = mapGame.addCard('p1', card('Top Card'), 'library')
const bear = mapGame.addCard('p1', creature('Bear', 2, 2), 'battlefield')
addMana(mapGame, 'G')
const map = makeToken(mapGame, { types: ['artifact'], subtypes: ['map'], colors: [] })
mapGame.activateAbility('p1', map.id, 0, { targets: [{ kind: 'object', id: bear.id }] })
mapGame.resolveStack()
assert.equal(bear.counters['+1/+1'], 1)
assert.equal(topCard.zone, 'graveyard')
addMana(mapGame, 'G')
const mutagen = makeToken(mapGame, { types: ['artifact'], subtypes: ['mutagen'], colors: [] })
mapGame.activateAbility('p1', mutagen.id, 0, { targets: [{ kind: 'object', id: bear.id }] })
mapGame.resolveStack()
assert.equal(bear.counters['+1/+1'], 2)
const landGame = setup([{ id: 'p1', deck: [card('Filler')] }, { id: 'p2' }])
landGame.start()
const forest = landGame.addCard('p1', land('Forest', 'G'), 'library')
addMana(landGame, 'G', 'G')
const lander = makeToken(landGame, { types: ['artifact'], subtypes: ['lander'], colors: [] })
landGame.activateAbility('p1', lander.id, 0)
landGame.resolveStack()
assert.equal(forest.zone, 'battlefield')
assert.equal(forest.tapped, true)
})
test('Junk exiles the top card and lets its controller cast it that turn', () => {
const game = setup([{ id: 'p1', deck: [card('Filler')] }, { id: 'p2' }])
game.start()
const exiled = game.addCard('p1', spell('Top Spell', [], ''), 'library')
const junk = makeToken(game, { types: ['artifact'], subtypes: ['junk'], colors: [] })
game.activateAbility('p1', junk.id, 0)
game.resolveStack()
assert.equal(exiled.zone, 'exile')
assert.equal(game.canPlayCard('p1', exiled.id), true)
game.castSpell('p1', exiled.id)
game.resolveStack()
assert.equal(exiled.zone, 'graveyard')
})
test('Role tokens attach to the target creature and apply their abilities', () => {
const game = setup([{ id: 'p1' }, { id: 'p2' }])
game.start()
const bear = game.addCard('p1', creature('Bear', 2, 2), 'battlefield')
const maker = game.addCard('p1', roleMaker('Monster'), 'battlefield')
assert.deepEqual(game.legalTargetsForAbility('p1', maker.id, 0), [{ kind: 'object', id: bear.id }])
game.activateAbility('p1', maker.id, 0, { targets: [{ kind: 'object', id: bear.id }] })
game.resolveStack()
const role = game.getPlayer('p1').battlefield
.map(id => game.getObject(id))
.find(object => object.isToken)
assert.ok(role)
assert.equal(role.definition.name, 'Monster Role')
assert.match(role.definition.typeLine.toLowerCase(), /enchantment — aura role/)
assert.equal(role.attachedTo, bear.id)
assert.equal(game.getPower(bear), 3)
assert.equal(game.getToughness(bear), 3)
assert.equal(game.hasKeyword(bear, 'Trample'), true)
})
test('Young Hero Role triggers when the enchanted creature attacks with toughness 3 or less', () => {
const game = setup([{ id: 'p1' }, { id: 'p2' }])
const bear = game.addCard('p1', creature('Bear', 2, 2), 'battlefield')
game.start()
const maker = game.addCard('p1', roleMaker('Young Hero'), 'battlefield')
game.activateAbility('p1', maker.id, 0, { targets: [{ kind: 'object', id: bear.id }] })
game.resolveStack()
game.declareAttackers('p1', [{ attackerId: bear.id, defenderId: 'p2' }])
game.resolveStack()
assert.equal(bear.counters['+1/+1'], 1)
assert.equal(game.getPower(bear), 3)
})