FEATURE: BitNode options (#1411)

This commit is contained in:
catloversg
2024-07-15 04:30:30 +07:00
committed by GitHub
parent 0e1e8a9862
commit 783120c886
71 changed files with 1315 additions and 308 deletions
+23 -22
View File
@@ -12,6 +12,7 @@ import { Skills } from "../Bladeburner/data/Skills";
import { assertString } from "../Netscript/TypeAssertion";
import { BlackOperations, blackOpsArray } from "../Bladeburner/data/BlackOperations";
import { checkSleeveAPIAccess, checkSleeveNumber } from "../NetscriptFunctions/Sleeve";
import { canAccessBitNodeFeature } from "../BitNode/BitNodeUtils";
export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
const checkBladeburnerAccess = function (ctx: NetscriptContext): void {
@@ -19,7 +20,7 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
return;
};
const getBladeburner = function (ctx: NetscriptContext): Bladeburner {
const apiAccess = Player.bitNodeN === 7 || Player.sourceFileLvl(7) > 0;
const apiAccess = canAccessBitNodeFeature(7);
if (!apiAccess) {
throw helpers.errorMessage(ctx, "You have not unlocked the Bladeburner API.", "API ACCESS");
}
@@ -298,28 +299,28 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
return !!attempt.success;
},
joinBladeburnerDivision: (ctx) => () => {
if (Player.bitNodeN === 7 || Player.sourceFileLvl(7) > 0) {
if (currentNodeMults.BladeburnerRank === 0) {
return false; // Disabled in this bitnode
}
if (Player.bladeburner) {
return true; // Already member
} else if (
Player.skills.strength >= 100 &&
Player.skills.defense >= 100 &&
Player.skills.dexterity >= 100 &&
Player.skills.agility >= 100
) {
Player.startBladeburner();
helpers.log(ctx, () => "You have been accepted into the Bladeburner division");
return true;
} else {
helpers.log(ctx, () => "You do not meet the requirements for joining the Bladeburner division");
return false;
}
if (!canAccessBitNodeFeature(7) || Player.bitNodeOptions.disableBladeburner) {
return false;
}
return false;
if (currentNodeMults.BladeburnerRank === 0) {
return false; // Disabled in this bitnode
}
if (Player.bladeburner) {
return true; // Already member
}
if (
Player.skills.strength < 100 ||
Player.skills.defense < 100 ||
Player.skills.dexterity < 100 ||
Player.skills.agility < 100
) {
helpers.log(ctx, () => "You do not meet the requirements for joining the Bladeburner division");
return false;
}
Player.startBladeburner();
helpers.log(ctx, () => "You have been accepted into the Bladeburner division");
return true;
},
getBonusTime: (ctx) => () => {
const bladeburner = getBladeburner(ctx);
+30 -15
View File
@@ -59,6 +59,7 @@ import { ServerConstants } from "../Server/data/Constants";
import { blackOpsArray } from "../Bladeburner/data/BlackOperations";
import { calculateEffectiveRequiredReputation } from "../Company/utils";
import { calculateFavorAfterResetting } from "../Faction/formulas/favor";
import { validBitNodes } from "../BitNode/BitNodeUtils";
export function NetscriptSingularity(): InternalAPI<ISingularity> {
const runAfterReset = function (cbScript: ScriptFilePath) {
@@ -628,7 +629,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
// Check if we're at max cores
const homeComputer = Player.getHomeComputer();
if (homeComputer.cpuCores >= 8) {
if (Player.bitNodeOptions.restrictHomePCUpgrade || homeComputer.cpuCores >= 8) {
helpers.log(ctx, () => `Your home computer is at max cores.`);
return false;
}
@@ -659,7 +660,10 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
// Check if we're at max RAM
const homeComputer = Player.getHomeComputer();
if (homeComputer.maxRam >= ServerConstants.HomeComputerMaxRam) {
if (
(Player.bitNodeOptions.restrictHomePCUpgrade && homeComputer.maxRam >= 128) ||
homeComputer.maxRam >= ServerConstants.HomeComputerMaxRam
) {
helpers.log(ctx, () => `Your home computer is at max RAM.`);
return false;
}
@@ -1137,38 +1141,47 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
}
return item.price;
},
b1tflum3: (ctx) => (_nextBN, _cbScript) => {
b1tflum3: (ctx) => (_nextBN, _cbScript, _bitNodeOptions) => {
helpers.checkSingularityAccess(ctx);
const nextBN = helpers.number(ctx, "nextBN", _nextBN);
const cbScript = _cbScript
? resolveScriptFilePath(helpers.string(ctx, "cbScript", _cbScript), ctx.workerScript.name)
: false;
if (cbScript === null) throw helpers.errorMessage(ctx, `Could not resolve file path: ${_cbScript}`);
enterBitNode(true, Player.bitNodeN, nextBN);
if (cbScript) setTimeout(() => runAfterReset(cbScript), 500);
if (cbScript === null) {
throw helpers.errorMessage(ctx, `Could not resolve file path: ${_cbScript}`);
}
enterBitNode(true, Player.bitNodeN, nextBN, helpers.validateBitNodeOptions(ctx, _bitNodeOptions));
if (cbScript) {
setTimeout(() => runAfterReset(cbScript), 500);
}
},
destroyW0r1dD43m0n: (ctx) => (_nextBN, _cbScript) => {
destroyW0r1dD43m0n: (ctx) => (_nextBN, _cbScript, _bitNodeOptions) => {
helpers.checkSingularityAccess(ctx);
const nextBN = helpers.number(ctx, "nextBN", _nextBN);
if (nextBN > 14 || nextBN < 1 || !Number.isInteger(nextBN)) {
throw new Error(`Invalid bitnode specified: ${_nextBN}`);
if (!validBitNodes.includes(nextBN)) {
throw new Error(`Invalid BitNode: ${_nextBN}.`);
}
const cbScript = _cbScript
? resolveScriptFilePath(helpers.string(ctx, "cbScript", _cbScript), ctx.workerScript.name)
: false;
if (cbScript === null) throw helpers.errorMessage(ctx, `Could not resolve file path: ${_cbScript}`);
if (cbScript === null) {
throw helpers.errorMessage(ctx, `Could not resolve file path: ${_cbScript}`);
}
const wd = GetServer(SpecialServers.WorldDaemon);
if (!(wd instanceof Server)) {
throw new Error("WorldDaemon is not a normal server. This is a bug. Please contact developers.");
}
const hackingRequirements = () => {
if (Player.skills.hacking < wd.requiredHackingSkill) return false;
if (!wd.hasAdminRights) return false;
if (Player.skills.hacking < wd.requiredHackingSkill || !wd.hasAdminRights) {
return false;
}
return true;
};
const bladeburnerRequirements = () => {
if (!Player.bladeburner) return false;
if (!Player.bladeburner) {
return false;
}
return Player.bladeburner.numBlackOpsComplete >= blackOpsArray.length;
};
@@ -1179,8 +1192,10 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
wd.backdoorInstalled = true;
calculateAchievements();
enterBitNode(false, Player.bitNodeN, nextBN);
if (cbScript) setTimeout(() => runAfterReset(cbScript), 500);
enterBitNode(false, Player.bitNodeN, nextBN, helpers.validateBitNodeOptions(ctx, _bitNodeOptions));
if (cbScript) {
setTimeout(() => runAfterReset(cbScript), 500);
}
},
getCurrentWork: (ctx) => () => {
helpers.checkSingularityAccess(ctx);
+18
View File
@@ -15,6 +15,7 @@ import { helpers } from "../Netscript/NetscriptHelpers";
import { getAugCost } from "../Augmentation/AugmentationHelpers";
import { Factions } from "../Faction/Factions";
import { SleeveWorkType } from "../PersonObjects/Sleeve/Work/Work";
import { canAccessBitNodeFeature } from "../BitNode/BitNodeUtils";
export const checkSleeveAPIAccess = function (ctx: NetscriptContext) {
if (Player.bitNodeN !== 10 && !Player.sourceFileLvl(10)) {
@@ -33,6 +34,23 @@ export const checkSleeveNumber = function (ctx: NetscriptContext, sleeveNumber:
};
export function NetscriptSleeve(): InternalAPI<NetscriptSleeve> {
const checkSleeveAPIAccess = function (ctx: NetscriptContext) {
if (!canAccessBitNodeFeature(10)) {
throw helpers.errorMessage(
ctx,
"You do not have access to the Sleeve API. This is either because you are not in BitNode-10 or because you do not have Source-File 10.",
);
}
};
const checkSleeveNumber = function (ctx: NetscriptContext, sleeveNumber: number) {
if (sleeveNumber >= Player.sleeves.length || sleeveNumber < 0) {
const msg = `Invalid sleeve number: ${sleeveNumber}`;
helpers.log(ctx, () => msg);
throw helpers.errorMessage(ctx, msg);
}
};
const sleeveFunctions: InternalAPI<NetscriptSleeve> = {
getNumSleeves: (ctx) => () => {
checkSleeveAPIAccess(ctx);
+20 -20
View File
@@ -167,10 +167,8 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
const symbol = helpers.string(ctx, "symbol", _symbol);
const shares = helpers.number(ctx, "shares", _shares);
checkTixApiAccess(ctx);
if (Player.bitNodeN !== 8) {
if (Player.sourceFileLvl(8) <= 1) {
throw helpers.errorMessage(ctx, "You must either be in BitNode-8 or you must have Source-File 8 Level 2.");
}
if (Player.bitNodeN !== 8 && Player.activeSourceFileLvl(8) <= 1) {
throw helpers.errorMessage(ctx, "You must either be in BitNode-8 or you must have Source-File 8 Level 2.");
}
const stock = getStockFromSymbol(ctx, symbol);
const res = shortStock(stock, shares, ctx, {});
@@ -181,10 +179,8 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
const symbol = helpers.string(ctx, "symbol", _symbol);
const shares = helpers.number(ctx, "shares", _shares);
checkTixApiAccess(ctx);
if (Player.bitNodeN !== 8) {
if (Player.sourceFileLvl(8) <= 1) {
throw helpers.errorMessage(ctx, "You must either be in BitNode-8 or you must have Source-File 8 Level 2.");
}
if (Player.bitNodeN !== 8 && Player.activeSourceFileLvl(8) <= 1) {
throw helpers.errorMessage(ctx, "You must either be in BitNode-8 or you must have Source-File 8 Level 2.");
}
const stock = getStockFromSymbol(ctx, symbol);
const res = sellShort(stock, shares, ctx, {});
@@ -198,10 +194,8 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
const type = helpers.string(ctx, "type", _type);
const pos = helpers.string(ctx, "pos", _pos);
checkTixApiAccess(ctx);
if (Player.bitNodeN !== 8) {
if (Player.sourceFileLvl(8) <= 2) {
throw helpers.errorMessage(ctx, "You must either be in BitNode-8 or you must have Source-File 8 Level 3.");
}
if (Player.bitNodeN !== 8 && Player.activeSourceFileLvl(8) <= 2) {
throw helpers.errorMessage(ctx, "You must either be in BitNode-8 or you must have Source-File 8 Level 3.");
}
const stock = getStockFromSymbol(ctx, symbol);
@@ -238,10 +232,8 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
const type = helpers.string(ctx, "type", _type);
const pos = helpers.string(ctx, "pos", _pos);
checkTixApiAccess(ctx);
if (Player.bitNodeN !== 8) {
if (Player.sourceFileLvl(8) <= 2) {
throw helpers.errorMessage(ctx, "You must either be in BitNode-8 or you must have Source-File 8 Level 3.");
}
if (Player.bitNodeN !== 8 && Player.activeSourceFileLvl(8) <= 2) {
throw helpers.errorMessage(ctx, "You must either be in BitNode-8 or you must have Source-File 8 Level 3.");
}
const stock = getStockFromSymbol(ctx, symbol);
if (isNaN(shares) || isNaN(price)) {
@@ -281,10 +273,8 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
},
getOrders: (ctx) => () => {
checkTixApiAccess(ctx);
if (Player.bitNodeN !== 8) {
if (Player.sourceFileLvl(8) <= 2) {
throw helpers.errorMessage(ctx, "You must either be in BitNode-8 or have Source-File 8 Level 3.");
}
if (Player.bitNodeN !== 8 && Player.activeSourceFileLvl(8) <= 2) {
throw helpers.errorMessage(ctx, "You must either be in BitNode-8 or have Source-File 8 Level 3.");
}
const orders: StockOrder = {};
@@ -328,6 +318,11 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
return forecast / 100; // Convert from percentage to decimal
},
purchase4SMarketData: (ctx) => () => {
if (Player.bitNodeOptions.disable4SData) {
helpers.log(ctx, () => "4S Market Data is disabled.");
return false;
}
if (Player.has4SData) {
helpers.log(ctx, () => "Already purchased 4S Market Data.");
return true;
@@ -344,6 +339,11 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
return true;
},
purchase4SMarketDataTixApi: (ctx) => () => {
if (Player.bitNodeOptions.disable4SData) {
helpers.log(ctx, () => "4S Market Data is disabled.");
return false;
}
checkTixApiAccess(ctx);
if (Player.has4SDataTixApi) {