mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-17 14:59:16 +02:00
FEATURE: BitNode options (#1411)
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
import type { NetscriptContext } from "./APIWrapper";
|
||||
import type { RunningScript as IRunningScript, Person as IPerson, Server as IServer, ScriptArg } from "@nsdefs";
|
||||
import type {
|
||||
RunningScript as IRunningScript,
|
||||
Person as IPerson,
|
||||
Server as IServer,
|
||||
ScriptArg,
|
||||
BitNodeOptions,
|
||||
} from "@nsdefs";
|
||||
import type { WorkerScript } from "./WorkerScript";
|
||||
|
||||
import React from "react";
|
||||
@@ -49,6 +55,12 @@ import { CustomBoundary } from "../ui/Components/CustomBoundary";
|
||||
import { ServerConstants } from "../Server/data/Constants";
|
||||
import { basicErrorMessage, errorMessage, log } from "./ErrorMessages";
|
||||
import { assertString, debugType } from "./TypeAssertion";
|
||||
import {
|
||||
canAccessBitNodeFeature,
|
||||
getDefaultBitNodeOptions,
|
||||
validateSourceFileOverrides,
|
||||
} from "../BitNode/BitNodeUtils";
|
||||
import { JSONMap } from "../Types/Jsonable";
|
||||
|
||||
export const helpers = {
|
||||
string,
|
||||
@@ -83,6 +95,7 @@ export const helpers = {
|
||||
getCannotFindRunningScriptErrorMessage,
|
||||
createPublicRunningScript,
|
||||
failOnHacknetServer,
|
||||
validateBitNodeOptions,
|
||||
};
|
||||
|
||||
/** RunOptions with non-optional, type-validated members, for passing between internal functions. */
|
||||
@@ -279,7 +292,7 @@ function validateHGWOptions(ctx: NetscriptContext, opts: unknown): CompleteHGWOp
|
||||
|
||||
/** Validate singularity access by throwing an error if the player does not have access. */
|
||||
function checkSingularityAccess(ctx: NetscriptContext): void {
|
||||
if (Player.bitNodeN !== 4 && Player.sourceFileLvl(4) === 0) {
|
||||
if (!canAccessBitNodeFeature(4)) {
|
||||
throw errorMessage(
|
||||
ctx,
|
||||
`This singularity function requires Source-File 4 to run. A power up you obtain later in the game.
|
||||
@@ -732,3 +745,40 @@ let customElementKey = 0;
|
||||
export function wrapUserNode(value: unknown) {
|
||||
return <CustomBoundary key={`PlayerContent${customElementKey++}`}>{value}</CustomBoundary>;
|
||||
}
|
||||
|
||||
function validateBitNodeOptions(ctx: NetscriptContext, bitNodeOptions: unknown): BitNodeOptions {
|
||||
const result = getDefaultBitNodeOptions();
|
||||
if (bitNodeOptions == null) {
|
||||
return result;
|
||||
}
|
||||
if (typeof bitNodeOptions !== "object") {
|
||||
throw errorMessage(ctx, `bitNodeOptions must be an object if it's specified. It was ${bitNodeOptions}.`);
|
||||
}
|
||||
const options = bitNodeOptions as Unknownify<BitNodeOptions>;
|
||||
if (!(options.sourceFileOverrides instanceof Map)) {
|
||||
throw errorMessage(ctx, `sourceFileOverrides must be a Map.`);
|
||||
}
|
||||
const validationResultForSourceFileOverrides = validateSourceFileOverrides(options.sourceFileOverrides, true);
|
||||
if (!validationResultForSourceFileOverrides.valid) {
|
||||
throw errorMessage(
|
||||
ctx,
|
||||
`sourceFileOverrides is invalid. Reason: ${validationResultForSourceFileOverrides.message}`,
|
||||
);
|
||||
}
|
||||
|
||||
result.sourceFileOverrides = new JSONMap(options.sourceFileOverrides);
|
||||
if (options.intelligenceOverride !== undefined) {
|
||||
result.intelligenceOverride = number(ctx, "intelligenceOverride", options.intelligenceOverride);
|
||||
} else {
|
||||
result.intelligenceOverride = undefined;
|
||||
}
|
||||
result.restrictHomePCUpgrade = !!options.restrictHomePCUpgrade;
|
||||
result.disableGang = !!options.disableGang;
|
||||
result.disableCorporation = !!options.disableCorporation;
|
||||
result.disableBladeburner = !!options.disableBladeburner;
|
||||
result.disable4SData = !!options.disable4SData;
|
||||
result.disableHacknetServer = !!options.disableHacknetServer;
|
||||
result.disableSleeveExpAndAugmentation = !!options.disableSleeveExpAndAugmentation;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -86,10 +86,16 @@ export const RamCostConstants = {
|
||||
|
||||
function SF4Cost(cost: number): () => number {
|
||||
return () => {
|
||||
if (Player.bitNodeN === 4) return cost;
|
||||
const sf4 = Player.sourceFileLvl(4);
|
||||
if (sf4 <= 1) return cost * 16;
|
||||
if (sf4 === 2) return cost * 4;
|
||||
if (Player.bitNodeN === 4) {
|
||||
return cost;
|
||||
}
|
||||
const sf4 = Player.activeSourceFileLvl(4);
|
||||
if (sf4 <= 1) {
|
||||
return cost * 16;
|
||||
}
|
||||
if (sf4 === 2) {
|
||||
return cost * 4;
|
||||
}
|
||||
return cost;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user