mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2025-03-08 11:29:19 +01:00
rm any
This commit is contained in:
@ -7,7 +7,40 @@ import React from "react";
|
||||
import { FactionNames } from "../../Faction/data/FactionNames";
|
||||
import { CONSTANTS } from "../../Constants";
|
||||
|
||||
function getRandomBonus(): any {
|
||||
interface CircadianBonus {
|
||||
bonuses: {
|
||||
[key: string]: number | undefined;
|
||||
agility?: number;
|
||||
agility_exp?: number;
|
||||
charisma?: number;
|
||||
charisma_exp?: number;
|
||||
company_rep?: number;
|
||||
crime_money?: number;
|
||||
crime_success?: number;
|
||||
defense?: number;
|
||||
defense_exp?: number;
|
||||
dexterity?: number;
|
||||
dexterity_exp?: number;
|
||||
faction_rep?: number;
|
||||
hacking?: number;
|
||||
hacking_chance?: number;
|
||||
hacking_exp?: number;
|
||||
hacking_grow?: number;
|
||||
hacking_money?: number;
|
||||
hacking_speed?: number;
|
||||
hacknet_node_core_cost?: number;
|
||||
hacknet_node_level_cost?: number;
|
||||
hacknet_node_money?: number;
|
||||
hacknet_node_purchase_cost?: number;
|
||||
hacknet_node_ram_cost?: number;
|
||||
strength?: number;
|
||||
strength_exp?: number;
|
||||
work_money?: number;
|
||||
};
|
||||
description: string;
|
||||
}
|
||||
|
||||
function getRandomBonus(): CircadianBonus {
|
||||
const bonuses = [
|
||||
{
|
||||
bonuses: {
|
||||
|
@ -178,7 +178,7 @@ export class Bladeburner implements IBladeburner {
|
||||
return this.resetAction();
|
||||
}
|
||||
this.actionTimeToComplete = action.getActionTime(this, person);
|
||||
} catch (e: any) {
|
||||
} catch (e: unknown) {
|
||||
exceptionAlert(e);
|
||||
}
|
||||
break;
|
||||
@ -195,7 +195,7 @@ export class Bladeburner implements IBladeburner {
|
||||
return this.resetAction();
|
||||
}
|
||||
this.actionTimeToComplete = action.getActionTime(this, person);
|
||||
} catch (e: any) {
|
||||
} catch (e: unknown) {
|
||||
exceptionAlert(e);
|
||||
}
|
||||
break;
|
||||
@ -213,7 +213,7 @@ export class Bladeburner implements IBladeburner {
|
||||
throw new Error("action should not be null");
|
||||
}
|
||||
this.actionTimeToComplete = testBlackOp.action.getActionTime(this, person);
|
||||
} catch (e: any) {
|
||||
} catch (e: unknown) {
|
||||
exceptionAlert(e);
|
||||
}
|
||||
break;
|
||||
@ -264,7 +264,7 @@ export class Bladeburner implements IBladeburner {
|
||||
for (let i = 0; i < arrayOfCommands.length; ++i) {
|
||||
this.executeConsoleCommand(player, arrayOfCommands[i]);
|
||||
}
|
||||
} catch (e: any) {
|
||||
} catch (e: unknown) {
|
||||
exceptionAlert(e);
|
||||
}
|
||||
}
|
||||
@ -1367,7 +1367,7 @@ export class Bladeburner implements IBladeburner {
|
||||
if (action.autoLevel) {
|
||||
action.level = action.maxLevel;
|
||||
} // Autolevel
|
||||
} catch (e: any) {
|
||||
} catch (e: unknown) {
|
||||
exceptionAlert(e);
|
||||
}
|
||||
break;
|
||||
@ -1462,7 +1462,7 @@ export class Bladeburner implements IBladeburner {
|
||||
this.log(`${person.whoAmI()}: You lost ${formatNumber(losses, 0)} team members during ${action.name}`);
|
||||
}
|
||||
}
|
||||
} catch (e: any) {
|
||||
} catch (e: unknown) {
|
||||
exceptionAlert(e);
|
||||
}
|
||||
break;
|
||||
@ -2154,7 +2154,8 @@ export class Bladeburner implements IBladeburner {
|
||||
() => `Starting bladeburner action with type '${type}' and name '${name}'`,
|
||||
);
|
||||
return true;
|
||||
} catch (e: any) {
|
||||
} catch (e: unknown) {
|
||||
console.error(e);
|
||||
this.resetAction();
|
||||
workerScript.log("bladeburner.startAction", () => errorLogText);
|
||||
return false;
|
||||
|
@ -60,40 +60,6 @@ export class Node {
|
||||
n.parent = this;
|
||||
}
|
||||
|
||||
// Return an object that describes a TreantJS-compatible markup/config for this Node
|
||||
// See: http://fperucic.github.io/treant-js/
|
||||
createTreantMarkup(): any {
|
||||
const childrenArray = [];
|
||||
for (let i = 0; i < this.children.length; ++i) {
|
||||
childrenArray.push(this.children[i].createTreantMarkup());
|
||||
}
|
||||
|
||||
// Determine what css class this Node should have in the diagram
|
||||
let htmlClass = "tooltip";
|
||||
if (this.researched) {
|
||||
htmlClass += " researched";
|
||||
} else if (this.parent && this.parent.researched === false) {
|
||||
htmlClass += " locked";
|
||||
} else {
|
||||
htmlClass += " unlocked";
|
||||
}
|
||||
|
||||
const research: Research | null = ResearchMap[this.text];
|
||||
const sanitizedName: string = this.text.replace(/\s/g, "");
|
||||
return {
|
||||
children: childrenArray,
|
||||
HTMLclass: htmlClass,
|
||||
innerHTML:
|
||||
`<div id="${sanitizedName}-corp-research-click-listener">` +
|
||||
`${this.text}<br>${numeralWrapper.format(this.cost, "0,0")} Scientific Research` +
|
||||
`<span class="tooltiptext">` +
|
||||
`${research.desc}` +
|
||||
`</span>` +
|
||||
`</div>`,
|
||||
text: { name: this.text },
|
||||
};
|
||||
}
|
||||
|
||||
// Recursive function for finding a Node with the specified text
|
||||
findNode(text: string): Node | null {
|
||||
// Is this the Node?
|
||||
@ -127,23 +93,6 @@ export class ResearchTree {
|
||||
// Root Node
|
||||
root: Node | null = null;
|
||||
|
||||
// Return an object that contains a Tree markup for TreantJS (using the JSON approach)
|
||||
// See: http://fperucic.github.io/treant-js/
|
||||
createTreantMarkup(): any {
|
||||
if (this.root == null) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const treeMarkup = this.root.createTreantMarkup();
|
||||
|
||||
return {
|
||||
chart: {
|
||||
container: "",
|
||||
},
|
||||
nodeStructure: treeMarkup,
|
||||
};
|
||||
}
|
||||
|
||||
// Gets an array with the 'text' values of ALL Nodes in the Research Tree
|
||||
getAllNodes(): string[] {
|
||||
const res: string[] = [];
|
||||
@ -236,7 +185,20 @@ export class ResearchTree {
|
||||
continue;
|
||||
}
|
||||
|
||||
const mult: any = (research as any)[propName];
|
||||
const mult =
|
||||
{
|
||||
advertisingMult: research.advertisingMult,
|
||||
employeeChaMult: research.employeeChaMult,
|
||||
employeeCreMult: research.employeeCreMult,
|
||||
employeeEffMult: research.employeeEffMult,
|
||||
employeeIntMult: research.employeeIntMult,
|
||||
productionMult: research.productionMult,
|
||||
productProductionMult: research.productProductionMult,
|
||||
salesMult: research.salesMult,
|
||||
sciResearchMult: research.sciResearchMult,
|
||||
storageMult: research.storageMult,
|
||||
}[propName] ?? null;
|
||||
|
||||
if (mult == null) {
|
||||
console.warn(`Invalid propName specified in ResearchTree.getMultiplierHelper: ${propName}`);
|
||||
continue;
|
||||
|
@ -99,7 +99,7 @@ export class Warehouse {
|
||||
updateSize(corporation: ICorporation, industry: IIndustry): void {
|
||||
try {
|
||||
this.size = this.level * 100 * corporation.getStorageMultiplier() * industry.getStorageMultiplier();
|
||||
} catch (e: any) {
|
||||
} catch (e: unknown) {
|
||||
exceptionAlert(e);
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ export function Overview({ rerender }: IProps): React.ReactElement {
|
||||
const corp = useCorporation();
|
||||
const profit: number = corp.revenue - corp.expenses;
|
||||
|
||||
const multRows: any[][] = [];
|
||||
const multRows: string[][] = [];
|
||||
function appendMult(name: string, value: number): void {
|
||||
if (value === 1) return;
|
||||
multRows.push([name, numeralWrapper.format(value, "0.000")]);
|
||||
|
@ -24,8 +24,8 @@ export function SaveFile(): React.ReactElement {
|
||||
const base64Save = await saveObject.getImportStringFromFile(event.target.files);
|
||||
const save = atob(base64Save);
|
||||
setSaveFile(save);
|
||||
} catch (ex: any) {
|
||||
SnackbarEvents.emit(ex.toString(), ToastVariant.ERROR, 5000);
|
||||
} catch (e: unknown) {
|
||||
SnackbarEvents.emit(String(e), ToastVariant.ERROR, 5000);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ const types = [KEY.PIPE, KEY.DOT, KEY.FORWARD_SLASH, KEY.HYPHEN, "█", KEY.HASH
|
||||
|
||||
const colors = ["red", "#FFC107", "blue", "white"];
|
||||
|
||||
const colorNames: any = {
|
||||
const colorNames: Record<string, string> = {
|
||||
red: "red",
|
||||
"#FFC107": "yellow",
|
||||
blue: "blue",
|
||||
|
@ -77,7 +77,9 @@ function LocationLetter(location: Location): React.ReactElement {
|
||||
|
||||
function ASCIICity(props: IProps): React.ReactElement {
|
||||
const locationLettersRegex = /[A-Z]/g;
|
||||
const letterMap: any = {
|
||||
const letterMap: {
|
||||
[key: string]: number;
|
||||
} = {
|
||||
A: 0,
|
||||
B: 1,
|
||||
C: 2,
|
||||
@ -106,10 +108,10 @@ function ASCIICity(props: IProps): React.ReactElement {
|
||||
Z: 25,
|
||||
};
|
||||
|
||||
const lineElems = (s: string): JSX.Element[] => {
|
||||
const elems: any[] = [];
|
||||
const matches: any[] = [];
|
||||
let match: any;
|
||||
const lineElems = (s: string): (string | React.ReactElement)[] => {
|
||||
const elems: (string | React.ReactElement)[] = [];
|
||||
const matches: RegExpExecArray[] = [];
|
||||
let match: RegExpExecArray | null = null;
|
||||
while ((match = locationLettersRegex.exec(s)) !== null) {
|
||||
matches.push(match);
|
||||
}
|
||||
|
@ -25,13 +25,11 @@ export class HospitalLocation extends React.Component<IProps, IState> {
|
||||
/**
|
||||
* Stores button styling that sets them all to block display
|
||||
*/
|
||||
btnStyle: any;
|
||||
btnStyle = { display: "block" };
|
||||
|
||||
constructor(props: IProps) {
|
||||
super(props);
|
||||
|
||||
this.btnStyle = { display: "block" };
|
||||
|
||||
this.getCost = this.getCost.bind(this);
|
||||
this.getHealed = this.getHealed.bind(this);
|
||||
|
||||
|
@ -56,7 +56,7 @@ export function SpecialLocation(props: IProps): React.ReactElement {
|
||||
router.toBladeburner();
|
||||
} else if (p.strength >= 100 && p.defense >= 100 && p.dexterity >= 100 && p.agility >= 100) {
|
||||
// Apply for Bladeburner division
|
||||
p.startBladeburner({ new: true });
|
||||
p.startBladeburner();
|
||||
dialogBoxCreate("You have been accepted into the Bladeburner division!");
|
||||
setRerender((old) => !old);
|
||||
|
||||
|
@ -4,9 +4,10 @@ import type { BaseServer } from "../Server/BaseServer";
|
||||
import type { WorkerScript } from "./WorkerScript";
|
||||
import { makeRuntimeRejectMsg } from "../NetscriptEvaluator";
|
||||
import { Player } from "../Player";
|
||||
import { CityName } from "src/Locations/data/CityNames";
|
||||
import { CityName } from "../Locations/data/CityNames";
|
||||
import { BasicHGWOptions } from "../ScriptEditor/NetscriptDefinitions";
|
||||
|
||||
type ExternalFunction = (...args: any[]) => any;
|
||||
type ExternalFunction = (...args: unknown[]) => unknown;
|
||||
export type ExternalAPI = {
|
||||
[string: string]: ExternalAPI | ExternalFunction;
|
||||
};
|
||||
@ -45,11 +46,11 @@ type NetscriptHelpers = {
|
||||
checkSingularityAccess: (func: string) => void;
|
||||
hack: (
|
||||
ctx: NetscriptContext,
|
||||
hostname: any,
|
||||
manual: any,
|
||||
{ threads: requestedThreads, stock }?: any,
|
||||
hostname: string,
|
||||
manual: boolean,
|
||||
{ threads: requestedThreads, stock }?: BasicHGWOptions,
|
||||
) => Promise<number>;
|
||||
getValidPort: (funcName: string, port: any) => IPort;
|
||||
getValidPort: (funcName: string, port: number) => IPort;
|
||||
};
|
||||
|
||||
type WrappedNetscriptHelpers = {
|
||||
@ -60,13 +61,13 @@ type WrappedNetscriptHelpers = {
|
||||
boolean: (v: unknown) => boolean;
|
||||
getServer: (hostname: string) => BaseServer;
|
||||
checkSingularityAccess: () => void;
|
||||
hack: (hostname: any, manual: any, { threads: requestedThreads, stock }?: any) => Promise<number>;
|
||||
getValidPort: (port: any) => IPort;
|
||||
hack: (hostname: string, manual: boolean, { threads: requestedThreads, stock }?: BasicHGWOptions) => Promise<number>;
|
||||
getValidPort: (port: number) => IPort;
|
||||
};
|
||||
|
||||
function wrapFunction(
|
||||
helpers: NetscriptHelpers,
|
||||
wrappedAPI: any,
|
||||
wrappedAPI: ExternalAPI,
|
||||
workerScript: WorkerScript,
|
||||
func: (_ctx: NetscriptContext) => (...args: unknown[]) => unknown,
|
||||
...tree: string[]
|
||||
@ -93,8 +94,8 @@ function wrapFunction(
|
||||
boolean: helpers.boolean,
|
||||
getServer: (hostname: string) => helpers.getServer(hostname, ctx),
|
||||
checkSingularityAccess: () => helpers.checkSingularityAccess(functionName),
|
||||
hack: (hostname: any, manual: any, extra?: any) => helpers.hack(ctx, hostname, manual, extra),
|
||||
getValidPort: (port: any) => helpers.getValidPort(functionPath, port),
|
||||
hack: (hostname: string, manual: boolean, extra?: BasicHGWOptions) => helpers.hack(ctx, hostname, manual, extra),
|
||||
getValidPort: (port: number) => helpers.getValidPort(functionPath, port),
|
||||
},
|
||||
};
|
||||
function wrappedFunction(...args: unknown[]): unknown {
|
||||
@ -136,7 +137,7 @@ export function wrapAPI(
|
||||
return wrappedAPI;
|
||||
}
|
||||
|
||||
function setNestedProperty(root: any, value: any, ...tree: string[]): any {
|
||||
function setNestedProperty(root: any, value: any, ...tree: string[]): void {
|
||||
let target = root;
|
||||
const key = tree.pop();
|
||||
if (typeof key !== "string") {
|
||||
|
1
src/Netscript/ScriptArg.ts
Normal file
1
src/Netscript/ScriptArg.ts
Normal file
@ -0,0 +1 @@
|
||||
export type ScriptArg = string | number | boolean;
|
@ -15,12 +15,14 @@ import { GetServer } from "../Server/AllServers";
|
||||
import { BaseServer } from "../Server/BaseServer";
|
||||
import { IMap } from "../types";
|
||||
import { NS } from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { ScriptDeath } from "./ScriptDeath";
|
||||
import { ScriptArg } from "./ScriptArg";
|
||||
|
||||
export class WorkerScript {
|
||||
/**
|
||||
* Script's arguments
|
||||
*/
|
||||
args: any[];
|
||||
args: ScriptArg[];
|
||||
|
||||
/**
|
||||
* Copy of the script's code
|
||||
@ -36,7 +38,7 @@ export class WorkerScript {
|
||||
/**
|
||||
* Holds the Promise reject() function while the script is "blocked" by an async op
|
||||
*/
|
||||
delayReject?: (reason?: any) => void;
|
||||
delayReject?: (reason?: ScriptDeath) => void;
|
||||
|
||||
/**
|
||||
* Stores names of all functions that have logging disabled
|
||||
@ -110,7 +112,7 @@ export class WorkerScript {
|
||||
/**
|
||||
* Function called when the script ends.
|
||||
*/
|
||||
atExit: any;
|
||||
atExit?: () => void;
|
||||
|
||||
constructor(runningScriptObj: RunningScript, pid: number, nsFuncsGenerator?: (ws: WorkerScript) => NS) {
|
||||
this.name = runningScriptObj.filename;
|
||||
|
@ -72,9 +72,11 @@ function stopAndCleanUpWorkerScript(workerScript: WorkerScript, rerenderUi = tru
|
||||
if (typeof workerScript.atExit === "function") {
|
||||
try {
|
||||
workerScript.atExit();
|
||||
} catch (e: any) {
|
||||
} catch (e: unknown) {
|
||||
dialogBoxCreate(
|
||||
`Error trying to call atExit for script ${workerScript.name} on ${workerScript.hostname} ${workerScript.scriptRef.args} ${e}`,
|
||||
`Error trying to call atExit for script ${workerScript.name} on ${workerScript.hostname} ${
|
||||
workerScript.scriptRef.args
|
||||
} ${String(e)}`,
|
||||
);
|
||||
}
|
||||
workerScript.atExit = undefined;
|
||||
|
@ -1940,8 +1940,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
// Coerce 'data' to be a string
|
||||
try {
|
||||
data = String(data);
|
||||
} catch (e: any) {
|
||||
throw ctx.makeRuntimeErrorMsg(`Invalid data (${e}). Data being written must be convertible to a string`);
|
||||
} catch (e: unknown) {
|
||||
throw ctx.makeRuntimeErrorMsg(`Invalid data (${String(e)}). Data being written must be convertible to a string`);
|
||||
}
|
||||
|
||||
const server = workerScript.getServer();
|
||||
@ -2470,7 +2470,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
}
|
||||
},
|
||||
flags: Flags(workerScript.args),
|
||||
flags: Flags(workerScript.args.map((a) => String(a))),
|
||||
};
|
||||
|
||||
// add undocumented functions
|
||||
|
@ -100,8 +100,8 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
try {
|
||||
return bladeburner.startActionNetscriptFn(player, type, name, workerScript);
|
||||
} catch (e: any) {
|
||||
throw ctx.makeRuntimeErrorMsg(e);
|
||||
} catch (e: unknown) {
|
||||
throw ctx.makeRuntimeErrorMsg(String(e));
|
||||
}
|
||||
},
|
||||
stopBladeburnerAction: (ctx: NetscriptContext) => (): void => {
|
||||
@ -133,8 +133,8 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
|
||||
} else {
|
||||
return time;
|
||||
}
|
||||
} catch (e: any) {
|
||||
throw ctx.makeRuntimeErrorMsg(e);
|
||||
} catch (e: unknown) {
|
||||
throw ctx.makeRuntimeErrorMsg(String(e));
|
||||
}
|
||||
},
|
||||
getActionCurrentTime: (ctx: NetscriptContext) => (): number => {
|
||||
@ -146,8 +146,8 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
|
||||
Math.min(bladeburner.actionTimeCurrent + bladeburner.actionTimeOverflow, bladeburner.actionTimeToComplete) *
|
||||
1000;
|
||||
return timecomputed;
|
||||
} catch (e: any) {
|
||||
throw ctx.makeRuntimeErrorMsg(e);
|
||||
} catch (e: unknown) {
|
||||
throw ctx.makeRuntimeErrorMsg(String(e));
|
||||
}
|
||||
},
|
||||
getActionEstimatedSuccessChance:
|
||||
@ -167,8 +167,8 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
|
||||
} else {
|
||||
return chance;
|
||||
}
|
||||
} catch (e: any) {
|
||||
throw ctx.makeRuntimeErrorMsg(e);
|
||||
} catch (e: unknown) {
|
||||
throw ctx.makeRuntimeErrorMsg(String(e));
|
||||
}
|
||||
},
|
||||
getActionRepGain:
|
||||
@ -198,8 +198,8 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
try {
|
||||
return bladeburner.getActionCountRemainingNetscriptFn(type, name, workerScript);
|
||||
} catch (e: any) {
|
||||
throw ctx.makeRuntimeErrorMsg(e);
|
||||
} catch (e: unknown) {
|
||||
throw ctx.makeRuntimeErrorMsg(String(e));
|
||||
}
|
||||
},
|
||||
getActionMaxLevel:
|
||||
@ -273,8 +273,8 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
try {
|
||||
return bladeburner.getSkillLevelNetscriptFn(skillName, workerScript);
|
||||
} catch (e: any) {
|
||||
throw ctx.makeRuntimeErrorMsg(e);
|
||||
} catch (e: unknown) {
|
||||
throw ctx.makeRuntimeErrorMsg(String(e));
|
||||
}
|
||||
},
|
||||
getSkillUpgradeCost:
|
||||
@ -286,8 +286,8 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
try {
|
||||
return bladeburner.getSkillUpgradeCostNetscriptFn(skillName, workerScript);
|
||||
} catch (e: any) {
|
||||
throw ctx.makeRuntimeErrorMsg(e);
|
||||
} catch (e: unknown) {
|
||||
throw ctx.makeRuntimeErrorMsg(String(e));
|
||||
}
|
||||
},
|
||||
upgradeSkill:
|
||||
@ -299,8 +299,8 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
try {
|
||||
return bladeburner.upgradeSkillNetscriptFn(skillName, workerScript);
|
||||
} catch (e: any) {
|
||||
throw ctx.makeRuntimeErrorMsg(e);
|
||||
} catch (e: unknown) {
|
||||
throw ctx.makeRuntimeErrorMsg(String(e));
|
||||
}
|
||||
},
|
||||
getTeamSize:
|
||||
@ -313,8 +313,8 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
try {
|
||||
return bladeburner.getTeamSizeNetscriptFn(type, name, workerScript);
|
||||
} catch (e: any) {
|
||||
throw ctx.makeRuntimeErrorMsg(e);
|
||||
} catch (e: unknown) {
|
||||
throw ctx.makeRuntimeErrorMsg(String(e));
|
||||
}
|
||||
},
|
||||
setTeamSize:
|
||||
@ -328,8 +328,8 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
try {
|
||||
return bladeburner.setTeamSizeNetscriptFn(type, name, size, workerScript);
|
||||
} catch (e: any) {
|
||||
throw ctx.makeRuntimeErrorMsg(e);
|
||||
} catch (e: unknown) {
|
||||
throw ctx.makeRuntimeErrorMsg(String(e));
|
||||
}
|
||||
},
|
||||
getCityEstimatedPopulation:
|
||||
|
@ -70,10 +70,10 @@ function startNetscript2Script(player: IPlayer, workerScript: WorkerScript): Pro
|
||||
// We need to go through the environment and wrap each function in such a way that it
|
||||
// can be called at most once at a time. This will prevent situations where multiple
|
||||
// hack promises are outstanding, for example.
|
||||
function wrap(propName: string, f: (...args: any[]) => Promise<void>): (...args: any[]) => Promise<void> {
|
||||
function wrap(propName: string, f: (...args: unknown[]) => Promise<void>): (...args: unknown[]) => Promise<void> {
|
||||
// This function unfortunately cannot be an async function, because we don't
|
||||
// know if the original one was, and there's no way to tell.
|
||||
return function (...args: any[]) {
|
||||
return async function (...args: unknown[]) {
|
||||
// Wrap every netscript function with a check for the stop flag.
|
||||
// This prevents cases where we never stop because we are only calling
|
||||
// netscript functions that don't check this.
|
||||
@ -101,7 +101,7 @@ function startNetscript2Script(player: IPlayer, workerScript: WorkerScript): Pro
|
||||
let result;
|
||||
try {
|
||||
result = f(...args);
|
||||
} catch (e: any) {
|
||||
} catch (e: unknown) {
|
||||
runningFn = null;
|
||||
throw e;
|
||||
}
|
||||
@ -176,15 +176,15 @@ function startNetscript1Script(workerScript: WorkerScript): Promise<void> {
|
||||
const importProcessingRes = processNetscript1Imports(code, workerScript);
|
||||
codeWithImports = importProcessingRes.code;
|
||||
codeLineOffset = importProcessingRes.lineOffset;
|
||||
} catch (e: any) {
|
||||
dialogBoxCreate("Error processing Imports in " + workerScript.name + ":<br>" + e);
|
||||
} catch (e: unknown) {
|
||||
dialogBoxCreate("Error processing Imports in " + workerScript.name + ":<br>" + String(e));
|
||||
workerScript.env.stopFlag = true;
|
||||
workerScript.running = false;
|
||||
killWorkerScript(workerScript);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
const interpreterInitialization = function (int: any, scope: any): void {
|
||||
const interpreterInitialization = function (int: Interpreter, scope: unknown): void {
|
||||
//Add the Netscript environment
|
||||
const ns = NetscriptFunctions(workerScript);
|
||||
for (const name of Object.keys(ns)) {
|
||||
@ -212,9 +212,8 @@ function startNetscript1Script(workerScript: WorkerScript): Promise<void> {
|
||||
.then(function (res: any) {
|
||||
cb(res);
|
||||
})
|
||||
.catch(function (err: any) {
|
||||
// workerscript is when you cancel a delay
|
||||
if (!(err instanceof ScriptDeath)) {
|
||||
.catch(function (err: unknown) {
|
||||
if (typeof err === "string") {
|
||||
console.error(err);
|
||||
const errorTextArray = err.split("|DELIMITER|");
|
||||
const hostname = errorTextArray[1];
|
||||
@ -282,11 +281,11 @@ function startNetscript1Script(workerScript: WorkerScript): Promise<void> {
|
||||
int.setProperty(scope, "args", int.nativeToPseudo(workerScript.args));
|
||||
};
|
||||
|
||||
let interpreter: any;
|
||||
let interpreter: Interpreter;
|
||||
try {
|
||||
interpreter = new Interpreter(codeWithImports, interpreterInitialization, codeLineOffset);
|
||||
} catch (e: any) {
|
||||
dialogBoxCreate("Syntax ERROR in " + workerScript.name + ":<br>" + e);
|
||||
} catch (e: unknown) {
|
||||
dialogBoxCreate("Syntax ERROR in " + workerScript.name + ":<br>" + String(e));
|
||||
workerScript.env.stopFlag = true;
|
||||
workerScript.running = false;
|
||||
killWorkerScript(workerScript);
|
||||
@ -312,8 +311,8 @@ function startNetscript1Script(workerScript: WorkerScript): Promise<void> {
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
} catch (e: any) {
|
||||
e = e.toString();
|
||||
} catch (_e: unknown) {
|
||||
let e = String(_e);
|
||||
if (!isScriptErrorMessage(e)) {
|
||||
e = makeRuntimeRejectMsg(workerScript, e);
|
||||
}
|
||||
@ -324,7 +323,7 @@ function startNetscript1Script(workerScript: WorkerScript): Promise<void> {
|
||||
|
||||
try {
|
||||
runInterpreter();
|
||||
} catch (e: any) {
|
||||
} catch (e: unknown) {
|
||||
if (isString(e)) {
|
||||
workerScript.errorMessage = e;
|
||||
return reject(new ScriptDeath(workerScript));
|
||||
|
@ -142,7 +142,7 @@ export interface IPlayer extends IPerson {
|
||||
reapplyAllAugmentations(resetMultipliers?: boolean): void;
|
||||
reapplyAllSourceFiles(): void;
|
||||
setMoney(amt: number): void;
|
||||
startBladeburner(p: any): void;
|
||||
startBladeburner(): void;
|
||||
startCorporation(corpName: string, additionalShares?: number): void;
|
||||
startFocusing(): void;
|
||||
startGang(facName: string, isHacking: boolean): void;
|
||||
|
@ -165,7 +165,7 @@ export class PlayerObject implements IPlayer {
|
||||
regenerateHp: (amt: number) => void;
|
||||
recordMoneySource: (amt: number, source: string) => void;
|
||||
setMoney: (amt: number) => void;
|
||||
startBladeburner: (p: any) => void;
|
||||
startBladeburner: () => void;
|
||||
startCorporation: (corpName: string, additionalShares?: number) => void;
|
||||
startFocusing: () => void;
|
||||
startGang: (facName: string, isHacking: boolean) => void;
|
||||
|
@ -186,7 +186,7 @@ async function parseOnlyRamCalculate(
|
||||
// Check if this identifier is a function in the workerScript environment.
|
||||
// If it is, then we need to get its RAM cost.
|
||||
try {
|
||||
function applyFuncRam(cost: any): number {
|
||||
function applyFuncRam(cost: number | ((p: IPlayer) => number)): number {
|
||||
if (typeof cost === "number") {
|
||||
return cost;
|
||||
} else if (typeof cost === "function") {
|
||||
@ -282,7 +282,7 @@ export function checkInfiniteLoop(code: string): number {
|
||||
ast,
|
||||
{},
|
||||
{
|
||||
WhileStatement: (node: acorn.Node, st: any, walkDeeper: walk.WalkerCallback<any>) => {
|
||||
WhileStatement: (node: acorn.Node, st: unknown, walkDeeper: walk.WalkerCallback<any>) => {
|
||||
if (nodeHasTrueTest((node as any).test) && !hasAwait(node)) {
|
||||
missingAwaitLine = (code.slice(0, node.start).match(/\n/g) || []).length + 1;
|
||||
} else {
|
||||
|
@ -44,6 +44,7 @@ import { Modal } from "../../ui/React/Modal";
|
||||
|
||||
import libSource from "!!raw-loader!../NetscriptDefinitions.d.ts";
|
||||
import { TextField, Tooltip } from "@mui/material";
|
||||
import { ExternalAPI } from "../../Netscript/APIWrapper";
|
||||
|
||||
interface IProps {
|
||||
// Map of filename -> code
|
||||
@ -58,18 +59,19 @@ interface IProps {
|
||||
let symbolsLoaded = false;
|
||||
let symbols: string[] = [];
|
||||
export function SetupTextEditor(): void {
|
||||
const ns = NetscriptFunctions({} as WorkerScript);
|
||||
const ns = NetscriptFunctions({ args: [] } as unknown as WorkerScript);
|
||||
|
||||
// Populates symbols for text editor
|
||||
function populate(ns: any): string[] {
|
||||
function populate(ns: ExternalAPI): string[] {
|
||||
let symbols: string[] = [];
|
||||
const keys = Object.keys(ns);
|
||||
for (const key of keys) {
|
||||
if (typeof ns[key] === "object") {
|
||||
const x = ns[key];
|
||||
if (typeof x === "object") {
|
||||
symbols.push(key);
|
||||
symbols = symbols.concat(populate(ns[key]));
|
||||
symbols = symbols.concat(populate(x));
|
||||
}
|
||||
if (typeof ns[key] === "function") {
|
||||
if (typeof x === "function") {
|
||||
symbols.push(key);
|
||||
}
|
||||
}
|
||||
@ -693,7 +695,7 @@ export function Root(props: IProps): React.ReactElement {
|
||||
if (server === null) throw new Error(`Server '${closingScript.hostname}' should not be null, but it is.`);
|
||||
|
||||
const serverScriptIndex = server.scripts.findIndex((script) => script.filename === closingScript.fileName);
|
||||
if (serverScriptIndex === -1 || savedScriptCode !== server.scripts[serverScriptIndex ].code) {
|
||||
if (serverScriptIndex === -1 || savedScriptCode !== server.scripts[serverScriptIndex].code) {
|
||||
PromptEvent.emit({
|
||||
txt: `Do you want to save changes to ${closingScript.fileName} on ${closingScript.hostname}?`,
|
||||
resolve: (result: boolean | string) => {
|
||||
|
@ -68,7 +68,7 @@ export function placeOrder(
|
||||
|
||||
// Process to see if it should be executed immediately
|
||||
const processOrderRefs = {
|
||||
stockMarket: StockMarket ,
|
||||
stockMarket: StockMarket,
|
||||
symbolToStockMap: SymbolToStockMap,
|
||||
};
|
||||
processOrders(stock, order.type, order.pos, processOrderRefs);
|
||||
@ -77,7 +77,7 @@ export function placeOrder(
|
||||
}
|
||||
|
||||
// Returns true if successfully cancels an order, false otherwise
|
||||
interface ICancelOrderParams {
|
||||
export interface ICancelOrderParams {
|
||||
order?: Order;
|
||||
pos?: PositionTypes;
|
||||
price?: number;
|
||||
|
@ -13,6 +13,8 @@ import { PositionTypes } from "../data/PositionTypes";
|
||||
|
||||
import { IPlayer } from "../../PersonObjects/IPlayer";
|
||||
import { EventEmitter } from "../../utils/EventEmitter";
|
||||
import { WorkerScript } from "../../Netscript/WorkerScript";
|
||||
import { ICancelOrderParams } from "../StockMarket";
|
||||
|
||||
type txFn = (stock: Stock, shares: number) => boolean;
|
||||
type placeOrderFn = (
|
||||
@ -26,7 +28,7 @@ type placeOrderFn = (
|
||||
type IProps = {
|
||||
buyStockLong: txFn;
|
||||
buyStockShort: txFn;
|
||||
cancelOrder: (params: any) => void;
|
||||
cancelOrder: (params: ICancelOrderParams, workerScript?: WorkerScript) => void;
|
||||
eventEmitterForReset?: EventEmitter<[]>;
|
||||
initStockMarket: () => void;
|
||||
p: IPlayer;
|
||||
|
@ -31,6 +31,8 @@ import Paper from "@mui/material/Paper";
|
||||
import Collapse from "@mui/material/Collapse";
|
||||
import ExpandMore from "@mui/icons-material/ExpandMore";
|
||||
import ExpandLess from "@mui/icons-material/ExpandLess";
|
||||
import { ICancelOrderParams } from "../StockMarket";
|
||||
import { WorkerScript } from "../../Netscript/WorkerScript";
|
||||
|
||||
enum SelectorOrderType {
|
||||
Market = "Market Order",
|
||||
@ -50,7 +52,7 @@ type placeOrderFn = (
|
||||
type IProps = {
|
||||
buyStockLong: txFn;
|
||||
buyStockShort: txFn;
|
||||
cancelOrder: (params: any) => void;
|
||||
cancelOrder: (params: ICancelOrderParams, workerScript?: WorkerScript) => void;
|
||||
orders: Order[];
|
||||
p: IPlayer;
|
||||
placeOrder: placeOrderFn;
|
||||
|
@ -11,9 +11,11 @@ import { Money } from "../../ui/React/Money";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import Button from "@mui/material/Button";
|
||||
import Box from "@mui/material/Box";
|
||||
import { ICancelOrderParams } from "../StockMarket";
|
||||
import { WorkerScript } from "../../Netscript/WorkerScript";
|
||||
|
||||
type IProps = {
|
||||
cancelOrder: (params: any) => void;
|
||||
cancelOrder: (params: ICancelOrderParams, workerScript?: WorkerScript) => void;
|
||||
order: Order;
|
||||
};
|
||||
|
||||
|
@ -10,9 +10,11 @@ import { Order } from "../Order";
|
||||
import { Stock } from "../Stock";
|
||||
|
||||
import { IPlayer } from "../../PersonObjects/IPlayer";
|
||||
import { ICancelOrderParams } from "../StockMarket";
|
||||
import { WorkerScript } from "../../Netscript/WorkerScript";
|
||||
|
||||
type IProps = {
|
||||
cancelOrder: (params: any) => void;
|
||||
cancelOrder: (params: ICancelOrderParams, workerScript?: WorkerScript) => void;
|
||||
orders: Order[];
|
||||
p: IPlayer;
|
||||
stock: Stock;
|
||||
|
@ -15,6 +15,8 @@ import { PositionTypes } from "../data/PositionTypes";
|
||||
|
||||
import { IPlayer } from "../../PersonObjects/IPlayer";
|
||||
import { EventEmitter } from "../../utils/EventEmitter";
|
||||
import { WorkerScript } from "../../Netscript/WorkerScript";
|
||||
import { ICancelOrderParams } from "../StockMarket";
|
||||
|
||||
type txFn = (stock: Stock, shares: number) => boolean;
|
||||
type placeOrderFn = (
|
||||
@ -28,7 +30,7 @@ type placeOrderFn = (
|
||||
type IProps = {
|
||||
buyStockLong: txFn;
|
||||
buyStockShort: txFn;
|
||||
cancelOrder: (params: any) => void;
|
||||
cancelOrder: (params: ICancelOrderParams, workerScript?: WorkerScript) => void;
|
||||
eventEmitterForReset?: EventEmitter<[]>;
|
||||
p: IPlayer;
|
||||
placeOrder: placeOrderFn;
|
||||
|
@ -55,8 +55,12 @@ export function download(
|
||||
try {
|
||||
exportScripts(fn, server);
|
||||
return;
|
||||
} catch (error: any) {
|
||||
return terminal.error(error.message);
|
||||
} catch (e: unknown) {
|
||||
let msg = String(e);
|
||||
if (e !== null && typeof e == "object" && e.hasOwnProperty("message")) {
|
||||
msg = String((e as { message: unknown }).message);
|
||||
}
|
||||
return terminal.error(msg);
|
||||
}
|
||||
} else if (isScriptFilename(fn)) {
|
||||
// Download a single script
|
||||
|
6
src/ThirdParty/JSInterpreter.d.ts
vendored
6
src/ThirdParty/JSInterpreter.d.ts
vendored
@ -1,7 +1,13 @@
|
||||
export declare class Interpreter {
|
||||
constructor(code: string, opt_initFunc: (int: Interpreter, scope: Object) => void, lineOffset?: number);
|
||||
getProperty(obj: Value, name: Value): Value;
|
||||
setProperty(obj: Object, name: Value, value: Value): void;
|
||||
hasProperty(obj: Value, name: Value): boolean;
|
||||
pseudoToNative(obj: Value): unknown;
|
||||
nativeToPseudo(obj: Value): unknown;
|
||||
createAsyncFunction(f: (...args: unknown[]) => unknown): Object;
|
||||
createNativeFunction(f: (...args: unknown[]) => unknown): Object;
|
||||
step(): boolean;
|
||||
}
|
||||
|
||||
// Object and Value are 2 different things in the interpreter;
|
||||
|
@ -112,13 +112,15 @@ const useStyles = makeStyles((theme: Theme) =>
|
||||
}),
|
||||
);
|
||||
|
||||
const uninitialized = (): any => {
|
||||
const uninitialized = (): void => {
|
||||
throw new Error("Router called before initialization");
|
||||
};
|
||||
|
||||
export let Router: IRouter = {
|
||||
isInitialized: false,
|
||||
page: uninitialized,
|
||||
page: () => {
|
||||
throw new Error("Router called before initialization");
|
||||
},
|
||||
allowRouting: uninitialized,
|
||||
toActiveScripts: uninitialized,
|
||||
toAugmentations: uninitialized,
|
||||
|
@ -51,7 +51,7 @@ export function LoadingScreen(): React.ReactElement {
|
||||
.then((saveString) => {
|
||||
try {
|
||||
Engine.load(saveString);
|
||||
} catch (err: any) {
|
||||
} catch (err: unknown) {
|
||||
ActivateRecoveryMode();
|
||||
setLoaded(true);
|
||||
throw err;
|
||||
|
@ -3,7 +3,7 @@ import { format } from "date-fns";
|
||||
export function formatTime(fmt: string): string {
|
||||
try {
|
||||
return format(new Date(), fmt);
|
||||
} catch (err: any) {
|
||||
} catch (e: unknown) {
|
||||
return "format error";
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
* Checks whether the value passed in can be considered a string.
|
||||
* @param value The value to check if it is a string.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
export function isString(value: any): boolean {
|
||||
export function isString(value: unknown): value is string {
|
||||
return typeof value === "string" || value instanceof String;
|
||||
}
|
||||
|
Reference in New Issue
Block a user