diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index 9485a7cc4..923d837a5 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -528,7 +528,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { const sleeve = NetscriptSleeve(Player, workerScript, helper); const extra = NetscriptExtra(Player, workerScript, helper); const hacknet = NetscriptHacknet(Player, workerScript, helper); - const infiltration = NetscriptInfiltration(Player, workerScript, helper); + const infiltration = wrapAPI(helper, {}, workerScript, NetscriptInfiltration(Player), "infiltration") + .infiltration as unknown as IInfiltration; const stanek = wrapAPI(helper, {}, workerScript, NetscriptStanek(Player, workerScript, helper), "stanek") .stanek as unknown as IStanek; const bladeburner = NetscriptBladeburner(Player, workerScript, helper); diff --git a/src/NetscriptFunctions/Infiltration.ts b/src/NetscriptFunctions/Infiltration.ts index 25a85271f..8fe7f7c50 100644 --- a/src/NetscriptFunctions/Infiltration.ts +++ b/src/NetscriptFunctions/Infiltration.ts @@ -18,28 +18,21 @@ import { } 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"; -export function NetscriptInfiltration( - player: IPlayer, - workerScript: WorkerScript, - helper: INetscriptHelper, -): IInfiltration { +export function NetscriptInfiltration(player: IPlayer): InternalAPI { const getLocationsWithInfiltrations = Object.values(Locations).filter( (location: Location) => location.infiltrationData, ); - const calculateInfiltrationData = (location: Location | undefined): InfiltrationLocation => { - if (location === undefined) - throw helper.makeRuntimeErrorMsg( - `infiltration.calculateReward`, - "The provided location does not exist or does not provide infiltrations", - ); - + 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 ctx.makeRuntimeErrorMsg(`Location '${location}' does not exists.`); if (location.infiltrationData === undefined) - throw helper.makeRuntimeErrorMsg( - `infiltration.calculateReward`, - "The provided location does not exist or does not provide infiltrations", - ); + throw ctx.makeRuntimeErrorMsg(`Location '${location}' does not provide infiltrations.`); const startingSecurityLevel = location.infiltrationData.startingSecurityLevel; const difficulty = calculateDifficulty(player, startingSecurityLevel); const reward = calculateReward(player, startingSecurityLevel); @@ -49,29 +42,20 @@ export function NetscriptInfiltration( reward: { tradeRep: calculateTradeInformationRepReward(player, reward, maxLevel, difficulty), sellCash: calculateSellInformationCashReward(player, reward, maxLevel, difficulty), - infiltratorRep: calculateInfiltratorsRepReward(player, Factions[FactionNames.ShadowsOfAnarchy], difficulty), + SoARep: calculateInfiltratorsRepReward(player, Factions[FactionNames.ShadowsOfAnarchy], difficulty), }, difficulty: difficulty, }; }; return { - calculateDifficulty: function (locationName: string): number { - const location = getLocationsWithInfiltrations.find((infilLocation) => infilLocation.name === locationName); - helper.updateDynamicRam("calculateDifficulty", getRamCost(player, "infiltration", "calculateDifficulty")); - return calculateInfiltrationData(location).difficulty; - }, - calculateRewards: function (locationName: string): InfiltrationReward { - const location = getLocationsWithInfiltrations.find((infilLocation) => infilLocation.name === locationName); - helper.updateDynamicRam("calculateReward", getRamCost(player, "infiltration", "calculateReward")); - return calculateInfiltrationData(location).reward; - }, - getLocations: function (): Location[] { - helper.updateDynamicRam("getLocations", getRamCost(player, "infiltration", "getLocations")); - return getLocationsWithInfiltrations; - }, - getInfiltrations: function (): InfiltrationLocation[] { - helper.updateDynamicRam("getInfiltrations", getRamCost(player, "infiltration", "getInfiltrations")); - return getLocationsWithInfiltrations.map(calculateInfiltrationData); + getPossibleLocations: () => (): string[] => { + return getLocationsWithInfiltrations.map((l) => l + ""); }, + getInfiltration: + (ctx: NetscriptContext) => + (_location: unknown): InfiltrationLocation => { + const location = ctx.helper.string("location", _location); + return calculateInfiltrationData(ctx, location); + }, }; } diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 3847f1fc2..6801bea07 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -4276,7 +4276,7 @@ interface Stanek { export interface InfiltrationReward { tradeRep: number; sellCash: number; - infiltratorRep: number; + SoARep: number; } export interface InfiltrationLocation { @@ -4290,24 +4290,6 @@ export interface InfiltrationLocation { * @public */ interface Infiltration { - /** - * Calculate the difficulty of performing an infiltration. - * @remarks - * RAM cost: 2.5 GB - * - * @param locationName - name of the location to check. - * @returns the difficulty. - */ - calculateDifficulty(locationName: string): number; - /** - * Calculate the rewards for trading and selling information for completing an infiltration. - * @remarks - * RAM cost: 2.5 GB - * - * @param locationName - name of the location to check. - * @returns the trade reputation, sell cash and infiltrators rep reward. - */ - calculateRewards(locationName: string): InfiltrationReward; /** * Get all locations that can be infiltrated. * @remarks @@ -4315,15 +4297,15 @@ interface Infiltration { * * @returns all locations that can be infiltrated. */ - getLocations(): any[]; + getPossibleLocations(): string[]; /** * Get all infiltrations with difficulty, location and rewards. * @remarks * RAM cost: 15 GB * - * @returns all infiltrations with difficulty, location and rewards. + * @returns Infiltration data for given location. */ - getInfiltrations(): InfiltrationLocation[]; + getInfiltration(location: string): InfiltrationLocation; } /**