mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 14:28:36 +02:00
* Types for InternalFunction and ExternalFunction have been modified to actually typecheck ns functions against docs. * Internal functions are required to use unknown for any params on the inner function. * Return types for internal function inner-function must match the respective external function. * Added new typecheck assertion function for asserting dynamic object types, to allow unknownifying params that were previously hardcoded objec structures. * Because type assertion for parameter types and return types is enforced by InternalAPI, removed all duplicate type declarations on NetscriptFunction params and returns.
55 lines
2.6 KiB
TypeScript
55 lines
2.6 KiB
TypeScript
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";
|
|
import {
|
|
calculateInfiltratorsRepReward,
|
|
calculateSellInformationCashReward,
|
|
calculateTradeInformationRepReward,
|
|
} from "../Infiltration/formulas/victory";
|
|
import { FactionNames } from "../Faction/data/FactionNames";
|
|
import { Factions } from "../Faction/Factions";
|
|
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
|
import { checkEnum } from "../utils/helpers/checkEnum";
|
|
import { LocationName } from "../Locations/data/LocationNames";
|
|
import { helpers } from "../Netscript/NetscriptHelpers";
|
|
|
|
export function NetscriptInfiltration(): InternalAPI<IInfiltration> {
|
|
const getLocationsWithInfiltrations = Object.values(Locations).filter(
|
|
(location: Location) => location.infiltrationData,
|
|
);
|
|
|
|
const calculateInfiltrationData = (ctx: NetscriptContext, locationName: string): InfiltrationLocation => {
|
|
if (!checkEnum(LocationName, locationName)) throw new Error(`Location '${locationName}' does not exists.`);
|
|
const location = Locations[locationName];
|
|
if (location === undefined) throw helpers.makeRuntimeErrorMsg(ctx, `Location '${location}' does not exists.`);
|
|
if (location.infiltrationData === undefined)
|
|
throw helpers.makeRuntimeErrorMsg(ctx, `Location '${location}' does not provide infiltrations.`);
|
|
const startingSecurityLevel = location.infiltrationData.startingSecurityLevel;
|
|
const difficulty = calculateDifficulty(startingSecurityLevel);
|
|
const reward = calculateReward(startingSecurityLevel);
|
|
const maxLevel = location.infiltrationData.maxClearanceLevel;
|
|
return {
|
|
location: JSON.parse(JSON.stringify(location)),
|
|
reward: {
|
|
tradeRep: calculateTradeInformationRepReward(reward, maxLevel, startingSecurityLevel),
|
|
sellCash: calculateSellInformationCashReward(reward, maxLevel, startingSecurityLevel),
|
|
SoARep: calculateInfiltratorsRepReward(Factions[FactionNames.ShadowsOfAnarchy], startingSecurityLevel),
|
|
},
|
|
difficulty: difficulty,
|
|
};
|
|
};
|
|
return {
|
|
getPossibleLocations: () => () => {
|
|
return getLocationsWithInfiltrations.map((l) => ({
|
|
city: l.city ?? "",
|
|
name: String(l.name),
|
|
}));
|
|
},
|
|
getInfiltration: (ctx) => (_location) => {
|
|
const location = helpers.string(ctx, "location", _location);
|
|
return calculateInfiltrationData(ctx, location);
|
|
},
|
|
};
|
|
}
|