@jeremyckahn/farmhand
Version:
A farming game
23 lines (18 loc) • 516 B
text/typescript
import { moneyTotal } from '../../utils/moneyTotal.js'
import { PURCHASEABLE_COMBINES } from '../../constants.js'
export const purchaseCombine = (
state: farmhand.state,
combineId: number
): farmhand.state => {
const { money, purchasedCombine } = state
if (purchasedCombine >= combineId) {
return state
}
const combine = PURCHASEABLE_COMBINES.get(combineId)
const price = combine?.price || 0
return {
...state,
purchasedCombine: combineId,
money: moneyTotal(money, -price),
}
}