From b7a54b0298972dbd21e6feb1178da0274487b4f8 Mon Sep 17 00:00:00 2001 From: Oliver Salzburg Date: Fri, 17 Nov 2023 18:21:08 +0100 Subject: [PATCH] fix(religion): Unicorns are sacrificed too slowly Because we were only "clicking" the regular sacrifice button every iteration, we would always only sacrifice 2500 unicorns. But players often spawn far more unicorns than that in the same time, making them grow infinitely. Fixes #192 --- .../source/ReligionManager.ts | 39 ++++++++++++++----- .../kitten-scientists/source/types/index.ts | 14 ++++++- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/packages/kitten-scientists/source/ReligionManager.ts b/packages/kitten-scientists/source/ReligionManager.ts index 8a571eee2..13acac328 100644 --- a/packages/kitten-scientists/source/ReligionManager.ts +++ b/packages/kitten-scientists/source/ReligionManager.ts @@ -22,6 +22,7 @@ import { ReligionUpgrades, TranscendenceUpgradeInfo, TranscendenceUpgrades, + TransformBtnController, UnicornItemVariant, ZiggurathUpgradeInfo, ZiggurathUpgrades, @@ -57,7 +58,7 @@ export class ReligionManager implements Automation { this._autoBuild(); if (this.settings.sacrificeUnicorns.enabled) { - await this._autoSacrificeUnicorns(); + this._autoSacrificeUnicorns(); } if (this.settings.sacrificeAlicorns.enabled) { @@ -510,7 +511,7 @@ export class ReligionManager implements Automation { return null; } - private async _autoSacrificeUnicorns() { + private _autoSacrificeUnicorns() { const unicorns = this._workshopManager.getResource("unicorns"); const available = this._workshopManager.getValueAvailable("unicorns"); if ( @@ -518,19 +519,37 @@ export class ReligionManager implements Automation { this.settings.sacrificeUnicorns.trigger <= available && this.settings.sacrificeUnicorns.trigger <= unicorns.value ) { + const unicornsForSacrifice = available - this.settings.sacrificeUnicorns.trigger; + const sacrificePercentage = unicornsForSacrifice / available; + const percentageInverse = 1 / sacrificePercentage; + const controller = this._host.gamePage.religionTab.sacrificeBtn.controller; const model = this._host.gamePage.religionTab.sacrificeBtn.model; - await new Promise(resolve => controller.buyItem(model, new MouseEvent("click"), resolve)); + const customController = new classes.ui.religion.TransformBtnController( + game, + controller.controllerOpts, + ) as TransformBtnController; - const cost = mustExist(model.prices?.[0]).val; + const link = customController._newLink(model, percentageInverse); + link.handler(new Event("decoy"), (success: boolean) => { + if (!success) { + return; + } - this._host.engine.iactivity("act.sacrificeUnicorns", [cost], "ks-faith"); - this._host.engine.storeForSummary( - this._host.engine.i18n("$resources.unicorns.title"), - 1, - "refine", - ); + const cost = unicornsForSacrifice; + + this._host.engine.iactivity( + "act.sacrificeUnicorns", + [this._host.gamePage.getDisplayValueExt(cost)], + "ks-faith", + ); + this._host.engine.storeForSummary( + this._host.engine.i18n("$resources.unicorns.title"), + 1, + "refine", + ); + }); } } diff --git a/packages/kitten-scientists/source/types/index.ts b/packages/kitten-scientists/source/types/index.ts index 75d505491..191464fc5 100644 --- a/packages/kitten-scientists/source/types/index.ts +++ b/packages/kitten-scientists/source/types/index.ts @@ -320,9 +320,19 @@ export type TechButtonController = BuildingNotStackableBtnController & { new (game: GamePage): TechButtonController; }; -export type TransformBtnController = ButtonModernController & { - new (game: GamePage): TransformBtnController; +export type Link = { + visible: boolean; + title: string; + tooltip: string; + getDisplayValueExt: () => string; + handler: (event: Event, callback: (success: boolean) => void) => void; +}; + +export type TransformBtnController> = ButtonModernController & { + new (game: GamePage, options: TOptions): TransformBtnController; _transform: (model: ButtonModel, amt: number) => boolean; + _newLink: (model: ButtonModel, divider: number) => Link; + controllerOpts: TOptions; }; export type ClassList = {