UNPKG

@jeremyckahn/farmhand

Version:
31 lines (24 loc) 905 B
import { moneyTotal } from '../../utils/moneyTotal.js' import { EXPERIENCE_VALUES, PURCHASEABLE_SMELTERS } from '../../constants.js' import { FORGE_AVAILABLE_NOTIFICATION } from '../../strings.js' import { addExperience } from './addExperience.js' import { showNotification } from './showNotification.js' import { updateLearnedRecipes } from './updateLearnedRecipes.js' export const purchaseSmelter = ( state: farmhand.state, smelterId: number ): farmhand.state => { const { money, purchasedSmelter } = state if (purchasedSmelter >= smelterId) return state state = { ...state, purchasedSmelter: smelterId, money: moneyTotal( money, -(PURCHASEABLE_SMELTERS.get(smelterId)?.price ?? 0) ), } state = showNotification(state, FORGE_AVAILABLE_NOTIFICATION) state = addExperience(state, EXPERIENCE_VALUES.SMELTER_ACQUIRED) return updateLearnedRecipes(state) }