diff --git a/src/calculateTreePrices.ts b/src/calculateTreePrices.ts index 00950cf..0ab6a3c 100755 --- a/src/calculateTreePrices.ts +++ b/src/calculateTreePrices.ts @@ -4,15 +4,18 @@ import { CURRENCY_DECISION_PRICES } from './static/currencyDecisionPrices' // Update the tree prices export function calculateTreePrices( tree: RecipeTreeWithCraftFlags, - itemPrices: Record + itemPrices: Record, + customCurrencyPrices?: Record ): RecipeTreeWithCraftFlags export function calculateTreePrices( tree: RecipeTreeWithQuantity, - itemPrices: Record + itemPrices: Record, + customCurrencyPrices?: Record ): RecipeTreeWithPrices export function calculateTreePrices( tree: RecipeTreeWithQuantity | RecipeTreeWithCraftFlags, - itemPrices: Record + itemPrices: Record, + customCurrencyPrices: Record = {} ): RecipeTreeWithPrices | RecipeTreeWithCraftFlags { // Calculate the buy prices let buyPriceEach = itemPrices[tree.id] || false @@ -26,7 +29,11 @@ export function calculateTreePrices( // Calculate the base decision price (may be overwritten later with the craft price) let decisionPriceEach = buyPriceEach || undefined if (tree.type === 'Currency') { - decisionPriceEach = CURRENCY_DECISION_PRICES[tree.id] + if (customCurrencyPrices && typeof customCurrencyPrices[tree.id] === 'number') { + decisionPriceEach = customCurrencyPrices[tree.id] + } else { + decisionPriceEach = CURRENCY_DECISION_PRICES[tree.id] + } } let decisionPrice = decisionPriceEach ? tree.usedQuantity * decisionPriceEach : false @@ -43,7 +50,9 @@ export function calculateTreePrices( } // Calculate the tree prices traversal for the sub-components - const components = tree.components.map((component) => calculateTreePrices(component, itemPrices)) + const components = tree.components.map((component) => + calculateTreePrices(component, itemPrices, customCurrencyPrices) + ) // Calculate the craft price out of the best prices const craftDecisionPrice = components.map((c) => c.decisionPrice || 0).reduce((a, b) => a + b, 0) diff --git a/src/cheapestTree.ts b/src/cheapestTree.ts index 9a24915..01bc49c 100755 --- a/src/cheapestTree.ts +++ b/src/cheapestTree.ts @@ -19,7 +19,8 @@ export function cheapestTree( '102306': '0', '102205': '0', '103049': '0', - } + }, + customCurrencyPrices: Record = {} ): RecipeTreeWithCraftFlags { tree = applyEfficiencyTiersToTree(tree, userEfficiencyTiers) if (valueOwnItems) { @@ -30,7 +31,8 @@ export function cheapestTree( ) const treeWithPriceWithoutAvailableItems = calculateTreePrices( treeWithQuantityWithoutAvailableItems, - itemPrices + itemPrices, + customCurrencyPrices ) const cheaperToBuyItemIds = getCheaperToBuyItemIds(treeWithPriceWithoutAvailableItems) @@ -43,7 +45,7 @@ export function cheapestTree( const treeWithQuantity = calculateTreeQuantity(amount, tree as RecipeTree, availableItems) // Set the initial craft flags based on the subtree prices - const treeWithPrices = calculateTreePrices(treeWithQuantity, itemPrices) + const treeWithPrices = calculateTreePrices(treeWithQuantity, itemPrices, customCurrencyPrices) let treeWithCraftFlags = calculateTreeCraftFlags(treeWithPrices, forceBuyItems) // Force the root to be crafted @@ -58,7 +60,7 @@ export function cheapestTree( ) // Recalculate the correct tree price - return calculateTreePrices(treeWithQuantityPostFlags, itemPrices) + return calculateTreePrices(treeWithQuantityPostFlags, itemPrices, customCurrencyPrices) } function getCheaperToBuyItemIds( diff --git a/src/updateTree.ts b/src/updateTree.ts index 254b747..b4e7211 100755 --- a/src/updateTree.ts +++ b/src/updateTree.ts @@ -6,11 +6,12 @@ export function updateTree( amount: number, tree: RecipeTreeWithCraftFlags, itemPrices: Record, - availableItems: Record = {} + availableItems: Record = {}, + customCurrencyPrices: Record = {} ) { // Update the tree total and used quantities const treeWithQuantity = calculateTreeQuantity(amount, tree, availableItems) // Recalculate the correct tree price - return calculateTreePrices(treeWithQuantity, itemPrices) + return calculateTreePrices(treeWithQuantity, itemPrices, customCurrencyPrices) }