hathora-et-labora-game
Version:
Game logic reducer for Uwe Rosenberg's Ora et Labora
31 lines • 1.38 kB
JavaScript
import { pipe } from 'ramda';
import { match } from 'ts-pattern';
import { revertActivePlayerToCurrent, setFrameToAllowFreeUsage, withFrame } from '../board/frame';
import { moveClergyToOwnBuilding } from '../board/landscape';
import { GameCommandEnum, NextUseClergy } from '../types';
const withAnyForCurrentPlayer = withFrame((frame) => ({
...frame,
nextUse: NextUseClergy.Any,
}));
const checkActivePlayerIsNotCurrent = withFrame((frame) => {
if (frame.activePlayerIndex === frame.currentPlayerIndex)
return undefined;
return frame;
});
const checkHasExactlyOneUsableBuilding = withFrame((frame) => {
if (frame.usableBuildings.length !== 1)
return undefined;
return frame;
});
export const withLaybrother = (state) => {
if (state === undefined)
return undefined;
return pipe(
//
checkActivePlayerIsNotCurrent, checkHasExactlyOneUsableBuilding, withAnyForCurrentPlayer, moveClergyToOwnBuilding(state.frame.usableBuildings[0]), setFrameToAllowFreeUsage([state.frame.usableBuildings[0]]), revertActivePlayerToCurrent)(state);
};
export const complete = (state) => (partial) => match(partial)
.with([], () => (checkActivePlayerIsNotCurrent(state) ? [GameCommandEnum.WITH_LAYBROTHER] : []))
.with([GameCommandEnum.WITH_LAYBROTHER], () => [''])
.otherwise(() => []);
//# sourceMappingURL=withLaybrother.js.map