From 8c85263cf6fe9c7f5e76a3ddbc2d1460dbc235b1 Mon Sep 17 00:00:00 2001 From: Oliver Salzburg Date: Tue, 10 Jan 2023 21:56:09 +0100 Subject: [PATCH] feat(religion): Sacrifice alicorns automatically Sacrifices alicorns to time crystals automatically. --- .vscode/settings.json | 5 ++ packages/userscript/source/ReligionManager.ts | 49 ++++++++++++------- packages/userscript/source/i18n/i18nData.json | 10 ++-- .../source/settings/ReligionSettings.ts | 8 +++ packages/userscript/source/types/index.ts | 1 + packages/userscript/source/types/religion.ts | 5 ++ .../source/ui/ReligionSettingsUi.ts | 16 ++++++ 7 files changed, 74 insertions(+), 20 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 487666ba3..d4660b178 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,6 +13,8 @@ "editor.defaultFormatter": "esbenp.prettier-vscode" }, "cSpell.words": [ + "alicorn", + "alicorns", "Astro", "autofeed", "automations", @@ -44,15 +46,18 @@ "hydroplant", "iactivity", "imessage", + "kairo", "Meoston", "mkdocs", "nagas", "nbsp", + "necrocorn", "oliversalzburg", "POSIX", "prio", "promotekittens", "railguns", + "redmoon", "savegame", "starchart", "Steamworks", diff --git a/packages/userscript/source/ReligionManager.ts b/packages/userscript/source/ReligionManager.ts index 832ab075b..d565faa2a 100644 --- a/packages/userscript/source/ReligionManager.ts +++ b/packages/userscript/source/ReligionManager.ts @@ -20,7 +20,6 @@ import { ReligionUpgrades, TranscendenceUpgradeInfo, TranscendenceUpgrades, - TransformBtnController, UnicornItemVariant, ZiggurathUpgradeInfo, ZiggurathUpgrades, @@ -57,6 +56,10 @@ export class ReligionManager implements Automation { this._autoBuild(); + if (this.settings.sacrificeAlicorns.enabled) { + await this._autoSacrificeAlicorns(); + } + if (this.settings.refineTears.enabled) { await this._autoTears(); } @@ -501,6 +504,29 @@ export class ReligionManager implements Automation { return null; } + private async _autoSacrificeAlicorns() { + const alicorns = this._workshopManager.getResource("alicorn"); + const available = this._workshopManager.getValueAvailable("alicorn"); + if ( + this.settings.sacrificeAlicorns.trigger <= available && + this.settings.sacrificeAlicorns.trigger <= alicorns.value + ) { + const controller = this._host.gamePage.religionTab.sacrificeAlicornsBtn.controller; + const model = this._host.gamePage.religionTab.sacrificeAlicornsBtn.model; + + await new Promise(resolve => controller.buyItem(model, new MouseEvent("click"), resolve)); + + const cost = mustExist(model.prices?.[0]).val; + + this._host.engine.iactivity("act.sacrificeAlicorns", [cost], "ks-faith"); + this._host.engine.storeForSummary( + this._host.engine.i18n("$resources.alicorn.title"), + 1, + "refine" + ); + } + } + private async _autoTears() { const tears = this._workshopManager.getResource("tears"); const available = this._workshopManager.getValueAvailable("tears"); @@ -509,14 +535,9 @@ export class ReligionManager implements Automation { this.settings.refineTears.trigger <= tears.value ) { const controller = new classes.ui.religion.RefineTearsBtnController(this._host.gamePage); + const model = this._host.gamePage.religionTab.refineBtn.model; - await new Promise(resolve => - controller.buyItem( - this._host.gamePage.religionTab.refineBtn.model, - new MouseEvent("click"), - resolve - ) - ); + await new Promise(resolve => controller.buyItem(model, new MouseEvent("click"), resolve)); this._host.engine.iactivity("act.refineTears", [], "ks-faith"); this._host.engine.storeForSummary( @@ -534,16 +555,10 @@ export class ReligionManager implements Automation { this.settings.refineTimeCrystals.trigger <= available && this.settings.refineTimeCrystals.trigger <= timeCrystals.value ) { - const controller = this._host.gamePage.religionTab.refineTCBtn - .controller as TransformBtnController; + const controller = this._host.gamePage.religionTab.refineTCBtn.controller; const model = this._host.gamePage.religionTab.refineTCBtn.model; - await new Promise(resolve => - controller.buyItem( - this._host.gamePage.religionTab.refineTCBtn.model, - new MouseEvent("click"), - resolve - ) - ); + + await new Promise(resolve => controller.buyItem(model, new MouseEvent("click"), resolve)); const cost = mustExist(model.prices?.[0]).val; diff --git a/packages/userscript/source/i18n/i18nData.json b/packages/userscript/source/i18n/i18nData.json index 51741db71..fabffba08 100644 --- a/packages/userscript/source/i18n/i18nData.json +++ b/packages/userscript/source/i18n/i18nData.json @@ -15,6 +15,7 @@ "act.promote": "Kittens' leader has been promoted to rank {0}", "act.refineTCs": "Refined {0} time crystals", "act.refineTears": "Refined tears into BLS", + "act.sacrificeAlicorns": "Sacrificed {0} alicorns", "act.sun.discover": "Kittens have discovered {0}", "act.sun.discovers": "Kittens have discovered {0} {1} times", "act.time.skip": "Kittens combust a time crystal, {0} years skipped!", @@ -54,17 +55,18 @@ "option.crypto": "Trade Blackcoin", "option.elect": "Elect leader", "option.embassies": "Build Embassies", - "option.faith.adore": "Auto Adore the Galaxy", + "option.faith.adore": "Adore the Galaxy", "option.faith.best.unicorn.desc": "Include auto Sacrifice Unicorns if tears are not enough to build the best unicorn building", "option.faith.best.unicorn": "Build Best Unicorn Building First", "option.faith.refineTears": "Refine Tears", "option.faith.refineTCs": "Refine TCs", - "option.faith.transcend": "Auto Transcend", + "option.faith.sacrificeAlicorns": "Sacrifice Alicorns", + "option.faith.transcend": "Transcend", "option.festival": "Hold festivals", "option.fix.cry": "Fix Cryochamber", "option.hunt": "Hunt", "option.observe": "Observe Astro Events", - "option.praise": "Auto Praise", + "option.praise": "Praise the Sun", "option.promote": "Promote leader", "option.promotekittens": "Promote kittens", "option.shipOverride": "Force Ships to 243", @@ -211,6 +213,7 @@ "act.promote": "领袖被提拔到 {0} 级", "act.refineTCs": "Refined {0} time crystals", "act.refineTears": "Refined tears into BLS", + "act.sacrificeAlicorns": "Sacrificed alicorns", "act.sun.discover": "小猫在 {0} 方面获得顿悟", "act.sun.discovers": "小猫在 {0} 方面获得 {1} 次顿悟", "act.time.skip": "燃烧时间水晶, 跳过接下来的 {0} 年!", @@ -255,6 +258,7 @@ "option.faith.best.unicorn": "优先最佳独角兽建筑", "option.faith.refineTears": "Refine Tears", "option.faith.refineTCs": "Refine TCs", + "option.faith.sacrificeAlicorns": "Sacrifice Alicorns", "option.faith.transcend": "自动超越", "option.festival": "举办节日", "option.fix.cry": "修复冷冻仓", diff --git a/packages/userscript/source/settings/ReligionSettings.ts b/packages/userscript/source/settings/ReligionSettings.ts index 1c254a8bf..99b4f1bc8 100644 --- a/packages/userscript/source/settings/ReligionSettings.ts +++ b/packages/userscript/source/settings/ReligionSettings.ts @@ -72,6 +72,11 @@ export class ReligionSettings extends SettingTrigger { */ bestUnicornBuilding: Setting; + /** + * Sacrifice alicorns for time crystals. + */ + sacrificeAlicorns: SettingTrigger; + /** * Refine tears into BLS. */ @@ -313,6 +318,7 @@ export class ReligionSettings extends SettingTrigger { ), }, bestUnicornBuilding = new Setting(false), + sacrificeAlicorns = new SettingTrigger(false, 25), refineTears = new SettingTrigger(false, 10000), refineTimeCrystals = new SettingTrigger(false, 15000), autoPraise = new SettingTrigger(true, 0.98), @@ -322,6 +328,7 @@ export class ReligionSettings extends SettingTrigger { super(enabled, trigger); this.buildings = buildings; this.bestUnicornBuilding = bestUnicornBuilding; + this.sacrificeAlicorns = sacrificeAlicorns; this.refineTears = refineTears; this.refineTimeCrystals = refineTimeCrystals; this.autoPraise = autoPraise; @@ -342,6 +349,7 @@ export class ReligionSettings extends SettingTrigger { }); this.bestUnicornBuilding.load(settings.bestUnicornBuilding); + this.sacrificeAlicorns.load(settings.sacrificeAlicorns); this.refineTears.load(settings.refineTears); this.refineTimeCrystals.load(settings.refineTimeCrystals); this.autoPraise.load(settings.autoPraise); diff --git a/packages/userscript/source/types/index.ts b/packages/userscript/source/types/index.ts index 407ab80cf..955992636 100644 --- a/packages/userscript/source/types/index.ts +++ b/packages/userscript/source/types/index.ts @@ -48,6 +48,7 @@ export type ResourceCraftable = export type Resource = | ResourceCraftable + | "alicorn" | "antimatter" | "blackcoin" | "bloodstone" diff --git a/packages/userscript/source/types/religion.ts b/packages/userscript/source/types/religion.ts index 334cedf5f..a596f1023 100644 --- a/packages/userscript/source/types/religion.ts +++ b/packages/userscript/source/types/religion.ts @@ -23,6 +23,11 @@ export type ReligionTab = GameTab & { */ rUpgradeButtons: Array>; + /** + * Sacrifice alicorns. + */ + sacrificeAlicornsBtn: BuildButton; + /** * Sacrifice unicorns. */ diff --git a/packages/userscript/source/ui/ReligionSettingsUi.ts b/packages/userscript/source/ui/ReligionSettingsUi.ts index 35845e921..b119f5f33 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.sacrificeAlicorns"), + this.setting.sacrificeAlicorns, + { + behavior: "integer", + onCheck: () => + this._host.engine.imessage("status.sub.enable", [ + this._host.engine.i18n("option.faith.sacrificeAlicorns"), + ]), + onUnCheck: () => + this._host.engine.imessage("status.sub.disable", [ + this._host.engine.i18n("option.faith.sacrificeAlicorns"), + ]), + } + ), new SettingTriggerListItem( this._host, this._host.engine.i18n("option.faith.refineTears"),