Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/calculateTreePrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import { CURRENCY_DECISION_PRICES } from './static/currencyDecisionPrices'
// Update the tree prices
export function calculateTreePrices(
tree: RecipeTreeWithCraftFlags,
itemPrices: Record<string, number>
itemPrices: Record<string, number>,
customCurrencyPrices?: Record<string, number>
): RecipeTreeWithCraftFlags
export function calculateTreePrices(
tree: RecipeTreeWithQuantity,
itemPrices: Record<string, number>
itemPrices: Record<string, number>,
customCurrencyPrices?: Record<string, number>
): RecipeTreeWithPrices
export function calculateTreePrices(
tree: RecipeTreeWithQuantity | RecipeTreeWithCraftFlags,
itemPrices: Record<string, number>
itemPrices: Record<string, number>,
customCurrencyPrices: Record<string, number> = {}
): RecipeTreeWithPrices | RecipeTreeWithCraftFlags {
// Calculate the buy prices
let buyPriceEach = itemPrices[tree.id] || false
Expand All @@ -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

Expand All @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions src/cheapestTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export function cheapestTree(
'102306': '0',
'102205': '0',
'103049': '0',
}
},
customCurrencyPrices: Record<string, number> = {}
): RecipeTreeWithCraftFlags {
tree = applyEfficiencyTiersToTree(tree, userEfficiencyTiers)
if (valueOwnItems) {
Expand All @@ -30,7 +31,8 @@ export function cheapestTree(
)
const treeWithPriceWithoutAvailableItems = calculateTreePrices(
treeWithQuantityWithoutAvailableItems,
itemPrices
itemPrices,
customCurrencyPrices
)

const cheaperToBuyItemIds = getCheaperToBuyItemIds(treeWithPriceWithoutAvailableItems)
Expand All @@ -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
Expand All @@ -58,7 +60,7 @@ export function cheapestTree(
)

// Recalculate the correct tree price
return calculateTreePrices(treeWithQuantityPostFlags, itemPrices)
return calculateTreePrices(treeWithQuantityPostFlags, itemPrices, customCurrencyPrices)
}

function getCheaperToBuyItemIds(
Expand Down
5 changes: 3 additions & 2 deletions src/updateTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ export function updateTree(
amount: number,
tree: RecipeTreeWithCraftFlags,
itemPrices: Record<string, number>,
availableItems: Record<string, number> = {}
availableItems: Record<string, number> = {},
customCurrencyPrices: Record<string, number> = {}
) {
// 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)
}