merge base

This commit is contained in:
phyzical
2022-04-14 21:27:08 +08:00
104 changed files with 1826 additions and 1276 deletions
+57 -16
View File
@@ -53,6 +53,9 @@ import {
SellShares,
BuyBackShares,
SetSmartSupplyUseLeftovers,
LimitMaterialProduction,
LimitProductProduction,
UpgradeWarehouseCost,
} from "../Corporation/Actions";
import { CorporationUnlockUpgrades } from "../Corporation/data/CorporationUnlockUpgrades";
import { CorporationUpgrades } from "../Corporation/data/CorporationUpgrades";
@@ -64,6 +67,7 @@ import { CorporationConstants } from "../Corporation/data/Constants";
import { IndustryUpgrades } from "../Corporation/IndustryUpgrades";
import { ResearchMap } from "../Corporation/ResearchMap";
import { Factions } from "../Faction/Factions";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
export function NetscriptCorporation(
player: IPlayer,
@@ -74,6 +78,8 @@ export function NetscriptCorporation(
if (!player.canAccessCorporation() || player.hasCorporation()) return false;
if (!corporationName) return false;
if (player.bitNodeN !== 3 && !selfFund) throw new Error("cannot use seed funds outside of BitNode 3");
if (BitNodeMultipliers.CorporationSoftCap < 0.15)
throw new Error(`You cannot create a corporation in Bitnode ${player.bitNodeN}`);
if (selfFund) {
if (!player.canAfford(150e9)) return false;
@@ -88,35 +94,35 @@ export function NetscriptCorporation(
function hasUnlockUpgrade(upgradeName: string): boolean {
const corporation = getCorporation();
const upgrade = Object.values(CorporationUnlockUpgrades).find((upgrade) => upgrade[2] === upgradeName);
const upgrade = Object.values(CorporationUnlockUpgrades).find((upgrade) => upgrade.name === upgradeName);
if (upgrade === undefined) throw new Error(`No upgrade named '${upgradeName}'`);
const upgN = upgrade[0];
const upgN = upgrade.index;
return corporation.unlockUpgrades[upgN] === 1;
}
function getUnlockUpgradeCost(upgradeName: string): number {
const upgrade = Object.values(CorporationUnlockUpgrades).find((upgrade) => upgrade[2] === upgradeName);
const upgrade = Object.values(CorporationUnlockUpgrades).find((upgrade) => upgrade.name === upgradeName);
if (upgrade === undefined) throw new Error(`No upgrade named '${upgradeName}'`);
return upgrade[1];
return upgrade.price;
}
function getUpgradeLevel(_upgradeName: string): number {
const upgradeName = helper.string("levelUpgrade", "upgradeName", _upgradeName);
const corporation = getCorporation();
const upgrade = Object.values(CorporationUpgrades).find((upgrade) => upgrade[4] === upgradeName);
const upgrade = Object.values(CorporationUpgrades).find((upgrade) => upgrade.name === upgradeName);
if (upgrade === undefined) throw new Error(`No upgrade named '${upgradeName}'`);
const upgN = upgrade[0];
const upgN = upgrade.index;
return corporation.upgrades[upgN];
}
function getUpgradeLevelCost(_upgradeName: string): number {
const upgradeName = helper.string("levelUpgrade", "upgradeName", _upgradeName);
const corporation = getCorporation();
const upgrade = Object.values(CorporationUpgrades).find((upgrade) => upgrade[4] === upgradeName);
const upgrade = Object.values(CorporationUpgrades).find((upgrade) => upgrade.name === upgradeName);
if (upgrade === undefined) throw new Error(`No upgrade named '${upgradeName}'`);
const upgN = upgrade[0];
const baseCost = upgrade[1];
const priceMult = upgrade[2];
const upgN = upgrade.index;
const baseCost = upgrade.basePrice;
const priceMult = upgrade.priceMult;
const level = corporation.upgrades[upgN];
return baseCost * Math.pow(priceMult, level);
}
@@ -311,12 +317,16 @@ export function NetscriptCorporation(
checkAccess("getPurchaseWarehouseCost", 7);
return CorporationConstants.WarehouseInitialCost;
},
getUpgradeWarehouseCost: function (_divisionName: unknown, _cityName: unknown): number {
getUpgradeWarehouseCost: function (_divisionName: unknown, _cityName: unknown, _amt: unknown = 1): number {
checkAccess("upgradeWarehouse", 7);
const divisionName = helper.string("getUpgradeWarehouseCost", "divisionName", _divisionName);
const cityName = helper.city("getUpgradeWarehouseCost", "cityName", _cityName);
const amt = helper.number("getUpgradeWarehouseCost", "amount", _amt);
if (amt < 1) {
throw helper.makeRuntimeErrorMsg(`corporation.getUpgradeWarehouseCost`, "You must provide a positive number");
}
const warehouse = getWarehouse(divisionName, cityName);
return CorporationConstants.WarehouseUpgradeBaseCost * Math.pow(1.07, warehouse.level + 1);
return UpgradeWarehouseCost(warehouse, amt);
},
hasWarehouse: function (_divisionName: unknown, _cityName: unknown): boolean {
checkAccess("hasWarehouse", 7);
@@ -348,6 +358,7 @@ export function NetscriptCorporation(
const material = getMaterial(divisionName, cityName, materialName);
const corporation = getCorporation();
return {
cost: material.bCost,
name: material.name,
qty: material.qty,
qlt: material.qlt,
@@ -389,12 +400,16 @@ export function NetscriptCorporation(
const corporation = getCorporation();
PurchaseWarehouse(corporation, getDivision(divisionName), cityName);
},
upgradeWarehouse: function (_divisionName: unknown, _cityName: unknown): void {
upgradeWarehouse: function (_divisionName: unknown, _cityName: unknown, _amt: unknown = 1): void {
checkAccess("upgradeWarehouse", 7);
const divisionName = helper.string("upgradeWarehouse", "divisionName", _divisionName);
const cityName = helper.city("upgradeWarehouse", "cityName", _cityName);
const amt = helper.number("upgradeWarehouse", "amount", _amt);
const corporation = getCorporation();
UpgradeWarehouse(corporation, getDivision(divisionName), getWarehouse(divisionName, cityName));
if (amt < 1) {
throw helper.makeRuntimeErrorMsg(`corporation.upgradeWarehouse`, "You must provide a positive number");
}
UpgradeWarehouse(corporation, getDivision(divisionName), getWarehouse(divisionName, cityName), amt);
},
sellMaterial: function (
_divisionName: unknown,
@@ -508,6 +523,19 @@ export function NetscriptCorporation(
const corporation = getCorporation();
MakeProduct(corporation, getDivision(divisionName), cityName, productName, designInvest, marketingInvest);
},
limitProductProduction: function (
_divisionName: unknown,
_productName: unknown,
_cityName: unknown,
_qty: unknown,
) {
checkAccess("limitProductProduction", 7);
const divisionName = helper.string("limitProductProduction", "divisionName", _divisionName);
const cityName = helper.city("limitMaterialProduction", "cityName", _cityName);
const productName = helper.string("limitProductProduction", "productName", _productName);
const qty = helper.number("limitMaterialProduction", "qty", _qty);
LimitProductProduction(getProduct(divisionName, productName), cityName, qty);
},
exportMaterial: function (
_sourceDivision: unknown,
_sourceCity: unknown,
@@ -548,6 +576,19 @@ export function NetscriptCorporation(
const amt = helper.string("cancelExportMaterial", "amt", _amt);
CancelExportMaterial(targetDivision, targetCity, getMaterial(sourceDivision, sourceCity, materialName), amt + "");
},
limitMaterialProduction: function (
_divisionName: unknown,
_cityName: unknown,
_materialName: unknown,
_qty: unknown,
) {
checkAccess("limitMaterialProduction", 7);
const divisionName = helper.string("limitMaterialProduction", "divisionName", _divisionName);
const cityName = helper.city("limitMaterialProduction", "cityName", _cityName);
const materialName = helper.string("limitMaterialProduction", "materialName", _materialName);
const qty = helper.number("limitMaterialProduction", "qty", _qty);
LimitMaterialProduction(getMaterial(divisionName, cityName, materialName), qty);
},
setMaterialMarketTA1: function (
_divisionName: unknown,
_cityName: unknown,
@@ -820,7 +861,7 @@ export function NetscriptCorporation(
checkAccess("unlockUpgrade");
const upgradeName = helper.string("unlockUpgrade", "upgradeName", _upgradeName);
const corporation = getCorporation();
const upgrade = Object.values(CorporationUnlockUpgrades).find((upgrade) => upgrade[2] === upgradeName);
const upgrade = Object.values(CorporationUnlockUpgrades).find((upgrade) => upgrade.name === upgradeName);
if (upgrade === undefined) throw new Error(`No upgrade named '${upgradeName}'`);
UnlockUpgrade(corporation, upgrade);
},
@@ -828,7 +869,7 @@ export function NetscriptCorporation(
checkAccess("levelUpgrade");
const upgradeName = helper.string("levelUpgrade", "upgradeName", _upgradeName);
const corporation = getCorporation();
const upgrade = Object.values(CorporationUpgrades).find((upgrade) => upgrade[4] === upgradeName);
const upgrade = Object.values(CorporationUpgrades).find((upgrade) => upgrade.name === upgradeName);
if (upgrade === undefined) throw new Error(`No upgrade named '${upgradeName}'`);
LevelUpgrade(corporation, upgrade);
},
+5
View File
@@ -3,11 +3,13 @@ import { IPlayer } from "../PersonObjects/IPlayer";
import { Exploit } from "../Exploits/Exploit";
import * as bcrypt from "bcryptjs";
import { INetscriptHelper } from "./INetscriptHelper";
import { Apr1Events as devMenu } from "../ui/Apr1";
export interface INetscriptExtra {
heart: {
break(): number;
};
openDevMenu(): void;
exploit(): void;
bypass(doc: Document): void;
alterReality(): void;
@@ -22,6 +24,9 @@ export function NetscriptExtra(player: IPlayer, workerScript: WorkerScript, help
return player.karma;
},
},
openDevMenu: function (): void {
devMenu.emit();
},
exploit: function (): void {
player.giveExploit(Exploit.UndocumentedFunctionCall);
},
+11 -4
View File
@@ -4,7 +4,7 @@ import { CityName } from "../Locations/data/CityNames";
import { getRamCost } from "../Netscript/RamCostGenerator";
import { WorkerScript } from "../Netscript/WorkerScript";
import { GraftableAugmentation } from "../PersonObjects/Grafting/GraftableAugmentation";
import { getAvailableAugs } from "../PersonObjects/Grafting/ui/GraftingRoot";
import { getGraftingAvailableAugs } from "../PersonObjects/Grafting/GraftingHelpers";
import { IPlayer } from "../PersonObjects/IPlayer";
import { Grafting as IGrafting } from "../ScriptEditor/NetscriptDefinitions";
import { Router } from "../ui/GameRoot";
@@ -28,7 +28,7 @@ export function NetscriptGrafting(player: IPlayer, workerScript: WorkerScript, h
updateRam("getAugmentationGraftPrice");
const augName = helper.string("getAugmentationGraftPrice", "augName", _augName);
checkGraftingAPIAccess("getAugmentationGraftPrice");
if (!Augmentations.hasOwnProperty(augName)) {
if (!getGraftingAvailableAugs(player).includes(augName) || !Augmentations.hasOwnProperty(augName)) {
throw helper.makeRuntimeErrorMsg("grafting.getAugmentationGraftPrice", `Invalid aug: ${augName}`);
}
const craftableAug = new GraftableAugmentation(Augmentations[augName]);
@@ -39,13 +39,20 @@ export function NetscriptGrafting(player: IPlayer, workerScript: WorkerScript, h
updateRam("getAugmentationGraftTime");
const augName = helper.string("getAugmentationGraftTime", "augName", _augName);
checkGraftingAPIAccess("getAugmentationGraftTime");
if (!Augmentations.hasOwnProperty(augName)) {
if (!getGraftingAvailableAugs(player).includes(augName) || !Augmentations.hasOwnProperty(augName)) {
throw helper.makeRuntimeErrorMsg("grafting.getAugmentationGraftTime", `Invalid aug: ${augName}`);
}
const craftableAug = new GraftableAugmentation(Augmentations[augName]);
return craftableAug.time;
},
getGraftableAugmentations: (): string[] => {
updateRam("getGraftableAugmentations");
checkGraftingAPIAccess("getGraftableAugmentations");
const graftableAugs = getGraftingAvailableAugs(player);
return graftableAugs;
},
graftAugmentation: (_augName: string, _focus: unknown = true): boolean => {
updateRam("graftAugmentation");
const augName = helper.string("graftAugmentation", "augName", _augName);
@@ -57,7 +64,7 @@ export function NetscriptGrafting(player: IPlayer, workerScript: WorkerScript, h
"You must be in New Tokyo to begin grafting an Augmentation.",
);
}
if (!getAvailableAugs(player).includes(augName)) {
if (!getGraftingAvailableAugs(player).includes(augName) || !Augmentations.hasOwnProperty(augName)) {
workerScript.log("grafting.graftAugmentation", () => `Invalid aug: ${augName}`);
return false;
}
+94 -33
View File
@@ -47,6 +47,8 @@ import { Server } from "../Server/Server";
import { netscriptCanHack } from "../Hacking/netscriptCanHack";
import { FactionInfos } from "../Faction/FactionInfo";
import { InternalAPI, NetscriptContext } from "src/Netscript/APIWrapper";
import { BlackOperationNames } from "../Bladeburner/data/BlackOperationNames";
import { enterBitNode } from "../RedPill";
export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript): InternalAPI<ISingularity> {
const getAugmentation = function (_ctx: NetscriptContext, name: string): Augmentation {
@@ -94,8 +96,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
return {
getOwnedAugmentations: (_ctx: NetscriptContext) =>
function (_purchased: unknown = false): string[] {
const purchased = _ctx.helper.boolean(_purchased);
_ctx.helper.checkSingularityAccess();
const purchased = _ctx.helper.boolean(_purchased);
const res = [];
for (let i = 0; i < player.augmentations.length; ++i) {
res.push(player.augmentations[i].name);
@@ -109,52 +111,52 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
},
getAugmentationsFromFaction: (_ctx: NetscriptContext) =>
function (_facName: unknown): string[] {
const facName = _ctx.helper.string("facName", _facName);
_ctx.helper.checkSingularityAccess();
const facName = _ctx.helper.string("facName", _facName);
const faction = getFaction(_ctx, facName);
return getFactionAugmentationsFiltered(player, faction);
},
getAugmentationCost: (_ctx: NetscriptContext) =>
function (_augName: unknown): [number, number] {
const augName = _ctx.helper.string("augName", _augName);
_ctx.helper.checkSingularityAccess();
const augName = _ctx.helper.string("augName", _augName);
const aug = getAugmentation(_ctx, augName);
return [aug.baseRepRequirement, aug.baseCost];
},
getAugmentationPrereq: (_ctx: NetscriptContext) =>
function (_augName: unknown): string[] {
const augName = _ctx.helper.string("augName", _augName);
_ctx.helper.checkSingularityAccess();
const augName = _ctx.helper.string("augName", _augName);
const aug = getAugmentation(_ctx, augName);
return aug.prereqs.slice();
},
getAugmentationPrice: (_ctx: NetscriptContext) =>
function (_augName: unknown): number {
const augName = _ctx.helper.string("augName", _augName);
_ctx.helper.checkSingularityAccess();
const augName = _ctx.helper.string("augName", _augName);
const aug = getAugmentation(_ctx, augName);
return aug.baseCost;
},
getAugmentationRepReq: (_ctx: NetscriptContext) =>
function (_augName: unknown): number {
const augName = _ctx.helper.string("augName", _augName);
_ctx.helper.checkSingularityAccess();
const augName = _ctx.helper.string("augName", _augName);
const aug = getAugmentation(_ctx, augName);
return aug.baseRepRequirement;
},
getAugmentationStats: (_ctx: NetscriptContext) =>
function (_augName: unknown): AugmentationStats {
const augName = _ctx.helper.string("augName", _augName);
_ctx.helper.checkSingularityAccess();
const augName = _ctx.helper.string("augName", _augName);
const aug = getAugmentation(_ctx, augName);
return Object.assign({}, aug.mults);
},
purchaseAugmentation: (_ctx: NetscriptContext) =>
function (_facName: unknown, _augName: unknown): boolean {
_ctx.helper.checkSingularityAccess();
const facName = _ctx.helper.string("facName", _facName);
const augName = _ctx.helper.string("augName", _augName);
_ctx.helper.checkSingularityAccess();
const fac = getFaction(_ctx, facName);
const aug = getAugmentation(_ctx, augName);
@@ -200,8 +202,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
},
softReset: (_ctx: NetscriptContext) =>
function (_cbScript: unknown = ""): void {
const cbScript = _ctx.helper.string("cbScript", _cbScript);
_ctx.helper.checkSingularityAccess();
const cbScript = _ctx.helper.string("cbScript", _cbScript);
workerScript.log("softReset", () => "Soft resetting. This will cause this script to be killed");
setTimeout(() => {
@@ -215,8 +217,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
},
installAugmentations: (_ctx: NetscriptContext) =>
function (_cbScript: unknown = ""): boolean {
const cbScript = _ctx.helper.string("cbScript", _cbScript);
_ctx.helper.checkSingularityAccess();
const cbScript = _ctx.helper.string("cbScript", _cbScript);
if (player.queuedAugmentations.length === 0) {
workerScript.log("installAugmentations", () => "You do not have any Augmentations to be installed.");
@@ -239,8 +241,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
goToLocation: (_ctx: NetscriptContext) =>
function (_locationName: unknown): boolean {
const locationName = _ctx.helper.string("locationName", _locationName);
_ctx.helper.checkSingularityAccess();
const locationName = _ctx.helper.string("locationName", _locationName);
const location = Object.values(Locations).find((l) => l.name === locationName);
if (!location) {
workerScript.log("goToLocation", () => `No location named ${locationName}`);
@@ -256,10 +258,10 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
},
universityCourse: (_ctx: NetscriptContext) =>
function (_universityName: unknown, _className: unknown, _focus: unknown = true): boolean {
_ctx.helper.checkSingularityAccess();
const universityName = _ctx.helper.string("universityName", _universityName);
const className = _ctx.helper.string("className", _className);
const focus = _ctx.helper.boolean(_focus);
_ctx.helper.checkSingularityAccess();
const wasFocusing = player.focus;
if (player.isWorking) {
const txt = player.singularityStopWork();
@@ -347,10 +349,10 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
gymWorkout: (_ctx: NetscriptContext) =>
function (_gymName: unknown, _stat: unknown, _focus: unknown = true): boolean {
_ctx.helper.checkSingularityAccess();
const gymName = _ctx.helper.string("gymName", _gymName);
const stat = _ctx.helper.string("stat", _stat);
const focus = _ctx.helper.boolean(_focus);
_ctx.helper.checkSingularityAccess();
const wasFocusing = player.focus;
if (player.isWorking) {
const txt = player.singularityStopWork();
@@ -462,8 +464,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
travelToCity: (_ctx: NetscriptContext) =>
function (_cityName: unknown): boolean {
const cityName = _ctx.helper.city("cityName", _cityName);
_ctx.helper.checkSingularityAccess();
const cityName = _ctx.helper.city("cityName", _cityName);
switch (cityName) {
case CityName.Aevum:
@@ -520,8 +522,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
},
purchaseProgram: (_ctx: NetscriptContext) =>
function (_programName: unknown): boolean {
const programName = _ctx.helper.string("programName", _programName).toLowerCase();
_ctx.helper.checkSingularityAccess();
const programName = _ctx.helper.string("programName", _programName).toLowerCase();
if (!player.hasTorRouter()) {
workerScript.log("purchaseProgram", () => "You do not have the TOR router.");
@@ -569,8 +571,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
},
connect: (_ctx: NetscriptContext) =>
function (_hostname: unknown): boolean {
const hostname = _ctx.helper.string("hostname", _hostname);
_ctx.helper.checkSingularityAccess();
const hostname = _ctx.helper.string("hostname", _hostname);
if (!hostname) {
throw _ctx.helper.makeRuntimeErrorMsg(`Invalid hostname: '${hostname}'`);
}
@@ -580,6 +582,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
throw _ctx.helper.makeRuntimeErrorMsg(`Invalid hostname: '${hostname}'`);
}
//Home case
if (hostname === "home") {
player.getCurrentServer().isConnectedTo = false;
player.currentServer = player.getHomeComputer().hostname;
@@ -588,6 +591,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
return true;
}
//Adjacent server case
const server = player.getCurrentServer();
for (let i = 0; i < server.serversOnNetwork.length; i++) {
const other = getServerOnNetwork(server, i);
@@ -601,6 +605,17 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
}
}
//Backdoor case
const other = GetServer(hostname);
if (other !== null && other instanceof Server && other.backdoorInstalled) {
player.getCurrentServer().isConnectedTo = false;
player.currentServer = target.hostname;
player.getCurrentServer().isConnectedTo = true;
Terminal.setcwd("/");
return true;
}
//Failure case
return false;
},
manualHack: (_ctx: NetscriptContext) =>
@@ -649,8 +664,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
},
setFocus: (_ctx: NetscriptContext) =>
function (_focus: unknown): boolean {
const focus = _ctx.helper.boolean(_focus);
_ctx.helper.checkSingularityAccess();
const focus = _ctx.helper.boolean(_focus);
if (!player.isWorking) {
throw _ctx.helper.makeRuntimeErrorMsg("Not currently working");
}
@@ -849,9 +864,9 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
},
workForCompany: (_ctx: NetscriptContext) =>
function (_companyName: unknown, _focus: unknown = true): boolean {
_ctx.helper.checkSingularityAccess();
let companyName = _ctx.helper.string("companyName", _companyName);
const focus = _ctx.helper.boolean(_focus);
_ctx.helper.checkSingularityAccess();
// Sanitize input
if (companyName == null) {
@@ -905,9 +920,9 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
},
applyToCompany: (_ctx: NetscriptContext) =>
function (_companyName: unknown, _field: unknown): boolean {
_ctx.helper.checkSingularityAccess();
const companyName = _ctx.helper.string("companyName", _companyName);
const field = _ctx.helper.string("field", _field);
_ctx.helper.checkSingularityAccess();
getCompany(_ctx, companyName);
player.location = companyName as LocationName;
@@ -977,22 +992,22 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
},
getCompanyRep: (_ctx: NetscriptContext) =>
function (_companyName: unknown): number {
const companyName = _ctx.helper.string("companyName", _companyName);
_ctx.helper.checkSingularityAccess();
const companyName = _ctx.helper.string("companyName", _companyName);
const company = getCompany(_ctx, companyName);
return company.playerReputation;
},
getCompanyFavor: (_ctx: NetscriptContext) =>
function (_companyName: unknown): number {
const companyName = _ctx.helper.string("companyName", _companyName);
_ctx.helper.checkSingularityAccess();
const companyName = _ctx.helper.string("companyName", _companyName);
const company = getCompany(_ctx, companyName);
return company.favor;
},
getCompanyFavorGain: (_ctx: NetscriptContext) =>
function (_companyName: unknown): number {
const companyName = _ctx.helper.string("companyName", _companyName);
_ctx.helper.checkSingularityAccess();
const companyName = _ctx.helper.string("companyName", _companyName);
const company = getCompany(_ctx, companyName);
return company.getFavorGain();
},
@@ -1004,8 +1019,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
},
joinFaction: (_ctx: NetscriptContext) =>
function (_facName: unknown): boolean {
const facName = _ctx.helper.string("facName", _facName);
_ctx.helper.checkSingularityAccess();
const facName = _ctx.helper.string("facName", _facName);
getFaction(_ctx, facName);
if (!player.factionInvitations.includes(facName)) {
@@ -1028,10 +1043,10 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
},
workForFaction: (_ctx: NetscriptContext) =>
function (_facName: unknown, _type: unknown, _focus: unknown = true): boolean {
_ctx.helper.checkSingularityAccess();
const facName = _ctx.helper.string("facName", _facName);
const type = _ctx.helper.string("type", _type);
const focus = _ctx.helper.boolean(_focus);
_ctx.helper.checkSingularityAccess();
getFaction(_ctx, facName);
// if the player is in a gang and the target faction is any of the gang faction, fail
@@ -1117,30 +1132,30 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
},
getFactionRep: (_ctx: NetscriptContext) =>
function (_facName: unknown): number {
const facName = _ctx.helper.string("facName", _facName);
_ctx.helper.checkSingularityAccess();
const facName = _ctx.helper.string("facName", _facName);
const faction = getFaction(_ctx, facName);
return faction.playerReputation;
},
getFactionFavor: (_ctx: NetscriptContext) =>
function (_facName: unknown): number {
const facName = _ctx.helper.string("facName", _facName);
_ctx.helper.checkSingularityAccess();
const facName = _ctx.helper.string("facName", _facName);
const faction = getFaction(_ctx, facName);
return faction.favor;
},
getFactionFavorGain: (_ctx: NetscriptContext) =>
function (_facName: unknown): number {
const facName = _ctx.helper.string("facName", _facName);
_ctx.helper.checkSingularityAccess();
const facName = _ctx.helper.string("facName", _facName);
const faction = getFaction(_ctx, facName);
return faction.getFavorGain();
},
donateToFaction: (_ctx: NetscriptContext) =>
function (_facName: unknown, _amt: unknown): boolean {
_ctx.helper.checkSingularityAccess();
const facName = _ctx.helper.string("facName", _facName);
const amt = _ctx.helper.number("amt", _amt);
_ctx.helper.checkSingularityAccess();
const faction = getFaction(_ctx, facName);
if (!player.factions.includes(faction.name)) {
workerScript.log("donateToFaction", () => `You can't donate to '${facName}' because you aren't a member`);
@@ -1187,9 +1202,9 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
},
createProgram: (_ctx: NetscriptContext) =>
function (_programName: unknown, _focus: unknown = true): boolean {
_ctx.helper.checkSingularityAccess();
const programName = _ctx.helper.string("programName", _programName).toLowerCase();
const focus = _ctx.helper.boolean(_focus);
_ctx.helper.checkSingularityAccess();
const wasFocusing = player.focus;
if (player.isWorking) {
@@ -1236,8 +1251,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
},
commitCrime: (_ctx: NetscriptContext) =>
function (_crimeRoughName: unknown): number {
const crimeRoughName = _ctx.helper.string("crimeRoughName", _crimeRoughName);
_ctx.helper.checkSingularityAccess();
const crimeRoughName = _ctx.helper.string("crimeRoughName", _crimeRoughName);
if (player.isWorking) {
const txt = player.singularityStopWork();
@@ -1257,8 +1272,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
},
getCrimeChance: (_ctx: NetscriptContext) =>
function (_crimeRoughName: unknown): number {
const crimeRoughName = _ctx.helper.string("crimeRoughName", _crimeRoughName);
_ctx.helper.checkSingularityAccess();
const crimeRoughName = _ctx.helper.string("crimeRoughName", _crimeRoughName);
const crime = findCrime(crimeRoughName.toLowerCase());
if (crime == null) {
@@ -1269,8 +1284,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
},
getCrimeStats: (_ctx: NetscriptContext) =>
function (_crimeRoughName: unknown): CrimeStats {
const crimeRoughName = _ctx.helper.string("crimeRoughName", _crimeRoughName);
_ctx.helper.checkSingularityAccess();
const crimeRoughName = _ctx.helper.string("crimeRoughName", _crimeRoughName);
const crime = findCrime(crimeRoughName.toLowerCase());
if (crime == null) {
@@ -1292,8 +1307,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
},
getDarkwebProgramCost: (_ctx: NetscriptContext) =>
function (_programName: unknown): number {
const programName = _ctx.helper.string("programName", _programName).toLowerCase();
_ctx.helper.checkSingularityAccess();
const programName = _ctx.helper.string("programName", _programName).toLowerCase();
// If we don't have Tor, log it and return -1
if (!player.hasTorRouter()) {
@@ -1322,5 +1337,51 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
}
return item.price;
},
b1tflum3:
(_ctx: NetscriptContext) =>
(_nextBN: unknown, _callbackScript: unknown = ""): void => {
_ctx.helper.checkSingularityAccess();
const nextBN = _ctx.helper.number("nextBN", _nextBN);
const callbackScript = _ctx.helper.string("callbackScript", _callbackScript);
_ctx.helper.checkSingularityAccess();
enterBitNode(Router, true, player.bitNodeN, nextBN);
if (callbackScript)
setTimeout(() => {
runAfterReset(callbackScript);
}, 0);
},
destroyW0r1dD43m0n:
(_ctx: NetscriptContext) =>
(_nextBN: unknown, _callbackScript: unknown = ""): void => {
_ctx.helper.checkSingularityAccess();
const nextBN = _ctx.helper.number("nextBN", _nextBN);
const callbackScript = _ctx.helper.string("callbackScript", _callbackScript);
_ctx.helper.checkSingularityAccess();
const hackingRequirements = (): boolean => {
const wd = GetServer(SpecialServers.WorldDaemon);
if (!(wd instanceof Server))
throw new Error("WorldDaemon was not a normal server. This is a bug contact dev.");
if (player.hacking < wd.requiredHackingSkill) return false;
if (!wd.hasAdminRights) return false;
return true;
};
const bladeburnerRequirements = (): boolean => {
if (!player.inBladeburner()) return false;
if (!player.bladeburner) return false;
return player.bladeburner.blackops[BlackOperationNames.OperationDaedalus];
};
if (!hackingRequirements() && !bladeburnerRequirements()) {
_ctx.log(() => "Requirements not met to destroy the world daemon");
return;
}
enterBitNode(Router, false, player.bitNodeN, nextBN);
if (callbackScript)
setTimeout(() => {
runAfterReset(callbackScript);
}, 0);
},
};
}
+1 -2
View File
@@ -2,7 +2,6 @@ import { INetscriptHelper } from "./INetscriptHelper";
import { IPlayer } from "../PersonObjects/IPlayer";
import { getRamCost } from "../Netscript/RamCostGenerator";
import { FactionWorkType } from "../Faction/FactionWorkTypeEnum";
import { SourceFileFlags } from "../SourceFile/SourceFileFlags";
import { SleeveTaskType } from "../PersonObjects/Sleeve/SleeveTaskTypesEnum";
import { WorkerScript } from "../Netscript/WorkerScript";
import { findSleevePurchasableAugs } from "../PersonObjects/Sleeve/SleeveHelpers";
@@ -20,7 +19,7 @@ import {
export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, helper: INetscriptHelper): ISleeve {
const checkSleeveAPIAccess = function (func: string): void {
if (player.bitNodeN !== 10 && !SourceFileFlags[10]) {
if (player.bitNodeN !== 10 && !player.sourceFileLvl(10)) {
throw helper.makeRuntimeErrorMsg(
`sleeve.${func}`,
"You do not currently 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",