getBitnodeM takes 2 arg

This commit is contained in:
Olivier Gagnon 2022-10-13 00:51:53 -04:00
parent ae5fc168bf
commit 8ff840edfa
2 changed files with 16 additions and 11 deletions

@ -1,7 +1,7 @@
import $ from "jquery"; import $ from "jquery";
import { vsprintf, sprintf } from "sprintf-js"; import { vsprintf, sprintf } from "sprintf-js";
import { WorkerScriptStartStopEventEmitter } from "./Netscript/WorkerScriptStartStopEventEmitter"; import { WorkerScriptStartStopEventEmitter } from "./Netscript/WorkerScriptStartStopEventEmitter";
import { BitNodeMultipliers } from "./BitNode/BitNodeMultipliers"; import { BitNodeMultipliers, IBitNodeMultipliers } from "./BitNode/BitNodeMultipliers";
import { CONSTANTS } from "./Constants"; import { CONSTANTS } from "./Constants";
import { import {
calculateHackingChance, calculateHackingChance,
@ -82,6 +82,7 @@ import { recentScripts } from "./Netscript/RecentScripts";
import { InternalAPI, wrapAPI } from "./Netscript/APIWrapper"; import { InternalAPI, wrapAPI } from "./Netscript/APIWrapper";
import { INetscriptExtra } from "./NetscriptFunctions/Extra"; import { INetscriptExtra } from "./NetscriptFunctions/Extra";
import { ScriptDeath } from "./Netscript/ScriptDeath"; import { ScriptDeath } from "./Netscript/ScriptDeath";
import { getBitNodeMultipliers } from "./BitNode/BitNode";
// "Enums" as object // "Enums" as object
export const enums = { export const enums = {
@ -1017,7 +1018,6 @@ const base: InternalAPI<NS> = {
}, },
hasRootAccess: (ctx) => (_hostname) => { hasRootAccess: (ctx) => (_hostname) => {
const hostname = helpers.string(ctx, "hostname", _hostname); const hostname = helpers.string(ctx, "hostname", _hostname);
const server = helpers.getServer(ctx, hostname); const server = helpers.getServer(ctx, hostname);
return server.hasAdminRights; return server.hasAdminRights;
}, },
@ -1044,13 +1044,18 @@ const base: InternalAPI<NS> = {
levelCost: Player.mults.hacknet_node_level_cost, levelCost: Player.mults.hacknet_node_level_cost,
}; };
}, },
getBitNodeMultipliers: (ctx) => () => { getBitNodeMultipliers:
if (Player.sourceFileLvl(5) <= 0 && Player.bitNodeN !== 5) { (ctx) =>
throw helpers.makeRuntimeErrorMsg(ctx, "Requires Source-File 5 to run."); (_n = Player.bitNodeN, _lvl = Player.sourceFileLvl(Player.bitNodeN) + 1): IBitNodeMultipliers => {
} if (Player.sourceFileLvl(5) <= 0 && Player.bitNodeN !== 5)
const copy = Object.assign({}, BitNodeMultipliers); throw helpers.makeRuntimeErrorMsg(ctx, "Requires Source-File 5 to run.");
return copy; const n = Math.round(helpers.number(ctx, "n", _n));
}, const lvl = Math.round(helpers.number(ctx, "lvl", _lvl));
if (n < 1 || n > 13) throw new Error("n must be between 1 and 13");
if (lvl < 1) throw new Error("lvl must be >= 1");
return Object.assign({}, getBitNodeMultipliers(n, lvl));
},
getServer: getServer:
(ctx) => (ctx) =>
(_hostname = ctx.workerScript.hostname) => { (_hostname = ctx.workerScript.hostname) => {

@ -6682,7 +6682,7 @@ export interface NS {
* @remarks * @remarks
* RAM cost: 4 GB * RAM cost: 4 GB
* *
* Returns an object containing the current BitNode multipliers. * Returns an object containing the current (or supplied) BitNode multipliers.
* This function requires you to be in Bitnode 5 or have Source-File 5 in order to run. * This function requires you to be in Bitnode 5 or have Source-File 5 in order to run.
* The multipliers are returned in decimal forms (e.g. 1.5 instead of 150%). * The multipliers are returned in decimal forms (e.g. 1.5 instead of 150%).
* The multipliers represent the difference between the current BitNode and * The multipliers represent the difference between the current BitNode and
@ -6708,7 +6708,7 @@ export interface NS {
* ``` * ```
* @returns Object containing the current BitNode multipliers. * @returns Object containing the current BitNode multipliers.
*/ */
getBitNodeMultipliers(): BitNodeMultipliers; getBitNodeMultipliers(n?: number, lvl?: number): BitNodeMultipliers;
/** /**
* Get information about the player. * Get information about the player.