160 lines
5.1 KiB
TypeScript
160 lines
5.1 KiB
TypeScript
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'
|
|
|
|
export function card(name: string, overrides: Partial<CardDefinition> = {}): CardDefinition {
|
|
return {
|
|
oracleId: name.toLowerCase().replace(/[^a-z0-9]+/g, '-'),
|
|
name,
|
|
typeLine: 'Creature — Test',
|
|
manaValue: 0,
|
|
colors: [],
|
|
abilities: [],
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function creature(name: string, power: number, toughness: number, abilities: Ability[] = []): CardDefinition {
|
|
return card(name, { typeLine: 'Creature — Test', power, toughness, abilities })
|
|
}
|
|
|
|
export function spell(name: string, effects: Effect[], manaCost = ''): CardDefinition {
|
|
return card(name, { typeLine: 'Instant', manaCost, manaValue: 0, abilities: [{ kind: 'spell', effects, optional: false, text: name }] })
|
|
}
|
|
|
|
export function land(name: string, color: string): CardDefinition {
|
|
return card(name, {
|
|
typeLine: `Basic Land — ${name}`,
|
|
power: undefined,
|
|
toughness: undefined,
|
|
abilities: [{
|
|
kind: 'activated',
|
|
costs: [{ kind: 'tap' }],
|
|
effects: [{ op: 'add_mana', player: 'you', mana: { kind: 'symbols', symbols: [`{${color}}`] } }],
|
|
optional: false,
|
|
text: `{T}: Add {${color}}.`,
|
|
}],
|
|
})
|
|
}
|
|
|
|
export function exoticOrchard(): CardDefinition {
|
|
return card('Exotic Orchard', {
|
|
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,
|
|
restriction: 'a land an opponent controls could produce',
|
|
},
|
|
}],
|
|
optional: false,
|
|
text: '{T}: Add one mana of any color that a land an opponent controls could produce.',
|
|
}],
|
|
})
|
|
}
|
|
|
|
export function setup(players: { id: string; deck?: CardDefinition[]; life?: number }[]): Game {
|
|
const game = new Game({
|
|
seed: 7,
|
|
startingHandSize: 0,
|
|
players: players.map(player => ({ id: player.id, life: player.life, deck: player.deck ?? [card('Filler')] })),
|
|
})
|
|
return game
|
|
}
|
|
|
|
export 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.',
|
|
}],
|
|
})
|
|
}
|
|
|
|
export 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.',
|
|
}],
|
|
})
|
|
}
|
|
|
|
export 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]
|
|
}
|
|
|
|
export 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)
|
|
}
|
|
}
|
|
|
|
export 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.`,
|
|
}],
|
|
})
|
|
}
|
|
|
|
|
|
export 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}.',
|
|
}],
|
|
})
|
|
}
|