@jeremyckahn/farmhand
Version:
A farming game
189 lines (178 loc) • 5.01 kB
JavaScript
import { itemType, toolType, toolLevel } from '../enums.js'
import * as items from './items.js'
import * as recipes from './recipes.js'
const coalNeededForIngots = (ingotId, amount = 1) => {
switch (ingotId) {
case recipes.bronzeIngot.id:
return amount * 2
case recipes.ironIngot.id:
return Math.round(amount * 3.5)
case recipes.silverIngot.id:
return Math.round(amount * 2.5)
case recipes.goldIngot.id:
return amount * 3
default:
return amount
}
}
const { bronzeIngot, ironIngot, silverIngot, goldIngot } = recipes
const { coal } = items
/**
* @type {farmhand.upgradesMetadata}
*/
const upgrades = {
[]: {
[]: {
id: 'hoe-default',
name: 'Basic Hoe',
nextLevel: toolLevel.BRONZE,
},
[]: {
id: 'hoe-bronze',
description: 'Gives 25% chance to retrieve seeds when digging up crops',
name: 'Bronze Hoe',
ingredients: {
[]: 8,
[]: coalNeededForIngots(bronzeIngot.id, 8),
},
nextLevel: toolLevel.IRON,
},
[]: {
id: 'hoe-iron',
description: 'Gives 50% chance to retrieve seeds when digging up crops',
name: 'Iron Hoe',
ingredients: {
[]: 8,
[]: coalNeededForIngots(ironIngot.id, 8),
},
nextLevel: toolLevel.SILVER,
},
[]: {
id: 'hoe-silver',
description: 'Gives 75% chance to retrieve seeds when digging up crops',
name: 'Silver Hoe',
ingredients: {
[]: 8,
[]: coalNeededForIngots(silverIngot.id, 8),
},
nextLevel: toolLevel.GOLD,
},
[]: {
id: 'hoe-gold',
description: 'Gives 100% chance to retrieve seeds when digging up crops',
name: 'Gold Hoe',
ingredients: {
[]: 8,
[]: coalNeededForIngots(goldIngot.id, 8),
},
isMaxLevel: true,
},
},
[]: {
[]: {
id: 'scythe-default',
name: 'Basic Scythe',
nextLevel: toolLevel.BRONZE,
},
[]: {
id: 'scythe-bronze',
description: 'Increases crop yield by 1 when harvesting',
name: 'Bronze Scythe',
ingredients: {
[]: 10,
[]: coalNeededForIngots(bronzeIngot.id, 10),
},
nextLevel: toolLevel.IRON,
},
[]: {
id: 'scythe-iron',
description: 'Increases crop yield by 2 when harvesting',
name: 'Iron Scythe',
ingredients: {
[]: 10,
[]: coalNeededForIngots(ironIngot.id, 10),
},
nextLevel: toolLevel.SILVER,
},
[]: {
id: 'scythe-silver',
description: 'Increases crop yield by 3 when harvesting',
name: 'Silver Scythe',
ingredients: {
[]: 10,
[]: coalNeededForIngots(silverIngot.id, 10),
},
nextLevel: toolLevel.GOLD,
},
[]: {
id: 'scythe-gold',
description: 'Increases crop yield by 4 when harvesting',
name: 'Gold Scythe',
ingredients: {
[]: 10,
[]: coalNeededForIngots(goldIngot.id, 10),
},
isMaxLevel: true,
},
},
[]: {
[]: {
id: 'shovel-default',
name: 'Basic Shovel',
nextLevel: toolLevel.BRONZE,
},
[]: {
id: 'shovel-bronze',
description: 'Increases chance of finding ore',
name: 'Bronze Shovel',
ingredients: {
[]: 15,
[]: coalNeededForIngots(bronzeIngot.id, 15),
},
nextLevel: toolLevel.IRON,
},
[]: {
id: 'shovel-iron',
description: 'Increases chance of finding ore',
name: 'Iron Shovel',
ingredients: {
[]: 15,
[]: coalNeededForIngots(ironIngot.id, 15),
},
nextLevel: toolLevel.SILVER,
},
[]: {
id: 'shovel-silver',
description: 'Increases chance of finding ore',
name: 'Silver Shovel',
ingredients: {
[]: 15,
[]: coalNeededForIngots(silverIngot.id, 15),
},
nextLevel: toolLevel.GOLD,
},
[]: {
id: 'shovel-gold',
description: 'Increases chance of finding ore',
name: 'Gold Shovel',
ingredients: {
[]: 15,
[]: coalNeededForIngots(goldIngot.id, 15),
},
isMaxLevel: true,
},
},
}
// add some defaults to each upgrade object
for (let toolType in upgrades) {
for (let i in upgrades[toolType]) {
Object.assign(upgrades[toolType][i], {
toolType,
value: 0,
doesPriceFluctuate: false,
type: itemType.TOOL_UPGRADE,
level: i,
})
}
}
export default upgrades