Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(religion): Sacrifice unicorns for tears #181

Merged
merged 1 commit into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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