diff --git a/src/task-113.js b/src/task-113.js index 0a6df3c..7f9eed7 100644 --- a/src/task-113.js +++ b/src/task-113.js @@ -4,6 +4,7 @@ */ +import {and, or} from 'xstate'; import {base} from './task-lib.js'; const machine = base.createMachine({ @@ -14,12 +15,16 @@ const machine = base.createMachine({ 'task.selected': [ { target: 'work', - guard: { - type: 'enough-supply?', + guard: and(['has-empty-fields?', or(['has-grain?', + 'has-vegetable?'])]), + actions: { + type: 'abort', params: { - grain: 1 + task_id: 113, + err: 'TODO' } } + }, { actions: { diff --git a/src/task-lib.js b/src/task-lib.js index 292dea2..c3be638 100644 --- a/src/task-lib.js +++ b/src/task-lib.js @@ -101,6 +101,32 @@ export const base = setup({ const {supply} = game_context; const checks = Object.entries(params); return checks.every(([k, min]) => supply[k] >= min); + }, + + // True if there is at least one grain available in the supply. + 'has-grain?': + ({event: {game_context}}) => { + const {supply} = game_context; + return supply.grain > 0; + }, + + // True if there is at least one vegetable available in the supply. + 'has-vegetable?': + ({event: {game_context}}) => { + const {supply} = game_context; + return supply.vegetable > 0; + }, + + // True if there is at least one empty field. + 'has-empty-fields?': + ({event: {game_context}}) => { + const {farmyard} = game_context; + const spaces = Object.values(farmyard); + return spaces.some(space => { + if (space?.type !== 'field') return false; + const {grain = 0, vegetable = 0} = space; + return !grain && !vegetable; + }); } } });