Skip to content

Commit

Permalink
fix(time): Void cost ignored when time skipping
Browse files Browse the repository at this point in the history
When repeating the 1000 Years challenge, combusting TCs costs void. KS ignored this and requested time skips, even if no void was available. It also flushed the log with time skip messages, even though none were actually happening.
  • Loading branch information
oliversalzburg committed Jan 25, 2023
1 parent 1748edf commit 4655d5b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 20 additions & 5 deletions packages/userscript/source/TimeControlManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,20 @@ export class TimeControlManager {
}

// If we have less time crystals than our required trigger value, bail out.
const shatterCostIncreaseChallenge = this._host.gamePage.getEffect(
"shatterCostIncreaseChallenge"
);
const timeCrystalsAvailable = this._workshopManager.getValueAvailable("timeCrystal");
if (timeCrystalsAvailable < this.settings.timeSkip.trigger) {
if (
timeCrystalsAvailable < this.settings.timeSkip.trigger ||
timeCrystalsAvailable < 1 + shatterCostIncreaseChallenge
) {
return;
}

const shatterVoidCost = this._host.gamePage.getEffect("shatterVoidCost");
const voidAvailable = this._workshopManager.getValueAvailable("void");
if (voidAvailable < shatterVoidCost) {
return;
}

Expand All @@ -414,9 +426,6 @@ export class TimeControlManager {
return;
}

const yearsPerCycle = this._host.gamePage.calendar.yearsPerCycle;
const remainingYearsCurrentCycle = yearsPerCycle - this._host.gamePage.calendar.cycleYear;
const cyclesPerEra = this._host.gamePage.calendar.cyclesPerEra;
const factor = this._host.gamePage.challenges.getChallenge("1000Years").researched ? 5 : 10;
// How many times/years we can skip before we reach our max heat.
const maxSkips =
Expand All @@ -425,10 +434,16 @@ export class TimeControlManager {
let canSkip = Math.min(
Math.floor((heatMax - heatNow) / factor),
maxSkips,
timeCrystalsAvailable
timeCrystalsAvailable / (1 + shatterCostIncreaseChallenge),
0 < shatterVoidCost ? voidAvailable / shatterVoidCost : Number.POSITIVE_INFINITY
);

// The amount of skips to perform.
let willSkip = 0;

const yearsPerCycle = this._host.gamePage.calendar.yearsPerCycle;
const remainingYearsCurrentCycle = yearsPerCycle - this._host.gamePage.calendar.cycleYear;
const cyclesPerEra = this._host.gamePage.calendar.cyclesPerEra;
// If the cycle has more years remaining than we can even skip, skip all of them.
// I guess the idea here is to not skip through years of another cycle, if that
// cycle may not be enabled for skipping.
Expand Down
2 changes: 2 additions & 0 deletions packages/userscript/source/types/gamePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ export type GamePage = {
| "oilReductionRatio"
| "priceRatio"
| "riftChance"
| "shatterCostIncreaseChallenge"
| "shatterVoidCost"
| "solarRevolutionLimit"
| "standingRatio"
| "tradeCatpowerDiscount"
Expand Down

0 comments on commit 4655d5b

Please sign in to comment.