From c4b7ca46e213b80f122d0e93f0ab7cf7c67e0b54 Mon Sep 17 00:00:00 2001 From: Oliver Salzburg Date: Sun, 12 Mar 2023 00:51:46 +0100 Subject: [PATCH] feat(religion): Sacrifice unicorns for tears --- .../documentation/docs/sections/religion.md | 4 +++ packages/userscript/source/ReligionManager.ts | 28 +++++++++++++++++++ packages/userscript/source/i18n/en.json | 1 + .../source/settings/ReligionSettings.ts | 8 ++++++ .../source/ui/ReligionSettingsUi.ts | 16 +++++++++++ 5 files changed, 57 insertions(+) diff --git a/packages/documentation/docs/sections/religion.md b/packages/documentation/docs/sections/religion.md index 06c780886..549056047 100644 --- a/packages/documentation/docs/sections/religion.md +++ b/packages/documentation/docs/sections/religion.md @@ -16,6 +16,10 @@ All selected buildings are built, until their `Max` is reached. ## Additional Options +### Sacrifice Unicorns + +When you have `Trigger` amount of unicorns, sacrifice them to earn tears. + ### Sacrifice Alicorns When you have `Trigger` amount of alicorns, sacrifice them to earn time crystals. diff --git a/packages/userscript/source/ReligionManager.ts b/packages/userscript/source/ReligionManager.ts index 981dfcf1d..5d128734e 100644 --- a/packages/userscript/source/ReligionManager.ts +++ b/packages/userscript/source/ReligionManager.ts @@ -56,6 +56,10 @@ export class ReligionManager implements Automation { this._autoBuild(); + if (this.settings.sacrificeUnicorns.enabled) { + await this._autoSacrificeUnicorns(); + } + if (this.settings.sacrificeAlicorns.enabled) { await this._autoSacrificeAlicorns(); } @@ -506,6 +510,30 @@ export class ReligionManager implements Automation { return null; } + private async _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 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 cost = mustExist(model.prices?.[0]).val; + + this._host.engine.iactivity("act.sacrificeUnicorns", [cost], "ks-faith"); + this._host.engine.storeForSummary( + this._host.engine.i18n("$resources.unicorns.title"), + 1, + "refine" + ); + } + } + private async _autoSacrificeAlicorns() { const alicorns = this._workshopManager.getResource("alicorn"); const available = this._workshopManager.getValueAvailable("alicorn"); diff --git a/packages/userscript/source/i18n/en.json b/packages/userscript/source/i18n/en.json index 151269f54..e45744262 100644 --- a/packages/userscript/source/i18n/en.json +++ b/packages/userscript/source/i18n/en.json @@ -63,6 +63,7 @@ "option.faith.refineTCs": "Refine TCs", "option.faith.refineTears": "Refine Tears", "option.faith.sacrificeAlicorns": "Sacrifice Alicorns", + "option.faith.sacrificeUnicorns": "Sacrifice Unicorns", "option.faith.transcend": "Transcend", "option.festival": "Hold festivals", "option.fix.cry": "Fix Cryochamber", diff --git a/packages/userscript/source/settings/ReligionSettings.ts b/packages/userscript/source/settings/ReligionSettings.ts index 872a1861f..fa0179bd3 100644 --- a/packages/userscript/source/settings/ReligionSettings.ts +++ b/packages/userscript/source/settings/ReligionSettings.ts @@ -80,6 +80,11 @@ export class ReligionSettings extends SettingTrigger { */ sacrificeAlicorns: SettingTrigger; + /** + * Sacrifice unicorns for tears. + */ + sacrificeUnicorns: SettingTrigger; + /** * Refine tears into BLS. */ @@ -237,6 +242,7 @@ export class ReligionSettings extends SettingTrigger { }, bestUnicornBuilding = new Setting(false), sacrificeAlicorns = new SettingTrigger(false, 25), + sacrificeUnicorns = new SettingTrigger(false, 1000000), refineTears = new SettingTrigger(false, 10000), refineTimeCrystals = new SettingTrigger(false, 15000), autoPraise = new SettingTrigger(true, 0.98), @@ -247,6 +253,7 @@ export class ReligionSettings extends SettingTrigger { this.buildings = buildings; this.bestUnicornBuilding = bestUnicornBuilding; this.sacrificeAlicorns = sacrificeAlicorns; + this.sacrificeUnicorns = sacrificeUnicorns; this.refineTears = refineTears; this.refineTimeCrystals = refineTimeCrystals; this.autoPraise = autoPraise; @@ -268,6 +275,7 @@ export class ReligionSettings extends SettingTrigger { this.bestUnicornBuilding.load(settings.bestUnicornBuilding); this.sacrificeAlicorns.load(settings.sacrificeAlicorns); + this.sacrificeUnicorns.load(settings.sacrificeUnicorns); this.refineTears.load(settings.refineTears); this.refineTimeCrystals.load(settings.refineTimeCrystals); this.autoPraise.load(settings.autoPraise); diff --git a/packages/userscript/source/ui/ReligionSettingsUi.ts b/packages/userscript/source/ui/ReligionSettingsUi.ts index 8867418a5..a9b298bec 100644 --- a/packages/userscript/source/ui/ReligionSettingsUi.ts +++ b/packages/userscript/source/ui/ReligionSettingsUi.ts @@ -207,6 +207,22 @@ export class ReligionSettingsUi extends SettingsSectionUi { const listAddition = new SettingsList(this._host, { children: [ new HeaderListItem(this._host, "Additional options"), + new SettingTriggerListItem( + this._host, + this._host.engine.i18n("option.faith.sacrificeUnicorns"), + this.setting.sacrificeUnicorns, + { + behavior: "integer", + onCheck: () => + this._host.engine.imessage("status.sub.enable", [ + this._host.engine.i18n("option.faith.sacrificeUnicorns"), + ]), + onUnCheck: () => + this._host.engine.imessage("status.sub.disable", [ + this._host.engine.i18n("option.faith.sacrificeUnicorns"), + ]), + } + ), new SettingTriggerListItem( this._host, this._host.engine.i18n("option.faith.sacrificeAlicorns"),