Skip to content

Commit

Permalink
feat(religion): Sacrifice alicorns automatically
Browse files Browse the repository at this point in the history
Sacrifices alicorns to time crystals automatically.
  • Loading branch information
oliversalzburg committed Jan 10, 2023
1 parent 3fec8e8 commit 8c85263
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"cSpell.words": [
"alicorn",
"alicorns",
"Astro",
"autofeed",
"automations",
Expand Down Expand Up @@ -44,15 +46,18 @@
"hydroplant",
"iactivity",
"imessage",
"kairo",
"Meoston",
"mkdocs",
"nagas",
"nbsp",
"necrocorn",
"oliversalzburg",
"POSIX",
"prio",
"promotekittens",
"railguns",
"redmoon",
"savegame",
"starchart",
"Steamworks",
Expand Down
49 changes: 32 additions & 17 deletions packages/userscript/source/ReligionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
ReligionUpgrades,
TranscendenceUpgradeInfo,
TranscendenceUpgrades,
TransformBtnController,
UnicornItemVariant,
ZiggurathUpgradeInfo,
ZiggurathUpgrades,
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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");
Expand All @@ -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(
Expand All @@ -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;

Expand Down
10 changes: 7 additions & 3 deletions packages/userscript/source/i18n/i18nData.json
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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} 年!",
Expand Down Expand Up @@ -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": "修复冷冻仓",
Expand Down
8 changes: 8 additions & 0 deletions packages/userscript/source/settings/ReligionSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export class ReligionSettings extends SettingTrigger {
*/
bestUnicornBuilding: Setting;

/**
* Sacrifice alicorns for time crystals.
*/
sacrificeAlicorns: SettingTrigger;

/**
* Refine tears into BLS.
*/
Expand Down Expand Up @@ -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),
Expand All @@ -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;
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions packages/userscript/source/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export type ResourceCraftable =

export type Resource =
| ResourceCraftable
| "alicorn"
| "antimatter"
| "blackcoin"
| "bloodstone"
Expand Down
5 changes: 5 additions & 0 deletions packages/userscript/source/types/religion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export type ReligionTab = GameTab & {
*/
rUpgradeButtons: Array<BuildButton<ReligionUpgrades>>;

/**
* Sacrifice alicorns.
*/
sacrificeAlicornsBtn: BuildButton<string, ButtonModernModel, TransformBtnController>;

/**
* Sacrifice unicorns.
*/
Expand Down
16 changes: 16 additions & 0 deletions packages/userscript/source/ui/ReligionSettingsUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,22 @@ export class ReligionSettingsUi extends SettingsSectionUi<ReligionSettings> {
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"),
Expand Down

0 comments on commit 8c85263

Please sign in to comment.