mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-20 05:05:47 +01:00
Merge pull request #4236 from Snarling/typeFix
NETSCRIPT: Fix internal typechecking of functions
This commit is contained in:
commit
68e90b8e6e
@ -5,13 +5,15 @@ import { ScriptArg } from "./ScriptArg";
|
||||
import { NSEnums } from "src/ScriptEditor/NetscriptDefinitions";
|
||||
import { NSFull } from "src/NetscriptFunctions";
|
||||
|
||||
type ExternalFunction = (...args: unknown[]) => unknown;
|
||||
type ExternalFunction = (...args: any[]) => void;
|
||||
|
||||
export type ExternalAPILayer = {
|
||||
[key: string]: ExternalAPILayer | ExternalFunction | ScriptArg[];
|
||||
};
|
||||
|
||||
type InternalFunction<F extends (...args: unknown[]) => unknown> = (ctx: NetscriptContext) => F;
|
||||
type InternalFunction<F extends ExternalFunction> = (
|
||||
ctx: NetscriptContext,
|
||||
) => ((...args: unknown[]) => ReturnType<F>) & F;
|
||||
|
||||
export type InternalAPI<API> = {
|
||||
[Property in keyof API]: API[Property] extends ExternalFunction
|
||||
|
@ -65,6 +65,39 @@ export const helpers = {
|
||||
failOnHacknetServer,
|
||||
};
|
||||
|
||||
export function assertObjectType<T extends object>(
|
||||
ctx: NetscriptContext,
|
||||
name: string,
|
||||
obj: unknown,
|
||||
desiredObject: T,
|
||||
): asserts obj is T {
|
||||
if (typeof obj !== "object" || obj === null) {
|
||||
throw makeRuntimeErrorMsg(
|
||||
ctx,
|
||||
`Type ${obj === null ? "null" : typeof obj} provided for ${name}. Must be an object.`,
|
||||
"TYPE",
|
||||
);
|
||||
}
|
||||
const objHas = Object.prototype.hasOwnProperty.bind(obj);
|
||||
for (const [key, val] of Object.entries(desiredObject)) {
|
||||
if (!objHas(key)) {
|
||||
throw makeRuntimeErrorMsg(
|
||||
ctx,
|
||||
`Object provided for argument ${name} is missing required property ${key}.`,
|
||||
"TYPE",
|
||||
);
|
||||
}
|
||||
const objVal = (obj as Record<string, unknown>)[key];
|
||||
if (typeof val !== typeof objVal) {
|
||||
throw makeRuntimeErrorMsg(
|
||||
ctx,
|
||||
`Incorrect type ${typeof objVal} provided for property ${key} on ${name} argument. Should be type ${typeof val}.`,
|
||||
"TYPE",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const userFriendlyString = (v: unknown): string => {
|
||||
const clip = (s: string): string => {
|
||||
if (s.length > 15) return s.slice(0, 12) + "...";
|
||||
@ -220,10 +253,7 @@ function resolveNetscriptRequestedThreads(ctx: NetscriptContext, requestedThread
|
||||
}
|
||||
const requestedThreadsAsInt = requestedThreads | 0;
|
||||
if (isNaN(requestedThreads) || requestedThreadsAsInt < 1) {
|
||||
throw makeRuntimeErrorMsg(
|
||||
ctx,
|
||||
`Invalid thread count passed to ${ctx.function}: ${requestedThreads}. Threads must be a positive number.`,
|
||||
);
|
||||
throw makeRuntimeErrorMsg(ctx, `Invalid thread count: ${requestedThreads}. Threads must be a positive number.`);
|
||||
}
|
||||
if (requestedThreadsAsInt > threads) {
|
||||
throw makeRuntimeErrorMsg(
|
||||
|
@ -546,6 +546,7 @@ export const RamCosts: RamCostTree<Omit<NSFull, "args" | "enums">> = {
|
||||
// Easter egg function
|
||||
break: 0,
|
||||
},
|
||||
iKnowWhatImDoing: 0,
|
||||
|
||||
formulas: {
|
||||
mockServer: 0,
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
import { Player } from "@player";
|
||||
import { Bladeburner } from "../Bladeburner/Bladeburner";
|
||||
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
|
||||
import { Bladeburner as INetscriptBladeburner, BladeburnerCurAction } from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { Bladeburner as INetscriptBladeburner } from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { Action } from "src/Bladeburner/Action";
|
||||
import { InternalAPI, NetscriptContext } from "src/Netscript/APIWrapper";
|
||||
import { BlackOperation } from "../Bladeburner/BlackOperation";
|
||||
@ -47,38 +47,34 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
};
|
||||
|
||||
return {
|
||||
getContractNames: (ctx: NetscriptContext) => (): string[] => {
|
||||
getContractNames: (ctx) => () => {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
return bladeburner.getContractNamesNetscriptFn();
|
||||
},
|
||||
getOperationNames: (ctx: NetscriptContext) => (): string[] => {
|
||||
getOperationNames: (ctx) => () => {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
return bladeburner.getOperationNamesNetscriptFn();
|
||||
},
|
||||
getBlackOpNames: (ctx: NetscriptContext) => (): string[] => {
|
||||
getBlackOpNames: (ctx) => () => {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
return bladeburner.getBlackOpNamesNetscriptFn();
|
||||
},
|
||||
getBlackOpRank:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_blackOpName: unknown): number => {
|
||||
getBlackOpRank: (ctx) => (_blackOpName) => {
|
||||
const blackOpName = helpers.string(ctx, "blackOpName", _blackOpName);
|
||||
checkBladeburnerAccess(ctx);
|
||||
const action = getBladeburnerActionObject(ctx, "blackops", blackOpName);
|
||||
if (!(action instanceof BlackOperation)) throw new Error("action was not a black operation");
|
||||
return action.reqdRank;
|
||||
},
|
||||
getGeneralActionNames: (ctx: NetscriptContext) => (): string[] => {
|
||||
getGeneralActionNames: (ctx) => () => {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
return bladeburner.getGeneralActionNamesNetscriptFn();
|
||||
},
|
||||
getSkillNames: (ctx: NetscriptContext) => (): string[] => {
|
||||
getSkillNames: (ctx) => () => {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
return bladeburner.getSkillNamesNetscriptFn();
|
||||
},
|
||||
startAction:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_type: unknown, _name: unknown): boolean => {
|
||||
startAction: (ctx) => (_type, _name) => {
|
||||
const type = helpers.string(ctx, "type", _type);
|
||||
const name = helpers.string(ctx, "name", _name);
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
@ -88,17 +84,15 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, String(e));
|
||||
}
|
||||
},
|
||||
stopBladeburnerAction: (ctx: NetscriptContext) => (): void => {
|
||||
stopBladeburnerAction: (ctx) => () => {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
return bladeburner.resetAction();
|
||||
},
|
||||
getCurrentAction: (ctx: NetscriptContext) => (): BladeburnerCurAction => {
|
||||
getCurrentAction: (ctx) => () => {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
return bladeburner.getTypeAndNameFromActionId(bladeburner.action);
|
||||
},
|
||||
getActionTime:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_type: unknown, _name: unknown): number => {
|
||||
getActionTime: (ctx) => (_type, _name) => {
|
||||
const type = helpers.string(ctx, "type", _type);
|
||||
const name = helpers.string(ctx, "name", _name);
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
@ -115,7 +109,7 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, String(e));
|
||||
}
|
||||
},
|
||||
getActionCurrentTime: (ctx: NetscriptContext) => (): number => {
|
||||
getActionCurrentTime: (ctx) => () => {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
try {
|
||||
const timecomputed =
|
||||
@ -126,9 +120,7 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, String(e));
|
||||
}
|
||||
},
|
||||
getActionEstimatedSuccessChance:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_type: unknown, _name: unknown): [number, number] => {
|
||||
getActionEstimatedSuccessChance: (ctx) => (_type, _name) => {
|
||||
const type = helpers.string(ctx, "type", _type);
|
||||
const name = helpers.string(ctx, "name", _name);
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
@ -145,9 +137,7 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, String(e));
|
||||
}
|
||||
},
|
||||
getActionRepGain:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_type: unknown, _name: unknown, _level: unknown): number => {
|
||||
getActionRepGain: (ctx) => (_type, _name, _level) => {
|
||||
const type = helpers.string(ctx, "type", _type);
|
||||
const name = helpers.string(ctx, "name", _name);
|
||||
const level = helpers.number(ctx, "level", _level);
|
||||
@ -162,9 +152,7 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
|
||||
return action.rankGain * rewardMultiplier * BitNodeMultipliers.BladeburnerRank;
|
||||
},
|
||||
getActionCountRemaining:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_type: unknown, _name: unknown): number => {
|
||||
getActionCountRemaining: (ctx) => (_type, _name) => {
|
||||
const type = helpers.string(ctx, "type", _type);
|
||||
const name = helpers.string(ctx, "name", _name);
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
@ -174,27 +162,21 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, String(e));
|
||||
}
|
||||
},
|
||||
getActionMaxLevel:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_type: unknown, _name: unknown): number => {
|
||||
getActionMaxLevel: (ctx) => (_type, _name) => {
|
||||
const type = helpers.string(ctx, "type", _type);
|
||||
const name = helpers.string(ctx, "name", _name);
|
||||
checkBladeburnerAccess(ctx);
|
||||
const action = getBladeburnerActionObject(ctx, type, name);
|
||||
return action.maxLevel;
|
||||
},
|
||||
getActionCurrentLevel:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_type: unknown, _name: unknown): number => {
|
||||
getActionCurrentLevel: (ctx) => (_type, _name) => {
|
||||
const type = helpers.string(ctx, "type", _type);
|
||||
const name = helpers.string(ctx, "name", _name);
|
||||
checkBladeburnerAccess(ctx);
|
||||
const action = getBladeburnerActionObject(ctx, type, name);
|
||||
return action.level;
|
||||
},
|
||||
getActionAutolevel:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_type: unknown, _name: unknown): boolean => {
|
||||
getActionAutolevel: (ctx) => (_type, _name) => {
|
||||
const type = helpers.string(ctx, "type", _type);
|
||||
const name = helpers.string(ctx, "name", _name);
|
||||
checkBladeburnerAccess(ctx);
|
||||
@ -202,8 +184,8 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
return action.autoLevel;
|
||||
},
|
||||
setActionAutolevel:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_type: unknown, _name: unknown, _autoLevel: unknown = true): void => {
|
||||
(ctx) =>
|
||||
(_type, _name, _autoLevel = true) => {
|
||||
const type = helpers.string(ctx, "type", _type);
|
||||
const name = helpers.string(ctx, "name", _name);
|
||||
const autoLevel = !!_autoLevel;
|
||||
@ -212,8 +194,8 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
action.autoLevel = autoLevel;
|
||||
},
|
||||
setActionLevel:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_type: unknown, _name: unknown, _level: unknown = 1): void => {
|
||||
(ctx) =>
|
||||
(_type, _name, _level = 1) => {
|
||||
const type = helpers.string(ctx, "type", _type);
|
||||
const name = helpers.string(ctx, "name", _name);
|
||||
const level = helpers.number(ctx, "level", _level);
|
||||
@ -224,17 +206,15 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
}
|
||||
action.level = level;
|
||||
},
|
||||
getRank: (ctx: NetscriptContext) => (): number => {
|
||||
getRank: (ctx) => () => {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
return bladeburner.rank;
|
||||
},
|
||||
getSkillPoints: (ctx: NetscriptContext) => (): number => {
|
||||
getSkillPoints: (ctx) => () => {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
return bladeburner.skillPoints;
|
||||
},
|
||||
getSkillLevel:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_skillName: unknown): number => {
|
||||
getSkillLevel: (ctx) => (_skillName) => {
|
||||
const skillName = helpers.string(ctx, "skillName", _skillName);
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
try {
|
||||
@ -244,8 +224,8 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
}
|
||||
},
|
||||
getSkillUpgradeCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_skillName: unknown, _count: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_skillName, _count = 1) => {
|
||||
const skillName = helpers.string(ctx, "skillName", _skillName);
|
||||
const count = helpers.number(ctx, "count", _count);
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
@ -256,8 +236,8 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
}
|
||||
},
|
||||
upgradeSkill:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_skillName: unknown, _count: unknown = 1): boolean => {
|
||||
(ctx) =>
|
||||
(_skillName, _count = 1) => {
|
||||
const skillName = helpers.string(ctx, "skillName", _skillName);
|
||||
const count = helpers.number(ctx, "count", _count);
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
@ -267,9 +247,7 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, String(e));
|
||||
}
|
||||
},
|
||||
getTeamSize:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_type: unknown, _name: unknown): number => {
|
||||
getTeamSize: (ctx) => (_type, _name) => {
|
||||
const type = helpers.string(ctx, "type", _type);
|
||||
const name = helpers.string(ctx, "name", _name);
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
@ -279,9 +257,7 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, String(e));
|
||||
}
|
||||
},
|
||||
setTeamSize:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_type: unknown, _name: unknown, _size: unknown): number => {
|
||||
setTeamSize: (ctx) => (_type, _name, _size) => {
|
||||
const type = helpers.string(ctx, "type", _type);
|
||||
const name = helpers.string(ctx, "name", _name);
|
||||
const size = helpers.number(ctx, "size", _size);
|
||||
@ -292,9 +268,7 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, String(e));
|
||||
}
|
||||
},
|
||||
getCityEstimatedPopulation:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_cityName: unknown): number => {
|
||||
getCityEstimatedPopulation: (ctx) => (_cityName) => {
|
||||
const cityName = helpers.string(ctx, "cityName", _cityName);
|
||||
checkBladeburnerAccess(ctx);
|
||||
checkBladeburnerCity(ctx, cityName);
|
||||
@ -302,9 +276,7 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
return bladeburner.cities[cityName].popEst;
|
||||
},
|
||||
getCityCommunities:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_cityName: unknown): number => {
|
||||
getCityCommunities: (ctx) => (_cityName) => {
|
||||
const cityName = helpers.string(ctx, "cityName", _cityName);
|
||||
checkBladeburnerAccess(ctx);
|
||||
checkBladeburnerCity(ctx, cityName);
|
||||
@ -312,9 +284,7 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
return bladeburner.cities[cityName].comms;
|
||||
},
|
||||
getCityChaos:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_cityName: unknown): number => {
|
||||
getCityChaos: (ctx) => (_cityName) => {
|
||||
const cityName = helpers.string(ctx, "cityName", _cityName);
|
||||
checkBladeburnerAccess(ctx);
|
||||
checkBladeburnerCity(ctx, cityName);
|
||||
@ -322,13 +292,11 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
return bladeburner.cities[cityName].chaos;
|
||||
},
|
||||
getCity: (ctx: NetscriptContext) => (): string => {
|
||||
getCity: (ctx) => () => {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
return bladeburner.city;
|
||||
},
|
||||
switchCity:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_cityName: unknown): boolean => {
|
||||
switchCity: (ctx) => (_cityName) => {
|
||||
const cityName = helpers.string(ctx, "cityName", _cityName);
|
||||
checkBladeburnerAccess(ctx);
|
||||
checkBladeburnerCity(ctx, cityName);
|
||||
@ -337,15 +305,15 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
bladeburner.city = cityName;
|
||||
return true;
|
||||
},
|
||||
getStamina: (ctx: NetscriptContext) => (): [number, number] => {
|
||||
getStamina: (ctx) => () => {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
return [bladeburner.stamina, bladeburner.maxStamina];
|
||||
},
|
||||
joinBladeburnerFaction: (ctx: NetscriptContext) => (): boolean => {
|
||||
joinBladeburnerFaction: (ctx) => () => {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
return bladeburner.joinBladeburnerFactionNetscriptFn(ctx.workerScript);
|
||||
},
|
||||
joinBladeburnerDivision: (ctx: NetscriptContext) => (): boolean => {
|
||||
joinBladeburnerDivision: (ctx) => () => {
|
||||
if (Player.bitNodeN === 7 || Player.sourceFileLvl(7) > 0) {
|
||||
if (BitNodeMultipliers.BladeburnerRank === 0) {
|
||||
return false; // Disabled in this bitnode
|
||||
@ -369,7 +337,7 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
}
|
||||
return false;
|
||||
},
|
||||
getBonusTime: (ctx: NetscriptContext) => (): number => {
|
||||
getBonusTime: (ctx) => () => {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
return Math.round(bladeburner.storedCycles / 5) * 1000;
|
||||
},
|
||||
|
@ -2,17 +2,12 @@ import { Player as player } from "../Player";
|
||||
import { CodingContract } from "../CodingContracts";
|
||||
import { CodingAttemptOptions, CodingContract as ICodingContract } from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
import { helpers, assertObjectType } from "../Netscript/NetscriptHelpers";
|
||||
import { codingContractTypesMetadata } from "../data/codingcontracttypes";
|
||||
import { generateDummyContract } from "../CodingContractGenerator";
|
||||
|
||||
export function NetscriptCodingContract(): InternalAPI<ICodingContract> {
|
||||
const getCodingContract = function (
|
||||
ctx: NetscriptContext,
|
||||
func: string,
|
||||
hostname: string,
|
||||
filename: string,
|
||||
): CodingContract {
|
||||
const getCodingContract = function (ctx: NetscriptContext, hostname: string, filename: string): CodingContract {
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
const contract = server.getContract(filename);
|
||||
if (contract == null) {
|
||||
@ -23,18 +18,14 @@ export function NetscriptCodingContract(): InternalAPI<ICodingContract> {
|
||||
};
|
||||
|
||||
return {
|
||||
attempt:
|
||||
(ctx: NetscriptContext) =>
|
||||
(
|
||||
answer: unknown,
|
||||
_filename: unknown,
|
||||
_hostname: unknown = ctx.workerScript.hostname,
|
||||
{ returnReward }: CodingAttemptOptions = { returnReward: false },
|
||||
): boolean | string => {
|
||||
attempt: (ctx) => (answer, _filename, _hostname?, opts?) => {
|
||||
const filename = helpers.string(ctx, "filename", _filename);
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const contract = getCodingContract(ctx, "attempt", hostname, filename);
|
||||
const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname;
|
||||
const contract = getCodingContract(ctx, hostname, filename);
|
||||
|
||||
const optsValidator: CodingAttemptOptions = { returnReward: true };
|
||||
opts ??= optsValidator;
|
||||
assertObjectType(ctx, "opts", opts, optsValidator);
|
||||
if (typeof answer !== "number" && typeof answer !== "string" && !Array.isArray(answer))
|
||||
throw new Error("The answer provided was not a number, string, or array");
|
||||
|
||||
@ -47,7 +38,7 @@ export function NetscriptCodingContract(): InternalAPI<ICodingContract> {
|
||||
const reward = player.gainCodingContractReward(creward, contract.getDifficulty());
|
||||
helpers.log(ctx, () => `Successfully completed Coding Contract '${filename}'. Reward: ${reward}`);
|
||||
serv.removeContract(filename);
|
||||
return returnReward ? reward : true;
|
||||
return opts.returnReward ? reward : true;
|
||||
} else {
|
||||
++contract.tries;
|
||||
if (contract.tries >= contract.getMaxNumTries()) {
|
||||
@ -63,23 +54,19 @@ export function NetscriptCodingContract(): InternalAPI<ICodingContract> {
|
||||
);
|
||||
}
|
||||
|
||||
return returnReward ? "" : false;
|
||||
return opts.returnReward ? "" : false;
|
||||
}
|
||||
},
|
||||
getContractType:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_filename: unknown, _hostname: unknown = ctx.workerScript.hostname): string => {
|
||||
getContractType: (ctx) => (_filename, _hostname?) => {
|
||||
const filename = helpers.string(ctx, "filename", _filename);
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const contract = getCodingContract(ctx, "getContractType", hostname, filename);
|
||||
const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname;
|
||||
const contract = getCodingContract(ctx, hostname, filename);
|
||||
return contract.getType();
|
||||
},
|
||||
getData:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_filename: unknown, _hostname: unknown = ctx.workerScript.hostname): unknown => {
|
||||
getData: (ctx) => (_filename, _hostname?) => {
|
||||
const filename = helpers.string(ctx, "filename", _filename);
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const contract = getCodingContract(ctx, "getData", hostname, filename);
|
||||
const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname;
|
||||
const contract = getCodingContract(ctx, hostname, filename);
|
||||
const data = contract.getData();
|
||||
if (Array.isArray(data)) {
|
||||
// For two dimensional arrays, we have to copy the internal arrays using
|
||||
@ -93,32 +80,24 @@ export function NetscriptCodingContract(): InternalAPI<ICodingContract> {
|
||||
}
|
||||
|
||||
return copy;
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
} else return data;
|
||||
},
|
||||
getDescription:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_filename: unknown, _hostname: unknown = ctx.workerScript.hostname): string => {
|
||||
getDescription: (ctx) => (_filename, _hostname?) => {
|
||||
const filename = helpers.string(ctx, "filename", _filename);
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const contract = getCodingContract(ctx, "getDescription", hostname, filename);
|
||||
const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname;
|
||||
const contract = getCodingContract(ctx, hostname, filename);
|
||||
return contract.getDescription();
|
||||
},
|
||||
getNumTriesRemaining:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_filename: unknown, _hostname: unknown = ctx.workerScript.hostname): number => {
|
||||
getNumTriesRemaining: (ctx) => (_filename, _hostname?) => {
|
||||
const filename = helpers.string(ctx, "filename", _filename);
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const contract = getCodingContract(ctx, "getNumTriesRemaining", hostname, filename);
|
||||
const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname;
|
||||
const contract = getCodingContract(ctx, hostname, filename);
|
||||
return contract.getMaxNumTries() - contract.tries;
|
||||
},
|
||||
createDummyContract:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_type: unknown): void => {
|
||||
createDummyContract: (ctx) => (_type) => {
|
||||
const type = helpers.string(ctx, "type", _type);
|
||||
generateDummyContract(type);
|
||||
},
|
||||
getContractTypes: () => (): string[] => codingContractTypesMetadata.map((c) => c.name),
|
||||
getContractTypes: () => () => codingContractTypesMetadata.map((c) => c.name),
|
||||
};
|
||||
}
|
||||
|
@ -10,16 +10,10 @@ import { Corporation } from "../Corporation/Corporation";
|
||||
|
||||
import {
|
||||
Corporation as NSCorporation,
|
||||
CorporationInfo,
|
||||
Employee as NSEmployee,
|
||||
Product as NSProduct,
|
||||
Material as NSMaterial,
|
||||
Warehouse as NSWarehouse,
|
||||
Division as NSDivision,
|
||||
WarehouseAPI,
|
||||
OfficeAPI,
|
||||
InvestmentOffer,
|
||||
Office as NSOffice,
|
||||
} from "../ScriptEditor/NetscriptDefinitions";
|
||||
|
||||
import {
|
||||
@ -308,13 +302,13 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
}
|
||||
|
||||
const warehouseAPI: InternalAPI<WarehouseAPI> = {
|
||||
getPurchaseWarehouseCost: (ctx: NetscriptContext) => (): number => {
|
||||
getPurchaseWarehouseCost: (ctx) => () => {
|
||||
checkAccess(ctx, 7);
|
||||
return CorporationConstants.WarehouseInitialCost;
|
||||
},
|
||||
getUpgradeWarehouseCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown, _amt: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_divisionName, _cityName, _amt = 1) => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -325,9 +319,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
const warehouse = getWarehouse(divisionName, cityName);
|
||||
return UpgradeWarehouseCost(warehouse, amt);
|
||||
},
|
||||
hasWarehouse:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown): boolean => {
|
||||
hasWarehouse: (ctx) => (_divisionName, _cityName) => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -336,9 +328,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
const warehouse = division.warehouses[cityName];
|
||||
return warehouse !== 0;
|
||||
},
|
||||
getWarehouse:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown): NSWarehouse => {
|
||||
getWarehouse: (ctx) => (_divisionName, _cityName) => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -351,9 +341,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
smartSupplyEnabled: warehouse.smartSupplyEnabled,
|
||||
};
|
||||
},
|
||||
getMaterial:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown, _materialName: unknown): NSMaterial => {
|
||||
getMaterial: (ctx) => (_divisionName, _cityName, _materialName) => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -376,9 +364,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
exp: exports,
|
||||
};
|
||||
},
|
||||
getProduct:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _productName: unknown): NSProduct => {
|
||||
getProduct: (ctx) => (_divisionName, _productName) => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const productName = helpers.string(ctx, "productName", _productName);
|
||||
@ -403,9 +389,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
developmentProgress: product.prog,
|
||||
};
|
||||
},
|
||||
purchaseWarehouse:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown): void => {
|
||||
purchaseWarehouse: (ctx) => (_divisionName, _cityName) => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -413,8 +397,8 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
PurchaseWarehouse(corporation, getDivision(divisionName), cityName);
|
||||
},
|
||||
upgradeWarehouse:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown, _amt: unknown = 1): void => {
|
||||
(ctx) =>
|
||||
(_divisionName, _cityName, _amt = 1): void => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -425,9 +409,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
}
|
||||
UpgradeWarehouse(corporation, getDivision(divisionName), getWarehouse(divisionName, cityName), amt);
|
||||
},
|
||||
sellMaterial:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown, _materialName: unknown, _amt: unknown, _price: unknown): void => {
|
||||
sellMaterial: (ctx) => (_divisionName, _cityName, _materialName, _amt, _price) => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -438,15 +420,8 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
SellMaterial(material, amt, price);
|
||||
},
|
||||
sellProduct:
|
||||
(ctx: NetscriptContext) =>
|
||||
(
|
||||
_divisionName: unknown,
|
||||
_cityName: unknown,
|
||||
_productName: unknown,
|
||||
_amt: unknown,
|
||||
_price: unknown,
|
||||
_all: unknown,
|
||||
): void => {
|
||||
(ctx) =>
|
||||
(_divisionName, _cityName, _productName, _amt, _price, _all): void => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -457,17 +432,13 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
const product = getProduct(divisionName, productName);
|
||||
SellProduct(product, cityName, amt, price, all);
|
||||
},
|
||||
discontinueProduct:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _productName: unknown): void => {
|
||||
discontinueProduct: (ctx) => (_divisionName, _productName) => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const productName = helpers.string(ctx, "productName", _productName);
|
||||
getDivision(divisionName).discontinueProduct(getProduct(divisionName, productName));
|
||||
},
|
||||
setSmartSupply:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown, _enabled: unknown): void => {
|
||||
setSmartSupply: (ctx) => (_divisionName, _cityName, _enabled) => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -477,9 +448,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `You have not purchased the Smart Supply upgrade!`);
|
||||
SetSmartSupply(warehouse, enabled);
|
||||
},
|
||||
setSmartSupplyUseLeftovers:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown, _materialName: unknown, _enabled: unknown): void => {
|
||||
setSmartSupplyUseLeftovers: (ctx) => (_divisionName, _cityName, _materialName, _enabled) => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -491,9 +460,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `You have not purchased the Smart Supply upgrade!`);
|
||||
SetSmartSupplyUseLeftovers(warehouse, material, enabled);
|
||||
},
|
||||
buyMaterial:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown, _materialName: unknown, _amt: unknown): void => {
|
||||
buyMaterial: (ctx) => (_divisionName, _cityName, _materialName, _amt) => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -503,9 +470,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
const material = getMaterial(divisionName, cityName, materialName);
|
||||
BuyMaterial(material, amt);
|
||||
},
|
||||
bulkPurchase:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown, _materialName: unknown, _amt: unknown): void => {
|
||||
bulkPurchase: (ctx) => (_divisionName, _cityName, _materialName, _amt) => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
if (!hasResearched(getDivision(divisionName), "Bulk Purchasing"))
|
||||
@ -519,14 +484,8 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
BulkPurchase(corporation, warehouse, material, amt);
|
||||
},
|
||||
makeProduct:
|
||||
(ctx: NetscriptContext) =>
|
||||
(
|
||||
_divisionName: unknown,
|
||||
_cityName: unknown,
|
||||
_productName: unknown,
|
||||
_designInvest: unknown,
|
||||
_marketingInvest: unknown,
|
||||
): void => {
|
||||
(ctx) =>
|
||||
(_divisionName, _cityName, _productName, _designInvest, _marketingInvest): void => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -536,9 +495,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
const corporation = getCorporation();
|
||||
MakeProduct(corporation, getDivision(divisionName), cityName, productName, designInvest, marketingInvest);
|
||||
},
|
||||
limitProductProduction:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown, _productName: unknown, _qty: unknown): void => {
|
||||
limitProductProduction: (ctx) => (_divisionName, _cityName, _productName, _qty) => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -547,15 +504,8 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
LimitProductProduction(getProduct(divisionName, productName), cityName, qty);
|
||||
},
|
||||
exportMaterial:
|
||||
(ctx: NetscriptContext) =>
|
||||
(
|
||||
_sourceDivision: unknown,
|
||||
_sourceCity: unknown,
|
||||
_targetDivision: unknown,
|
||||
_targetCity: unknown,
|
||||
_materialName: unknown,
|
||||
_amt: unknown,
|
||||
): void => {
|
||||
(ctx) =>
|
||||
(_sourceDivision, _sourceCity, _targetDivision, _targetCity, _materialName, _amt): void => {
|
||||
checkAccess(ctx, 7);
|
||||
const sourceDivision = helpers.string(ctx, "sourceDivision", _sourceDivision);
|
||||
const sourceCity = helpers.string(ctx, "sourceCity", _sourceCity);
|
||||
@ -572,15 +522,8 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
);
|
||||
},
|
||||
cancelExportMaterial:
|
||||
(ctx: NetscriptContext) =>
|
||||
(
|
||||
_sourceDivision: unknown,
|
||||
_sourceCity: unknown,
|
||||
_targetDivision: unknown,
|
||||
_targetCity: unknown,
|
||||
_materialName: unknown,
|
||||
_amt: unknown,
|
||||
): void => {
|
||||
(ctx) =>
|
||||
(_sourceDivision, _sourceCity, _targetDivision, _targetCity, _materialName, _amt): void => {
|
||||
checkAccess(ctx, 7);
|
||||
const sourceDivision = helpers.string(ctx, "sourceDivision", _sourceDivision);
|
||||
const sourceCity = helpers.string(ctx, "sourceCity", _sourceCity);
|
||||
@ -595,9 +538,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
amt + "",
|
||||
);
|
||||
},
|
||||
limitMaterialProduction:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown, _materialName: unknown, _qty: unknown): void => {
|
||||
limitMaterialProduction: (ctx) => (_divisionName, _cityName, _materialName, _qty) => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -605,9 +546,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
const qty = helpers.number(ctx, "qty", _qty);
|
||||
LimitMaterialProduction(getMaterial(divisionName, cityName, materialName), qty);
|
||||
},
|
||||
setMaterialMarketTA1:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown, _materialName: unknown, _on: unknown): void => {
|
||||
setMaterialMarketTA1: (ctx) => (_divisionName, _cityName, _materialName, _on) => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -617,9 +556,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `You have not researched MarketTA.I for division: ${divisionName}`);
|
||||
SetMaterialMarketTA1(getMaterial(divisionName, cityName, materialName), on);
|
||||
},
|
||||
setMaterialMarketTA2:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown, _materialName: unknown, _on: unknown): void => {
|
||||
setMaterialMarketTA2: (ctx) => (_divisionName, _cityName, _materialName, _on) => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -629,9 +566,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `You have not researched MarketTA.II for division: ${divisionName}`);
|
||||
SetMaterialMarketTA2(getMaterial(divisionName, cityName, materialName), on);
|
||||
},
|
||||
setProductMarketTA1:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _productName: unknown, _on: unknown): void => {
|
||||
setProductMarketTA1: (ctx) => (_divisionName, _productName, _on) => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const productName = helpers.string(ctx, "productName", _productName);
|
||||
@ -640,9 +575,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `You have not researched MarketTA.I for division: ${divisionName}`);
|
||||
SetProductMarketTA1(getProduct(divisionName, productName), on);
|
||||
},
|
||||
setProductMarketTA2:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _productName: unknown, _on: unknown): void => {
|
||||
setProductMarketTA2: (ctx) => (_divisionName, _productName, _on) => {
|
||||
checkAccess(ctx, 7);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const productName = helpers.string(ctx, "productName", _productName);
|
||||
@ -654,41 +587,31 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
};
|
||||
|
||||
const officeAPI: InternalAPI<OfficeAPI> = {
|
||||
getHireAdVertCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown): number => {
|
||||
getHireAdVertCost: (ctx) => (_divisionName) => {
|
||||
checkAccess(ctx, 8);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const division = getDivision(divisionName);
|
||||
return division.getAdVertCost();
|
||||
},
|
||||
getHireAdVertCount:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown): number => {
|
||||
getHireAdVertCount: (ctx) => (_divisionName) => {
|
||||
checkAccess(ctx, 8);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const division = getDivision(divisionName);
|
||||
return division.numAdVerts;
|
||||
},
|
||||
getResearchCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _researchName: unknown): number => {
|
||||
getResearchCost: (ctx) => (_divisionName, _researchName) => {
|
||||
checkAccess(ctx, 8);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const researchName = helpers.string(ctx, "researchName", _researchName);
|
||||
return getResearchCost(getDivision(divisionName), researchName);
|
||||
},
|
||||
hasResearched:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _researchName: unknown): boolean => {
|
||||
hasResearched: (ctx) => (_divisionName, _researchName) => {
|
||||
checkAccess(ctx, 8);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const researchName = helpers.string(ctx, "researchName", _researchName);
|
||||
return hasResearched(getDivision(divisionName), researchName);
|
||||
},
|
||||
getOfficeSizeUpgradeCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown, _size: unknown): number => {
|
||||
getOfficeSizeUpgradeCost: (ctx) => (_divisionName, _cityName, _size) => {
|
||||
checkAccess(ctx, 8);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -703,9 +626,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
}
|
||||
return CorporationConstants.OfficeInitialCost * mult;
|
||||
},
|
||||
assignJob:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown, _employeeName: unknown, _job: unknown): void => {
|
||||
assignJob: (ctx) => (_divisionName, _cityName, _employeeName, _job) => {
|
||||
checkAccess(ctx, 8);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -717,9 +638,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
|
||||
AssignJob(office, employeeName, job);
|
||||
},
|
||||
setAutoJobAssignment:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown, _job: unknown, _amount: unknown): boolean => {
|
||||
setAutoJobAssignment: (ctx) => (_divisionName, _cityName, _job, _amount) => {
|
||||
checkAccess(ctx, 8);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -731,9 +650,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
|
||||
return AutoAssignJob(office, job, amount);
|
||||
},
|
||||
hireEmployee:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown): NSEmployee | undefined => {
|
||||
hireEmployee: (ctx) => (_divisionName, _cityName) => {
|
||||
checkAccess(ctx, 8);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -755,9 +672,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
pos: employee.pos,
|
||||
};
|
||||
},
|
||||
upgradeOfficeSize:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown, _size: unknown): void => {
|
||||
upgradeOfficeSize: (ctx) => (_divisionName, _cityName, _size) => {
|
||||
checkAccess(ctx, 8);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -767,9 +682,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
const corporation = getCorporation();
|
||||
UpgradeOfficeSize(corporation, office, size);
|
||||
},
|
||||
throwParty:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown, _costPerEmployee: unknown): number => {
|
||||
throwParty: (ctx) => (_divisionName, _cityName, _costPerEmployee) => {
|
||||
checkAccess(ctx, 8);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -784,9 +697,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
|
||||
return ThrowParty(corporation, office, costPerEmployee);
|
||||
},
|
||||
buyCoffee:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown): boolean => {
|
||||
buyCoffee: (ctx) => (_divisionName, _cityName) => {
|
||||
checkAccess(ctx, 8);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -796,25 +707,19 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
|
||||
return BuyCoffee(corporation, office);
|
||||
},
|
||||
hireAdVert:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown): void => {
|
||||
hireAdVert: (ctx) => (_divisionName) => {
|
||||
checkAccess(ctx, 8);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const corporation = getCorporation();
|
||||
HireAdVert(corporation, getDivision(divisionName));
|
||||
},
|
||||
research:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _researchName: unknown): void => {
|
||||
research: (ctx) => (_divisionName, _researchName) => {
|
||||
checkAccess(ctx, 8);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const researchName = helpers.string(ctx, "researchName", _researchName);
|
||||
Research(getDivision(divisionName), researchName);
|
||||
},
|
||||
getOffice:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown): NSOffice => {
|
||||
getOffice: (ctx) => (_divisionName, _cityName) => {
|
||||
checkAccess(ctx, 8);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -849,9 +754,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
},
|
||||
};
|
||||
},
|
||||
getEmployee:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown, _employeeName: unknown): NSEmployee => {
|
||||
getEmployee: (ctx) => (_divisionName, _cityName, _employeeName) => {
|
||||
checkAccess(ctx, 8);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -877,38 +780,34 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
return {
|
||||
...warehouseAPI,
|
||||
...officeAPI,
|
||||
getMaterialNames: (ctx: NetscriptContext) => (): string[] => {
|
||||
getMaterialNames: (ctx) => () => {
|
||||
checkAccess(ctx);
|
||||
return [...CorporationConstants.AllMaterials];
|
||||
},
|
||||
getIndustryTypes: (ctx: NetscriptContext) => (): string[] => {
|
||||
getIndustryTypes: (ctx) => () => {
|
||||
checkAccess(ctx);
|
||||
return [...CorporationConstants.AllIndustryTypes];
|
||||
},
|
||||
getUnlockables: (ctx: NetscriptContext) => (): string[] => {
|
||||
getUnlockables: (ctx) => () => {
|
||||
checkAccess(ctx);
|
||||
return [...CorporationConstants.AllUnlocks];
|
||||
},
|
||||
getUpgradeNames: (ctx: NetscriptContext) => (): string[] => {
|
||||
getUpgradeNames: (ctx) => () => {
|
||||
checkAccess(ctx);
|
||||
return [...CorporationConstants.AllUpgrades];
|
||||
},
|
||||
getResearchNames: (ctx: NetscriptContext) => (): string[] => {
|
||||
getResearchNames: (ctx) => () => {
|
||||
checkAccess(ctx);
|
||||
return [...CorporationConstants.AllResearch];
|
||||
},
|
||||
expandIndustry:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_industryName: unknown, _divisionName: unknown): void => {
|
||||
expandIndustry: (ctx) => (_industryName, _divisionName) => {
|
||||
checkAccess(ctx);
|
||||
const industryName = helpers.string(ctx, "industryName", _industryName);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const corporation = getCorporation();
|
||||
NewIndustry(corporation, industryName, divisionName);
|
||||
},
|
||||
expandCity:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown, _cityName: unknown): void => {
|
||||
expandCity: (ctx) => (_divisionName, _cityName) => {
|
||||
checkAccess(ctx);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
@ -917,9 +816,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
const division = getDivision(divisionName);
|
||||
NewCity(corporation, division, cityName);
|
||||
},
|
||||
unlockUpgrade:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_upgradeName: unknown): void => {
|
||||
unlockUpgrade: (ctx) => (_upgradeName) => {
|
||||
checkAccess(ctx);
|
||||
const upgradeName = helpers.string(ctx, "upgradeName", _upgradeName);
|
||||
const corporation = getCorporation();
|
||||
@ -927,9 +824,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
if (upgrade === undefined) throw new Error(`No upgrade named '${upgradeName}'`);
|
||||
UnlockUpgrade(corporation, upgrade);
|
||||
},
|
||||
levelUpgrade:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_upgradeName: unknown): void => {
|
||||
levelUpgrade: (ctx) => (_upgradeName) => {
|
||||
checkAccess(ctx);
|
||||
const upgradeName = helpers.string(ctx, "upgradeName", _upgradeName);
|
||||
const corporation = getCorporation();
|
||||
@ -937,9 +832,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
if (upgrade === undefined) throw new Error(`No upgrade named '${upgradeName}'`);
|
||||
LevelUpgrade(corporation, upgrade);
|
||||
},
|
||||
issueDividends:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_rate: unknown): void => {
|
||||
issueDividends: (ctx) => (_rate) => {
|
||||
checkAccess(ctx);
|
||||
const rate = helpers.number(ctx, "rate", _rate);
|
||||
const max = CorporationConstants.DividendMaxRate;
|
||||
@ -952,15 +845,13 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
|
||||
// If you modify these objects you will affect them for real, it's not
|
||||
// copies.
|
||||
getDivision:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_divisionName: unknown): NSDivision => {
|
||||
getDivision: (ctx) => (_divisionName) => {
|
||||
checkAccess(ctx);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const division = getDivision(divisionName);
|
||||
return getSafeDivision(division);
|
||||
},
|
||||
getCorporation: (ctx: NetscriptContext) => (): CorporationInfo => {
|
||||
getCorporation: (ctx) => () => {
|
||||
checkAccess(ctx);
|
||||
const corporation = getCorporation();
|
||||
return {
|
||||
@ -982,89 +873,71 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
};
|
||||
},
|
||||
createCorporation:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_corporationName: unknown, _selfFund: unknown = true): boolean => {
|
||||
(ctx) =>
|
||||
(_corporationName, _selfFund = true): boolean => {
|
||||
const corporationName = helpers.string(ctx, "corporationName", _corporationName);
|
||||
const selfFund = !!_selfFund;
|
||||
return createCorporation(corporationName, selfFund);
|
||||
},
|
||||
hasUnlockUpgrade:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_upgradeName: unknown): boolean => {
|
||||
hasUnlockUpgrade: (ctx) => (_upgradeName) => {
|
||||
checkAccess(ctx);
|
||||
const upgradeName = helpers.string(ctx, "upgradeName", _upgradeName);
|
||||
return hasUnlockUpgrade(upgradeName);
|
||||
},
|
||||
getUnlockUpgradeCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_upgradeName: unknown): number => {
|
||||
getUnlockUpgradeCost: (ctx) => (_upgradeName) => {
|
||||
checkAccess(ctx);
|
||||
const upgradeName = helpers.string(ctx, "upgradeName", _upgradeName);
|
||||
return getUnlockUpgradeCost(upgradeName);
|
||||
},
|
||||
getUpgradeLevel:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_upgradeName: unknown): number => {
|
||||
getUpgradeLevel: (ctx) => (_upgradeName) => {
|
||||
checkAccess(ctx);
|
||||
const upgradeName = helpers.string(ctx, "upgradeName", _upgradeName);
|
||||
return getUpgradeLevel(ctx, upgradeName);
|
||||
},
|
||||
getUpgradeLevelCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_upgradeName: unknown): number => {
|
||||
getUpgradeLevelCost: (ctx) => (_upgradeName) => {
|
||||
checkAccess(ctx);
|
||||
const upgradeName = helpers.string(ctx, "upgradeName", _upgradeName);
|
||||
return getUpgradeLevelCost(ctx, upgradeName);
|
||||
},
|
||||
getExpandIndustryCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_industryName: unknown): number => {
|
||||
getExpandIndustryCost: (ctx) => (_industryName) => {
|
||||
checkAccess(ctx);
|
||||
const industryName = helpers.string(ctx, "industryName", _industryName);
|
||||
return getExpandIndustryCost(industryName);
|
||||
},
|
||||
getExpandCityCost: (ctx: NetscriptContext) => (): number => {
|
||||
getExpandCityCost: (ctx) => () => {
|
||||
checkAccess(ctx);
|
||||
return getExpandCityCost();
|
||||
},
|
||||
getInvestmentOffer: (ctx: NetscriptContext) => (): InvestmentOffer => {
|
||||
getInvestmentOffer: (ctx) => () => {
|
||||
checkAccess(ctx);
|
||||
return getInvestmentOffer();
|
||||
},
|
||||
acceptInvestmentOffer: (ctx: NetscriptContext) => (): boolean => {
|
||||
acceptInvestmentOffer: (ctx) => () => {
|
||||
checkAccess(ctx);
|
||||
return acceptInvestmentOffer();
|
||||
},
|
||||
goPublic:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_numShares: unknown): boolean => {
|
||||
goPublic: (ctx) => (_numShares) => {
|
||||
checkAccess(ctx);
|
||||
const numShares = helpers.number(ctx, "numShares", _numShares);
|
||||
return goPublic(numShares);
|
||||
},
|
||||
sellShares:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_numShares: unknown): number => {
|
||||
sellShares: (ctx) => (_numShares) => {
|
||||
checkAccess(ctx);
|
||||
const numShares = helpers.number(ctx, "numShares", _numShares);
|
||||
return SellShares(getCorporation(), numShares);
|
||||
},
|
||||
buyBackShares:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_numShares: unknown): boolean => {
|
||||
buyBackShares: (ctx) => (_numShares) => {
|
||||
checkAccess(ctx);
|
||||
const numShares = helpers.number(ctx, "numShares", _numShares);
|
||||
return BuyBackShares(getCorporation(), numShares);
|
||||
},
|
||||
bribe:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_factionName: unknown, _amountCash: unknown): boolean => {
|
||||
bribe: (ctx) => (_factionName, _amountCash) => {
|
||||
checkAccess(ctx);
|
||||
const factionName = helpers.string(ctx, "factionName", _factionName);
|
||||
const amountCash = helpers.number(ctx, "amountCash", _amountCash);
|
||||
return bribe(factionName, amountCash);
|
||||
},
|
||||
getBonusTime: (ctx: NetscriptContext) => (): number => {
|
||||
getBonusTime: (ctx) => () => {
|
||||
checkAccess(ctx);
|
||||
return Math.round(getCorporation().storedCycles / 5) * 1000;
|
||||
},
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { Player as player } from "../Player";
|
||||
import { Player } from "../Player";
|
||||
import { Exploit } from "../Exploits/Exploit";
|
||||
import * as bcrypt from "bcryptjs";
|
||||
import { Apr1Events as devMenu } from "../ui/Apr1";
|
||||
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
||||
import { InternalAPI } from "../Netscript/APIWrapper";
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
import { Terminal } from "../Terminal";
|
||||
|
||||
export interface INetscriptExtra {
|
||||
heart: {
|
||||
@ -14,25 +15,24 @@ export interface INetscriptExtra {
|
||||
bypass(doc: Document): void;
|
||||
alterReality(): void;
|
||||
rainbow(guess: string): void;
|
||||
iKnowWhatImDoing(): void;
|
||||
}
|
||||
|
||||
export function NetscriptExtra(): InternalAPI<INetscriptExtra> {
|
||||
return {
|
||||
heart: {
|
||||
// Easter egg function
|
||||
break: () => (): number => {
|
||||
return player.karma;
|
||||
break: () => () => {
|
||||
return Player.karma;
|
||||
},
|
||||
},
|
||||
openDevMenu: () => (): void => {
|
||||
openDevMenu: () => () => {
|
||||
devMenu.emit();
|
||||
},
|
||||
exploit: () => (): void => {
|
||||
player.giveExploit(Exploit.UndocumentedFunctionCall);
|
||||
exploit: () => () => {
|
||||
Player.giveExploit(Exploit.UndocumentedFunctionCall);
|
||||
},
|
||||
bypass:
|
||||
(ctx: NetscriptContext) =>
|
||||
(doc: unknown): void => {
|
||||
bypass: (ctx) => (doc) => {
|
||||
// reset both fields first
|
||||
type temporary = { completely_unused_field: unknown };
|
||||
const d = doc as temporary;
|
||||
@ -42,12 +42,12 @@ export function NetscriptExtra(): InternalAPI<INetscriptExtra> {
|
||||
// set one to true and check that it affected the other.
|
||||
real_document.completely_unused_field = true;
|
||||
if (d.completely_unused_field && ctx.workerScript.ramUsage === 1.6) {
|
||||
player.giveExploit(Exploit.Bypass);
|
||||
Player.giveExploit(Exploit.Bypass);
|
||||
}
|
||||
d.completely_unused_field = undefined;
|
||||
real_document.completely_unused_field = undefined;
|
||||
},
|
||||
alterReality: () => (): void => {
|
||||
alterReality: () => () => {
|
||||
// We need to trick webpack into not optimizing a variable that is guaranteed to be false (and doesn't use prototypes)
|
||||
let x = false;
|
||||
const recur = function (depth: number): void {
|
||||
@ -59,12 +59,10 @@ export function NetscriptExtra(): InternalAPI<INetscriptExtra> {
|
||||
console.warn("I am sure that this variable is false.");
|
||||
if (x !== false) {
|
||||
console.warn("Reality has been altered!");
|
||||
player.giveExploit(Exploit.RealityAlteration);
|
||||
Player.giveExploit(Exploit.RealityAlteration);
|
||||
}
|
||||
},
|
||||
rainbow:
|
||||
(ctx: NetscriptContext) =>
|
||||
(guess: unknown): boolean => {
|
||||
rainbow: (ctx) => (guess) => {
|
||||
function tryGuess(): boolean {
|
||||
// eslint-disable-next-line no-sync
|
||||
const verified = bcrypt.compareSync(
|
||||
@ -72,12 +70,17 @@ export function NetscriptExtra(): InternalAPI<INetscriptExtra> {
|
||||
"$2a$10$aertxDEkgor8baVtQDZsLuMwwGYmkRM/ohcA6FjmmzIHQeTCsrCcO",
|
||||
);
|
||||
if (verified) {
|
||||
player.giveExploit(Exploit.INeedARainbow);
|
||||
Player.giveExploit(Exploit.INeedARainbow);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return tryGuess();
|
||||
},
|
||||
iKnowWhatImDoing: (ctx) => () => {
|
||||
helpers.log(ctx, () => "Unlocking unsupported feature: window.tprintRaw");
|
||||
// @ts-ignore window has no tprintRaw property defined
|
||||
window.tprintRaw = Terminal.printRaw.bind(Terminal);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -26,11 +26,7 @@ import {
|
||||
calculateWeakenTime,
|
||||
} from "../Hacking";
|
||||
import { Programs } from "../Programs/Programs";
|
||||
import {
|
||||
Formulas as IFormulas,
|
||||
HacknetNodeConstants as DefHacknetNodeConstants,
|
||||
HacknetServerConstants as DefHacknetServerConstants,
|
||||
} from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { Formulas as IFormulas } from "../ScriptEditor/NetscriptDefinitions";
|
||||
import {
|
||||
calculateRespectGain,
|
||||
calculateWantedLevelGain,
|
||||
@ -43,7 +39,6 @@ import { favorToRep as calculateFavorToRep, repToFavor as calculateRepToFavor }
|
||||
import { repFromDonation } from "../Faction/formulas/donation";
|
||||
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
import { WorkStats } from "../Work/WorkStats";
|
||||
import { calculateCrimeWorkStats } from "../Work/formulas/Crime";
|
||||
import { Crimes } from "../Crime/Crimes";
|
||||
import { calculateClassEarnings } from "../Work/formulas/Class";
|
||||
@ -52,7 +47,6 @@ import { LocationName } from "../Locations/data/LocationNames";
|
||||
import { calculateFactionExp, calculateFactionRep } from "../Work/formulas/Faction";
|
||||
import { FactionWorkType } from "../Work/data/FactionWorkType";
|
||||
|
||||
import { Player as INetscriptPlayer, Server as IServerDef } from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { defaultMultipliers } from "../PersonObjects/Multipliers";
|
||||
|
||||
export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
@ -62,7 +56,7 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
}
|
||||
};
|
||||
return {
|
||||
mockServer: () => (): IServerDef => ({
|
||||
mockServer: () => () => ({
|
||||
cpuCores: 0,
|
||||
ftpPortOpen: false,
|
||||
hasAdminRights: false,
|
||||
@ -88,7 +82,7 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
requiredHackingSkill: 0,
|
||||
serverGrowth: 0,
|
||||
}),
|
||||
mockPlayer: () => (): INetscriptPlayer => ({
|
||||
mockPlayer: () => () => ({
|
||||
hp: { current: 0, max: 0 },
|
||||
skills: {
|
||||
hacking: 0,
|
||||
@ -125,23 +119,17 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
entropy: 0,
|
||||
}),
|
||||
reputation: {
|
||||
calculateFavorToRep:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_favor: unknown): number => {
|
||||
calculateFavorToRep: (ctx) => (_favor) => {
|
||||
const favor = helpers.number(ctx, "favor", _favor);
|
||||
checkFormulasAccess(ctx);
|
||||
return calculateFavorToRep(favor);
|
||||
},
|
||||
calculateRepToFavor:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_rep: unknown): number => {
|
||||
calculateRepToFavor: (ctx) => (_rep) => {
|
||||
const rep = helpers.number(ctx, "rep", _rep);
|
||||
checkFormulasAccess(ctx);
|
||||
return calculateRepToFavor(rep);
|
||||
},
|
||||
repFromDonation:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_amount: unknown, _player: unknown): number => {
|
||||
repFromDonation: (ctx) => (_amount, _player) => {
|
||||
const amount = helpers.number(ctx, "amount", _amount);
|
||||
const player = helpers.player(ctx, _player);
|
||||
checkFormulasAccess(ctx);
|
||||
@ -150,16 +138,16 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
},
|
||||
skills: {
|
||||
calculateSkill:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_exp: unknown, _mult: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_exp, _mult = 1) => {
|
||||
const exp = helpers.number(ctx, "exp", _exp);
|
||||
const mult = helpers.number(ctx, "mult", _mult);
|
||||
checkFormulasAccess(ctx);
|
||||
return calculateSkill(exp, mult);
|
||||
},
|
||||
calculateExp:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_skill: unknown, _mult: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_skill, _mult = 1) => {
|
||||
const skill = helpers.number(ctx, "skill", _skill);
|
||||
const mult = helpers.number(ctx, "mult", _mult);
|
||||
checkFormulasAccess(ctx);
|
||||
@ -167,33 +155,27 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
},
|
||||
},
|
||||
hacking: {
|
||||
hackChance:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_server: unknown, _player: unknown): number => {
|
||||
hackChance: (ctx) => (_server, _player) => {
|
||||
const server = helpers.server(ctx, _server);
|
||||
const player = helpers.player(ctx, _player);
|
||||
checkFormulasAccess(ctx);
|
||||
return calculateHackingChance(server, player);
|
||||
},
|
||||
hackExp:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_server: unknown, _player: unknown): number => {
|
||||
hackExp: (ctx) => (_server, _player) => {
|
||||
const server = helpers.server(ctx, _server);
|
||||
const player = helpers.player(ctx, _player);
|
||||
checkFormulasAccess(ctx);
|
||||
return calculateHackingExpGain(server, player);
|
||||
},
|
||||
hackPercent:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_server: unknown, _player: unknown): number => {
|
||||
hackPercent: (ctx) => (_server, _player) => {
|
||||
const server = helpers.server(ctx, _server);
|
||||
const player = helpers.player(ctx, _player);
|
||||
checkFormulasAccess(ctx);
|
||||
return calculatePercentMoneyHacked(server, player);
|
||||
},
|
||||
growPercent:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_server: unknown, _threads: unknown, _player: unknown, _cores: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_server, _threads, _player, _cores = 1) => {
|
||||
const server = helpers.server(ctx, _server);
|
||||
const player = helpers.player(ctx, _player);
|
||||
const threads = helpers.number(ctx, "threads", _threads);
|
||||
@ -201,25 +183,19 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
checkFormulasAccess(ctx);
|
||||
return calculateServerGrowth(server, threads, player, cores);
|
||||
},
|
||||
hackTime:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_server: unknown, _player: unknown): number => {
|
||||
hackTime: (ctx) => (_server, _player) => {
|
||||
const server = helpers.server(ctx, _server);
|
||||
const player = helpers.player(ctx, _player);
|
||||
checkFormulasAccess(ctx);
|
||||
return calculateHackingTime(server, player) * 1000;
|
||||
},
|
||||
growTime:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_server: unknown, _player: unknown): number => {
|
||||
growTime: (ctx) => (_server, _player) => {
|
||||
const server = helpers.server(ctx, _server);
|
||||
const player = helpers.player(ctx, _player);
|
||||
checkFormulasAccess(ctx);
|
||||
return calculateGrowTime(server, player) * 1000;
|
||||
},
|
||||
weakenTime:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_server: unknown, _player: unknown): number => {
|
||||
weakenTime: (ctx) => (_server, _player) => {
|
||||
const server = helpers.server(ctx, _server);
|
||||
const player = helpers.player(ctx, _player);
|
||||
checkFormulasAccess(ctx);
|
||||
@ -228,8 +204,8 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
},
|
||||
hacknetNodes: {
|
||||
moneyGainRate:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_level: unknown, _ram: unknown, _cores: unknown, _mult: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_level, _ram, _cores, _mult = 1) => {
|
||||
const level = helpers.number(ctx, "level", _level);
|
||||
const ram = helpers.number(ctx, "ram", _ram);
|
||||
const cores = helpers.number(ctx, "cores", _cores);
|
||||
@ -238,8 +214,8 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
return calculateMoneyGainRate(level, ram, cores, mult);
|
||||
},
|
||||
levelUpgradeCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_startingLevel: unknown, _extraLevels: unknown = 1, _costMult: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_startingLevel, _extraLevels = 1, _costMult = 1) => {
|
||||
const startingLevel = helpers.number(ctx, "startingLevel", _startingLevel);
|
||||
const extraLevels = helpers.number(ctx, "extraLevels", _extraLevels);
|
||||
const costMult = helpers.number(ctx, "costMult", _costMult);
|
||||
@ -247,8 +223,8 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
return calculateLevelUpgradeCost(startingLevel, extraLevels, costMult);
|
||||
},
|
||||
ramUpgradeCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_startingRam: unknown, _extraLevels: unknown = 1, _costMult: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_startingRam, _extraLevels = 1, _costMult = 1) => {
|
||||
const startingRam = helpers.number(ctx, "startingRam", _startingRam);
|
||||
const extraLevels = helpers.number(ctx, "extraLevels", _extraLevels);
|
||||
const costMult = helpers.number(ctx, "costMult", _costMult);
|
||||
@ -256,31 +232,29 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
return calculateRamUpgradeCost(startingRam, extraLevels, costMult);
|
||||
},
|
||||
coreUpgradeCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_startingCore: unknown, _extraCores: unknown = 1, _costMult: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_startingCore, _extraCores = 1, _costMult = 1) => {
|
||||
const startingCore = helpers.number(ctx, "startingCore", _startingCore);
|
||||
const extraCores = helpers.number(ctx, "extraCores", _extraCores);
|
||||
const costMult = helpers.number(ctx, "costMult", _costMult);
|
||||
checkFormulasAccess(ctx);
|
||||
return calculateCoreUpgradeCost(startingCore, extraCores, costMult);
|
||||
},
|
||||
hacknetNodeCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_n: unknown, _mult: unknown): number => {
|
||||
hacknetNodeCost: (ctx) => (_n, _mult) => {
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
const mult = helpers.number(ctx, "mult", _mult);
|
||||
checkFormulasAccess(ctx);
|
||||
return calculateNodeCost(n, mult);
|
||||
},
|
||||
constants: (ctx: NetscriptContext) => (): DefHacknetNodeConstants => {
|
||||
constants: (ctx) => () => {
|
||||
checkFormulasAccess(ctx);
|
||||
return Object.assign({}, HacknetNodeConstants);
|
||||
},
|
||||
},
|
||||
hacknetServers: {
|
||||
hashGainRate:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_level: unknown, _ramUsed: unknown, _maxRam: unknown, _cores: unknown, _mult: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_level, _ramUsed, _maxRam, _cores, _mult = 1) => {
|
||||
const level = helpers.number(ctx, "level", _level);
|
||||
const ramUsed = helpers.number(ctx, "ramUsed", _ramUsed);
|
||||
const maxRam = helpers.number(ctx, "maxRam", _maxRam);
|
||||
@ -290,8 +264,8 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
return HScalculateHashGainRate(level, ramUsed, maxRam, cores, mult);
|
||||
},
|
||||
levelUpgradeCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_startingLevel: unknown, _extraLevels: unknown = 1, _costMult: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_startingLevel, _extraLevels = 1, _costMult = 1) => {
|
||||
const startingLevel = helpers.number(ctx, "startingLevel", _startingLevel);
|
||||
const extraLevels = helpers.number(ctx, "extraLevels", _extraLevels);
|
||||
const costMult = helpers.number(ctx, "costMult", _costMult);
|
||||
@ -299,8 +273,8 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
return HScalculateLevelUpgradeCost(startingLevel, extraLevels, costMult);
|
||||
},
|
||||
ramUpgradeCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_startingRam: unknown, _extraLevels: unknown = 1, _costMult: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_startingRam, _extraLevels = 1, _costMult = 1) => {
|
||||
const startingRam = helpers.number(ctx, "startingRam", _startingRam);
|
||||
const extraLevels = helpers.number(ctx, "extraLevels", _extraLevels);
|
||||
const costMult = helpers.number(ctx, "costMult", _costMult);
|
||||
@ -308,8 +282,8 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
return HScalculateRamUpgradeCost(startingRam, extraLevels, costMult);
|
||||
},
|
||||
coreUpgradeCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_startingCore: unknown, _extraCores: unknown = 1, _costMult: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_startingCore, _extraCores = 1, _costMult = 1) => {
|
||||
const startingCore = helpers.number(ctx, "startingCore", _startingCore);
|
||||
const extraCores = helpers.number(ctx, "extraCores", _extraCores);
|
||||
const costMult = helpers.number(ctx, "costMult", _costMult);
|
||||
@ -317,16 +291,14 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
return HScalculateCoreUpgradeCost(startingCore, extraCores, costMult);
|
||||
},
|
||||
cacheUpgradeCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_startingCache: unknown, _extraCache: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_startingCache, _extraCache = 1) => {
|
||||
const startingCache = helpers.number(ctx, "startingCache", _startingCache);
|
||||
const extraCache = helpers.number(ctx, "extraCache", _extraCache);
|
||||
checkFormulasAccess(ctx);
|
||||
return HScalculateCacheUpgradeCost(startingCache, extraCache);
|
||||
},
|
||||
hashUpgradeCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_upgName: unknown, _level: unknown): number => {
|
||||
hashUpgradeCost: (ctx) => (_upgName, _level) => {
|
||||
const upgName = helpers.string(ctx, "upgName", _upgName);
|
||||
const level = helpers.number(ctx, "level", _level);
|
||||
checkFormulasAccess(ctx);
|
||||
@ -337,88 +309,70 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
return upg.getCost(level);
|
||||
},
|
||||
hacknetServerCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_n: unknown, _mult: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_n, _mult = 1) => {
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
const mult = helpers.number(ctx, "mult", _mult);
|
||||
checkFormulasAccess(ctx);
|
||||
return HScalculateServerCost(n, mult);
|
||||
},
|
||||
constants: (ctx: NetscriptContext) => (): DefHacknetServerConstants => {
|
||||
constants: (ctx) => () => {
|
||||
checkFormulasAccess(ctx);
|
||||
return Object.assign({}, HacknetServerConstants);
|
||||
},
|
||||
},
|
||||
gang: {
|
||||
wantedPenalty:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_gang: unknown): number => {
|
||||
wantedPenalty: (ctx) => (_gang) => {
|
||||
const gang = helpers.gang(ctx, _gang);
|
||||
checkFormulasAccess(ctx);
|
||||
return calculateWantedPenalty(gang);
|
||||
},
|
||||
respectGain:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_gang: unknown, _member: unknown, _task: unknown): number => {
|
||||
respectGain: (ctx) => (_gang, _member, _task) => {
|
||||
const gang = helpers.gang(ctx, _gang);
|
||||
const member = helpers.gangMember(ctx, _member);
|
||||
const task = helpers.gangTask(ctx, _task);
|
||||
checkFormulasAccess(ctx);
|
||||
return calculateRespectGain(gang, member, task);
|
||||
},
|
||||
wantedLevelGain:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_gang: unknown, _member: unknown, _task: unknown): number => {
|
||||
wantedLevelGain: (ctx) => (_gang, _member, _task) => {
|
||||
const gang = helpers.gang(ctx, _gang);
|
||||
const member = helpers.gangMember(ctx, _member);
|
||||
const task = helpers.gangTask(ctx, _task);
|
||||
checkFormulasAccess(ctx);
|
||||
return calculateWantedLevelGain(gang, member, task);
|
||||
},
|
||||
moneyGain:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_gang: unknown, _member: unknown, _task: unknown): number => {
|
||||
moneyGain: (ctx) => (_gang, _member, _task) => {
|
||||
const gang = helpers.gang(ctx, _gang);
|
||||
const member = helpers.gangMember(ctx, _member);
|
||||
const task = helpers.gangTask(ctx, _task);
|
||||
checkFormulasAccess(ctx);
|
||||
return calculateMoneyGain(gang, member, task);
|
||||
},
|
||||
ascensionPointsGain:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_exp: unknown): number => {
|
||||
ascensionPointsGain: (ctx) => (_exp) => {
|
||||
const exp = helpers.number(ctx, "exp", _exp);
|
||||
checkFormulasAccess(ctx);
|
||||
return calculateAscensionPointsGain(exp);
|
||||
},
|
||||
ascensionMultiplier:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_points: unknown): number => {
|
||||
ascensionMultiplier: (ctx) => (_points) => {
|
||||
const points = helpers.number(ctx, "points", _points);
|
||||
checkFormulasAccess(ctx);
|
||||
return calculateAscensionMult(points);
|
||||
},
|
||||
},
|
||||
work: {
|
||||
crimeGains:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_crimeType: unknown): WorkStats => {
|
||||
crimeGains: (ctx) => (_crimeType) => {
|
||||
const crimeType = helpers.string(ctx, "crimeType", _crimeType);
|
||||
const crime = Object.values(Crimes).find((c) => String(c.type) === crimeType);
|
||||
if (!crime) throw new Error(`Invalid crime type: ${crimeType}`);
|
||||
return calculateCrimeWorkStats(crime);
|
||||
},
|
||||
classGains:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_person: unknown, _classType: unknown, _locationName: unknown): WorkStats => {
|
||||
classGains: (ctx) => (_person, _classType, _locationName) => {
|
||||
const person = helpers.player(ctx, _person);
|
||||
const classType = helpers.string(ctx, "classType", _classType);
|
||||
const locationName = helpers.string(ctx, "locationName", _locationName);
|
||||
return calculateClassEarnings(person, classType as ClassType, locationName as LocationName);
|
||||
},
|
||||
factionGains:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_player: unknown, _workType: unknown, _favor: unknown): WorkStats => {
|
||||
factionGains: (ctx) => (_player, _workType, _favor) => {
|
||||
const player = helpers.player(ctx, _player);
|
||||
const workType = helpers.string(ctx, "_workType", _workType) as FactionWorkType;
|
||||
const favor = helpers.number(ctx, "favor", _favor);
|
||||
@ -427,7 +381,7 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
exp.reputation = rep;
|
||||
return exp;
|
||||
},
|
||||
// companyGains: (ctx: NetscriptContext) =>_player: unknown (): WorkStats {
|
||||
// companyGains: (ctx) => (_player) {
|
||||
// const player = helpers.player(ctx, _player);
|
||||
|
||||
// },
|
||||
|
@ -9,16 +9,7 @@ import { GangMember } from "../Gang/GangMember";
|
||||
import { GangMemberTask } from "../Gang/GangMemberTask";
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
|
||||
import {
|
||||
Gang as IGang,
|
||||
GangGenInfo,
|
||||
GangOtherInfo,
|
||||
GangMemberInfo,
|
||||
GangMemberAscension,
|
||||
EquipmentStats,
|
||||
GangTaskStats,
|
||||
GangOtherInfoObject,
|
||||
} from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { Gang as IGang, EquipmentStats, GangOtherInfoObject } from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
||||
|
||||
export function NetscriptGang(): InternalAPI<IGang> {
|
||||
@ -44,9 +35,7 @@ export function NetscriptGang(): InternalAPI<IGang> {
|
||||
};
|
||||
|
||||
return {
|
||||
createGang:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_faction: unknown): boolean => {
|
||||
createGang: (ctx) => (_faction) => {
|
||||
const faction = helpers.string(ctx, "faction", _faction);
|
||||
// this list is copied from Faction/ui/Root.tsx
|
||||
|
||||
@ -58,14 +47,14 @@ export function NetscriptGang(): InternalAPI<IGang> {
|
||||
Player.startGang(faction, isHacking);
|
||||
return true;
|
||||
},
|
||||
inGang: () => (): boolean => {
|
||||
inGang: () => () => {
|
||||
return Player.gang ? true : false;
|
||||
},
|
||||
getMemberNames: (ctx: NetscriptContext) => (): string[] => {
|
||||
getMemberNames: (ctx) => () => {
|
||||
const gang = getGang(ctx);
|
||||
return gang.members.map((member) => member.name);
|
||||
},
|
||||
getGangInformation: (ctx: NetscriptContext) => (): GangGenInfo => {
|
||||
getGangInformation: (ctx) => () => {
|
||||
const gang = getGang(ctx);
|
||||
return {
|
||||
faction: gang.facName,
|
||||
@ -82,7 +71,7 @@ export function NetscriptGang(): InternalAPI<IGang> {
|
||||
wantedPenalty: gang.getWantedPenalty(),
|
||||
};
|
||||
},
|
||||
getOtherGangInformation: (ctx: NetscriptContext) => (): GangOtherInfo => {
|
||||
getOtherGangInformation: (ctx) => () => {
|
||||
getGang(ctx);
|
||||
const cpy: Record<string, GangOtherInfoObject> = {};
|
||||
for (const gang of Object.keys(AllGangs)) {
|
||||
@ -91,9 +80,7 @@ export function NetscriptGang(): InternalAPI<IGang> {
|
||||
|
||||
return cpy;
|
||||
},
|
||||
getMemberInformation:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_memberName: unknown): GangMemberInfo => {
|
||||
getMemberInformation: (ctx) => (_memberName) => {
|
||||
const memberName = helpers.string(ctx, "memberName", _memberName);
|
||||
const gang = getGang(ctx);
|
||||
const member = getGangMember(ctx, memberName);
|
||||
@ -144,13 +131,11 @@ export function NetscriptGang(): InternalAPI<IGang> {
|
||||
moneyGain: member.calculateMoneyGain(gang),
|
||||
};
|
||||
},
|
||||
canRecruitMember: (ctx: NetscriptContext) => (): boolean => {
|
||||
canRecruitMember: (ctx) => () => {
|
||||
const gang = getGang(ctx);
|
||||
return gang.canRecruitMember();
|
||||
},
|
||||
recruitMember:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_memberName: unknown): boolean => {
|
||||
recruitMember: (ctx) => (_memberName) => {
|
||||
const memberName = helpers.string(ctx, "memberName", _memberName);
|
||||
const gang = getGang(ctx);
|
||||
const recruited = gang.recruitMember(memberName);
|
||||
@ -162,15 +147,13 @@ export function NetscriptGang(): InternalAPI<IGang> {
|
||||
|
||||
return recruited;
|
||||
},
|
||||
getTaskNames: (ctx: NetscriptContext) => (): string[] => {
|
||||
getTaskNames: (ctx) => () => {
|
||||
const gang = getGang(ctx);
|
||||
const tasks = gang.getAllTaskNames();
|
||||
tasks.unshift("Unassigned");
|
||||
return tasks;
|
||||
},
|
||||
setMemberTask:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_memberName: unknown, _taskName: unknown): boolean => {
|
||||
setMemberTask: (ctx) => (_memberName, _taskName) => {
|
||||
const memberName = helpers.string(ctx, "memberName", _memberName);
|
||||
const taskName = helpers.string(ctx, "taskName", _taskName);
|
||||
const gang = getGang(ctx);
|
||||
@ -192,16 +175,13 @@ export function NetscriptGang(): InternalAPI<IGang> {
|
||||
} else {
|
||||
ctx.workerScript.log(
|
||||
"gang.setMemberTask",
|
||||
() =>
|
||||
`Failed to assign Gang Member '${memberName}' to '${taskName}' task. '${memberName}' is now Unassigned`,
|
||||
() => `Failed to assign Gang Member '${memberName}' to '${taskName}' task. '${memberName}' is now Unassigned`,
|
||||
);
|
||||
}
|
||||
|
||||
return success;
|
||||
},
|
||||
getTaskStats:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_taskName: unknown): GangTaskStats => {
|
||||
getTaskStats: (ctx) => (_taskName) => {
|
||||
const taskName = helpers.string(ctx, "taskName", _taskName);
|
||||
getGang(ctx);
|
||||
const task = getGangTask(ctx, taskName);
|
||||
@ -209,31 +189,25 @@ export function NetscriptGang(): InternalAPI<IGang> {
|
||||
copy.territory = Object.assign({}, task.territory);
|
||||
return copy;
|
||||
},
|
||||
getEquipmentNames: (ctx: NetscriptContext) => (): string[] => {
|
||||
getEquipmentNames: (ctx) => () => {
|
||||
getGang(ctx);
|
||||
return Object.keys(GangMemberUpgrades);
|
||||
},
|
||||
getEquipmentCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_equipName: unknown): number => {
|
||||
getEquipmentCost: (ctx) => (_equipName) => {
|
||||
const equipName = helpers.string(ctx, "equipName", _equipName);
|
||||
const gang = getGang(ctx);
|
||||
const upg = GangMemberUpgrades[equipName];
|
||||
if (upg === null) return Infinity;
|
||||
return gang.getUpgradeCost(upg);
|
||||
},
|
||||
getEquipmentType:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_equipName: unknown): string => {
|
||||
getEquipmentType: (ctx) => (_equipName) => {
|
||||
const equipName = helpers.string(ctx, "equipName", _equipName);
|
||||
getGang(ctx);
|
||||
const upg = GangMemberUpgrades[equipName];
|
||||
if (upg == null) return "";
|
||||
return upg.getType();
|
||||
},
|
||||
getEquipmentStats:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_equipName: unknown): EquipmentStats => {
|
||||
getEquipmentStats: (ctx) => (_equipName) => {
|
||||
const equipName = helpers.string(ctx, "equipName", _equipName);
|
||||
getGang(ctx);
|
||||
const equipment = GangMemberUpgrades[equipName];
|
||||
@ -241,11 +215,9 @@ export function NetscriptGang(): InternalAPI<IGang> {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid equipment: ${equipName}`);
|
||||
}
|
||||
const typecheck: EquipmentStats = equipment.mults;
|
||||
return Object.assign({}, typecheck) as any;
|
||||
return Object.assign({}, typecheck);
|
||||
},
|
||||
purchaseEquipment:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_memberName: unknown, _equipName: unknown): boolean => {
|
||||
purchaseEquipment: (ctx) => (_memberName, _equipName) => {
|
||||
const memberName = helpers.string(ctx, "memberName", _memberName);
|
||||
const equipName = helpers.string(ctx, "equipName", _equipName);
|
||||
getGang(ctx);
|
||||
@ -267,18 +239,14 @@ export function NetscriptGang(): InternalAPI<IGang> {
|
||||
|
||||
return res;
|
||||
},
|
||||
ascendMember:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_memberName: unknown): GangMemberAscension | undefined => {
|
||||
ascendMember: (ctx) => (_memberName) => {
|
||||
const memberName = helpers.string(ctx, "memberName", _memberName);
|
||||
const gang = getGang(ctx);
|
||||
const member = getGangMember(ctx, memberName);
|
||||
if (!member.canAscend()) return;
|
||||
return gang.ascendMember(member, ctx.workerScript);
|
||||
},
|
||||
getAscensionResult:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_memberName: unknown): GangMemberAscension | undefined => {
|
||||
getAscensionResult: (ctx) => (_memberName) => {
|
||||
const memberName = helpers.string(ctx, "memberName", _memberName);
|
||||
getGang(ctx);
|
||||
const member = getGangMember(ctx, memberName);
|
||||
@ -288,9 +256,7 @@ export function NetscriptGang(): InternalAPI<IGang> {
|
||||
...member.getAscensionResults(),
|
||||
};
|
||||
},
|
||||
setTerritoryWarfare:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_engage: unknown): void => {
|
||||
setTerritoryWarfare: (ctx) => (_engage) => {
|
||||
const engage = !!_engage;
|
||||
const gang = getGang(ctx);
|
||||
if (engage) {
|
||||
@ -301,9 +267,7 @@ export function NetscriptGang(): InternalAPI<IGang> {
|
||||
ctx.workerScript.log("gang.setTerritoryWarfare", () => "Disengaging in Gang Territory Warfare");
|
||||
}
|
||||
},
|
||||
getChanceToWinClash:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_otherGang: unknown): number => {
|
||||
getChanceToWinClash: (ctx) => (_otherGang) => {
|
||||
const otherGang = helpers.string(ctx, "otherGang", _otherGang);
|
||||
const gang = getGang(ctx);
|
||||
if (AllGangs[otherGang] == null) {
|
||||
@ -315,7 +279,7 @@ export function NetscriptGang(): InternalAPI<IGang> {
|
||||
|
||||
return playerPower / (otherPower + playerPower);
|
||||
},
|
||||
getBonusTime: (ctx: NetscriptContext) => (): number => {
|
||||
getBonusTime: (ctx) => () => {
|
||||
const gang = getGang(ctx);
|
||||
return Math.round(gang.storedCycles / 5) * 1000;
|
||||
},
|
||||
|
@ -21,9 +21,7 @@ export function NetscriptGrafting(): InternalAPI<IGrafting> {
|
||||
};
|
||||
|
||||
return {
|
||||
getAugmentationGraftPrice:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_augName: unknown): number => {
|
||||
getAugmentationGraftPrice: (ctx) => (_augName) => {
|
||||
const augName = helpers.string(ctx, "augName", _augName);
|
||||
checkGraftingAPIAccess(ctx);
|
||||
if (!getGraftingAvailableAugs().includes(augName) || !StaticAugmentations.hasOwnProperty(augName)) {
|
||||
@ -33,9 +31,7 @@ export function NetscriptGrafting(): InternalAPI<IGrafting> {
|
||||
return graftableAug.cost;
|
||||
},
|
||||
|
||||
getAugmentationGraftTime:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_augName: string): number => {
|
||||
getAugmentationGraftTime: (ctx) => (_augName) => {
|
||||
const augName = helpers.string(ctx, "augName", _augName);
|
||||
checkGraftingAPIAccess(ctx);
|
||||
if (!getGraftingAvailableAugs().includes(augName) || !StaticAugmentations.hasOwnProperty(augName)) {
|
||||
@ -45,15 +41,15 @@ export function NetscriptGrafting(): InternalAPI<IGrafting> {
|
||||
return calculateGraftingTimeWithBonus(graftableAug);
|
||||
},
|
||||
|
||||
getGraftableAugmentations: (ctx: NetscriptContext) => (): string[] => {
|
||||
getGraftableAugmentations: (ctx) => () => {
|
||||
checkGraftingAPIAccess(ctx);
|
||||
const graftableAugs = getGraftingAvailableAugs();
|
||||
return graftableAugs;
|
||||
},
|
||||
|
||||
graftAugmentation:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_augName: string, _focus: unknown = true): boolean => {
|
||||
(ctx) =>
|
||||
(_augName, _focus = true) => {
|
||||
const augName = helpers.string(ctx, "augName", _augName);
|
||||
const focus = !!_focus;
|
||||
checkGraftingAPIAccess(ctx);
|
||||
|
@ -50,28 +50,26 @@ export function NetscriptHacknet(): InternalAPI<IHacknet> {
|
||||
};
|
||||
|
||||
return {
|
||||
numNodes: () => (): number => {
|
||||
numNodes: () => () => {
|
||||
return player.hacknetNodes.length;
|
||||
},
|
||||
maxNumNodes: () => (): number => {
|
||||
maxNumNodes: () => () => {
|
||||
if (hasHacknetServers()) {
|
||||
return HacknetServerConstants.MaxServers;
|
||||
}
|
||||
return Infinity;
|
||||
},
|
||||
purchaseNode: () => (): number => {
|
||||
purchaseNode: () => () => {
|
||||
return purchaseHacknet();
|
||||
},
|
||||
getPurchaseNodeCost: () => (): number => {
|
||||
getPurchaseNodeCost: () => () => {
|
||||
if (hasHacknetServers()) {
|
||||
return getCostOfNextHacknetServer();
|
||||
} else {
|
||||
return getCostOfNextHacknetNode();
|
||||
}
|
||||
},
|
||||
getNodeStats:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_i: unknown): NodeStats => {
|
||||
getNodeStats: (ctx) => (_i) => {
|
||||
const i = helpers.number(ctx, "i", _i);
|
||||
const node = getHacknetNode(ctx, i);
|
||||
const hasUpgraded = hasHacknetServers();
|
||||
@ -94,32 +92,32 @@ export function NetscriptHacknet(): InternalAPI<IHacknet> {
|
||||
return res;
|
||||
},
|
||||
upgradeLevel:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_i: unknown, _n: unknown = 1): boolean => {
|
||||
(ctx) =>
|
||||
(_i, _n = 1) => {
|
||||
const i = helpers.number(ctx, "i", _i);
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
const node = getHacknetNode(ctx, i);
|
||||
return purchaseLevelUpgrade(node, n);
|
||||
},
|
||||
upgradeRam:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_i: unknown, _n: unknown = 1): boolean => {
|
||||
(ctx) =>
|
||||
(_i, _n = 1) => {
|
||||
const i = helpers.number(ctx, "i", _i);
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
const node = getHacknetNode(ctx, i);
|
||||
return purchaseRamUpgrade(node, n);
|
||||
},
|
||||
upgradeCore:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_i: unknown, _n: unknown = 1): boolean => {
|
||||
(ctx) =>
|
||||
(_i, _n = 1) => {
|
||||
const i = helpers.number(ctx, "i", _i);
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
const node = getHacknetNode(ctx, i);
|
||||
return purchaseCoreUpgrade(node, n);
|
||||
},
|
||||
upgradeCache:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_i: unknown, _n: unknown = 1): boolean => {
|
||||
(ctx) =>
|
||||
(_i, _n = 1) => {
|
||||
const i = helpers.number(ctx, "i", _i);
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
if (!hasHacknetServers()) {
|
||||
@ -137,32 +135,32 @@ export function NetscriptHacknet(): InternalAPI<IHacknet> {
|
||||
return res;
|
||||
},
|
||||
getLevelUpgradeCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_i: unknown, _n: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_i, _n = 1) => {
|
||||
const i = helpers.number(ctx, "i", _i);
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
const node = getHacknetNode(ctx, i);
|
||||
return node.calculateLevelUpgradeCost(n, player.mults.hacknet_node_level_cost);
|
||||
},
|
||||
getRamUpgradeCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_i: unknown, _n: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_i, _n = 1) => {
|
||||
const i = helpers.number(ctx, "i", _i);
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
const node = getHacknetNode(ctx, i);
|
||||
return node.calculateRamUpgradeCost(n, player.mults.hacknet_node_ram_cost);
|
||||
},
|
||||
getCoreUpgradeCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_i: unknown, _n: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_i, _n = 1) => {
|
||||
const i = helpers.number(ctx, "i", _i);
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
const node = getHacknetNode(ctx, i);
|
||||
return node.calculateCoreUpgradeCost(n, player.mults.hacknet_node_core_cost);
|
||||
},
|
||||
getCacheUpgradeCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_i: unknown, _n: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_i, _n = 1) => {
|
||||
const i = helpers.number(ctx, "i", _i);
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
if (!hasHacknetServers()) {
|
||||
@ -175,21 +173,21 @@ export function NetscriptHacknet(): InternalAPI<IHacknet> {
|
||||
}
|
||||
return node.calculateCacheUpgradeCost(n);
|
||||
},
|
||||
numHashes: () => (): number => {
|
||||
numHashes: () => () => {
|
||||
if (!hasHacknetServers()) {
|
||||
return 0;
|
||||
}
|
||||
return player.hashManager.hashes;
|
||||
},
|
||||
hashCapacity: () => (): number => {
|
||||
hashCapacity: () => () => {
|
||||
if (!hasHacknetServers()) {
|
||||
return 0;
|
||||
}
|
||||
return player.hashManager.capacity;
|
||||
},
|
||||
hashCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_upgName: unknown, _count: unknown = 1): number => {
|
||||
(ctx) =>
|
||||
(_upgName, _count = 1) => {
|
||||
const upgName = helpers.string(ctx, "upgName", _upgName);
|
||||
const count = helpers.number(ctx, "count", _count);
|
||||
if (!hasHacknetServers()) {
|
||||
@ -199,8 +197,8 @@ export function NetscriptHacknet(): InternalAPI<IHacknet> {
|
||||
return player.hashManager.getUpgradeCost(upgName, count);
|
||||
},
|
||||
spendHashes:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_upgName: unknown, _upgTarget: unknown = "", _count: unknown = 1): boolean => {
|
||||
(ctx) =>
|
||||
(_upgName, _upgTarget = "", _count = 1) => {
|
||||
const upgName = helpers.string(ctx, "upgName", _upgName);
|
||||
const upgTarget = helpers.string(ctx, "upgTarget", _upgTarget);
|
||||
const count = helpers.number(ctx, "count", _count);
|
||||
@ -209,15 +207,13 @@ export function NetscriptHacknet(): InternalAPI<IHacknet> {
|
||||
}
|
||||
return purchaseHashUpgrade(upgName, upgTarget, count);
|
||||
},
|
||||
getHashUpgrades: () => (): string[] => {
|
||||
getHashUpgrades: () => () => {
|
||||
if (!hasHacknetServers()) {
|
||||
return [];
|
||||
}
|
||||
return Object.values(HashUpgrades).map((upgrade: HashUpgrade) => upgrade.name);
|
||||
},
|
||||
getHashUpgradeLevel:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_upgName: unknown): number => {
|
||||
getHashUpgradeLevel: (ctx) => (_upgName) => {
|
||||
const upgName = helpers.string(ctx, "upgName", _upgName);
|
||||
const level = player.hashManager.upgrades[upgName];
|
||||
if (level === undefined) {
|
||||
@ -225,13 +221,13 @@ export function NetscriptHacknet(): InternalAPI<IHacknet> {
|
||||
}
|
||||
return level;
|
||||
},
|
||||
getStudyMult: () => (): number => {
|
||||
getStudyMult: () => () => {
|
||||
if (!hasHacknetServers()) {
|
||||
return 1;
|
||||
}
|
||||
return player.hashManager.getStudyMult();
|
||||
},
|
||||
getTrainingMult: () => (): number => {
|
||||
getTrainingMult: () => () => {
|
||||
if (!hasHacknetServers()) {
|
||||
return 1;
|
||||
}
|
||||
|
@ -1,8 +1,4 @@
|
||||
import {
|
||||
Infiltration as IInfiltration,
|
||||
InfiltrationLocation,
|
||||
PossibleInfiltrationLocation,
|
||||
} from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { Infiltration as IInfiltration, InfiltrationLocation } from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { Location } from "../Locations/Location";
|
||||
import { Locations } from "../Locations/Locations";
|
||||
import { calculateDifficulty, calculateReward } from "../Infiltration/formulas/game";
|
||||
@ -44,15 +40,13 @@ export function NetscriptInfiltration(): InternalAPI<IInfiltration> {
|
||||
};
|
||||
};
|
||||
return {
|
||||
getPossibleLocations: () => (): PossibleInfiltrationLocation[] => {
|
||||
getPossibleLocations: () => () => {
|
||||
return getLocationsWithInfiltrations.map((l) => ({
|
||||
city: l.city ?? "",
|
||||
name: String(l.name),
|
||||
}));
|
||||
},
|
||||
getInfiltration:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_location: unknown): InfiltrationLocation => {
|
||||
getInfiltration: (ctx) => (_location) => {
|
||||
const location = helpers.string(ctx, "location", _location);
|
||||
return calculateInfiltrationData(ctx, location);
|
||||
},
|
||||
|
@ -11,12 +11,7 @@ import { isString } from "../utils/helpers/isString";
|
||||
import { RunningScript } from "../Script/RunningScript";
|
||||
import { calculateAchievements } from "../Achievements/Achievements";
|
||||
|
||||
import {
|
||||
Multipliers,
|
||||
CrimeStats,
|
||||
Singularity as ISingularity,
|
||||
SourceFileLvl,
|
||||
} from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { Singularity as ISingularity } from "../ScriptEditor/NetscriptDefinitions";
|
||||
|
||||
import { findCrime } from "../Crime/CrimeHelpers";
|
||||
import { CompanyPositions } from "../Company/CompanyPositions";
|
||||
@ -79,7 +74,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
return company;
|
||||
};
|
||||
|
||||
const runAfterReset = function (cbScript: string | null = null): void {
|
||||
const runAfterReset = function (cbScript: string | null = null) {
|
||||
//Run a script after reset
|
||||
if (!cbScript) return;
|
||||
const home = Player.getHomeComputer();
|
||||
@ -98,11 +93,10 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
};
|
||||
|
||||
return {
|
||||
getOwnedAugmentations: (ctx: NetscriptContext) =>
|
||||
function (_purchased: unknown = false): string[] {
|
||||
getOwnedAugmentations: (ctx) => (_purchased) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const purchased = !!_purchased;
|
||||
const res = [];
|
||||
const res: string[] = [];
|
||||
for (let i = 0; i < Player.augmentations.length; ++i) {
|
||||
res.push(Player.augmentations[i].name);
|
||||
}
|
||||
@ -113,69 +107,56 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
}
|
||||
return res;
|
||||
},
|
||||
getOwnedSourceFiles: () => (): SourceFileLvl[] => {
|
||||
const res: SourceFileLvl[] = [];
|
||||
for (let i = 0; i < Player.sourceFiles.length; ++i) {
|
||||
res.push({
|
||||
n: Player.sourceFiles[i].n,
|
||||
lvl: Player.sourceFiles[i].lvl,
|
||||
getOwnedSourceFiles: () => () => {
|
||||
return Player.sourceFiles.map((sf) => {
|
||||
return { n: sf.n, lvl: sf.lvl };
|
||||
});
|
||||
}
|
||||
return res;
|
||||
},
|
||||
getAugmentationsFromFaction: (ctx: NetscriptContext) =>
|
||||
function (_facName: unknown): string[] {
|
||||
getAugmentationsFromFaction: (ctx) => (_facName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const facName = helpers.string(ctx, "facName", _facName);
|
||||
const faction = getFaction(ctx, facName);
|
||||
|
||||
return getFactionAugmentationsFiltered(faction);
|
||||
},
|
||||
getAugmentationCost: (ctx: NetscriptContext) =>
|
||||
function (_augName: unknown): [number, number] {
|
||||
getAugmentationCost: (ctx) => (_augName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const augName = helpers.string(ctx, "augName", _augName);
|
||||
const aug = getAugmentation(ctx, augName);
|
||||
const costs = aug.getCost();
|
||||
return [costs.repCost, costs.moneyCost];
|
||||
},
|
||||
getAugmentationPrereq: (ctx: NetscriptContext) =>
|
||||
function (_augName: unknown): string[] {
|
||||
getAugmentationPrereq: (ctx) => (_augName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const augName = helpers.string(ctx, "augName", _augName);
|
||||
const aug = getAugmentation(ctx, augName);
|
||||
return aug.prereqs.slice();
|
||||
},
|
||||
getAugmentationBasePrice: (ctx: NetscriptContext) =>
|
||||
function (_augName: unknown): number {
|
||||
getAugmentationBasePrice: (ctx) => (_augName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const augName = helpers.string(ctx, "augName", _augName);
|
||||
const aug = getAugmentation(ctx, augName);
|
||||
return aug.baseCost * BitNodeMultipliers.AugmentationMoneyCost;
|
||||
},
|
||||
getAugmentationPrice: (ctx: NetscriptContext) =>
|
||||
function (_augName: unknown): number {
|
||||
getAugmentationPrice: (ctx) => (_augName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const augName = helpers.string(ctx, "augName", _augName);
|
||||
const aug = getAugmentation(ctx, augName);
|
||||
return aug.getCost().moneyCost;
|
||||
},
|
||||
getAugmentationRepReq: (ctx: NetscriptContext) =>
|
||||
function (_augName: unknown): number {
|
||||
getAugmentationRepReq: (ctx) => (_augName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const augName = helpers.string(ctx, "augName", _augName);
|
||||
const aug = getAugmentation(ctx, augName);
|
||||
return aug.getCost().repCost;
|
||||
},
|
||||
getAugmentationStats: (ctx: NetscriptContext) =>
|
||||
function (_augName: unknown): Multipliers {
|
||||
getAugmentationStats: (ctx) => (_augName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const augName = helpers.string(ctx, "augName", _augName);
|
||||
const aug = getAugmentation(ctx, augName);
|
||||
return Object.assign({}, aug.mults);
|
||||
},
|
||||
purchaseAugmentation: (ctx: NetscriptContext) =>
|
||||
function (_facName: unknown, _augName: unknown): boolean {
|
||||
purchaseAugmentation: (ctx) => (_facName, _augName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const facName = helpers.string(ctx, "facName", _facName);
|
||||
const augName = helpers.string(ctx, "augName", _augName);
|
||||
@ -224,10 +205,9 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
softReset: (ctx: NetscriptContext) =>
|
||||
function (_cbScript: unknown = ""): void {
|
||||
softReset: (ctx) => (_cbScript) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const cbScript = helpers.string(ctx, "cbScript", _cbScript);
|
||||
const cbScript = _cbScript ? helpers.string(ctx, "cbScript", _cbScript) : "";
|
||||
|
||||
helpers.log(ctx, () => "Soft resetting. This will cause this script to be killed");
|
||||
setTimeout(() => {
|
||||
@ -237,10 +217,9 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
|
||||
killWorkerScript(ctx.workerScript);
|
||||
},
|
||||
installAugmentations: (ctx: NetscriptContext) =>
|
||||
function (_cbScript: unknown = ""): boolean {
|
||||
installAugmentations: (ctx) => (_cbScript) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const cbScript = helpers.string(ctx, "cbScript", _cbScript);
|
||||
const cbScript = _cbScript ? helpers.string(ctx, "cbScript", _cbScript) : "";
|
||||
|
||||
if (Player.queuedAugmentations.length === 0) {
|
||||
helpers.log(ctx, () => "You do not have any Augmentations to be installed.");
|
||||
@ -257,8 +236,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
return true;
|
||||
},
|
||||
|
||||
goToLocation: (ctx: NetscriptContext) =>
|
||||
function (_locationName: unknown): boolean {
|
||||
goToLocation: (ctx) => (_locationName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const locationName = helpers.string(ctx, "locationName", _locationName);
|
||||
const location = Object.values(Locations).find((l) => l.name === locationName);
|
||||
@ -280,8 +258,9 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
Player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain / 50000);
|
||||
return true;
|
||||
},
|
||||
universityCourse: (ctx: NetscriptContext) =>
|
||||
function (_universityName: unknown, _className: unknown, _focus: unknown = true): boolean {
|
||||
universityCourse:
|
||||
(ctx) =>
|
||||
(_universityName, _className, _focus = true) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const universityName = helpers.string(ctx, "universityName", _universityName);
|
||||
const className = helpers.string(ctx, "className", _className);
|
||||
@ -366,8 +345,9 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
return true;
|
||||
},
|
||||
|
||||
gymWorkout: (ctx: NetscriptContext) =>
|
||||
function (_gymName: unknown, _stat: unknown, _focus: unknown = true): boolean {
|
||||
gymWorkout:
|
||||
(ctx) =>
|
||||
(_gymName, _stat, _focus = true) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const gymName = helpers.string(ctx, "gymName", _gymName);
|
||||
const stat = helpers.string(ctx, "stat", _stat);
|
||||
@ -475,8 +455,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
return true;
|
||||
},
|
||||
|
||||
travelToCity: (ctx: NetscriptContext) =>
|
||||
function (_cityName: unknown): boolean {
|
||||
travelToCity: (ctx) => (_cityName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
|
||||
@ -501,8 +480,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
}
|
||||
},
|
||||
|
||||
purchaseTor: (ctx: NetscriptContext) =>
|
||||
function (): boolean {
|
||||
purchaseTor: (ctx) => () => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
|
||||
if (Player.hasTorRouter()) {
|
||||
@ -525,8 +503,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
helpers.log(ctx, () => "You have purchased a Tor router!");
|
||||
return true;
|
||||
},
|
||||
purchaseProgram: (ctx: NetscriptContext) =>
|
||||
function (_programName: unknown): boolean {
|
||||
purchaseProgram: (ctx) => (_programName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const programName = helpers.string(ctx, "programName", _programName).toLowerCase();
|
||||
|
||||
@ -568,13 +545,11 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
Player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain / 5000);
|
||||
return true;
|
||||
},
|
||||
getCurrentServer: (ctx: NetscriptContext) =>
|
||||
function (): string {
|
||||
getCurrentServer: (ctx) => () => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
return Player.getCurrentServer().hostname;
|
||||
},
|
||||
connect: (ctx: NetscriptContext) =>
|
||||
function (_hostname: unknown): boolean {
|
||||
connect: (ctx) => (_hostname) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
if (!hostname) {
|
||||
@ -622,13 +597,12 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
//Failure case
|
||||
return false;
|
||||
},
|
||||
manualHack: (ctx: NetscriptContext) =>
|
||||
function (): Promise<number> {
|
||||
manualHack: (ctx) => () => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const server = Player.getCurrentServer();
|
||||
return helpers.hack(ctx, server.hostname, true);
|
||||
},
|
||||
installBackdoor: (ctx: NetscriptContext) => async (): Promise<void> => {
|
||||
installBackdoor: (ctx) => async (): Promise<void> => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const baseserver = Player.getCurrentServer();
|
||||
if (!(baseserver instanceof Server)) {
|
||||
@ -660,13 +634,11 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
return Promise.resolve();
|
||||
});
|
||||
},
|
||||
isFocused: (ctx: NetscriptContext) =>
|
||||
function (): boolean {
|
||||
isFocused: (ctx) => () => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
return Player.focus;
|
||||
},
|
||||
setFocus: (ctx: NetscriptContext) =>
|
||||
function (_focus: unknown): boolean {
|
||||
setFocus: (ctx) => (_focus) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const focus = !!_focus;
|
||||
if (Player.currentWork === null) {
|
||||
@ -684,8 +656,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
}
|
||||
return false;
|
||||
},
|
||||
hospitalize: (ctx: NetscriptContext) =>
|
||||
function (): void {
|
||||
hospitalize: (ctx) => () => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
if (Player.currentWork || Router.page() === Page.Infiltration || Router.page() === Page.BitVerse) {
|
||||
helpers.log(ctx, () => "Cannot go to the hospital because the player is busy.");
|
||||
@ -693,20 +664,17 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
}
|
||||
Player.hospitalize();
|
||||
},
|
||||
isBusy: (ctx: NetscriptContext) =>
|
||||
function (): boolean {
|
||||
isBusy: (ctx) => () => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
return Player.currentWork !== null || Router.page() === Page.Infiltration || Router.page() === Page.BitVerse;
|
||||
},
|
||||
stopAction: (ctx: NetscriptContext) =>
|
||||
function (): boolean {
|
||||
stopAction: (ctx) => () => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const wasWorking = Player.currentWork !== null;
|
||||
Player.finishWork(true);
|
||||
return wasWorking;
|
||||
},
|
||||
upgradeHomeCores: (ctx: NetscriptContext) =>
|
||||
function (): boolean {
|
||||
upgradeHomeCores: (ctx) => () => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
|
||||
// Check if we're at max cores
|
||||
@ -732,14 +700,12 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
);
|
||||
return true;
|
||||
},
|
||||
getUpgradeHomeCoresCost: (ctx: NetscriptContext) =>
|
||||
function (): number {
|
||||
getUpgradeHomeCoresCost: (ctx) => () => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
|
||||
return Player.getUpgradeHomeCoresCost();
|
||||
},
|
||||
upgradeHomeRam: (ctx: NetscriptContext) =>
|
||||
function (): boolean {
|
||||
upgradeHomeRam: (ctx) => () => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
|
||||
// Check if we're at max RAM
|
||||
@ -768,14 +734,14 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
);
|
||||
return true;
|
||||
},
|
||||
getUpgradeHomeRamCost: (ctx: NetscriptContext) =>
|
||||
function (): number {
|
||||
getUpgradeHomeRamCost: (ctx) => () => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
|
||||
return Player.getUpgradeHomeRamCost();
|
||||
},
|
||||
workForCompany: (ctx: NetscriptContext) =>
|
||||
function (_companyName: unknown, _focus: unknown = true): boolean {
|
||||
workForCompany:
|
||||
(ctx) =>
|
||||
(_companyName, _focus = true) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const companyName = helpers.string(ctx, "companyName", _companyName);
|
||||
const focus = !!_focus;
|
||||
@ -818,8 +784,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
helpers.log(ctx, () => `Began working at '${companyName}' with position '${companyPositionName}'`);
|
||||
return true;
|
||||
},
|
||||
applyToCompany: (ctx: NetscriptContext) =>
|
||||
function (_companyName: unknown, _field: unknown): boolean {
|
||||
applyToCompany: (ctx) => (_companyName, _field) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const companyName = helpers.string(ctx, "companyName", _companyName);
|
||||
const field = helpers.string(ctx, "field", _field);
|
||||
@ -887,41 +852,35 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
}
|
||||
return res;
|
||||
},
|
||||
quitJob: (ctx: NetscriptContext) =>
|
||||
function (_companyName: unknown): void {
|
||||
quitJob: (ctx) => (_companyName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const companyName = helpers.string(ctx, "companyName", _companyName);
|
||||
Player.quitJob(companyName);
|
||||
},
|
||||
getCompanyRep: (ctx: NetscriptContext) =>
|
||||
function (_companyName: unknown): number {
|
||||
getCompanyRep: (ctx) => (_companyName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const companyName = helpers.string(ctx, "companyName", _companyName);
|
||||
const company = getCompany(ctx, companyName);
|
||||
return company.playerReputation;
|
||||
},
|
||||
getCompanyFavor: (ctx: NetscriptContext) =>
|
||||
function (_companyName: unknown): number {
|
||||
getCompanyFavor: (ctx) => (_companyName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const companyName = helpers.string(ctx, "companyName", _companyName);
|
||||
const company = getCompany(ctx, companyName);
|
||||
return company.favor;
|
||||
},
|
||||
getCompanyFavorGain: (ctx: NetscriptContext) =>
|
||||
function (_companyName: unknown): number {
|
||||
getCompanyFavorGain: (ctx) => (_companyName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const companyName = helpers.string(ctx, "companyName", _companyName);
|
||||
const company = getCompany(ctx, companyName);
|
||||
return company.getFavorGain();
|
||||
},
|
||||
checkFactionInvitations: (ctx: NetscriptContext) =>
|
||||
function (): string[] {
|
||||
checkFactionInvitations: (ctx) => () => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
// Make a copy of player.factionInvitations
|
||||
return Player.factionInvitations.slice();
|
||||
},
|
||||
joinFaction: (ctx: NetscriptContext) =>
|
||||
function (_facName: unknown): boolean {
|
||||
joinFaction: (ctx) => (_facName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const facName = helpers.string(ctx, "facName", _facName);
|
||||
getFaction(ctx, facName);
|
||||
@ -944,8 +903,9 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
helpers.log(ctx, () => `Joined the '${facName}' faction.`);
|
||||
return true;
|
||||
},
|
||||
workForFaction: (ctx: NetscriptContext) =>
|
||||
function (_facName: unknown, _type: unknown, _focus: unknown = true): boolean {
|
||||
workForFaction:
|
||||
(ctx) =>
|
||||
(_facName, _type, _focus = true) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const facName = helpers.string(ctx, "facName", _facName);
|
||||
const type = helpers.string(ctx, "type", _type);
|
||||
@ -1040,29 +1000,25 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
getFactionRep: (ctx: NetscriptContext) =>
|
||||
function (_facName: unknown): number {
|
||||
getFactionRep: (ctx) => (_facName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const facName = helpers.string(ctx, "facName", _facName);
|
||||
const faction = getFaction(ctx, facName);
|
||||
return faction.playerReputation;
|
||||
},
|
||||
getFactionFavor: (ctx: NetscriptContext) =>
|
||||
function (_facName: unknown): number {
|
||||
getFactionFavor: (ctx) => (_facName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const facName = helpers.string(ctx, "facName", _facName);
|
||||
const faction = getFaction(ctx, facName);
|
||||
return faction.favor;
|
||||
},
|
||||
getFactionFavorGain: (ctx: NetscriptContext) =>
|
||||
function (_facName: unknown): number {
|
||||
getFactionFavorGain: (ctx) => (_facName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const facName = helpers.string(ctx, "facName", _facName);
|
||||
const faction = getFaction(ctx, facName);
|
||||
return faction.getFavorGain();
|
||||
},
|
||||
donateToFaction: (ctx: NetscriptContext) =>
|
||||
function (_facName: unknown, _amt: unknown): boolean {
|
||||
donateToFaction: (ctx) => (_facName, _amt) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const facName = helpers.string(ctx, "facName", _facName);
|
||||
const amt = helpers.number(ctx, "amt", _amt);
|
||||
@ -1111,8 +1067,9 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
);
|
||||
return true;
|
||||
},
|
||||
createProgram: (ctx: NetscriptContext) =>
|
||||
function (_programName: unknown, _focus: unknown = true): boolean {
|
||||
createProgram:
|
||||
(ctx) =>
|
||||
(_programName, _focus = true) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const programName = helpers.string(ctx, "programName", _programName).toLowerCase();
|
||||
const focus = !!_focus;
|
||||
@ -1158,8 +1115,9 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
helpers.log(ctx, () => `Began creating program: '${programName}'`);
|
||||
return true;
|
||||
},
|
||||
commitCrime: (ctx: NetscriptContext) =>
|
||||
function (_crimeRoughName: unknown, _focus: unknown = true): number {
|
||||
commitCrime:
|
||||
(ctx) =>
|
||||
(_crimeRoughName, _focus = true) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const crimeRoughName = helpers.string(ctx, "crimeRoughName", _crimeRoughName);
|
||||
const focus = !!_focus;
|
||||
@ -1188,8 +1146,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
}
|
||||
return crimeTime;
|
||||
},
|
||||
getCrimeChance: (ctx: NetscriptContext) =>
|
||||
function (_crimeRoughName: unknown): number {
|
||||
getCrimeChance: (ctx) => (_crimeRoughName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const crimeRoughName = helpers.string(ctx, "crimeRoughName", _crimeRoughName);
|
||||
|
||||
@ -1200,8 +1157,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
|
||||
return crime.successRate(Player);
|
||||
},
|
||||
getCrimeStats: (ctx: NetscriptContext) =>
|
||||
function (_crimeRoughName: unknown): CrimeStats {
|
||||
getCrimeStats: (ctx) => (_crimeRoughName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const crimeRoughName = helpers.string(ctx, "crimeRoughName", _crimeRoughName);
|
||||
|
||||
@ -1224,8 +1180,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
intelligence_exp: crimeStatsWithMultipliers.intExp,
|
||||
});
|
||||
},
|
||||
getDarkwebPrograms: (ctx: NetscriptContext) =>
|
||||
function (): string[] {
|
||||
getDarkwebPrograms: (ctx) => () => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
|
||||
// If we don't have Tor, log it and return [] (empty list)
|
||||
@ -1235,8 +1190,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
}
|
||||
return Object.values(DarkWebItems).map((p) => p.program);
|
||||
},
|
||||
getDarkwebProgramCost: (ctx: NetscriptContext) =>
|
||||
function (_programName: unknown): number {
|
||||
getDarkwebProgramCost: (ctx) => (_programName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const programName = helpers.string(ctx, "programName", _programName).toLowerCase();
|
||||
|
||||
@ -1269,8 +1223,8 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
return item.price;
|
||||
},
|
||||
b1tflum3:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_nextBN: unknown, _callbackScript: unknown = ""): void => {
|
||||
(ctx) =>
|
||||
(_nextBN, _callbackScript = "") => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const nextBN = helpers.number(ctx, "nextBN", _nextBN);
|
||||
const callbackScript = helpers.string(ctx, "callbackScript", _callbackScript);
|
||||
@ -1282,20 +1236,20 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
}, 0);
|
||||
},
|
||||
destroyW0r1dD43m0n:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_nextBN: unknown, _callbackScript: unknown = ""): void => {
|
||||
(ctx) =>
|
||||
(_nextBN, _callbackScript = "") => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const nextBN = helpers.number(ctx, "nextBN", _nextBN);
|
||||
const callbackScript = helpers.string(ctx, "callbackScript", _callbackScript);
|
||||
|
||||
const wd = GetServer(SpecialServers.WorldDaemon);
|
||||
if (!(wd instanceof Server)) throw new Error("WorldDaemon was not a normal server. This is a bug contact dev.");
|
||||
const hackingRequirements = (): boolean => {
|
||||
const hackingRequirements = () => {
|
||||
if (Player.skills.hacking < wd.requiredHackingSkill) return false;
|
||||
if (!wd.hasAdminRights) return false;
|
||||
return true;
|
||||
};
|
||||
const bladeburnerRequirements = (): boolean => {
|
||||
const bladeburnerRequirements = () => {
|
||||
if (!Player.inBladeburner()) return false;
|
||||
if (!Player.bladeburner) return false;
|
||||
return Player.bladeburner.blackops[BlackOperationNames.OperationDaedalus];
|
||||
@ -1314,16 +1268,16 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
runAfterReset(callbackScript);
|
||||
}, 0);
|
||||
},
|
||||
getCurrentWork: () => (): any | null => {
|
||||
getCurrentWork: () => () => {
|
||||
if (!Player.currentWork) return null;
|
||||
return Player.currentWork.APICopy();
|
||||
},
|
||||
exportGame: (ctx: NetscriptContext) => (): void => {
|
||||
exportGame: (ctx) => () => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
onExport();
|
||||
return saveObject.exportGame();
|
||||
},
|
||||
exportGameBonus: (ctx: NetscriptContext) => (): boolean => {
|
||||
exportGameBonus: (ctx) => () => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
return canGetBonus();
|
||||
},
|
||||
|
@ -4,13 +4,7 @@ import { CityName } from "../Locations/data/CityNames";
|
||||
import { findCrime } from "../Crime/CrimeHelpers";
|
||||
import { Augmentation } from "../Augmentation/Augmentation";
|
||||
|
||||
import {
|
||||
AugmentPair,
|
||||
Sleeve as ISleeve,
|
||||
SleeveInformation,
|
||||
SleeveSkills,
|
||||
SleeveTask,
|
||||
} from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { Sleeve as ISleeve, SleeveSkills } from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { checkEnum } from "../utils/helpers/checkEnum";
|
||||
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
||||
import { isSleeveBladeburnerWork } from "../PersonObjects/Sleeve/Work/SleeveBladeburnerWork";
|
||||
@ -19,7 +13,7 @@ import { isSleeveCompanyWork } from "../PersonObjects/Sleeve/Work/SleeveCompanyW
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
|
||||
export function NetscriptSleeve(): InternalAPI<ISleeve> {
|
||||
const checkSleeveAPIAccess = function (ctx: NetscriptContext): void {
|
||||
const checkSleeveAPIAccess = function (ctx: NetscriptContext) {
|
||||
if (Player.bitNodeN !== 10 && !Player.sourceFileLvl(10)) {
|
||||
throw helpers.makeRuntimeErrorMsg(
|
||||
ctx,
|
||||
@ -28,7 +22,7 @@ export function NetscriptSleeve(): InternalAPI<ISleeve> {
|
||||
}
|
||||
};
|
||||
|
||||
const checkSleeveNumber = function (ctx: NetscriptContext, sleeveNumber: number): void {
|
||||
const checkSleeveNumber = function (ctx: NetscriptContext, sleeveNumber: number) {
|
||||
if (sleeveNumber >= Player.sleeves.length || sleeveNumber < 0) {
|
||||
const msg = `Invalid sleeve number: ${sleeveNumber}`;
|
||||
helpers.log(ctx, () => msg);
|
||||
@ -52,29 +46,23 @@ export function NetscriptSleeve(): InternalAPI<ISleeve> {
|
||||
};
|
||||
|
||||
return {
|
||||
getNumSleeves: (ctx: NetscriptContext) => (): number => {
|
||||
getNumSleeves: (ctx) => () => {
|
||||
checkSleeveAPIAccess(ctx);
|
||||
return Player.sleeves.length;
|
||||
},
|
||||
setToShockRecovery:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_sleeveNumber: unknown): boolean => {
|
||||
setToShockRecovery: (ctx) => (_sleeveNumber) => {
|
||||
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
||||
checkSleeveAPIAccess(ctx);
|
||||
checkSleeveNumber(ctx, sleeveNumber);
|
||||
return Player.sleeves[sleeveNumber].shockRecovery();
|
||||
},
|
||||
setToSynchronize:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_sleeveNumber: unknown): boolean => {
|
||||
setToSynchronize: (ctx) => (_sleeveNumber) => {
|
||||
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
||||
checkSleeveAPIAccess(ctx);
|
||||
checkSleeveNumber(ctx, sleeveNumber);
|
||||
return Player.sleeves[sleeveNumber].synchronize();
|
||||
},
|
||||
setToCommitCrime:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_sleeveNumber: unknown, _crimeRoughName: unknown): boolean => {
|
||||
setToCommitCrime: (ctx) => (_sleeveNumber, _crimeRoughName) => {
|
||||
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
||||
const crimeRoughName = helpers.string(ctx, "crimeName", _crimeRoughName);
|
||||
checkSleeveAPIAccess(ctx);
|
||||
@ -85,9 +73,7 @@ export function NetscriptSleeve(): InternalAPI<ISleeve> {
|
||||
}
|
||||
return Player.sleeves[sleeveNumber].commitCrime(crime.name);
|
||||
},
|
||||
setToUniversityCourse:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_sleeveNumber: unknown, _universityName: unknown, _className: unknown): boolean => {
|
||||
setToUniversityCourse: (ctx) => (_sleeveNumber, _universityName, _className) => {
|
||||
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
||||
const universityName = helpers.string(ctx, "universityName", _universityName);
|
||||
const className = helpers.string(ctx, "className", _className);
|
||||
@ -95,9 +81,7 @@ export function NetscriptSleeve(): InternalAPI<ISleeve> {
|
||||
checkSleeveNumber(ctx, sleeveNumber);
|
||||
return Player.sleeves[sleeveNumber].takeUniversityCourse(universityName, className);
|
||||
},
|
||||
travel:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_sleeveNumber: unknown, _cityName: unknown): boolean => {
|
||||
travel: (ctx) => (_sleeveNumber, _cityName) => {
|
||||
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
||||
const cityName = helpers.string(ctx, "cityName", _cityName);
|
||||
checkSleeveAPIAccess(ctx);
|
||||
@ -108,9 +92,7 @@ export function NetscriptSleeve(): InternalAPI<ISleeve> {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid city name: '${cityName}'.`);
|
||||
}
|
||||
},
|
||||
setToCompanyWork:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_sleeveNumber: unknown, acompanyName: unknown): boolean => {
|
||||
setToCompanyWork: (ctx) => (_sleeveNumber, acompanyName) => {
|
||||
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
||||
const companyName = helpers.string(ctx, "companyName", acompanyName);
|
||||
checkSleeveAPIAccess(ctx);
|
||||
@ -132,9 +114,7 @@ export function NetscriptSleeve(): InternalAPI<ISleeve> {
|
||||
|
||||
return Player.sleeves[sleeveNumber].workForCompany(companyName);
|
||||
},
|
||||
setToFactionWork:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_sleeveNumber: unknown, _factionName: unknown, _workType: unknown): boolean | undefined => {
|
||||
setToFactionWork: (ctx) => (_sleeveNumber, _factionName, _workType) => {
|
||||
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
||||
const factionName = helpers.string(ctx, "factionName", _factionName);
|
||||
const workType = helpers.string(ctx, "workType", _workType);
|
||||
@ -164,9 +144,7 @@ export function NetscriptSleeve(): InternalAPI<ISleeve> {
|
||||
|
||||
return Player.sleeves[sleeveNumber].workForFaction(factionName, workType);
|
||||
},
|
||||
setToGymWorkout:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_sleeveNumber: unknown, _gymName: unknown, _stat: unknown): boolean => {
|
||||
setToGymWorkout: (ctx) => (_sleeveNumber, _gymName, _stat) => {
|
||||
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
||||
const gymName = helpers.string(ctx, "gymName", _gymName);
|
||||
const stat = helpers.string(ctx, "stat", _stat);
|
||||
@ -175,17 +153,13 @@ export function NetscriptSleeve(): InternalAPI<ISleeve> {
|
||||
|
||||
return Player.sleeves[sleeveNumber].workoutAtGym(gymName, stat);
|
||||
},
|
||||
getSleeveStats:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_sleeveNumber: unknown): SleeveSkills => {
|
||||
getSleeveStats: (ctx) => (_sleeveNumber) => {
|
||||
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
||||
checkSleeveAPIAccess(ctx);
|
||||
checkSleeveNumber(ctx, sleeveNumber);
|
||||
return getSleeveStats(sleeveNumber);
|
||||
},
|
||||
getTask:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_sleeveNumber: unknown): SleeveTask | null => {
|
||||
getTask: (ctx) => (_sleeveNumber) => {
|
||||
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
||||
checkSleeveAPIAccess(ctx);
|
||||
checkSleeveNumber(ctx, sleeveNumber);
|
||||
@ -194,9 +168,7 @@ export function NetscriptSleeve(): InternalAPI<ISleeve> {
|
||||
if (sl.currentWork === null) return null;
|
||||
return sl.currentWork.APICopy();
|
||||
},
|
||||
getInformation:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_sleeveNumber: unknown): SleeveInformation => {
|
||||
getInformation: (ctx) => (_sleeveNumber) => {
|
||||
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
||||
checkSleeveAPIAccess(ctx);
|
||||
checkSleeveNumber(ctx, sleeveNumber);
|
||||
@ -230,9 +202,7 @@ export function NetscriptSleeve(): InternalAPI<ISleeve> {
|
||||
},
|
||||
};
|
||||
},
|
||||
getSleeveAugmentations:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_sleeveNumber: unknown): string[] => {
|
||||
getSleeveAugmentations: (ctx) => (_sleeveNumber) => {
|
||||
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
||||
checkSleeveAPIAccess(ctx);
|
||||
checkSleeveNumber(ctx, sleeveNumber);
|
||||
@ -243,9 +213,7 @@ export function NetscriptSleeve(): InternalAPI<ISleeve> {
|
||||
}
|
||||
return augs;
|
||||
},
|
||||
getSleevePurchasableAugs:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_sleeveNumber: unknown): AugmentPair[] => {
|
||||
getSleevePurchasableAugs: (ctx) => (_sleeveNumber) => {
|
||||
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
||||
checkSleeveAPIAccess(ctx);
|
||||
checkSleeveNumber(ctx, sleeveNumber);
|
||||
@ -262,9 +230,7 @@ export function NetscriptSleeve(): InternalAPI<ISleeve> {
|
||||
|
||||
return augs;
|
||||
},
|
||||
purchaseSleeveAug:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_sleeveNumber: unknown, _augName: unknown): boolean => {
|
||||
purchaseSleeveAug: (ctx) => (_sleeveNumber, _augName) => {
|
||||
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
||||
const augName = helpers.string(ctx, "augName", _augName);
|
||||
checkSleeveAPIAccess(ctx);
|
||||
@ -281,25 +247,19 @@ export function NetscriptSleeve(): InternalAPI<ISleeve> {
|
||||
|
||||
return Player.sleeves[sleeveNumber].tryBuyAugmentation(aug);
|
||||
},
|
||||
getSleeveAugmentationPrice:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_augName: unknown): number => {
|
||||
getSleeveAugmentationPrice: (ctx) => (_augName) => {
|
||||
checkSleeveAPIAccess(ctx);
|
||||
const augName = helpers.string(ctx, "augName", _augName);
|
||||
const aug: Augmentation = StaticAugmentations[augName];
|
||||
return aug.baseCost;
|
||||
},
|
||||
getSleeveAugmentationRepReq:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_augName: unknown): number => {
|
||||
getSleeveAugmentationRepReq: (ctx) => (_augName) => {
|
||||
checkSleeveAPIAccess(ctx);
|
||||
const augName = helpers.string(ctx, "augName", _augName);
|
||||
const aug: Augmentation = StaticAugmentations[augName];
|
||||
return aug.getCost().repCost;
|
||||
},
|
||||
setToBladeburnerAction:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_sleeveNumber: unknown, _action: unknown, _contract?: unknown): boolean => {
|
||||
setToBladeburnerAction: (ctx) => (_sleeveNumber, _action, _contract?) => {
|
||||
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
||||
const action = helpers.string(ctx, "action", _action);
|
||||
let contract: string;
|
||||
|
@ -4,11 +4,7 @@ import { staneksGift } from "../CotMG/Helper";
|
||||
import { Fragments, FragmentById } from "../CotMG/Fragment";
|
||||
import { FragmentType } from "../CotMG/FragmentType";
|
||||
|
||||
import {
|
||||
Fragment as IFragment,
|
||||
ActiveFragment as IActiveFragment,
|
||||
Stanek as IStanek,
|
||||
} from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { Stanek as IStanek } from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
|
||||
import { NetscriptContext, InternalAPI } from "../Netscript/APIWrapper";
|
||||
import { applyAugmentation } from "../Augmentation/AugmentationHelpers";
|
||||
@ -25,18 +21,15 @@ export function NetscriptStanek(): InternalAPI<IStanek> {
|
||||
}
|
||||
|
||||
return {
|
||||
giftWidth: (ctx: NetscriptContext) =>
|
||||
function (): number {
|
||||
giftWidth: (ctx) => () => {
|
||||
checkStanekAPIAccess(ctx);
|
||||
return staneksGift.width();
|
||||
},
|
||||
giftHeight: (ctx: NetscriptContext) =>
|
||||
function (): number {
|
||||
giftHeight: (ctx) => () => {
|
||||
checkStanekAPIAccess(ctx);
|
||||
return staneksGift.height();
|
||||
},
|
||||
chargeFragment: (ctx: NetscriptContext) =>
|
||||
function (_rootX: unknown, _rootY: unknown): Promise<void> {
|
||||
chargeFragment: (ctx) => (_rootX, _rootY) => {
|
||||
//Get the fragment object using the given coordinates
|
||||
const rootX = helpers.number(ctx, "rootX", _rootX);
|
||||
const rootY = helpers.number(ctx, "rootY", _rootY);
|
||||
@ -58,28 +51,24 @@ export function NetscriptStanek(): InternalAPI<IStanek> {
|
||||
return Promise.resolve();
|
||||
});
|
||||
},
|
||||
fragmentDefinitions: (ctx: NetscriptContext) =>
|
||||
function (): IFragment[] {
|
||||
fragmentDefinitions: (ctx) => () => {
|
||||
checkStanekAPIAccess(ctx);
|
||||
helpers.log(ctx, () => `Returned ${Fragments.length} fragments`);
|
||||
return Fragments.map((f) => f.copy());
|
||||
},
|
||||
activeFragments: (ctx: NetscriptContext) =>
|
||||
function (): IActiveFragment[] {
|
||||
activeFragments: (ctx) => () => {
|
||||
checkStanekAPIAccess(ctx);
|
||||
helpers.log(ctx, () => `Returned ${staneksGift.fragments.length} fragments`);
|
||||
return staneksGift.fragments.map((af) => {
|
||||
return { ...af.copy(), ...af.fragment().copy() };
|
||||
});
|
||||
},
|
||||
clearGift: (ctx: NetscriptContext) =>
|
||||
function (): void {
|
||||
clearGift: (ctx) => () => {
|
||||
checkStanekAPIAccess(ctx);
|
||||
helpers.log(ctx, () => `Cleared Stanek's Gift.`);
|
||||
staneksGift.clear();
|
||||
},
|
||||
canPlaceFragment: (ctx: NetscriptContext) =>
|
||||
function (_rootX: unknown, _rootY: unknown, _rotation: unknown, _fragmentId: unknown): boolean {
|
||||
canPlaceFragment: (ctx) => (_rootX, _rootY, _rotation, _fragmentId) => {
|
||||
const rootX = helpers.number(ctx, "rootX", _rootX);
|
||||
const rootY = helpers.number(ctx, "rootY", _rootY);
|
||||
const rotation = helpers.number(ctx, "rotation", _rotation);
|
||||
@ -90,8 +79,7 @@ export function NetscriptStanek(): InternalAPI<IStanek> {
|
||||
const can = staneksGift.canPlace(rootX, rootY, rotation, fragment);
|
||||
return can;
|
||||
},
|
||||
placeFragment: (ctx: NetscriptContext) =>
|
||||
function (_rootX: unknown, _rootY: unknown, _rotation: unknown, _fragmentId: unknown): boolean {
|
||||
placeFragment: (ctx) => (_rootX, _rootY, _rotation, _fragmentId) => {
|
||||
const rootX = helpers.number(ctx, "rootX", _rootX);
|
||||
const rootY = helpers.number(ctx, "rootY", _rootY);
|
||||
const rotation = helpers.number(ctx, "rotation", _rotation);
|
||||
@ -101,8 +89,7 @@ export function NetscriptStanek(): InternalAPI<IStanek> {
|
||||
if (!fragment) throw helpers.makeRuntimeErrorMsg(ctx, `Invalid fragment id: ${fragmentId}`);
|
||||
return staneksGift.place(rootX, rootY, rotation, fragment);
|
||||
},
|
||||
getFragment: (ctx: NetscriptContext) =>
|
||||
function (_rootX: unknown, _rootY: unknown): IActiveFragment | undefined {
|
||||
getFragment: (ctx) => (_rootX, _rootY) => {
|
||||
const rootX = helpers.number(ctx, "rootX", _rootX);
|
||||
const rootY = helpers.number(ctx, "rootY", _rootY);
|
||||
checkStanekAPIAccess(ctx);
|
||||
@ -110,15 +97,13 @@ export function NetscriptStanek(): InternalAPI<IStanek> {
|
||||
if (fragment !== undefined) return fragment.copy();
|
||||
return undefined;
|
||||
},
|
||||
removeFragment: (ctx: NetscriptContext) =>
|
||||
function (_rootX: unknown, _rootY: unknown): boolean {
|
||||
removeFragment: (ctx) => (_rootX, _rootY) => {
|
||||
const rootX = helpers.number(ctx, "rootX", _rootX);
|
||||
const rootY = helpers.number(ctx, "rootY", _rootY);
|
||||
checkStanekAPIAccess(ctx);
|
||||
return staneksGift.delete(rootX, rootY);
|
||||
},
|
||||
acceptGift: (ctx: NetscriptContext) =>
|
||||
function (): boolean {
|
||||
acceptGift: (ctx) => () => {
|
||||
//Check if the player is eligible to join the church
|
||||
if (
|
||||
player.canAccessCotMG() &&
|
||||
|
@ -37,52 +37,44 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
};
|
||||
|
||||
return {
|
||||
hasWSEAccount: () => (): boolean => {
|
||||
hasWSEAccount: () => () => {
|
||||
return player.hasWseAccount;
|
||||
},
|
||||
hasTIXAPIAccess: () => (): boolean => {
|
||||
hasTIXAPIAccess: () => () => {
|
||||
return player.hasTixApiAccess;
|
||||
},
|
||||
has4SData: () => (): boolean => {
|
||||
has4SData: () => () => {
|
||||
return player.has4SData;
|
||||
},
|
||||
has4SDataTIXAPI: () => (): boolean => {
|
||||
has4SDataTIXAPI: () => () => {
|
||||
return player.has4SDataTixApi;
|
||||
},
|
||||
getSymbols: (ctx: NetscriptContext) => (): string[] => {
|
||||
getSymbols: (ctx) => () => {
|
||||
checkTixApiAccess(ctx);
|
||||
return Object.values(StockSymbols);
|
||||
},
|
||||
getPrice:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_symbol: unknown): number => {
|
||||
getPrice: (ctx) => (_symbol) => {
|
||||
const symbol = helpers.string(ctx, "symbol", _symbol);
|
||||
checkTixApiAccess(ctx);
|
||||
const stock = getStockFromSymbol(ctx, symbol);
|
||||
|
||||
return stock.price;
|
||||
},
|
||||
getAskPrice:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_symbol: unknown): number => {
|
||||
getAskPrice: (ctx) => (_symbol) => {
|
||||
const symbol = helpers.string(ctx, "symbol", _symbol);
|
||||
checkTixApiAccess(ctx);
|
||||
const stock = getStockFromSymbol(ctx, symbol);
|
||||
|
||||
return stock.getAskPrice();
|
||||
},
|
||||
getBidPrice:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_symbol: unknown): number => {
|
||||
getBidPrice: (ctx) => (_symbol) => {
|
||||
const symbol = helpers.string(ctx, "symbol", _symbol);
|
||||
checkTixApiAccess(ctx);
|
||||
const stock = getStockFromSymbol(ctx, symbol);
|
||||
|
||||
return stock.getBidPrice();
|
||||
},
|
||||
getPosition:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_symbol: unknown): [number, number, number, number] => {
|
||||
getPosition: (ctx) => (_symbol) => {
|
||||
const symbol = helpers.string(ctx, "symbol", _symbol);
|
||||
checkTixApiAccess(ctx);
|
||||
const stock = SymbolToStockMap[symbol];
|
||||
@ -91,18 +83,14 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
}
|
||||
return [stock.playerShares, stock.playerAvgPx, stock.playerShortShares, stock.playerAvgShortPx];
|
||||
},
|
||||
getMaxShares:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_symbol: unknown): number => {
|
||||
getMaxShares: (ctx) => (_symbol) => {
|
||||
const symbol = helpers.string(ctx, "symbol", _symbol);
|
||||
checkTixApiAccess(ctx);
|
||||
const stock = getStockFromSymbol(ctx, symbol);
|
||||
|
||||
return stock.maxShares;
|
||||
},
|
||||
getPurchaseCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_symbol: unknown, _shares: unknown, _posType: unknown): number => {
|
||||
getPurchaseCost: (ctx) => (_symbol, _shares, _posType) => {
|
||||
const symbol = helpers.string(ctx, "symbol", _symbol);
|
||||
let shares = helpers.number(ctx, "shares", _shares);
|
||||
const posType = helpers.string(ctx, "posType", _posType);
|
||||
@ -127,9 +115,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
|
||||
return res;
|
||||
},
|
||||
getSaleGain:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_symbol: unknown, _shares: unknown, _posType: unknown): number => {
|
||||
getSaleGain: (ctx) => (_symbol, _shares, _posType) => {
|
||||
const symbol = helpers.string(ctx, "symbol", _symbol);
|
||||
let shares = helpers.number(ctx, "shares", _shares);
|
||||
const posType = helpers.string(ctx, "posType", _posType);
|
||||
@ -154,9 +140,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
|
||||
return res;
|
||||
},
|
||||
buyStock:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_symbol: unknown, _shares: unknown): number => {
|
||||
buyStock: (ctx) => (_symbol, _shares) => {
|
||||
const symbol = helpers.string(ctx, "symbol", _symbol);
|
||||
const shares = helpers.number(ctx, "shares", _shares);
|
||||
checkTixApiAccess(ctx);
|
||||
@ -164,9 +148,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
const res = buyStock(stock, shares, ctx, {});
|
||||
return res ? stock.getAskPrice() : 0;
|
||||
},
|
||||
sellStock:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_symbol: unknown, _shares: unknown): number => {
|
||||
sellStock: (ctx) => (_symbol, _shares) => {
|
||||
const symbol = helpers.string(ctx, "symbol", _symbol);
|
||||
const shares = helpers.number(ctx, "shares", _shares);
|
||||
checkTixApiAccess(ctx);
|
||||
@ -175,9 +157,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
|
||||
return res ? stock.getBidPrice() : 0;
|
||||
},
|
||||
buyShort:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_symbol: unknown, _shares: unknown): number => {
|
||||
buyShort: (ctx) => (_symbol, _shares) => {
|
||||
const symbol = helpers.string(ctx, "symbol", _symbol);
|
||||
const shares = helpers.number(ctx, "shares", _shares);
|
||||
checkTixApiAccess(ctx);
|
||||
@ -194,9 +174,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
|
||||
return res ? stock.getBidPrice() : 0;
|
||||
},
|
||||
sellShort:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_symbol: unknown, _shares: unknown): number => {
|
||||
sellShort: (ctx) => (_symbol, _shares) => {
|
||||
const symbol = helpers.string(ctx, "symbol", _symbol);
|
||||
const shares = helpers.number(ctx, "shares", _shares);
|
||||
checkTixApiAccess(ctx);
|
||||
@ -213,9 +191,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
|
||||
return res ? stock.getAskPrice() : 0;
|
||||
},
|
||||
placeOrder:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_symbol: unknown, _shares: unknown, _price: unknown, _type: unknown, _pos: unknown): boolean => {
|
||||
placeOrder: (ctx) => (_symbol, _shares, _price, _type, _pos) => {
|
||||
const symbol = helpers.string(ctx, "symbol", _symbol);
|
||||
const shares = helpers.number(ctx, "shares", _shares);
|
||||
const price = helpers.number(ctx, "price", _price);
|
||||
@ -258,9 +234,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
|
||||
return placeOrder(stock, shares, price, orderType, orderPos, ctx);
|
||||
},
|
||||
cancelOrder:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_symbol: unknown, _shares: unknown, _price: unknown, _type: unknown, _pos: unknown): boolean => {
|
||||
cancelOrder: (ctx) => (_symbol, _shares, _price, _type, _pos) => {
|
||||
const symbol = helpers.string(ctx, "symbol", _symbol);
|
||||
const shares = helpers.number(ctx, "shares", _shares);
|
||||
const price = helpers.number(ctx, "price", _price);
|
||||
@ -314,7 +288,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
};
|
||||
return cancelOrder(params, ctx);
|
||||
},
|
||||
getOrders: (ctx: NetscriptContext) => (): StockOrder => {
|
||||
getOrders: (ctx) => () => {
|
||||
checkTixApiAccess(ctx);
|
||||
if (player.bitNodeN !== 8) {
|
||||
if (player.sourceFileLvl(8) <= 2) {
|
||||
@ -342,9 +316,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
|
||||
return orders;
|
||||
},
|
||||
getVolatility:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_symbol: unknown): number => {
|
||||
getVolatility: (ctx) => (_symbol) => {
|
||||
const symbol = helpers.string(ctx, "symbol", _symbol);
|
||||
if (!player.has4SDataTixApi) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, "You don't have 4S Market Data TIX API Access!");
|
||||
@ -353,9 +325,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
|
||||
return stock.mv / 100; // Convert from percentage to decimal
|
||||
},
|
||||
getForecast:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_symbol: unknown): number => {
|
||||
getForecast: (ctx) => (_symbol) => {
|
||||
const symbol = helpers.string(ctx, "symbol", _symbol);
|
||||
if (!player.has4SDataTixApi) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, "You don't have 4S Market Data TIX API Access!");
|
||||
@ -366,7 +336,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
stock.b ? (forecast += stock.otlkMag) : (forecast -= stock.otlkMag);
|
||||
return forecast / 100; // Convert from percentage to decimal
|
||||
},
|
||||
purchase4SMarketData: (ctx: NetscriptContext) => (): boolean => {
|
||||
purchase4SMarketData: (ctx) => () => {
|
||||
if (player.has4SData) {
|
||||
helpers.log(ctx, () => "Already purchased 4S Market Data.");
|
||||
return true;
|
||||
@ -382,7 +352,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
helpers.log(ctx, () => "Purchased 4S Market Data");
|
||||
return true;
|
||||
},
|
||||
purchase4SMarketDataTixApi: (ctx: NetscriptContext) => (): boolean => {
|
||||
purchase4SMarketDataTixApi: (ctx) => () => {
|
||||
checkTixApiAccess(ctx);
|
||||
|
||||
if (player.has4SDataTixApi) {
|
||||
@ -400,7 +370,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
helpers.log(ctx, () => "Purchased 4S Market Data TIX API");
|
||||
return true;
|
||||
},
|
||||
purchaseWseAccount: (ctx: NetscriptContext) => (): boolean => {
|
||||
purchaseWseAccount: (ctx) => () => {
|
||||
if (player.hasWseAccount) {
|
||||
helpers.log(ctx, () => "Already purchased WSE Account");
|
||||
return true;
|
||||
@ -417,7 +387,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
helpers.log(ctx, () => "Purchased WSE Account Access");
|
||||
return true;
|
||||
},
|
||||
purchaseTixApi: (ctx: NetscriptContext) => (): boolean => {
|
||||
purchaseTixApi: (ctx) => () => {
|
||||
if (player.hasTixApiAccess) {
|
||||
helpers.log(ctx, () => "Already purchased TIX API");
|
||||
return true;
|
||||
|
@ -1,38 +1,34 @@
|
||||
import {
|
||||
GameInfo,
|
||||
IStyleSettings,
|
||||
UserInterface as IUserInterface,
|
||||
UserInterfaceTheme,
|
||||
} from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { UserInterface as IUserInterface } from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { Settings } from "../Settings/Settings";
|
||||
import { ThemeEvents } from "../Themes/ui/Theme";
|
||||
import { defaultTheme } from "../Themes/Themes";
|
||||
import { defaultStyles } from "../Themes/Styles";
|
||||
import { CONSTANTS } from "../Constants";
|
||||
import { hash } from "../hash/hash";
|
||||
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
||||
import { InternalAPI } from "../Netscript/APIWrapper";
|
||||
import { Terminal } from "../../src/Terminal";
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
import { helpers, assertObjectType } from "../Netscript/NetscriptHelpers";
|
||||
|
||||
export function NetscriptUserInterface(): InternalAPI<IUserInterface> {
|
||||
return {
|
||||
windowSize: () => (): [number, number] => {
|
||||
windowSize: () => () => {
|
||||
return [window.innerWidth, window.innerHeight];
|
||||
},
|
||||
getTheme: () => (): UserInterfaceTheme => {
|
||||
getTheme: () => () => {
|
||||
return { ...Settings.theme };
|
||||
},
|
||||
|
||||
getStyles: () => (): IStyleSettings => {
|
||||
getStyles: () => () => {
|
||||
return { ...Settings.styles };
|
||||
},
|
||||
|
||||
setTheme:
|
||||
(ctx: NetscriptContext) =>
|
||||
(newTheme: UserInterfaceTheme): void => {
|
||||
setTheme: (ctx) => (newTheme) => {
|
||||
const themeValidator: Record<string, string | undefined> = {};
|
||||
assertObjectType(ctx, "newTheme", newTheme, themeValidator);
|
||||
const hex = /^(#)((?:[A-Fa-f0-9]{2}){3,4}|(?:[A-Fa-f0-9]{3}))$/;
|
||||
const currentTheme = { ...Settings.theme };
|
||||
const errors: string[] = [];
|
||||
if (typeof newTheme !== "object")
|
||||
for (const key of Object.keys(newTheme)) {
|
||||
if (!currentTheme[key]) {
|
||||
// Invalid key
|
||||
@ -53,9 +49,9 @@ export function NetscriptUserInterface(): InternalAPI<IUserInterface> {
|
||||
}
|
||||
},
|
||||
|
||||
setStyles:
|
||||
(ctx: NetscriptContext) =>
|
||||
(newStyles: IStyleSettings): void => {
|
||||
setStyles: (ctx) => (newStyles) => {
|
||||
const styleValidator: Record<string, string | number | undefined> = {};
|
||||
assertObjectType(ctx, "newStyles", newStyles, styleValidator);
|
||||
const currentStyles = { ...Settings.styles };
|
||||
const errors: string[] = [];
|
||||
for (const key of Object.keys(newStyles)) {
|
||||
@ -63,7 +59,7 @@ export function NetscriptUserInterface(): InternalAPI<IUserInterface> {
|
||||
// Invalid key
|
||||
errors.push(`Invalid key "${key}"`);
|
||||
} else {
|
||||
(currentStyles as any)[key] = (newStyles as any)[key];
|
||||
(currentStyles as any)[key] = newStyles[key];
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,19 +72,19 @@ export function NetscriptUserInterface(): InternalAPI<IUserInterface> {
|
||||
}
|
||||
},
|
||||
|
||||
resetTheme: (ctx: NetscriptContext) => (): void => {
|
||||
resetTheme: (ctx) => () => {
|
||||
Settings.theme = { ...defaultTheme };
|
||||
ThemeEvents.emit();
|
||||
helpers.log(ctx, () => `Reinitialized theme to default`);
|
||||
},
|
||||
|
||||
resetStyles: (ctx: NetscriptContext) => (): void => {
|
||||
resetStyles: (ctx) => () => {
|
||||
Settings.styles = { ...defaultStyles };
|
||||
ThemeEvents.emit();
|
||||
helpers.log(ctx, () => `Reinitialized styles to default`);
|
||||
},
|
||||
|
||||
getGameInfo: () => (): GameInfo => {
|
||||
getGameInfo: () => () => {
|
||||
const version = CONSTANTS.VersionString;
|
||||
const commit = hash();
|
||||
const platform = navigator.userAgent.toLowerCase().indexOf(" electron/") > -1 ? "Steam" : "Browser";
|
||||
@ -102,7 +98,7 @@ export function NetscriptUserInterface(): InternalAPI<IUserInterface> {
|
||||
return gameInfo;
|
||||
},
|
||||
|
||||
clearTerminal: (ctx: NetscriptContext) => (): void => {
|
||||
clearTerminal: (ctx) => () => {
|
||||
helpers.log(ctx, () => `Clearing terminal`);
|
||||
Terminal.clear();
|
||||
},
|
||||
|
@ -1,28 +1,39 @@
|
||||
import { Settings } from "./Settings/Settings";
|
||||
|
||||
type PortData = string | number;
|
||||
export interface IPort {
|
||||
write: (value: unknown) => unknown;
|
||||
write: (value: unknown) => PortData | null;
|
||||
tryWrite: (value: unknown) => boolean;
|
||||
read: () => unknown;
|
||||
peek: () => unknown;
|
||||
read: () => PortData;
|
||||
peek: () => PortData;
|
||||
full: () => boolean;
|
||||
empty: () => boolean;
|
||||
clear: () => void;
|
||||
}
|
||||
|
||||
export function NetscriptPort(): IPort {
|
||||
const data: unknown[] = [];
|
||||
const data: PortData[] = [];
|
||||
|
||||
return {
|
||||
write: (value: unknown): unknown => {
|
||||
write: (value) => {
|
||||
if (typeof value !== "number" && typeof value !== "string") {
|
||||
throw new Error(
|
||||
`port.write: Tried to write type ${typeof value}. Only string and number types may be written to ports.`,
|
||||
);
|
||||
}
|
||||
data.push(value);
|
||||
if (data.length > Settings.MaxPortCapacity) {
|
||||
return data.shift();
|
||||
return data.shift() as PortData;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
tryWrite: (value: unknown): boolean => {
|
||||
tryWrite: (value) => {
|
||||
if (typeof value != "number" && typeof value != "string") {
|
||||
throw new Error(
|
||||
`port.write: Tried to write type ${typeof value}. Only string and number types may be written to ports.`,
|
||||
);
|
||||
}
|
||||
if (data.length >= Settings.MaxPortCapacity) {
|
||||
return false;
|
||||
}
|
||||
@ -30,31 +41,25 @@ export function NetscriptPort(): IPort {
|
||||
return true;
|
||||
},
|
||||
|
||||
read: (): unknown => {
|
||||
if (data.length === 0) {
|
||||
return "NULL PORT DATA";
|
||||
}
|
||||
return data.shift();
|
||||
read: () => {
|
||||
if (data.length === 0) return "NULL PORT DATA";
|
||||
return data.shift() as PortData;
|
||||
},
|
||||
|
||||
peek: (): unknown => {
|
||||
if (data.length === 0) {
|
||||
return "NULL PORT DATA";
|
||||
} else {
|
||||
const foo = data.slice();
|
||||
return foo[0];
|
||||
}
|
||||
peek: () => {
|
||||
if (data.length === 0) return "NULL PORT DATA";
|
||||
return data[0];
|
||||
},
|
||||
|
||||
full: (): boolean => {
|
||||
full: () => {
|
||||
return data.length == Settings.MaxPortCapacity;
|
||||
},
|
||||
|
||||
empty: (): boolean => {
|
||||
empty: () => {
|
||||
return data.length === 0;
|
||||
},
|
||||
|
||||
clear: (): void => {
|
||||
clear: () => {
|
||||
data.length = 0;
|
||||
},
|
||||
};
|
||||
|
6
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
6
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -961,7 +961,7 @@ export interface NetscriptPort {
|
||||
*
|
||||
* @returns The data popped off the queue if it was full.
|
||||
*/
|
||||
write(value: string | number): null | string | number;
|
||||
write(value: string | number): PortData | null;
|
||||
|
||||
/**
|
||||
* Attempt to write data to the port.
|
||||
@ -981,7 +981,7 @@ export interface NetscriptPort {
|
||||
* If the port is empty, then the string “NULL PORT DATA” will be returned.
|
||||
* @returns the data read.
|
||||
*/
|
||||
read(): string | number;
|
||||
read(): PortData;
|
||||
|
||||
/**
|
||||
* Retrieve the first element from the port without removing it.
|
||||
@ -993,7 +993,7 @@ export interface NetscriptPort {
|
||||
* the port is empty, the string “NULL PORT DATA” will be returned.
|
||||
* @returns the data read
|
||||
*/
|
||||
peek(): string | number;
|
||||
peek(): PortData;
|
||||
|
||||
/**
|
||||
* Check if the port is full.
|
||||
|
@ -1,3 +1,2 @@
|
||||
import { Terminal as TTerminal } from "./Terminal/Terminal";
|
||||
|
||||
export const Terminal = new TTerminal();
|
||||
|
@ -1,4 +1,4 @@
|
||||
// This works for both enums and regular objects.
|
||||
/** Verifies that a supplied value is a member of the provided object/enum. Works for enums as well as enum-like objects (const {} as const). */
|
||||
export function checkEnum<T extends Record<string, unknown>>(obj: T, value: unknown): value is T[keyof T] {
|
||||
return Object.values(obj).includes(value);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user