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
9 changes: 6 additions & 3 deletions src/calculateTreeQuantity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ function calculateTreeQuantityInner(
const output = tree.output || 1

// Calculate the total quantity needed
const treeQuantity = amount * tree.quantity
const totalQuantity = treeQuantity
let treeQuantity = amount * tree.quantity

// Round amount to nearest multiple of the tree output
treeQuantity = Math.ceil(treeQuantity / output) * output
const totalQuantity = Math.round(treeQuantity)

// If the item is available and the higher tree is not
// bought or already available get as many items of it as possible
Expand All @@ -52,7 +55,7 @@ function calculateTreeQuantityInner(

// Get the amount of components that need to be crafted
// e.g. a recipe outputs 10 and we need 20 -> 2x components
const componentAmount = usedQuantity / output
const componentAmount = Math.ceil(usedQuantity / output)

// Ignore available items in components if the tree
// doesn't get crafted or is completely available anyway
Expand Down
72 changes: 36 additions & 36 deletions tests/__snapshots__/calculateTreeQuantity.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ Object {
"output": 1,
"prerequisites": Array [],
"quantity": 1,
"totalQuantity": 0.2,
"totalQuantity": 1,
"type": "Item",
"usedQuantity": 0.2,
"usedQuantity": 1,
"weekly_purchase_cap": 0,
},
Object {
Expand All @@ -180,9 +180,9 @@ Object {
"output": 1,
"prerequisites": Array [],
"quantity": 5,
"totalQuantity": 1,
"totalQuantity": 5,
"type": "Item",
"usedQuantity": 1,
"usedQuantity": 5,
"weekly_purchase_cap": 0,
},
],
Expand All @@ -201,9 +201,9 @@ Object {
},
],
"quantity": 1,
"totalQuantity": 1,
"totalQuantity": 5,
"type": "Recipe",
"usedQuantity": 1,
"usedQuantity": 5,
"weekly_purchase_cap": 0,
}
`;
Expand All @@ -221,9 +221,9 @@ Object {
"output": 1,
"prerequisites": Array [],
"quantity": 1,
"totalQuantity": 0.8,
"totalQuantity": 1,
"type": "Item",
"usedQuantity": 0.8,
"usedQuantity": 1,
"weekly_purchase_cap": 0,
},
Object {
Expand All @@ -236,9 +236,9 @@ Object {
"output": 1,
"prerequisites": Array [],
"quantity": 5,
"totalQuantity": 4,
"totalQuantity": 5,
"type": "Item",
"usedQuantity": 4,
"usedQuantity": 5,
"weekly_purchase_cap": 0,
},
],
Expand All @@ -257,9 +257,9 @@ Object {
},
],
"quantity": 1,
"totalQuantity": 4,
"totalQuantity": 5,
"type": "Recipe",
"usedQuantity": 4,
"usedQuantity": 5,
"weekly_purchase_cap": 0,
}
`;
Expand Down Expand Up @@ -333,9 +333,9 @@ Object {
"output": 10,
"prerequisites": Array [],
"quantity": 1,
"totalQuantity": 0.5,
"totalQuantity": 10,
"type": "Item",
"usedQuantity": 0.5,
"usedQuantity": 10,
"weekly_purchase_cap": 0,
},
Object {
Expand All @@ -348,9 +348,9 @@ Object {
"output": 5,
"prerequisites": Array [],
"quantity": 7,
"totalQuantity": 3.5,
"totalQuantity": 10,
"type": "Item",
"usedQuantity": 3.5,
"usedQuantity": 10,
"weekly_purchase_cap": 0,
},
],
Expand All @@ -369,9 +369,9 @@ Object {
},
],
"quantity": 1,
"totalQuantity": 1,
"totalQuantity": 2,
"type": "Recipe",
"usedQuantity": 1,
"usedQuantity": 2,
"weekly_purchase_cap": 0,
}
`;
Expand All @@ -389,9 +389,9 @@ Object {
"output": 10,
"prerequisites": Array [],
"quantity": 1,
"totalQuantity": 1.5,
"totalQuantity": 10,
"type": "Item",
"usedQuantity": 1.5,
"usedQuantity": 10,
"weekly_purchase_cap": 0,
},
Object {
Expand All @@ -404,9 +404,9 @@ Object {
"output": 5,
"prerequisites": Array [],
"quantity": 7,
"totalQuantity": 10.5,
"totalQuantity": 15,
"type": "Item",
"usedQuantity": 10.5,
"usedQuantity": 15,
"weekly_purchase_cap": 0,
},
],
Expand All @@ -425,9 +425,9 @@ Object {
},
],
"quantity": 1,
"totalQuantity": 3,
"totalQuantity": 4,
"type": "Recipe",
"usedQuantity": 3,
"usedQuantity": 4,
"weekly_purchase_cap": 0,
}
`;
Expand Down Expand Up @@ -760,9 +760,9 @@ Object {
"output": 1,
"prerequisites": Array [],
"quantity": 25,
"totalQuantity": 35,
"totalQuantity": 50,
"type": "Item",
"usedQuantity": 35,
"usedQuantity": 50,
"weekly_purchase_cap": 0,
},
Object {
Expand All @@ -777,9 +777,9 @@ Object {
"output": 1,
"prerequisites": Array [],
"quantity": 3,
"totalQuantity": 42,
"totalQuantity": 60,
"type": "Item",
"usedQuantity": 42,
"usedQuantity": 60,
"weekly_purchase_cap": 0,
},
],
Expand All @@ -798,9 +798,9 @@ Object {
},
],
"quantity": 10,
"totalQuantity": 14,
"totalQuantity": 20,
"type": "Recipe",
"usedQuantity": 14,
"usedQuantity": 20,
"weekly_purchase_cap": 0,
},
Object {
Expand All @@ -815,9 +815,9 @@ Object {
"output": 1,
"prerequisites": Array [],
"quantity": 2,
"totalQuantity": 11.2,
"totalQuantity": 16,
"type": "Item",
"usedQuantity": 11.2,
"usedQuantity": 16,
"weekly_purchase_cap": 0,
},
],
Expand All @@ -836,9 +836,9 @@ Object {
},
],
"quantity": 4,
"totalQuantity": 5.6,
"totalQuantity": 8,
"type": "Recipe",
"usedQuantity": 5.6,
"usedQuantity": 8,
"weekly_purchase_cap": 0,
},
],
Expand All @@ -857,9 +857,9 @@ Object {
},
],
"quantity": 1,
"totalQuantity": 7,
"totalQuantity": 10,
"type": "Recipe",
"usedQuantity": 7,
"usedQuantity": 10,
"weekly_purchase_cap": 0,
}
`;
Expand Down