diff --git a/packages/userscript/source/ScienceManager.ts b/packages/userscript/source/ScienceManager.ts index 132357646..497a053bc 100644 --- a/packages/userscript/source/ScienceManager.ts +++ b/packages/userscript/source/ScienceManager.ts @@ -68,7 +68,7 @@ export class ScienceManager extends UpgradeManager { let prices = UserScript.window.dojo.clone(tech.prices); prices = this._host.gamePage.village.getEffectLeader("scientist", prices); for (const resource of prices) { - if (this._workshopManager.getValueAvailable(resource.name, true) < resource.val) { + if (this._workshopManager.getValueAvailable(resource.name) < resource.val) { continue workLoop; } } diff --git a/packages/userscript/source/SpaceManager.ts b/packages/userscript/source/SpaceManager.ts index d04e2229c..7d7e81ced 100644 --- a/packages/userscript/source/SpaceManager.ts +++ b/packages/userscript/source/SpaceManager.ts @@ -105,7 +105,7 @@ export class SpaceManager implements Automation { const prices = mustExist(model.model.prices); for (const resource of prices) { // If we can't afford this resource price, continue with the next mission. - if (this._workshopManager.getValueAvailable(resource.name, true) < resource.val) { + if (this._workshopManager.getValueAvailable(resource.name) < resource.val) { continue missionLoop; } } diff --git a/packages/userscript/source/TradeManager.ts b/packages/userscript/source/TradeManager.ts index 96d63d4a7..483fd5ac3 100644 --- a/packages/userscript/source/TradeManager.ts +++ b/packages/userscript/source/TradeManager.ts @@ -283,7 +283,7 @@ export class TradeManager implements Automation { } const racePanels = this._host.gamePage.diplomacyTab.racePanels; - cultureVal = this._workshopManager.getValueAvailable("culture", true); + cultureVal = this._workshopManager.getValueAvailable("culture"); const embassyBulk: Partial< Record< @@ -365,7 +365,7 @@ export class TradeManager implements Automation { if (emBulk.val === 0) { continue; } - cultureVal = this._workshopManager.getValueAvailable("culture", true); + cultureVal = this._workshopManager.getValueAvailable("culture"); if (cultureVal < emBulk.priceSum) { cwarn("Something has gone horribly wrong.", emBulk.priceSum, cultureVal); } @@ -428,7 +428,7 @@ export class TradeManager implements Automation { let refreshRequired = false; // Get the currently available catpower. - let manpower = this._workshopManager.getValueAvailable("manpower", true); + let manpower = this._workshopManager.getValueAvailable("manpower"); // TODO: These should be checked in reverse order. Otherwise the check for lizards // can cause the zebras to be discovered at later stages in the game. Then it // gets to the check for the zebras and doesn't explore again, as they're @@ -762,14 +762,12 @@ export class TradeManager implements Automation { for (const [resource, required] of objectEntries(materials)) { // If this resource is manpower, the amount of trades it allows is straight forward. if (resource === "manpower") { - total = this._workshopManager.getValueAvailable(resource, true) / required; + total = this._workshopManager.getValueAvailable(resource) / required; } else { // For other resources, use a different path to determine the available resource // amount. // TODO: It's unclear how this works - total = - this._workshopManager.getValueAvailable(resource, limited, this.settings.trigger) / - required; + total = this._workshopManager.getValueAvailable(resource) / required; } // Set the amount to the lowest amount of possible trades seen yet. @@ -903,7 +901,7 @@ export class TradeManager implements Automation { const materials = this.getMaterials(name); for (const [resource, amount] of objectEntries(materials)) { // Check if we have a sufficient amount of that resource in storage. - if (this._workshopManager.getValueAvailable(resource, true) < amount) { + if (this._workshopManager.getValueAvailable(resource) < amount) { return false; } } diff --git a/packages/userscript/source/VillageManager.ts b/packages/userscript/source/VillageManager.ts index c4eefa80b..5e54b26d7 100644 --- a/packages/userscript/source/VillageManager.ts +++ b/packages/userscript/source/VillageManager.ts @@ -267,9 +267,9 @@ export class VillageManager implements Automation { // Check if we can afford a festival. const craftManager = this._workshopManager; if ( - craftManager.getValueAvailable("manpower", true) < 1500 || - craftManager.getValueAvailable("culture", true) < 5000 || - craftManager.getValueAvailable("parchment", true) < 2500 + craftManager.getValueAvailable("manpower") < 1500 || + craftManager.getValueAvailable("culture") < 5000 || + craftManager.getValueAvailable("parchment") < 2500 ) { return; } diff --git a/packages/userscript/source/WorkshopManager.ts b/packages/userscript/source/WorkshopManager.ts index b084e68fe..086df8f7f 100644 --- a/packages/userscript/source/WorkshopManager.ts +++ b/packages/userscript/source/WorkshopManager.ts @@ -66,7 +66,7 @@ export class WorkshopManager extends UpgradeManager implements Automation { prices = this._host.gamePage.village.getEffectLeader("scientist", prices); for (const resource of prices) { // If we can't afford this resource price, continue with the next upgrade. - if (this.getValueAvailable(resource.name, true) < resource.val) { + if (this.getValueAvailable(resource.name) < resource.val) { continue workLoop; } } @@ -193,7 +193,9 @@ export class WorkshopManager extends UpgradeManager implements Automation { 0 < materialResource.maxValue || // For materials that are also crafted, if they have already been crafted to their `max`, // treat them the same as capped source materials, to avoid the same conflict. - (materialCraft ? materialCraft.max - materialResource.value < 1 : false) || + (!isNil(materialCraft) && -1 < materialCraft.max + ? materialCraft.max - materialResource.value < 1 + : false) || // Handle the ship override. (craft.resource === "ship" && this.settings.shipOverride.enabled) ) { @@ -205,9 +207,9 @@ export class WorkshopManager extends UpgradeManager implements Automation { // Quantity of source and target resource currently available. const availableSource = - this.getValueAvailable(material.resource, true) / + this.getValueAvailable(material.resource) / mustExist(billOfMaterials.get(material.resource)).length; - const availableTarget = this.getValueAvailable(craft.resource, true); + const availableTarget = this.getValueAvailable(craft.resource); // How much source resource is consumed and target resource is crafted per craft operation. const recipeRequires = materialAmount; @@ -324,7 +326,7 @@ export class WorkshopManager extends UpgradeManager implements Automation { const materials = this.getMaterials(name); for (const [material, amount] of objectEntries(materials)) { - if (this.getValueAvailable(material, true) < amount) { + if (this.getValueAvailable(material) < amount) { return false; } } @@ -475,15 +477,9 @@ export class WorkshopManager extends UpgradeManager implements Automation { * to use. * * @param name The resource to check. - * @param all ? - * @param typeTrigger The trigger value associated with this check. * @returns The available amount of the resource. */ - getValueAvailable( - name: Resource, - all: boolean | undefined = undefined, - typeTrigger: number | undefined = undefined - ): number { + getValueAvailable(name: Resource): number { // How many items to keep in stock. let stock = this.getStock(name); @@ -512,26 +508,12 @@ export class WorkshopManager extends UpgradeManager implements Automation { // Subtract the amount to keep in stock. value = Math.max(value - stock, 0); - // If the user has not requested "all", and this is a capped resource. - // TODO: This makes absolutely no sense. This should likely be a different method. - if (!all && 0 < this.getResource(name).maxValue) { - // Determine our de-facto trigger value to use. - let trigger: number; - if (!typeTrigger && typeTrigger !== 0) { - trigger = this.settings.trigger; - } else { - trigger = typeTrigger; - } - - // Determine the consume rate. Either it's configured on the resource, or globally. - // If the consume rate is 0.6, we'll always only make 60% of the resource available. - const resourceSettings = this._host.engine.settings.resources.resources[name]; - const consume = resourceSettings.consume; - - value -= Math.min(this.getResource(name).maxValue * trigger, value) * (1 - consume); - } + // Determine the consume rate. + // If the consume rate is 0.6, we'll always only make 60% of the resource available. + const resourceSettings = this._host.engine.settings.resources.resources[name]; + const consume = resourceSettings.consume; - return value; + return value * consume; } /** diff --git a/packages/userscript/source/helper/BulkPurchaseHelper.ts b/packages/userscript/source/helper/BulkPurchaseHelper.ts index bca6487d5..9ad5cea23 100644 --- a/packages/userscript/source/helper/BulkPurchaseHelper.ts +++ b/packages/userscript/source/helper/BulkPurchaseHelper.ts @@ -228,7 +228,7 @@ export class BulkPurchaseHelper { // Create a copy of the currently available resources. const tempPool: Record = {} as Record; for (const res of this._host.gamePage.resPool.resources) { - tempPool[res.name] = this._workshopManager.getValueAvailable(res.name, true); + tempPool[res.name] = this._workshopManager.getValueAvailable(res.name); } for (const potentialBuild of potentialBuilds) { @@ -578,10 +578,7 @@ export class BulkPurchaseHelper { 0.75 ); const oilPrice = finalResourcePrice * (1 - oilModifier); - if ( - this._workshopManager.getValueAvailable("oil", true) < - oilPrice * Math.pow(1.05, build.val) - ) { + if (this._workshopManager.getValueAvailable("oil") < oilPrice * Math.pow(1.05, build.val)) { return false; } @@ -593,14 +590,14 @@ export class BulkPurchaseHelper { ); const karmaPrice = finalResourcePrice * (1 - karmaModifier); if ( - this._workshopManager.getValueAvailable("karma", true) < + this._workshopManager.getValueAvailable("karma") < karmaPrice * Math.pow(priceRatio, build.val) ) { return false; } } else { if ( - this._workshopManager.getValueAvailable(price.name, true) < + this._workshopManager.getValueAvailable(price.name) < finalResourcePrice * Math.pow(priceRatio, build.val) ) { return false;