recipe-calculation
Calculate the cheapest tree traversal, price and used items of crafting recipes.
This is part of gw2efficiency. Please report all issues in the central repository.
Installation •
Usage •
Contributors •
License
Installation
yarn add @gw2efficiency/recipe-calculation
The recipe trees this package consumes are generated via
@gw2efficiency/recipe-nesting
.
Usage
Calculate the cheapest tree
import {cheapestTree} from '@gw2efficiency/recipe-calculation'
const amount = 1
const recipeTree = {
id: 13243,
quantity: 5,
output: 1,
components: []
}
const itemPrices = {1: 123, 2: 42, 3: 1337}
const availableItems = {1: 1, 2: 250, 3: 5}
const craftingDisabled = [1337, 42]
const calculatedTree = cheapestTree(amount, recipeTree, itemPrices, availableItems, craftingDisabled)
{
id: 13243,
quantity: 5,
output: 1,
components: [],
totalQuantity: 5,
usedQuantity: 5,
craft: true,
buyPrice: 50,
buyPriceEach: 10,
craftPrice: 42
}
Update tree quantities & prices
If you want to update the tree, because the amount
, availableItems
or itemPrices
changed or
the user flipped a craft
flag, you should use this method. This updates the following keys:
totalQuantity
, usedQuantity
, buyPrice
, buyPriceEach
and craftPrice
This method does not change any craft
flags (= uses the pre-calculated best tree). If you want
to recalculate the cheapest tree, just use cheapestTree
again!
import { updateTree } from '@gw2efficiency/recipe-calculation'
const amount = 1
const calculatedTree = {
}
const itemPrices = { 1: 123, 2: 42, 3: 1337 }
const availableItems = { 1: 1, 2: 250, 3: 5 }
const updatedTree = updateTree(amount, calculatedTree, itemPrices, availableItems)
Generate list of items to buy & used available items
import {usedItems} from '@gw2efficiency/recipe-calculation'
const calculatedTree = {}
const usedItemsMap = usedItems(calculatedTree)
{
buy: {1: 5, 3: 10, },
available: {1: 10, 2: 5, }
}
Generate list of crafting steps
import {craftingSteps} from '@gw2efficiency/recipe-calculation'
const calculatedTree = {}
const craftingStepsArray = craftingSteps(calculatedTree)
[
{
id: 1,
quantity: 10,
components: [
{id: 2, quantity: 20},
{id: 3, quantity: 10}
]
},
]
Static content
import {staticItems} from '@gw2efficiency/recipe-calculation'
const dailyCooldowns = staticItems.dailyCooldowns
const buyableDailyCooldowns = staticItems.buyableDailyCooldowns
const vendorItems = staticItems.vendorItems
{
20798: {
type: 'spirit-shard',
quantity: 1,
cost: 1,
npcs: [
{name: 'Miyani / Mystic Forge Attendant', position: 'Mystic Forge'}
]
},
}
Helpers
import { recipeItems, dailyCooldowns, useVendorPrices } from '@gw2efficiency/recipe-calculation'
const recipeTree = {
}
const itemIds = recipeItems(recipeTree)
const calculatedTree = {
}
const cooldownItemsMap = dailyCooldowns(calculatedTree)
const prices = useVendorPrices({ 1: 1233, 19750: 50000 })
Contributors
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors
specification. Contributions of any kind welcome!
License
MIT