Skip to content

Commit ea98427

Browse files
fix(religion): Missing safety checks
Some automations would try to interact with buttons that might not exist early in the game.
1 parent 1c7ac7c commit ea98427

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

packages/userscript/source/ReligionManager.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ export class ReligionManager implements Automation {
129129
const tearsAvailableForUse =
130130
this._workshopManager.getValue("tears") - this._workshopManager.getStock("tears");
131131

132-
if (tearsAvailableForUse < tearsNeeded) {
132+
if (
133+
!isNil(this._host.gamePage.religionTab.sacrificeBtn) &&
134+
tearsAvailableForUse < tearsNeeded
135+
) {
133136
// if no ziggurat, getBestUnicornBuilding will return unicornPasture
134137
// TODO: ☝ Yeah. So?
135138

@@ -508,6 +511,7 @@ export class ReligionManager implements Automation {
508511
const alicorns = this._workshopManager.getResource("alicorn");
509512
const available = this._workshopManager.getValueAvailable("alicorn");
510513
if (
514+
!isNil(this._host.gamePage.religionTab.sacrificeAlicornsBtn) &&
511515
this.settings.sacrificeAlicorns.trigger <= available &&
512516
this.settings.sacrificeAlicorns.trigger <= alicorns.value
513517
) {
@@ -531,6 +535,7 @@ export class ReligionManager implements Automation {
531535
const tears = this._workshopManager.getResource("tears");
532536
const available = this._workshopManager.getValueAvailable("tears");
533537
if (
538+
!isNil(this._host.gamePage.religionTab.refineBtn) &&
534539
this.settings.refineTears.trigger <= available &&
535540
this.settings.refineTears.trigger <= tears.value
536541
) {
@@ -552,6 +557,7 @@ export class ReligionManager implements Automation {
552557
const timeCrystals = this._workshopManager.getResource("timeCrystal");
553558
const available = this._workshopManager.getValueAvailable("timeCrystal");
554559
if (
560+
!isNil(this._host.gamePage.religionTab.refineTCBtn) &&
555561
this.settings.refineTimeCrystals.trigger <= available &&
556562
this.settings.refineTimeCrystals.trigger <= timeCrystals.value
557563
) {

packages/userscript/source/types/religion.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ export type ReligionTab = GameTab & {
1111
/**
1212
* Refine tears.
1313
*/
14-
refineBtn: BuildButton;
14+
refineBtn?: BuildButton;
1515

1616
/**
1717
* Refine time crystals.
1818
*/
19-
refineTCBtn: BuildButton;
19+
refineTCBtn?: BuildButton;
2020

2121
/**
2222
* Religion upgrade (Order of the sun) buttons.
@@ -26,12 +26,12 @@ export type ReligionTab = GameTab & {
2626
/**
2727
* Sacrifice alicorns.
2828
*/
29-
sacrificeAlicornsBtn: BuildButton<string, ButtonModernModel, TransformBtnController>;
29+
sacrificeAlicornsBtn: BuildButton<string, ButtonModernModel, TransformBtnController> | null;
3030

3131
/**
3232
* Sacrifice unicorns.
3333
*/
34-
sacrificeBtn: BuildButton<string, ButtonModernModel, TransformBtnController>;
34+
sacrificeBtn: BuildButton<string, ButtonModernModel, TransformBtnController> | null;
3535

3636
/**
3737
* Ziggurath upgrade buttons.

0 commit comments

Comments
 (0)