From 23ebfdb79f0b9ff1564278a20f02d9ae2bfd970d Mon Sep 17 00:00:00 2001 From: spaghetti-squash Date: Sun, 4 Oct 2026 12:44:11 -0400 Subject: [PATCH 1/2] fill only up to the amount we need --- src/resources/2017/AsdonMartin.ts | 71 ++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/src/resources/2017/AsdonMartin.ts b/src/resources/2017/AsdonMartin.ts index 5faec8f8df..f14a3009a1 100644 --- a/src/resources/2017/AsdonMartin.ts +++ b/src/resources/2017/AsdonMartin.ts @@ -19,6 +19,7 @@ import { import { getAcquirePrice, getAverageAdventures, + getRange, have as haveItem, } from "../../lib.js"; import { $effect, $item, $items } from "../../template-string.js"; @@ -116,6 +117,45 @@ function tryInsert(item: Item, count: number) { } } +function fillWith( + item: Item, + targetUnits: number, + obtain: (amount: number) => void, +) { + while (getFuel() < targetUnits) { + const [, maxFuelFromItem] = getRange(item.adventures); + const unitsNeeded = targetUnits - getFuel(); + const minimumFuel = Math.ceil(unitsNeeded / maxFuelFromItem); + obtain(minimumFuel); + const retrievalSuccess = itemAmount(item) >= minimumFuel; + tryInsert(item, minimumFuel); + if (!retrievalSuccess) break; + } +} + +const obtainBread = (amount: number) => { + const breadToMake = amount - itemAmount($item`loaf of soda bread`); + if ( + npcPrice($item`wad of dough`) === 0 && + npcPrice($item`all-purpose flower`) > 0 + ) { + const maxTries = Math.ceil(breadToMake / 35); // minimum amount of wad of dough created from all-purpose flower is 35 + for ( + let i = 0; + i < maxTries && availableAmount($item`wad of dough`) < breadToMake; + i++ + ) { + buy($item`all-purpose flower`); + use($item`all-purpose flower`); + } + } + try { + retrieveItem(amount, $item`loaf of soda bread`); + } catch (e) { + logger.debug(`error retrieving soda bread: ${e}`); + } +}; + /** * Fill your Asdon Martin to the given fuel level in the cheapest way possible * @@ -152,35 +192,14 @@ export function fillTo(targetUnits: number): boolean { : currentPrice); logger.debug(`price ceiling: ${priceCeiling}`); - const count = Math.ceil(targetUnits / getAverageAdventures(currentFuel)); - - withProperty("autoBuyPriceLimit", priceCeiling, () => - retrieveItem(count, currentFuel), + fillWith(currentFuel, targetUnits, (amount) => + withProperty("autoBuyPriceLimit", priceCeiling, () => + retrieveItem(amount, currentFuel), + ), ); - - tryInsert(currentFuel, count); } } else { - const fuel = $item`loaf of soda bread`; - const count = Math.ceil(targetUnits / getAverageAdventures(fuel)); - - const breadToMake = count - itemAmount(fuel); - if ( - npcPrice($item`wad of dough`) === 0 && - npcPrice($item`all-purpose flower`) > 0 - ) { - const maxTries = Math.ceil(breadToMake / 35); // minimum amount of wad of dough created from all-purpose flower is 35 - for ( - let i = 0; - i < maxTries && availableAmount($item`wad of dough`) < breadToMake; - i++ - ) { - buy($item`all-purpose flower`); - use($item`all-purpose flower`); - } - } - retrieveItem(count, fuel); - tryInsert(fuel, count); + fillWith($item`loaf of soda bread`, targetUnits, obtainBread); } return getFuel() >= targetUnits; } From 6d6971ca7324dbe7cc04bb9432faeca28b30adfb Mon Sep 17 00:00:00 2001 From: spaghetti-squash Date: Sun, 4 Oct 2026 13:16:52 -0400 Subject: [PATCH 2/2] early-abort for obtainBread --- src/resources/2017/AsdonMartin.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/resources/2017/AsdonMartin.ts b/src/resources/2017/AsdonMartin.ts index f14a3009a1..c858dabb87 100644 --- a/src/resources/2017/AsdonMartin.ts +++ b/src/resources/2017/AsdonMartin.ts @@ -135,6 +135,7 @@ function fillWith( const obtainBread = (amount: number) => { const breadToMake = amount - itemAmount($item`loaf of soda bread`); + if (breadToMake <= 0) return; if ( npcPrice($item`wad of dough`) === 0 && npcPrice($item`all-purpose flower`) > 0