Skip to content

Commit

Permalink
chore: fix spelling mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronvanston committed Feb 26, 2020
1 parent dbf53d9 commit f532c2c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 53 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ You can customise the products, producers and sellers within the farm library. I
{
name: 'bakery',
cost: 1000,
multipler: 1.05,
multiplier: 1.05,
produces: {
name: 'cookie`
rate: 0.1
Expand Down Expand Up @@ -250,7 +250,7 @@ You can customise the products, producers and sellers within the farm library. I
{
name: 'stall',
cost: 1000,
multipler: 1.05,
multiplier: 1.05,
products: {
name: 'cookie`
rate: 1
Expand Down Expand Up @@ -286,7 +286,7 @@ import FarmLib from '@aaronvanston/farm-lib'
const customProducers = [{
name: 'gold mind',
cost: 10000,
multipler: 1.10,
multiplier: 1.10,
produces: {
name: 'gold_ore',
rate: 0.1,
Expand All @@ -301,7 +301,7 @@ const customProducts = [{
const customSellers = [{
name: 'smelter',
cost: 10000,
multipler: 1.02,
multiplier: 1.02,
products: {
name: 'gold_ore',
rate: 1,
Expand Down
28 changes: 14 additions & 14 deletions src/Farm/Farm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getProduct, getProducer, getSeller } from '../utils/getters'
import calculateStore from '../utils/calculateStore'
import message from '../utils/message'
import { formatPrice } from '../utils/format'
import calculateMultiplerCost from '../utils/calculateMultiplerCost'
import calculateMultiplierCost from '../utils/calculateMultiplierCost'
import config from '../config'

import defaultProducers from '../catalogue/producers'
Expand Down Expand Up @@ -65,56 +65,56 @@ export default class Farm {
const producerInfo = getProducer(item as ProducerType, this.producers)
const currentQuantity = this.farmProducers[item] || 0

const multiplerCost = calculateMultiplerCost(
const multiplierCost = calculateMultiplierCost(
producerInfo.cost,
currentQuantity,
producerInfo.multiplier,
buyQuantity
)

if (this.farmBank <= multiplerCost) {
if (this.farmBank <= multiplierCost) {
return message('Not enough money', false)
}

this.farmBank -= multiplerCost
this.farmBank -= multiplierCost
this.farmProducers = calculateStore(
this.farmProducers,
item as ProducerType,
buyQuantity
)

return message(
`Bought ${item} (x${buyQuantity}) for ${formatPrice(multiplerCost)}`,
`Bought ${item} (x${buyQuantity}) for ${formatPrice(multiplierCost)}`,
true
)
} else if (item in SellerType) {
const sellerInfo = getSeller(item as SellerType, this.sellers)
const currentQuantity = this.farmSellers[item] || 0

const multiplerCost = calculateMultiplerCost(
const multiplierCost = calculateMultiplierCost(
sellerInfo.cost,
currentQuantity,
sellerInfo.multiplier,
buyQuantity
)

if (this.farmBank <= multiplerCost) {
if (this.farmBank <= multiplierCost) {
return message('Not enough money', false)
}

this.farmBank -= multiplerCost
this.farmBank -= multiplierCost
this.farmSellers = calculateStore(
this.farmSellers,
item as SellerType,
buyQuantity
)

return message(
`Bought ${item} (x${buyQuantity}) for ${formatPrice(multiplerCost)}`,
`Bought ${item} (x${buyQuantity}) for ${formatPrice(multiplierCost)}`,
true
)
} else {
return message(`Cannot find: ${item} in availible lists`, false)
return message(`Cannot find: ${item} in available lists`, false)
}
}

Expand All @@ -129,7 +129,7 @@ export default class Farm {
// Does the product exist?
// Is there enough product to sell?
if ((this.farmProducts[product] || 0) <= quantity) {
return message(`You dont have enough ${product}s to sell`, false)
return message(`You don't have enough ${product}s to sell`, false)
}

this.farmBank += productInfo.value * quantity
Expand Down Expand Up @@ -177,12 +177,12 @@ export default class Farm {
const sellerInfo = getSeller(sellerName as SellerType, this.sellers)
const productToSell = sellerInfo?.products.name
const totalSell = sellerInfo.products.rate * (quantity || 0)
const availibleProducts = Math.floor(
const availableProducts = Math.floor(
this.farmProducts[productToSell] || 0
)

// If total sell exceeds availible, only sell availible
const maxSell = Math.min(totalSell, availibleProducts)
// If total sell exceeds available, only sell available
const maxSell = Math.min(totalSell, availableProducts)

if (maxSell > 0) {
this.sell(productToSell, maxSell)
Expand Down
29 changes: 0 additions & 29 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,3 @@ import sellers from './catalogue/sellers'

export default Farm
export { producers, products, sellers }

// ----
// TEST CODE
// ----
import debugLogger from './utils/debugLogger'
const farmLib = new Farm({
handleTick: debugLogger,
})

// console.log(farmLib.buy('for_sale_sign'))
console.log(farmLib.buy('chicken', 10))
console.log(farmLib.buy('chicken'))
console.log(farmLib.buy('chicken'))
console.log(farmLib.buy('chicken'))
console.log(farmLib.buy('chicken'))
console.log(farmLib.buy('chicken'))
console.log(farmLib.buy('chicken'))
console.log(farmLib.buy('chicken'))
console.log(farmLib.buy('chicken'))
console.log(farmLib.buy('chicken'))
console.log(farmLib.buy('chicken'))
console.log(farmLib.buy('chicken'))
console.log(farmLib.buy('chicken'))

// console.log(
// farmLib.load(
// 'eyJmYXJtUHJvZHVjZXJzIjp7ImNoaWNrZW5fY29vcCI6MX0sImZhcm1Qcm9kdWN0cyI6e30sImZhcm1TZWxsZXJzIjp7ImZvcl9zYWxlX3NpZ24iOjF9LCJmYXJtQmFuayI6ODkwMDAsImRhdGUiOjE1ODE1MDY0MDE1NDF9'
// )
// )
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const addMultiplier = (
cost: number,
currentQuantity: number,
multipler: number
) => Math.floor(cost * multipler ** currentQuantity)
multiplier: number
) => Math.floor(cost * multiplier ** currentQuantity)

const calculateMultiplerCost = (
const calculateMultiplierCost = (
cost: number,
currentQuantity: number,
multipler: number,
multiplier: number,
purchaseQuantity: number
) => {
const quantities = [...Array(purchaseQuantity).keys()].map(item => {
const tempQuantity = item + currentQuantity

return tempQuantity === 0
? cost
: addMultiplier(cost, tempQuantity, multipler)
: addMultiplier(cost, tempQuantity, multiplier)
})
return quantities.reduce((total, amount) => total + amount)
}

export default calculateMultiplerCost
export default calculateMultiplierCost

0 comments on commit f532c2c

Please sign in to comment.