Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
fix: Remaining compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
oliversalzburg committed Jul 17, 2021
1 parent 8a8ce09 commit 0650752
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 19 deletions.
13 changes: 9 additions & 4 deletions packages/userscript/source/CraftManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,18 +441,23 @@ export class CraftManager {
// Start of by checking how much catnip we produce per tick at base level.
let productionField = this._host.gamePage.getEffect("catnipPerTickBase");

// `worstWeather` is `true` in all calls, which is good, because the `else` path
// here is broken.
// TODO: Maybe fix this, if it could be useful.
if (worstWeather) {
// Assume fields run at -90%
productionField *= 0.1;
// Factor in cold harshness.
productionField *=
1 + this._host.gamePage.getLimitedDR(this._host.gamePage.getEffect("coldHarshness"), 1);
} else {
productionField *=
this._host.gamePage.calendar.getWeatherMod() +
this._host.gamePage.calendar.getWeatherMod({ name: "catnip" }) +
this._host.gamePage.calendar.getCurSeason().modifiers["catnip"];
}

// When the communism policy is active,
if (this._host.gamePage.science.getPolicy("communism").researched) {
productionField = 0;
}

// Get base production values for jobs.
const resourceProduction = this._host.gamePage.village.getResProduction();
// Check how much catnip we're producing through kitten jobs.
Expand Down
36 changes: 25 additions & 11 deletions packages/userscript/source/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { SpaceManager } from "./SpaceManager";
import { TabManager } from "./TabManager";
import { TimeManager } from "./TimeManager";
import { objectEntries } from "./tools/Entries";
import { mustExist } from "./tools/Maybe";
import { isNil, mustExist } from "./tools/Maybe";
import { TradeManager } from "./TradeManager";
import {
BuildButton,
Expand Down Expand Up @@ -231,11 +231,25 @@ export class Engine {
for (const [name, entry] of objectEntries(this._host.options.auto.timeCtrl.buildItems))
if (entry.checkForReset) {
// TODO: Obvious error here. For upgraded buildings, it needs special handling.
const bld = this._host.gamePage.bld.get(name);
checkedList.push({ name: bld.label, trigger: entry.triggerForReset, val: bld.val });
let bld;
try {
// @ts-expect-error Obvious error here. For upgraded buildings, it needs special handling.
bld = this._host.gamePage.bld.getBuildingExt(name);
} catch (error) {
bld = null;
}
if (isNil(bld)) {
continue;
}

checkedList.push({
name: mustExist(bld.meta.label),
trigger: entry.triggerForReset,
val: bld.meta.val,
});
if (0 < entry.triggerForReset) {
// If the required amount of buildings hasn't been built yet, bail out.
if (bld.val < entry.triggerForReset) {
if (bld.meta.val < entry.triggerForReset) {
return;
}
} else {
Expand All @@ -248,14 +262,14 @@ export class Engine {
// actually a bonfire item.
const unicornPasture = this._host.options.auto.timeCtrl.religionItems.unicornPasture;
if (unicornPasture.checkForReset) {
const bld = this._host.gamePage.bld.get("unicornPasture");
const bld = this._host.gamePage.bld.getBuildingExt("unicornPasture");
checkedList.push({
name: mustExist(bld.label),
name: mustExist(bld.meta.label),
trigger: unicornPasture.triggerForReset,
val: bld.val,
val: bld.meta.val,
});
if (0 < unicornPasture.triggerForReset) {
if (bld.val < unicornPasture.triggerForReset) {
if (bld.meta.val < unicornPasture.triggerForReset) {
return;
}
} else {
Expand Down Expand Up @@ -669,9 +683,9 @@ export class Engine {

// Waits for coin price to drop below a certain treshold before starting the exchange process
// TODO: This is obviously broken.
if (waitForBestPrice === true && coinPrice < 860.0) {
waitForBestPrice = false;
}
// if (waitForBestPrice === true && coinPrice < 860.0) {
// waitForBestPrice = false;
// }

// All of this code is straight-forward. Buy low, sell high.

Expand Down
26 changes: 22 additions & 4 deletions packages/userscript/source/types/gamePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Challenge,
GameTab,
Jobs,
Policy,
Price,
Race,
RaceInfo,
Expand Down Expand Up @@ -59,7 +60,7 @@ export type GamePage = {
/**
* Get the production modifier contribution of the weather for certain resource.
*/
getWeatherMod: (res: Resource) => number;
getWeatherMod: (res: { name: Resource }) => number;
observeBtn: BuildButton | null;
observeHandler: () => void;
season: number;
Expand All @@ -70,9 +71,10 @@ export type GamePage = {
challenges: {
currentChallenge: Challenge;
challenges: Array<{ pending: boolean }>;
getChallenge: (
challenge: Challenge
) => { calculateEffects: (model: unknown, game: GamePage) => void; researched: number };
getChallenge: (challenge: Challenge) => {
calculateEffects: (model: unknown, game: GamePage) => void;
researched: number;
};
};
console: {
maxMessages: number;
Expand Down Expand Up @@ -111,6 +113,7 @@ export type GamePage = {
| "catnipDemandWorkerRatioGlobal"
| "catnipJobRatio"
| "catnipPerTickBase"
| "coldHarshness"
| "corruptionBoostRatio"
| "dataCenterAIRatio"
| "heatMax"
Expand Down Expand Up @@ -259,6 +262,21 @@ export type GamePage = {
};
science: {
get: (name: "civil" | "cryptotheology" | "drama" | "nuclearFission") => { researched: boolean };
getPolicy: (name: Policy) => {
blocked: boolean;
blocks: Array<Policy>;
description: string;
effects: {
goldPriceRatio?: number;
};
label: string;
name: Policy;
prices: Array<Price>;
researched: boolean;
unlocked: boolean;
unlocks: { policies: Array<Policy> };
upgrades: { buildings: Array<Building> };
};
techs: Array<{
description: string;
effectDesdc: string;
Expand Down
11 changes: 11 additions & 0 deletions packages/userscript/source/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ export type GameTab = {

export type Challenge = "1000Years" | "anarchy" | "atheism" | "energy" | "winterIsComing";

export type Policy =
| "authocracy"
| "clearCutting"
| "communism"
| "diplomacy"
| "environmentalism"
| "isolationism"
| "monarchy"
| "republic"
| "stripMining";

export * from "./buildings";
export * from "./gamePage";
export * from "./religion";
Expand Down

0 comments on commit 0650752

Please sign in to comment.