UNPKG

hathora-et-labora-game

Version:

Game logic reducer for Uwe Rosenberg's Ora et Labora

25 lines 1.12 kB
import { always, curry, pipe, view } from 'ramda'; import { P, match } from 'ts-pattern'; import { activeLens, getWonder, payCost, withActivePlayer } from '../board/player'; import { parseResourceParam } from '../board/resource'; import { removeWonder } from '../board/state'; import { ResourceEnum } from '../types'; export const sacristy = (param = '') => { const input = parseResourceParam(param); const iterations = Math.min(1, Math.max( // input.book ?? 0, input.ceramic ?? 0, input.ornament ?? 0, input.reliquary ?? 0)); return pipe(withActivePlayer(pipe( // payCost(input), getWonder(iterations))), removeWonder); }; export const complete = curry((partial, state) => match(partial) .with([], () => { const { book = 0, ceramic = 0, ornament = 0, reliquary = 0 } = view(activeLens(state), state); if (book && ceramic && ornament && reliquary) return [`${ResourceEnum.Book}${ResourceEnum.Ceramic}${ResourceEnum.Ornament}${ResourceEnum.Reliquary}`, '']; return ['']; }) .with([P._], always([''])) .otherwise(always([]))); //# sourceMappingURL=sacristy.js.map