Skip to content

Commit

Permalink
fix(religion): Unicorns are sacrificed too slowly
Browse files Browse the repository at this point in the history
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
  • Loading branch information
oliversalzburg committed Nov 18, 2023
1 parent 341db77 commit b7a54b0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
39 changes: 29 additions & 10 deletions packages/kitten-scientists/source/ReligionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
ReligionUpgrades,
TranscendenceUpgradeInfo,
TranscendenceUpgrades,
TransformBtnController,
UnicornItemVariant,
ZiggurathUpgradeInfo,
ZiggurathUpgrades,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -510,27 +511,45 @@ 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 (
!isNil(this._host.gamePage.religionTab.sacrificeBtn) &&
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",
);
});
}
}

Expand Down
14 changes: 12 additions & 2 deletions packages/kitten-scientists/source/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TOptions = Record<string, unknown>> = ButtonModernController & {
new (game: GamePage, options: TOptions): TransformBtnController<TOptions>;
_transform: (model: ButtonModel, amt: number) => boolean;
_newLink: (model: ButtonModel, divider: number) => Link;
controllerOpts: TOptions;
};

export type ClassList = {
Expand Down

0 comments on commit b7a54b0

Please sign in to comment.