mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-18 05:33:54 +01:00
lint fixes
This commit is contained in:
parent
76ccb0ba36
commit
c1650e332b
@ -70,17 +70,17 @@ export class Bladeburner implements IBladeburner {
|
|||||||
type: ActionTypes["Idle"],
|
type: ActionTypes["Idle"],
|
||||||
});
|
});
|
||||||
|
|
||||||
cities: any = {};
|
cities: Record<string, City> = {};
|
||||||
city: string = BladeburnerConstants.CityNames[2];
|
city: string = BladeburnerConstants.CityNames[2];
|
||||||
skills: any = {};
|
skills: Record<string, number> = {};
|
||||||
skillMultipliers: any = {};
|
skillMultipliers: Record<string, number> = {};
|
||||||
staminaBonus = 0;
|
staminaBonus = 0;
|
||||||
maxStamina = 0;
|
maxStamina = 0;
|
||||||
stamina = 0;
|
stamina = 0;
|
||||||
contracts: any = {};
|
contracts: Record<string, Contract> = {};
|
||||||
operations: any = {};
|
operations: Record<string, Operation> = {};
|
||||||
blackops: any = {};
|
blackops: Record<string, boolean> = {};
|
||||||
logging: any = {
|
logging = {
|
||||||
general: true,
|
general: true,
|
||||||
contracts: true,
|
contracts: true,
|
||||||
ops: true,
|
ops: true,
|
||||||
@ -477,54 +477,54 @@ export class Bladeburner implements IBladeburner {
|
|||||||
this.postToConsole("Effects: ");
|
this.postToConsole("Effects: ");
|
||||||
const multKeys = Object.keys(this.skillMultipliers);
|
const multKeys = Object.keys(this.skillMultipliers);
|
||||||
for (let i = 0; i < multKeys.length; ++i) {
|
for (let i = 0; i < multKeys.length; ++i) {
|
||||||
let mult = this.skillMultipliers[multKeys[i]];
|
const mult = this.skillMultipliers[multKeys[i]];
|
||||||
if (mult && mult !== 1) {
|
if (mult && mult !== 1) {
|
||||||
mult = formatNumber(mult, 3);
|
const mults = formatNumber(mult, 3);
|
||||||
switch (multKeys[i]) {
|
switch (multKeys[i]) {
|
||||||
case "successChanceAll":
|
case "successChanceAll":
|
||||||
this.postToConsole("Total Success Chance: x" + mult);
|
this.postToConsole("Total Success Chance: x" + mults);
|
||||||
break;
|
break;
|
||||||
case "successChanceStealth":
|
case "successChanceStealth":
|
||||||
this.postToConsole("Stealth Success Chance: x" + mult);
|
this.postToConsole("Stealth Success Chance: x" + mults);
|
||||||
break;
|
break;
|
||||||
case "successChanceKill":
|
case "successChanceKill":
|
||||||
this.postToConsole("Retirement Success Chance: x" + mult);
|
this.postToConsole("Retirement Success Chance: x" + mults);
|
||||||
break;
|
break;
|
||||||
case "successChanceContract":
|
case "successChanceContract":
|
||||||
this.postToConsole("Contract Success Chance: x" + mult);
|
this.postToConsole("Contract Success Chance: x" + mults);
|
||||||
break;
|
break;
|
||||||
case "successChanceOperation":
|
case "successChanceOperation":
|
||||||
this.postToConsole("Operation Success Chance: x" + mult);
|
this.postToConsole("Operation Success Chance: x" + mults);
|
||||||
break;
|
break;
|
||||||
case "successChanceEstimate":
|
case "successChanceEstimate":
|
||||||
this.postToConsole("Synthoid Data Estimate: x" + mult);
|
this.postToConsole("Synthoid Data Estimate: x" + mults);
|
||||||
break;
|
break;
|
||||||
case "actionTime":
|
case "actionTime":
|
||||||
this.postToConsole("Action Time: x" + mult);
|
this.postToConsole("Action Time: x" + mults);
|
||||||
break;
|
break;
|
||||||
case "effHack":
|
case "effHack":
|
||||||
this.postToConsole("Hacking Skill: x" + mult);
|
this.postToConsole("Hacking Skill: x" + mults);
|
||||||
break;
|
break;
|
||||||
case "effStr":
|
case "effStr":
|
||||||
this.postToConsole("Strength: x" + mult);
|
this.postToConsole("Strength: x" + mults);
|
||||||
break;
|
break;
|
||||||
case "effDef":
|
case "effDef":
|
||||||
this.postToConsole("Defense: x" + mult);
|
this.postToConsole("Defense: x" + mults);
|
||||||
break;
|
break;
|
||||||
case "effDex":
|
case "effDex":
|
||||||
this.postToConsole("Dexterity: x" + mult);
|
this.postToConsole("Dexterity: x" + mults);
|
||||||
break;
|
break;
|
||||||
case "effAgi":
|
case "effAgi":
|
||||||
this.postToConsole("Agility: x" + mult);
|
this.postToConsole("Agility: x" + mults);
|
||||||
break;
|
break;
|
||||||
case "effCha":
|
case "effCha":
|
||||||
this.postToConsole("Charisma: x" + mult);
|
this.postToConsole("Charisma: x" + mults);
|
||||||
break;
|
break;
|
||||||
case "effInt":
|
case "effInt":
|
||||||
this.postToConsole("Intelligence: x" + mult);
|
this.postToConsole("Intelligence: x" + mults);
|
||||||
break;
|
break;
|
||||||
case "stamina":
|
case "stamina":
|
||||||
this.postToConsole("Stamina: x" + mult);
|
this.postToConsole("Stamina: x" + mults);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.warn(`Unrecognized SkillMult Key: ${multKeys[i]}`);
|
console.warn(`Unrecognized SkillMult Key: ${multKeys[i]}`);
|
||||||
|
@ -66,7 +66,7 @@ export function DevMenuRoot(props: IProps): React.ReactElement {
|
|||||||
<TimeSkip player={props.player} engine={props.engine} />
|
<TimeSkip player={props.player} engine={props.engine} />
|
||||||
<Achievements player={props.player} engine={props.engine} />
|
<Achievements player={props.player} engine={props.engine} />
|
||||||
<Entropy player={props.player} engine={props.engine} />
|
<Entropy player={props.player} engine={props.engine} />
|
||||||
<SaveFile player={props.player} />
|
<SaveFile />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
* The environment in which a script runs. The environment holds
|
* The environment in which a script runs. The environment holds
|
||||||
* Netscript functions and arguments for that script.
|
* Netscript functions and arguments for that script.
|
||||||
*/
|
*/
|
||||||
|
import { NS } from "src/ScriptEditor/NetscriptDefinitions";
|
||||||
import { IMap } from "../types";
|
import { IMap } from "../types";
|
||||||
|
|
||||||
export class Environment {
|
export class Environment {
|
||||||
@ -18,7 +19,7 @@ export class Environment {
|
|||||||
/**
|
/**
|
||||||
* Environment variables (currently only Netscript functions)
|
* Environment variables (currently only Netscript functions)
|
||||||
*/
|
*/
|
||||||
vars: IMap<any> = {};
|
vars: any = {};
|
||||||
|
|
||||||
constructor(parent: Environment | null) {
|
constructor(parent: Environment | null) {
|
||||||
if (parent instanceof Environment) {
|
if (parent instanceof Environment) {
|
||||||
|
@ -14,6 +14,7 @@ import { Script } from "../Script/Script";
|
|||||||
import { GetServer } from "../Server/AllServers";
|
import { GetServer } from "../Server/AllServers";
|
||||||
import { BaseServer } from "../Server/BaseServer";
|
import { BaseServer } from "../Server/BaseServer";
|
||||||
import { IMap } from "../types";
|
import { IMap } from "../types";
|
||||||
|
import { NS } from "../ScriptEditor/NetscriptDefinitions";
|
||||||
|
|
||||||
export class WorkerScript {
|
export class WorkerScript {
|
||||||
/**
|
/**
|
||||||
@ -116,7 +117,7 @@ export class WorkerScript {
|
|||||||
*/
|
*/
|
||||||
infiniteLoopSafety = performance.now();
|
infiniteLoopSafety = performance.now();
|
||||||
|
|
||||||
constructor(runningScriptObj: RunningScript, pid: number, nsFuncsGenerator?: (ws: WorkerScript) => any) {
|
constructor(runningScriptObj: RunningScript, pid: number, nsFuncsGenerator?: (ws: WorkerScript) => NS) {
|
||||||
this.name = runningScriptObj.filename;
|
this.name = runningScriptObj.filename;
|
||||||
this.hostname = runningScriptObj.server;
|
this.hostname = runningScriptObj.server;
|
||||||
|
|
||||||
|
@ -5,11 +5,12 @@
|
|||||||
* @param obj the object to clear all properties
|
* @param obj the object to clear all properties
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||||
export function clearObject(obj: any): void {
|
export function clearObject(obj: unknown): void {
|
||||||
for (const key in obj) {
|
if (typeof obj !== "object" || obj === null || obj === undefined) return;
|
||||||
|
for (const key of Object.getOwnPropertyNames(obj)) {
|
||||||
if (obj.hasOwnProperty(key)) {
|
if (obj.hasOwnProperty(key)) {
|
||||||
// tslint:disable-next-line:no-dynamic-delete
|
// tslint:disable-next-line:no-dynamic-delete
|
||||||
delete obj[key];
|
delete (obj as any)[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,18 +9,18 @@ export function compareArrays<T>(a1: T[], a2: T[]): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < a1.length; ++i) {
|
for (let i = 0; i < a1.length; ++i) {
|
||||||
if (Array.isArray(a1[i])) {
|
const v1 = a1[i];
|
||||||
|
const v2 = a2[i];
|
||||||
|
if (Array.isArray(v1)) {
|
||||||
// If the other element is not an array, then these cannot be equal
|
// If the other element is not an array, then these cannot be equal
|
||||||
if (!Array.isArray(a2[i])) {
|
if (!Array.isArray(v2)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const elem1 = a1[i] as any;
|
if (!compareArrays(v1, v2)) {
|
||||||
const elem2 = a2[i] as any;
|
|
||||||
if (!compareArrays(elem1, elem2)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (a1[i] !== a2[i] && !(Number.isNaN(a1[i]) && Number.isNaN(a2[i]))) {
|
} else if (v1 !== v2 && !(Number.isNaN(v1) && Number.isNaN(v2))) {
|
||||||
// strict (in)equality considers NaN not equal to itself
|
// strict (in)equality considers NaN not equal to itself
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -7,15 +7,25 @@ interface IError {
|
|||||||
|
|
||||||
export function exceptionAlert(e: IError | string): void {
|
export function exceptionAlert(e: IError | string): void {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
let msg = "";
|
||||||
|
let file = "UNKNOWN FILE NAME";
|
||||||
|
let line = "UNKNOWN LINE NUMBER";
|
||||||
|
const isError = (e: IError | string): e is IError => e.hasOwnProperty("fileName");
|
||||||
|
if (isError(e)) {
|
||||||
|
file = e.fileName ?? file;
|
||||||
|
line = e.lineNumber?.toString() ?? line;
|
||||||
|
} else {
|
||||||
|
msg = e;
|
||||||
|
}
|
||||||
dialogBoxCreate(
|
dialogBoxCreate(
|
||||||
"Caught an exception: " +
|
"Caught an exception: " +
|
||||||
e +
|
msg +
|
||||||
"<br><br>" +
|
"<br><br>" +
|
||||||
"Filename: " +
|
"Filename: " +
|
||||||
((e as any).fileName || "UNKNOWN FILE NAME") +
|
file +
|
||||||
"<br><br>" +
|
"<br><br>" +
|
||||||
"Line Number: " +
|
"Line Number: " +
|
||||||
((e as any).lineNumber || "UNKNOWN LINE NUMBER") +
|
line +
|
||||||
"<br><br>" +
|
"<br><br>" +
|
||||||
"This is a bug, please report to game developer with this " +
|
"This is a bug, please report to game developer with this " +
|
||||||
"message as well as details about how to reproduce the bug.<br><br>" +
|
"message as well as details about how to reproduce the bug.<br><br>" +
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
|
export function isArray(arr: unknown): arr is unknown[] {
|
||||||
|
return Array.isArray(arr);
|
||||||
|
}
|
||||||
|
|
||||||
// Checks whether an array is a 2D array.
|
// Checks whether an array is a 2D array.
|
||||||
// For this, a 2D array is an array which contains only other arrays.
|
// For this, a 2D array is an array which contains only other arrays.
|
||||||
// If one element in the array is a number or string, it is NOT a 2D array
|
// If one element in the array is a number or string, it is NOT a 2D array
|
||||||
export function is2DArray(arr: any[]): boolean {
|
export function is2DArray(arr: unknown): arr is unknown[][] {
|
||||||
if (arr.constructor !== Array) {
|
return isArray(arr) && arr.every((u) => isArray(u));
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return arr.every((e) => {
|
|
||||||
return e.constructor === Array;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,11 @@ const ScriptBaseCost = RamCostConstants.ScriptBaseRamCost;
|
|||||||
|
|
||||||
describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
|
describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
|
||||||
// Creates a mock RunningScript object
|
// Creates a mock RunningScript object
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} code
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
async function createRunningScript(code) {
|
async function createRunningScript(code) {
|
||||||
const script = new Script();
|
const script = new Script();
|
||||||
script.code = code;
|
script.code = code;
|
||||||
@ -24,12 +29,23 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Tests numeric equality, allowing for floating point imprecision
|
// Tests numeric equality, allowing for floating point imprecision
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {number} val
|
||||||
|
* @param {number} expected
|
||||||
|
*/
|
||||||
function testEquality(val, expected) {
|
function testEquality(val, expected) {
|
||||||
expect(val).toBeGreaterThanOrEqual(expected - 100 * Number.EPSILON);
|
expect(val).toBeGreaterThanOrEqual(expected - 100 * Number.EPSILON);
|
||||||
expect(val).toBeLessThanOrEqual(expected + 100 * Number.EPSILON);
|
expect(val).toBeLessThanOrEqual(expected + 100 * Number.EPSILON);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Runs a Netscript function and properly catches it if it returns promise
|
// Runs a Netscript function and properly catches it if it returns promise
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {(...args: unknown[]) => unknown} fn
|
||||||
|
* @param {unknown[]} args
|
||||||
|
*/
|
||||||
function runPotentiallyAsyncFunction(fn, ...args) {
|
function runPotentiallyAsyncFunction(fn, ...args) {
|
||||||
const res = fn(...args);
|
const res = fn(...args);
|
||||||
if (res instanceof Promise) {
|
if (res instanceof Promise) {
|
||||||
@ -93,7 +109,7 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
|
|||||||
runPotentiallyAsyncFunction(curr, ...args);
|
runPotentiallyAsyncFunction(curr, ...args);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Invalid function specified: [${fnDesc}]`);
|
throw new Error(`Invalid function specified: [${fnDesc.toString()}]`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fnName = fnDesc[fnDesc.length - 1];
|
const fnName = fnDesc[fnDesc.length - 1];
|
||||||
|
@ -11,6 +11,11 @@ const HacknetNamespaceCost = RamCostConstants.ScriptHacknetNodesRamCost;
|
|||||||
|
|
||||||
describe("Netscript Static RAM Calculation/Generation Tests", function () {
|
describe("Netscript Static RAM Calculation/Generation Tests", function () {
|
||||||
// Tests numeric equality, allowing for floating point imprecision
|
// Tests numeric equality, allowing for floating point imprecision
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {number} val
|
||||||
|
* @param {number} expected
|
||||||
|
*/
|
||||||
function testEquality(val, expected) {
|
function testEquality(val, expected) {
|
||||||
expect(val).toBeGreaterThanOrEqual(expected - 100 * Number.EPSILON);
|
expect(val).toBeGreaterThanOrEqual(expected - 100 * Number.EPSILON);
|
||||||
expect(val).toBeLessThanOrEqual(expected + 100 * Number.EPSILON);
|
expect(val).toBeLessThanOrEqual(expected + 100 * Number.EPSILON);
|
||||||
@ -25,9 +30,6 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () {
|
|||||||
* including the namespace(s). e.g. ["gang", "getMemberNames"]
|
* including the namespace(s). e.g. ["gang", "getMemberNames"]
|
||||||
*/
|
*/
|
||||||
async function expectNonZeroRamCost(fnDesc) {
|
async function expectNonZeroRamCost(fnDesc) {
|
||||||
if (!Array.isArray(fnDesc)) {
|
|
||||||
expect.fail("Non-array passed to expectNonZeroRamCost()");
|
|
||||||
}
|
|
||||||
const expected = getRamCost(Player, ...fnDesc);
|
const expected = getRamCost(Player, ...fnDesc);
|
||||||
expect(expected).toBeGreaterThan(0);
|
expect(expected).toBeGreaterThan(0);
|
||||||
|
|
||||||
@ -50,9 +52,6 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () {
|
|||||||
* including the namespace(s). e.g. ["gang", "getMemberNames"]
|
* including the namespace(s). e.g. ["gang", "getMemberNames"]
|
||||||
*/
|
*/
|
||||||
async function expectZeroRamCost(fnDesc) {
|
async function expectZeroRamCost(fnDesc) {
|
||||||
if (!Array.isArray(fnDesc)) {
|
|
||||||
expect.fail("Non-array passed to expectZeroRamCost()");
|
|
||||||
}
|
|
||||||
const expected = getRamCost(Player, ...fnDesc);
|
const expected = getRamCost(Player, ...fnDesc);
|
||||||
expect(expected).toEqual(0);
|
expect(expected).toEqual(0);
|
||||||
|
|
||||||
@ -64,7 +63,12 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () {
|
|||||||
expect(multipleCallsCalculated).toEqual(ScriptBaseCost);
|
expect(multipleCallsCalculated).toEqual(ScriptBaseCost);
|
||||||
}
|
}
|
||||||
|
|
||||||
// simplyfied version from RamCostGenerator.ts
|
/**
|
||||||
|
*
|
||||||
|
* @param {Player} player
|
||||||
|
* @param {number} cost
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
function SF4Cost(player, cost) {
|
function SF4Cost(player, cost) {
|
||||||
if (player.bitNodeN === 4) return cost;
|
if (player.bitNodeN === 4) return cost;
|
||||||
const sf4 = player.sourceFileLvl(4);
|
const sf4 = player.sourceFileLvl(4);
|
||||||
@ -83,9 +87,6 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () {
|
|||||||
* @param {number} cost - expected cost
|
* @param {number} cost - expected cost
|
||||||
*/
|
*/
|
||||||
async function expectSpecificRamCost(fnDesc, cost) {
|
async function expectSpecificRamCost(fnDesc, cost) {
|
||||||
if (!Array.isArray(fnDesc)) {
|
|
||||||
expect.fail("Non-array passed to expectZeroRamCost()");
|
|
||||||
}
|
|
||||||
const expected = getRamCost(Player, ...fnDesc);
|
const expected = getRamCost(Player, ...fnDesc);
|
||||||
expect(expected).toEqual(SF4Cost(Player, cost));
|
expect(expected).toEqual(SF4Cost(Player, cost));
|
||||||
|
|
||||||
|
@ -18,6 +18,11 @@ const CorpCost = 1024 - ScriptBaseCost;
|
|||||||
|
|
||||||
describe("Parsing NetScript code to work out static RAM costs", function () {
|
describe("Parsing NetScript code to work out static RAM costs", function () {
|
||||||
// Tests numeric equality, allowing for floating point imprecision - and includes script base cost
|
// Tests numeric equality, allowing for floating point imprecision - and includes script base cost
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {number} val
|
||||||
|
* @param {number} expected
|
||||||
|
*/
|
||||||
function expectCost(val, expected) {
|
function expectCost(val, expected) {
|
||||||
const expectedWithBase = expected + ScriptBaseCost;
|
const expectedWithBase = expected + ScriptBaseCost;
|
||||||
expect(val).toBeGreaterThanOrEqual(expectedWithBase - 100 * Number.EPSILON);
|
expect(val).toBeGreaterThanOrEqual(expectedWithBase - 100 * Number.EPSILON);
|
||||||
|
@ -457,17 +457,13 @@ describe("Stock Market Tests", function () {
|
|||||||
|
|
||||||
it("should trigger a price update when it has enough cycles", function () {
|
it("should trigger a price update when it has enough cycles", function () {
|
||||||
// Get the initial prices
|
// Get the initial prices
|
||||||
const initialValues: IMap<any> = {};
|
const initialValues: IMap<Stock> = {};
|
||||||
for (const stockName in StockMarket) {
|
for (const stockName in StockMarket) {
|
||||||
const stock = StockMarket[stockName];
|
const stock = StockMarket[stockName];
|
||||||
if (!(stock instanceof Stock)) {
|
if (!(stock instanceof Stock)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
initialValues[stock.symbol] = {
|
initialValues[stock.symbol] = stock;
|
||||||
b: stock.b,
|
|
||||||
otlkMag: stock.otlkMag,
|
|
||||||
price: stock.price,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't know or care how many exact cycles are required
|
// Don't know or care how many exact cycles are required
|
||||||
|
Loading…
Reference in New Issue
Block a user