
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
@gw2efficiency/recipe-calculation
Advanced tools
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
yarn add @gw2efficiency/recipe-calculation
The recipe trees this package consumes are generated via
@gw2efficiency/recipe-nesting
.
import {cheapestTree} from '@gw2efficiency/recipe-calculation'
// How many times do we want to craft this item
// Note: If you want to craft a item 5 times and the output of the
// recipe is 5, it will calculate 1 craft if you pass in amount = 5
const amount = 1
// A nested recipe tree, as generated from "@gw2efficiency/recipe-nesting"
const recipeTree = {
id: 13243,
quantity: 5,
output: 1,
components: [/* ... */]
}
// The item prices, as a map of item id -> price
const itemPrices = {1: 123, 2: 42, 3: 1337}
// (Optional) The available items, e.g. from the material storage, bank and characters,
// as a map of item id -> amount
const availableItems = {1: 1, 2: 250, 3: 5}
// (Optional) A list of item ids for which crafting is *disabled* when generating the
// cheapest tree (e.g. for excluding precursor crafting or daily cooldowns)
const craftingDisabled = [1337, 42]
// Calculate the tree
const calculatedTree = cheapestTree(amount, recipeTree, itemPrices, availableItems, craftingDisabled)
// The result looks like this:
{
id: 13243,
quantity: 5,
output: 1,
components: [/* ... */],
// (The following keys get set for the top level and all sub-components)
// The total quantity of this component
totalQuantity: 5,
// The total used quantity of this component. This is after
// subtracting the available items of the user. If this is 0
// then the user owns all items already.
usedQuantity: 5,
// The flag if the component should be crafted (true) or bought (false)
craft: true,
// Total buy price of the component
buyPrice: 50,
// Buy price for one of the components
buyPriceEach: 10,
// Total price to craft this component
craftPrice: 42
}
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'
// How many times do we want to craft this item
const amount = 1
// The already calculated tree (from "cheapestTree") that got changed
const calculatedTree = {
/* ... */
}
// The item prices, as a map of item id -> price
const itemPrices = { 1: 123, 2: 42, 3: 1337 }
// (Optional) The available items, e.g. from the material storage, bank and characters,
// as a map of item id -> amount
const availableItems = { 1: 1, 2: 250, 3: 5 }
// Update the tree
const updatedTree = updateTree(amount, calculatedTree, itemPrices, availableItems)
import {usedItems} from '@gw2efficiency/recipe-calculation'
// Get all item ids of a calculated recipe tree (after "cheapestTree")
const calculatedTree = {/* ... */}
const usedItemsMap = usedItems(calculatedTree)
// Generates a object with maps of item id -> amount
{
buy: {1: 5, 3: 10, /* ... */},
available: {1: 10, 2: 5, /* ... */}
}
import {craftingSteps} from '@gw2efficiency/recipe-calculation'
// Get the crafting steps of a calculated recipe tree (after "cheapestTree")
const calculatedTree = {/* ... */}
const craftingStepsArray = craftingSteps(calculatedTree)
// Generates an array with the crafting steps in correct order
[
{
id: 1,
quantity: 10,
components: [
{id: 2, quantity: 20},
{id: 3, quantity: 10}
]
},
// ...
]
import {staticItems} from '@gw2efficiency/recipe-calculation'
// Get all item ids of items that can only be crafted once a day
const dailyCooldowns = staticItems.dailyCooldowns
// -> [1, 2, 3, 4]
// Get all item ids of items that can be bought, where the item or the immediate component
// (e.g. Deldrimor Steel Ingot-> Lump of Mithrillium) is a daily cooldown
const buyableDailyCooldowns = staticItems.buyableDailyCooldowns
// -> [1, 2, 3, 4]
// Get an object with item ids as keys of all vendor-buyable items
const vendorItems = staticItems.vendorItems
// Returns an object like this:
{
20798: {
type: 'spirit-shard', // can be gold, spirit shards, karma or dungeon currency
quantity: 1, // quantity the vendor sells
cost: 1, // copper the vendor sells the quantity for
npcs: [
{name: 'Miyani / Mystic Forge Attendant', position: 'Mystic Forge'}
]
},
// ...
}
import { recipeItems, dailyCooldowns, useVendorPrices } from '@gw2efficiency/recipe-calculation'
// Get all item ids of a recipe tree (before or after "cheapestTree")
const recipeTree = {
/* ... */
}
const itemIds = recipeItems(recipeTree)
// -> [1, 2, 3, 4]
// Get a map of item id -> count of all needed daily cooldowns (after "cheapestTree")
const calculatedTree = {
/* ... */
}
const cooldownItemsMap = dailyCooldowns(calculatedTree)
// -> {46740: 3, 66913: 4}
// Overwrite and add all vendor prices to a price array
// To show the users more information afterwards use "staticItems.vendorItems"
const prices = useVendorPrices({ 1: 1233, 19750: 50000 })
// -> {1: 1233, 19750: 16, 19924: 48, /* ... */}
Thanks goes to these wonderful people (emoji key):
David Reeß 💻 📖 ⚠️ | Ben Lubar 🔣 | Holox 🔣 | Ecmelt 💻 ⚠️ | darthmaim 💻 ⚠️ |
This project follows the all-contributors specification. Contributions of any kind welcome!
MIT
FAQs
Calculate the cheapest tree traversal, price and used items of crafting recipes
The npm package @gw2efficiency/recipe-calculation receives a total of 18 weekly downloads. As such, @gw2efficiency/recipe-calculation popularity was classified as not popular.
We found that @gw2efficiency/recipe-calculation demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.