Skip to content

Commit

Permalink
fix(workshop): Trigger not evaluated correctly
Browse files Browse the repository at this point in the history
Relates to #801
  • Loading branch information
oliversalzburg committed Dec 18, 2024
1 parent 5a3ef79 commit 55c380c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
3 changes: 2 additions & 1 deletion packages/kitten-scientists/source/BonfireManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ export class BonfireManager implements Automation {
(build.baseBuilding ?? build.building) as Building,
).meta;
}
const sectionTrigger = this.settings.trigger;

// Let the bulkmanager determine the builds we can make.
const buildList = bulkManager.bulk(builds, metaData, this.settings.trigger, "Bonfire");
const buildList = bulkManager.bulk(builds, metaData, sectionTrigger, "Bonfire");

// Build all entries in the build list, where we can build any items.
for (const build of buildList.filter(item => 0 < item.count)) {
Expand Down
7 changes: 5 additions & 2 deletions packages/kitten-scientists/source/ReligionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ export class ReligionManager implements Automation {
return;
}

const sectionTrigger = this.settings.trigger;

if (bestUnicornBuilding === "unicornPasture") {
this._bonfireManager.build(bestUnicornBuilding, 0, 1);
} else {
Expand Down Expand Up @@ -177,7 +179,7 @@ export class ReligionManager implements Automation {
const build = this._bulkManager.bulk(
buildRequest,
this.getBuildMetaData(buildRequest),
this.settings.trigger,
sectionTrigger,
"Religion",
);
if (0 < build.length && 0 < build[0].count) {
Expand Down Expand Up @@ -207,9 +209,10 @@ export class ReligionManager implements Automation {
const metaData: Partial<
Record<FaithItem, ReligionUpgradeInfo | TranscendenceUpgradeInfo | ZiggurathUpgradeInfo>
> = this.getBuildMetaData(builds);
const sectionTrigger = this.settings.trigger;

// Let the bulk manager figure out which of the builds to actually build.
const buildList = this._bulkManager.bulk(builds, metaData, this.settings.trigger, "Religion");
const buildList = this._bulkManager.bulk(builds, metaData, sectionTrigger, "Religion");

for (const build of buildList) {
if (0 < build.count) {
Expand Down
4 changes: 2 additions & 2 deletions packages/kitten-scientists/source/SpaceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class SpaceManager implements Automation {
builds: Partial<Record<SpaceBuilding, SpaceBuildingSetting>> = this.settings.buildings,
) {
const bulkManager = this._bulkManager;
const trigger = this.settings.trigger;
const sectionTrigger = this.settings.trigger;

// Get the current metadata for all the referenced buildings.
const metaData: Partial<Record<SpaceBuilding, SpaceBuildingInfo>> = {};
Expand All @@ -73,7 +73,7 @@ export class SpaceManager implements Automation {
}

// Let the bulkmanager determine the builds we can make.
const buildList = bulkManager.bulk(builds, metaData, trigger, "Space");
const buildList = bulkManager.bulk(builds, metaData, sectionTrigger, "Space");

// Build all entries in the build list, where we can build any items.
for (const build of buildList) {
Expand Down
4 changes: 2 additions & 2 deletions packages/kitten-scientists/source/TimeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class TimeManager {
builds: Partial<Record<TimeItem, TimeSettingsItem>> = this.settings.buildings,
) {
const bulkManager = this._bulkManager;
const trigger = this.settings.trigger;
const sectionTrigger = this.settings.trigger;

// Get the current metadata for all the referenced buildings.
const metaData: Partial<Record<TimeItem, ChronoForgeUpgradeInfo | VoidSpaceUpgradeInfo>> = {};
Expand All @@ -90,7 +90,7 @@ export class TimeManager {
}

// Let the bulkmanager determine the builds we can make.
const buildList = bulkManager.bulk(builds, metaData, trigger, "Time");
const buildList = bulkManager.bulk(builds, metaData, sectionTrigger, "Time");

for (const build of buildList) {
if (build.count > 0) {
Expand Down
12 changes: 6 additions & 6 deletions packages/kitten-scientists/source/TradeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ export class TradeManager implements Automation {
autoTrade(cacheManager?: MaterialsCache) {
const catpower = this._workshopManager.getResource("manpower");
const gold = this._workshopManager.getResource("gold");
const requireTrigger = this.settings.trigger;
const sectionTrigger = this.settings.trigger;

// We should only trade if catpower and gold hit the trigger value.
// Trades can additionally require specific resources. We will check for those later.
if (
catpower.value / catpower.maxValue < requireTrigger ||
gold.value / gold.maxValue < requireTrigger
catpower.value / catpower.maxValue < sectionTrigger ||
gold.value / gold.maxValue < sectionTrigger
) {
return;
}
Expand Down Expand Up @@ -108,7 +108,7 @@ export class TradeManager implements Automation {
// the required resource must be over the trigger value.
// Additionally, gold must also be over the trigger value.
!require ||
requireTrigger <= require.value / require.maxValue
sectionTrigger <= require.value / require.maxValue
) {
trades.push(trade.race);
}
Expand Down Expand Up @@ -144,8 +144,8 @@ export class TradeManager implements Automation {
: this._workshopManager.getResource(tradeSettings.require);
// Have the trigger conditions for this trade been met?
const trigConditions =
(!require || requireTrigger <= require.value / require.maxValue) &&
requireTrigger <= gold.value / gold.maxValue;
(!require || sectionTrigger <= require.value / require.maxValue) &&
sectionTrigger <= gold.value / gold.maxValue;
// How many trades could we do?
const tradePos = this.getLowestTradeAmount(race, tradeSettings.limited, trigConditions);
// If no trades are possible, remove the race.
Expand Down
7 changes: 4 additions & 3 deletions packages/kitten-scientists/source/WorkshopManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export class WorkshopManager extends UpgradeManager implements Automation {
}>;
}
>();
const sectionTrigger = this.settings.trigger;

// Find all resources we would want to craft.
// For crafts that require resources with a capacity, those resources must
Expand All @@ -133,10 +134,10 @@ export class WorkshopManager extends UpgradeManager implements Automation {
.map(material => this.getResource(material))
.filter(material => 0 < material.maxValue);

const trigger = Engine.evaluateSubSectionTrigger(sectionTrigger, craft.trigger);
const allMaterialsAboveTrigger =
requiredMaterials.filter(
material => material.value / material.maxValue < this.settings.trigger,
).length === 0;
requiredMaterials.filter(material => material.value / material.maxValue < trigger)
.length === 0;

if (!allMaterialsAboveTrigger) {
continue;
Expand Down

0 comments on commit 55c380c

Please sign in to comment.