Skip to content

Commit

Permalink
fix(time): Cryochamber repairs ignore resource control
Browse files Browse the repository at this point in the history
Cryochambers were fixed ASAP instead.

Fixes #212
Fixes #193
  • Loading branch information
oliversalzburg committed Dec 21, 2023
1 parent ec5b4f8 commit af37656
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
58 changes: 34 additions & 24 deletions packages/kitten-scientists/source/TimeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ export class TimeManager {
readonly settings: TimeSettings;
readonly manager: TabManager<TimeTab>;
private readonly _bulkManager: BulkPurchaseHelper;
private readonly _workshopManager: WorkshopManager;

constructor(host: UserScript, workshopManager: WorkshopManager, settings = new TimeSettings()) {
this._host = host;
this.settings = settings;
this.manager = new TabManager(this._host, "Time");
this._bulkManager = new BulkPurchaseHelper(this._host, workshopManager);
this._workshopManager = workshopManager;
}

tick(context: TickContext) {
Expand Down Expand Up @@ -166,33 +168,41 @@ export class TimeManager {
}

fixCryochambers() {
// Fix used cryochambers
// If the option is enabled and we have used cryochambers...
if (0 < this._host.game.time.getVSU("usedCryochambers").val) {
const btn = this.manager.tab.vsPanel.children[0].children[0];

let fixed = 0;
let fixHappened;
do {
fixHappened = false;

(btn.controller as FixCryochamberBtnController).buyItem(
btn.model as ButtonModernModel,
new MouseEvent("click"),
// This callback is invoked at the end of the `buyItem` call.
// Thus, the callback should be invoked before this loop ends.
(didHappen: boolean) => {
fixHappened = didHappen;
fixed += didHappen ? 1 : 0;
},
);
} while (fixHappened);
if (this._host.game.time.getVSU("usedCryochambers").val < 1) {
return;
}

if (0 < fixed) {
this._host.engine.iactivity("act.fix.cry", [fixed], "ks-fixCry");
this._host.engine.storeForSummary("fix.cry", fixed);
const prices = mustExist(this._host.game.time.getVSU("usedCryochambers").fixPrices);
for (const price of prices) {
const available = this._workshopManager.getValueAvailable(price.name);
if (available < price.val) {
return;
}
}

const btn = this.manager.tab.vsPanel.children[0].children[0];

let fixed = 0;
let fixHappened;
do {
fixHappened = false;

(btn.controller as FixCryochamberBtnController).buyItem(
btn.model as ButtonModernModel,
new MouseEvent("click"),
// This callback is invoked at the end of the `buyItem` call.
// Thus, the callback should be invoked before this loop ends.
(didHappen: boolean) => {
fixHappened = didHappen;
fixed += didHappen ? 1 : 0;
},
);
} while (fixHappened);

if (0 < fixed) {
this._host.engine.iactivity("act.fix.cry", [fixed], "ks-fixCry");
this._host.engine.storeForSummary("fix.cry", fixed);
}
}

turnOnChronoFurnace() {
Expand Down
1 change: 1 addition & 0 deletions packages/kitten-scientists/source/types/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export type VoidSpaceUpgradeInfo = AbstractTimeUpgradeInfo & {
flavor: string;
limitBuild: 0;
name: VoidSpaceUpgrades;
fixPrices?: Array<Price>;
upgrades: {
voidSpace: Array<"cryochambers">;
};
Expand Down

0 comments on commit af37656

Please sign in to comment.