Skip to content

Commit

Permalink
feat(religion): Sacrifice unicorns for tears
Browse files Browse the repository at this point in the history
  • Loading branch information
oliversalzburg committed Mar 12, 2023
1 parent 806bbd9 commit 645816f
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/documentation/docs/sections/religion.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 28 additions & 0 deletions packages/userscript/source/ReligionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions packages/userscript/source/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
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 @@ -80,6 +80,11 @@ export class ReligionSettings extends SettingTrigger {
*/
sacrificeAlicorns: SettingTrigger;

/**
* Sacrifice unicorns for tears.
*/
sacrificeUnicorns: SettingTrigger;

/**
* Refine tears into BLS.
*/
Expand Down Expand Up @@ -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),
Expand All @@ -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;
Expand All @@ -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);
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.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"),
Expand Down

0 comments on commit 645816f

Please sign in to comment.