Skip to content

Commit

Permalink
feat(core): Individual triggers for build items
Browse files Browse the repository at this point in the history
Contributes to #451
  • Loading branch information
oliversalzburg committed Nov 5, 2024
1 parent 8a06a5e commit 5766d34
Show file tree
Hide file tree
Showing 42 changed files with 753 additions and 343 deletions.
3 changes: 1 addition & 2 deletions packages/kitten-scientists/source/BonfireManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export class BonfireManager implements Automation {
builds: Partial<Record<BonfireItem, BonfireBuildingSetting>> = this.settings.buildings,
) {
const bulkManager = this._bulkManager;
const trigger = this.settings.trigger;

// Get the current metadata for all the referenced buildings.
const metaData: Partial<Record<BonfireItem, BuildingMeta>> = {};
Expand All @@ -78,7 +77,7 @@ export class BonfireManager implements Automation {
}

// Let the bulkmanager determine the builds we can make.
const buildList = bulkManager.bulk(builds, metaData, trigger, "Bonfire");
const buildList = bulkManager.bulk(builds, metaData, this.settings.trigger, "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
18 changes: 11 additions & 7 deletions packages/kitten-scientists/source/helper/BulkPurchaseHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ export class BulkPurchaseHelper {
/**
* Take a hash of potential builds and determine how many of them can be built.
*
* @param builds All potential builds.
* @param metaData The metadata for the potential builds.
* @param trigger The configured trigger threshold for these builds.
* @param sourceTab The tab these builds originate from.
* @param builds - All potential builds.
* @param metaData - The metadata for the potential builds.
* @param sectionTrigger - The configured trigger threshold for the section of these builds.
* @param sourceTab - The tab these builds originate from.
* @returns All the possible builds.
*/
bulk(
Expand All @@ -88,6 +88,7 @@ export class BulkPurchaseHelper {
baseBuilding?: Building;
building?: AllBuildings | BonfireItem;
stage?: number;
trigger: number;
variant?: TimeItemVariant | UnicornItemVariant;
}
>
Expand All @@ -104,7 +105,7 @@ export class BulkPurchaseHelper {
| ZiggurathUpgradeInfo
>
>,
trigger: number,
sectionTrigger: number,
sourceTab: TabId,
): Array<BulkBuildListItem> {
const buildsPerformed: Array<BulkBuildListItem> = [];
Expand Down Expand Up @@ -172,8 +173,11 @@ export class BulkPurchaseHelper {
.map(price => this._workshopManager.getResource(price.name))
.filter(material => 0 < material.maxValue);
const allMaterialsAboveTrigger =
requiredMaterials.filter(material => material.value / material.maxValue < trigger)
.length === 0;
requiredMaterials.filter(
material =>
material.value / material.maxValue <
(build.trigger < 0 ? sectionTrigger : build.trigger),
).length === 0;

if (allMaterialsAboveTrigger) {
// If the build is for a stage that the building isn't currently at, skip it.
Expand Down
31 changes: 20 additions & 11 deletions packages/kitten-scientists/source/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
"act.sacrificeUnicorns": "Sacrificed {0} unicorns",
"act.sun.discover": "Kittens have discovered {0}",
"act.sun.discovers": "Kittens have discovered {0} {1} times",
"act.time.activeHeatTransferStart": "Start active Heat Transfer",
"act.time.activeHeatTransferEnd": "End active Heat Transfer",
"act.time.activeHeatTransferStart": "Start active Heat Transfer",
"act.time.getTemporalFlux": "Burn crystals to obtain time flux to maintain time acceleration",
"act.time.skip": "Kittens combust a time crystal, {0} years skipped!",
"act.trade": "Kittens have traded {0} times with {1}",
"act.transcend": "Spent {0} epiphany, Transcended to T-level: {1}",
"blackcoin.buy": "Kittens sold your Relics and bought {0} Blackcoins",
"blackcoin.buy.threshold": "Buy Blackcoins below this price:",
"blackcoin.buy.trigger": "buying Blackcoins (in relics)",
"blackcoin.sell": "Kittens sold your Blackcoins and bought {0} Relics",
"blackcoin.buy": "Kittens sold your Relics and bought {0} Blackcoins",
"blackcoin.sell.threshold": "Sell Blackcoins above this price:",
"blackcoin.sell": "Kittens sold your Blackcoins and bought {0} Relics",
"build.embassies": "Built {0} embassies for {1}",
"build.embassy": "Built {0} embassy for {1}",
"copy": "Copy to clipboard",
Expand Down Expand Up @@ -64,16 +64,16 @@
"option.catnip": "Gather Catnip",
"option.chronofurnace": "Turn on Chrono Furnaces",
"option.crypto": "Trade Blackcoin",
"option.elect": "Elect leader",
"option.elect.job": "Job",
"option.elect.job.any": "Any",
"option.elect.job": "Job",
"option.elect.trait": "Trait",
"option.elect": "Elect leader",
"option.embassies": "Build Embassies",
"option.faith.adore": "Adore the Galaxy",
"option.faith.autoPraise": "Praise the Sun",
"option.faith.best.unicorn": "Build Best Unicorn Building First",
"option.faith.refineTimeCrystals": "Refine TCs",
"option.faith.refineTears": "Refine Tears",
"option.faith.refineTimeCrystals": "Refine TCs",
"option.faith.sacrificeAlicorns": "Sacrifice Alicorns",
"option.faith.sacrificeUnicorns": "Sacrifice Unicorns",
"option.faith.transcend": "Transcend",
Expand All @@ -92,7 +92,6 @@
"option.time.reset": "Reset Timeline (Danger!)",
"option.time.skip.ignoreOverheat": "Ignore overheat",
"option.time.skip": "Time Skip",
"reset": "Reset",
"reset.after": "Nice to meet you, the cute Kitten Scientists will serve you",
"reset.cancel.activity": "Meoston, We Have a Problem",
"reset.cancel.message": "Timeline Reset canceled",
Expand All @@ -111,6 +110,7 @@
"reset.countdown.9": "9 - Sacrificing Unicorns",
"reset.last.message": "See you next poincaré recurrence",
"reset.tip": "You can cancel this reset by disabling \"Enable Kitten Scientists\" at the top of the settings.",
"reset": "Reset",
"resources.consume.set": "Consume rate for {0}",
"resources.consume": "Consume: {0}",
"resources.stock.set": "Stock for {0}",
Expand Down Expand Up @@ -221,9 +221,10 @@
"ui.engine": "Enable Kitten Scientists",
"ui.faith": "Religion",
"ui.filter": "Log Filters",
"ui.internals": "Internals",
"ui.internals.interval": "Interval: {0}",
"ui.infinity": "",
"ui.internals.interval.input": "Enter a new interval at which KS should run (in milliseconds):",
"ui.internals.interval": "Interval: {0}",
"ui.internals": "Internals",
"ui.itemsHide": "Hide options",
"ui.itemsShow": "Show options",
"ui.ksColumn": "Display KS in fourth column in UI",
Expand All @@ -241,8 +242,16 @@
"ui.time": "Time",
"ui.timeCtrl": "Time Control",
"ui.trade": "Trade",
"ui.trigger.setinteger": "Enter a new trigger value for {0}. Should be in the range of 0 to Infinity (-1).",
"ui.trigger.setpercentage": "Enter a new trigger value for {0}. Should be in the range of 0 to 1.",
"ui.trigger.build.blocked": "\n🛈 The {0} section has no trigger set. This build will not be triggered!",
"ui.trigger.build.inherited": "inherited from section",
"ui.trigger.build.prompt": "Trigger for {0} (Current: {1})",
"ui.trigger.build.promptExplainer": "If you submit an empty value, or a negative value, the section trigger is used instead. If you submit an invalid value, it will be treated as if you hit Cancel.",
"ui.trigger.prompt.percentage": "Enter the new trigger value as a percentage between 0.0 and 100.0.",
"ui.trigger.section.inactive": "∞ (nothing is built automatically)",
"ui.trigger.section.prompt": "Trigger for section {0} (Current: {1})",
"ui.trigger.section.promptExplainer": "If you submit an empty value, or a negative value, the section trigger will be set to infinity (∞), which disables all builds, unless they have their own trigger set.\nIf you submit an invalid value, it will be treated as if you hit Cancel.",
"ui.trigger.setinteger": "Enter a new trigger value for {0}. Should be in the range from 0 up to any number. -1 means infinity.",
"ui.trigger.setpercentage": "Enter a new trigger value for {0}. Should be in the range from 0 to 100.",
"ui.trigger": "Trigger: {0}",
"ui.upgrade.buildings": "Upgrade buildings",
"ui.upgrade.missions": "Start missions",
Expand Down
19 changes: 13 additions & 6 deletions packages/kitten-scientists/source/settings/BonfireSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Maybe, isNil } from "@oliversalzburg/js-utils/data/nil.js";
import { consumeEntriesPedantic } from "../tools/Entries.js";
import { Building, Buildings, StagedBuilding, StagedBuildings } from "../types/index.js";
import { BuildingUpgradeSettings } from "./BuildingUpgradeSettings.js";
import { Setting, SettingMax, SettingTrigger } from "./Settings.js";
import { Setting, SettingTrigger, SettingTriggerMax } from "./Settings.js";

/**
* One of the building options in the KS menu.
Expand All @@ -11,7 +11,7 @@ import { Setting, SettingMax, SettingTrigger } from "./Settings.js";
*/
export type BonfireItem = Building | StagedBuilding;

export class BonfireBuildingSetting extends SettingMax {
export class BonfireBuildingSetting extends SettingTriggerMax {
/**
* In case this is an upgrade of another building, this is the name of the
* base building.
Expand All @@ -35,8 +35,14 @@ export class BonfireBuildingSetting extends SettingMax {
return this.#stage;
}

constructor(building: BonfireItem, enabled = false, max = -1, baseStage?: Building | false) {
super(enabled, max);
constructor(
building: BonfireItem,
enabled = false,
trigger = -1,
max = -1,
baseStage?: Building | false,
) {
super(enabled, trigger, max);

this.#building = building;
if (baseStage) {
Expand All @@ -62,7 +68,7 @@ export class BonfireSettings extends SettingTrigger {

constructor(
enabled = false,
trigger = 0,
trigger = -1,
gatherCatnip = new Setting(true),
turnOnSteamworks = new Setting(true),
turnOnMagnetos = new Setting(false),
Expand Down Expand Up @@ -93,7 +99,7 @@ export class BonfireSettings extends SettingTrigger {
items[item] = new BonfireBuildingSetting(item);
});
StagedBuildings.forEach(item => {
items[item] = new BonfireBuildingSetting(item, false, -1, baseStage[item]);
items[item] = new BonfireBuildingSetting(item, false, -1, -1, baseStage[item]);
});

return items;
Expand All @@ -109,6 +115,7 @@ export class BonfireSettings extends SettingTrigger {
consumeEntriesPedantic(this.buildings, settings.buildings, (building, item) => {
building.enabled = item?.enabled ?? building.enabled;
building.max = item?.max ?? building.max;
building.trigger = item?.trigger ?? building.trigger;
});

this.gatherCatnip.enabled = settings.gatherCatnip?.enabled ?? this.gatherCatnip.enabled;
Expand Down
16 changes: 6 additions & 10 deletions packages/kitten-scientists/source/settings/ReligionSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ZiggurathUpgrade,
ZiggurathUpgrades,
} from "../types/index.js";
import { Setting, SettingMax, SettingThreshold, SettingTrigger } from "./Settings.js";
import { Setting, SettingThreshold, SettingTrigger, SettingTriggerMax } from "./Settings.js";

export type FaithItem = Exclude<ReligionItem, UnicornItem>;

Expand Down Expand Up @@ -38,7 +38,7 @@ export const ReligionOptions = [
] as const;
export type ReligionOption = (typeof ReligionOptions)[number];

export class ReligionSettingsItem extends SettingMax {
export class ReligionSettingsItem extends SettingTriggerMax {
readonly #building: FaithItem | UnicornItem;
readonly #variant: UnicornItemVariant;

Expand All @@ -49,13 +49,8 @@ export class ReligionSettingsItem extends SettingMax {
return this.#variant;
}

constructor(
building: FaithItem | UnicornItem,
variant: UnicornItemVariant,
enabled = false,
max = -1,
) {
super(enabled, max);
constructor(building: FaithItem | UnicornItem, variant: UnicornItemVariant, enabled = false) {
super(enabled);
this.#building = building;
this.#variant = variant;
}
Expand Down Expand Up @@ -108,7 +103,7 @@ export class ReligionSettings extends SettingTrigger {

constructor(
enabled = false,
trigger = 1,
trigger = -1,
bestUnicornBuilding = new Setting(false),
sacrificeAlicorns = new SettingThreshold(false, 25),
sacrificeUnicorns = new SettingThreshold(false, 1000000),
Expand Down Expand Up @@ -164,6 +159,7 @@ export class ReligionSettings extends SettingTrigger {
consumeEntriesPedantic(this.buildings, settings.buildings, (building, item) => {
building.enabled = item?.enabled ?? building.enabled;
building.max = item?.max ?? building.max;
building.trigger = item?.trigger ?? building.trigger;
});

this.bestUnicornBuilding.load(settings.bestUnicornBuilding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ export class ResetBonfireBuildingSetting extends SettingThreshold {
return this.#stage;
}

constructor(building: BonfireItem, enabled = false, trigger = -1, baseStage?: Building | false) {
super(enabled, trigger);
constructor(
building: BonfireItem,
enabled = false,
threshold = -1,
baseStage?: Building | false,
) {
super(enabled, threshold);

this.#building = building;
if (baseStage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export class ResetReligionBuildingSetting extends SettingThreshold {
building: FaithItem | UnicornItem,
variant: UnicornItemVariant,
enabled = false,
trigger = -1,
threshold = -1,
) {
super(enabled, trigger);
super(enabled, threshold);
this.#building = building;
this.#variant = variant;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export class ResetSpaceBuildingSetting extends SettingThreshold {
return this.#building;
}

constructor(building: SpaceBuilding, enabled = false, trigger = -1) {
super(enabled, trigger);
constructor(building: SpaceBuilding, enabled = false, threshold = -1) {
super(enabled, threshold);
this.#building = building;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export class ResetTimeBuildingSetting extends SettingThreshold {
return this.#variant;
}

constructor(id: TimeItem, variant: TimeItemVariant, enabled = false, trigger = -1) {
super(enabled, trigger);
constructor(id: TimeItem, variant: TimeItemVariant, enabled = false, threshold = -1) {
super(enabled, threshold);
this.#building = id;
this.#variant = variant;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/kitten-scientists/source/settings/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ export class SettingTrigger extends Setting {
export class SettingThreshold extends Setting {
trigger: number;

constructor(enabled = false, trigger = 1) {
constructor(enabled = false, threshold = 1) {
super(enabled);
this.trigger = trigger;
this.trigger = threshold;
}

load(setting: Maybe<Partial<SettingThreshold>>) {
Expand Down
11 changes: 6 additions & 5 deletions packages/kitten-scientists/source/settings/SpaceSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import { Maybe, isNil } from "@oliversalzburg/js-utils/data/nil.js";
import { consumeEntriesPedantic } from "../tools/Entries.js";
import { Game, SpaceBuilding, SpaceBuildings } from "../types/index.js";
import { MissionSettings } from "./MissionSettings.js";
import { SettingMax, SettingTrigger } from "./Settings.js";
import { SettingTrigger, SettingTriggerMax } from "./Settings.js";

export class SpaceBuildingSetting extends SettingMax {
export class SpaceBuildingSetting extends SettingTriggerMax {
readonly #building: SpaceBuilding;

get building() {
return this.#building;
}

constructor(building: SpaceBuilding, enabled = false) {
super(enabled);
constructor(building: SpaceBuilding) {
super();
this.#building = building;
}
}
Expand All @@ -24,7 +24,7 @@ export class SpaceSettings extends SettingTrigger {

unlockMissions: MissionSettings;

constructor(enabled = false, trigger = 0, unlockMissions = new MissionSettings()) {
constructor(enabled = false, trigger = -1, unlockMissions = new MissionSettings()) {
super(enabled, trigger);
this.buildings = this.initBuildings();
this.unlockMissions = unlockMissions;
Expand Down Expand Up @@ -52,6 +52,7 @@ export class SpaceSettings extends SettingTrigger {
consumeEntriesPedantic(this.buildings, settings.buildings, (building, item) => {
building.enabled = item?.enabled ?? building.enabled;
building.max = item?.max ?? building.max;
building.trigger = item?.trigger ?? building.trigger;
});

this.unlockMissions.load(settings.unlockMissions);
Expand Down
7 changes: 4 additions & 3 deletions packages/kitten-scientists/source/settings/TimeSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {
VoidSpaceUpgrade,
VoidSpaceUpgrades,
} from "../types/index.js";
import { Setting, SettingMax, SettingTrigger } from "./Settings.js";
import { Setting, SettingTrigger, SettingTriggerMax } from "./Settings.js";

/**
* The upgrades on the Time tab that we have options for.
*/
export type TimeItem = Exclude<ChronoForgeUpgrade | VoidSpaceUpgrade, "usedCryochambers">;

export class TimeSettingsItem extends SettingMax {
export class TimeSettingsItem extends SettingTriggerMax {
readonly #building: TimeItem;
readonly #variant: TimeItemVariant;

Expand Down Expand Up @@ -42,7 +42,7 @@ export class TimeSettings extends SettingTrigger {

constructor(
enabled = false,
trigger = 1,
trigger = -1,
fixCryochambers = new Setting(false),
turnOnChronoFurnace = new Setting(false),
) {
Expand Down Expand Up @@ -74,6 +74,7 @@ export class TimeSettings extends SettingTrigger {
consumeEntriesPedantic(this.buildings, settings.buildings, (building, item) => {
building.enabled = item?.enabled ?? building.enabled;
building.max = item?.max ?? building.max;
building.trigger = item?.trigger ?? building.trigger;
});

this.fixCryochambers.load(settings.fixCryochambers);
Expand Down
Loading

0 comments on commit 5766d34

Please sign in to comment.