Wrap Singularity API with wrapper

also refactored the RamCosts IMap as it didnt quite work properly due to
how the wrapper calculates function names
This commit is contained in:
TheMas3212
2022-04-12 16:51:10 +10:00
parent 2d74b493ee
commit b2689eaa5a
4 changed files with 1405 additions and 1380 deletions

View File

@ -4,6 +4,7 @@ import type { BaseServer } from "../Server/BaseServer";
import type { WorkerScript } from "./WorkerScript";
import { makeRuntimeRejectMsg } from "../NetscriptEvaluator";
import { Player } from "../Player";
import { CityName } from "src/Locations/data/CityNames";
type ExternalFunction = (...args: any[]) => any;
type ExternalAPI = {
@ -37,6 +38,7 @@ type NetscriptHelpers = {
makeRuntimeErrorMsg: (caller: string, msg: string) => string;
string: (funcName: string, argName: string, v: unknown) => string;
number: (funcName: string, argName: string, v: unknown) => number;
city: (funcName: string, argName: string, v: unknown) => CityName;
boolean: (v: unknown) => boolean;
getServer: (hostname: string, callingFnName: string) => BaseServer;
checkSingularityAccess: (func: string) => void;
@ -48,6 +50,7 @@ type WrappedNetscriptHelpers = {
makeRuntimeErrorMsg: (msg: string) => string;
string: (argName: string, v: unknown) => string;
number: (argName: string, v: unknown) => number;
city: (argName: string, v: unknown) => CityName;
boolean: (v: unknown) => boolean;
getServer: (hostname: string) => BaseServer;
checkSingularityAccess: () => void;
@ -80,6 +83,7 @@ function wrapFunction(
makeRuntimeErrorMsg: (msg: string) => helpers.makeRuntimeErrorMsg(functionPath, msg),
string: (argName: string, v: unknown) => helpers.string(functionPath, argName, v),
number: (argName: string, v: unknown) => helpers.number(functionPath, argName, v),
city: (argName: string, v: unknown) => helpers.city(functionPath, argName, v),
boolean: helpers.boolean,
getServer: (hostname: string) => helpers.getServer(hostname, functionPath),
checkSingularityAccess: () => helpers.checkSingularityAccess(functionName),

View File

@ -81,8 +81,8 @@ function SF4Cost(cost: number): (player: IPlayer) => number {
};
}
export const RamCosts: IMap<any> = {
hacknet: {
// Hacknet API
const hacknet: IMap<any> = {
numNodes: 0,
purchaseNode: 0,
getPurchaseNodeCost: 0,
@ -98,7 +98,222 @@ export const RamCosts: IMap<any> = {
numHashes: 0,
hashCost: 0,
spendHashes: 0,
},
};
// Stock API
const stock: IMap<any> = {
getSymbols: RamCostConstants.ScriptGetStockRamCost,
getPrice: RamCostConstants.ScriptGetStockRamCost,
getAskPrice: RamCostConstants.ScriptGetStockRamCost,
getBidPrice: RamCostConstants.ScriptGetStockRamCost,
getPosition: RamCostConstants.ScriptGetStockRamCost,
getMaxShares: RamCostConstants.ScriptGetStockRamCost,
getPurchaseCost: RamCostConstants.ScriptGetStockRamCost,
getSaleGain: RamCostConstants.ScriptGetStockRamCost,
buy: RamCostConstants.ScriptBuySellStockRamCost,
sell: RamCostConstants.ScriptBuySellStockRamCost,
short: RamCostConstants.ScriptBuySellStockRamCost,
sellShort: RamCostConstants.ScriptBuySellStockRamCost,
placeOrder: RamCostConstants.ScriptBuySellStockRamCost,
cancelOrder: RamCostConstants.ScriptBuySellStockRamCost,
getOrders: RamCostConstants.ScriptBuySellStockRamCost,
getVolatility: RamCostConstants.ScriptBuySellStockRamCost,
getForecast: RamCostConstants.ScriptBuySellStockRamCost,
purchase4SMarketData: RamCostConstants.ScriptBuySellStockRamCost,
purchase4SMarketDataTixApi: RamCostConstants.ScriptBuySellStockRamCost,
purchaseWseAccount: RamCostConstants.ScriptBuySellStockRamCost,
purchaseTixApi: RamCostConstants.ScriptBuySellStockRamCost,
};
// Singularity API
const singularity: IMap<any> = {
universityCourse: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
gymWorkout: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
travelToCity: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
goToLocation: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
purchaseTor: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
purchaseProgram: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
getCurrentServer: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
connect: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
manualHack: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
installBackdoor: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
getDarkwebProgramCost: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 4),
getDarkwebPrograms: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 4),
getStats: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 4),
getCharacterInformation: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 4),
hospitalize: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 4),
isBusy: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 4),
stopAction: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 2),
upgradeHomeRam: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost),
upgradeHomeCores: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost),
getUpgradeHomeRamCost: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 2),
getUpgradeHomeCoresCost: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 2),
workForCompany: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost),
applyToCompany: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost),
getCompanyRep: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 3),
getCompanyFavor: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 3),
getCompanyFavorGain: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 4),
checkFactionInvitations: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost),
joinFaction: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost),
workForFaction: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost),
getFactionRep: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 3),
getFactionFavor: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 3),
getFactionFavorGain: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 4),
donateToFaction: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
createProgram: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
commitCrime: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
getCrimeChance: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
getCrimeStats: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
getOwnedAugmentations: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
getAugmentationsFromFaction: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
getAugmentationCost: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
getAugmentationPrereq: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
getAugmentationPrice: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost / 2),
getAugmentationRepReq: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost / 2),
getAugmentationStats: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
purchaseAugmentation: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
softReset: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
installAugmentations: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
isFocused: SF4Cost(0.1),
setFocus: SF4Cost(0.1),
};
// Gang API
const gang: IMap<any> = {
createGang: RamCostConstants.ScriptGangApiBaseRamCost / 4,
inGang: RamCostConstants.ScriptGangApiBaseRamCost / 4,
getMemberNames: RamCostConstants.ScriptGangApiBaseRamCost / 4,
getGangInformation: RamCostConstants.ScriptGangApiBaseRamCost / 2,
getOtherGangInformation: RamCostConstants.ScriptGangApiBaseRamCost / 2,
getMemberInformation: RamCostConstants.ScriptGangApiBaseRamCost / 2,
canRecruitMember: RamCostConstants.ScriptGangApiBaseRamCost / 4,
recruitMember: RamCostConstants.ScriptGangApiBaseRamCost / 2,
getTaskNames: RamCostConstants.ScriptGangApiBaseRamCost / 4,
getTaskStats: RamCostConstants.ScriptGangApiBaseRamCost / 4,
setMemberTask: RamCostConstants.ScriptGangApiBaseRamCost / 2,
getEquipmentNames: RamCostConstants.ScriptGangApiBaseRamCost / 4,
getEquipmentCost: RamCostConstants.ScriptGangApiBaseRamCost / 2,
getEquipmentType: RamCostConstants.ScriptGangApiBaseRamCost / 2,
getEquipmentStats: RamCostConstants.ScriptGangApiBaseRamCost / 2,
purchaseEquipment: RamCostConstants.ScriptGangApiBaseRamCost,
ascendMember: RamCostConstants.ScriptGangApiBaseRamCost,
getAscensionResult: RamCostConstants.ScriptGangApiBaseRamCost / 2,
setTerritoryWarfare: RamCostConstants.ScriptGangApiBaseRamCost / 2,
getChanceToWinClash: RamCostConstants.ScriptGangApiBaseRamCost,
getBonusTime: 0,
};
// Bladeburner API
const bladeburner: IMap<any> = {
getContractNames: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 10,
getOperationNames: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 10,
getBlackOpNames: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 10,
getBlackOpRank: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 2,
getGeneralActionNames: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 10,
getSkillNames: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 10,
startAction: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
stopBladeburnerAction: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 2,
getCurrentAction: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 4,
getActionTime: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getActionEstimatedSuccessChance: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getActionRepGain: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getActionCountRemaining: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getActionMaxLevel: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getActionCurrentLevel: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getActionAutolevel: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
setActionAutolevel: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
setActionLevel: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getRank: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getSkillPoints: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getSkillLevel: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getSkillUpgradeCost: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
upgradeSkill: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getTeamSize: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
setTeamSize: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getCityEstimatedPopulation: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getCityCommunities: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getCityChaos: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getCity: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
switchCity: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getStamina: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
joinBladeburnerFaction: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
joinBladeburnerDivision: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getBonusTime: 0,
};
// Coding Contract API
const codingcontract: IMap<any> = {
attempt: RamCostConstants.ScriptCodingContractBaseRamCost,
getContractType: RamCostConstants.ScriptCodingContractBaseRamCost / 2,
getData: RamCostConstants.ScriptCodingContractBaseRamCost / 2,
getDescription: RamCostConstants.ScriptCodingContractBaseRamCost / 2,
getNumTriesRemaining: RamCostConstants.ScriptCodingContractBaseRamCost / 5,
};
// Duplicate Sleeve API
const sleeve: IMap<any> = {
getNumSleeves: RamCostConstants.ScriptSleeveBaseRamCost,
setToShockRecovery: RamCostConstants.ScriptSleeveBaseRamCost,
setToSynchronize: RamCostConstants.ScriptSleeveBaseRamCost,
setToCommitCrime: RamCostConstants.ScriptSleeveBaseRamCost,
setToUniversityCourse: RamCostConstants.ScriptSleeveBaseRamCost,
travel: RamCostConstants.ScriptSleeveBaseRamCost,
setToCompanyWork: RamCostConstants.ScriptSleeveBaseRamCost,
setToFactionWork: RamCostConstants.ScriptSleeveBaseRamCost,
setToGymWorkout: RamCostConstants.ScriptSleeveBaseRamCost,
getSleeveStats: RamCostConstants.ScriptSleeveBaseRamCost,
getTask: RamCostConstants.ScriptSleeveBaseRamCost,
getInformation: RamCostConstants.ScriptSleeveBaseRamCost,
getSleeveAugmentations: RamCostConstants.ScriptSleeveBaseRamCost,
getSleevePurchasableAugs: RamCostConstants.ScriptSleeveBaseRamCost,
purchaseSleeveAug: RamCostConstants.ScriptSleeveBaseRamCost,
};
// Stanek API
const stanek: IMap<any> = {
giftWidth: RamCostConstants.ScriptStanekWidth,
giftHeight: RamCostConstants.ScriptStanekHeight,
chargeFragment: RamCostConstants.ScriptStanekCharge,
fragmentDefinitions: RamCostConstants.ScriptStanekFragmentDefinitions,
activeFragments: RamCostConstants.ScriptStanekPlacedFragments,
clearGift: RamCostConstants.ScriptStanekClear,
canPlaceFragment: RamCostConstants.ScriptStanekCanPlace,
placeFragment: RamCostConstants.ScriptStanekPlace,
getFragment: RamCostConstants.ScriptStanekFragmentAt,
removeFragment: RamCostConstants.ScriptStanekDeleteAt,
};
// UI API
const ui: IMap<any> = {
getTheme: 0,
setTheme: 0,
resetTheme: 0,
getStyles: 0,
setStyles: 0,
resetStyles: 0,
getGameInfo: 0,
};
// Grafting API
const grafting: IMap<any> = {
getAugmentationGraftPrice: 3.75,
getAugmentationGraftTime: 3.75,
graftAugmentation: 7.5,
};
export const RamCosts: IMap<any> = {
hacknet,
stock,
singularity,
...singularity, // singularity is in namespace & toplevel
gang,
bladeburner,
codingcontract,
sleeve,
stanek,
ui,
grafting,
sprintf: 0,
vsprintf: 0,
scan: RamCostConstants.ScriptScanRamCost,
@ -162,29 +377,6 @@ export const RamCosts: IMap<any> = {
serverExists: RamCostConstants.ScriptGetServerRamCost,
fileExists: RamCostConstants.ScriptFileExistsRamCost,
isRunning: RamCostConstants.ScriptIsRunningRamCost,
stock: {
getSymbols: RamCostConstants.ScriptGetStockRamCost,
getPrice: RamCostConstants.ScriptGetStockRamCost,
getAskPrice: RamCostConstants.ScriptGetStockRamCost,
getBidPrice: RamCostConstants.ScriptGetStockRamCost,
getPosition: RamCostConstants.ScriptGetStockRamCost,
getMaxShares: RamCostConstants.ScriptGetStockRamCost,
getPurchaseCost: RamCostConstants.ScriptGetStockRamCost,
getSaleGain: RamCostConstants.ScriptGetStockRamCost,
buy: RamCostConstants.ScriptBuySellStockRamCost,
sell: RamCostConstants.ScriptBuySellStockRamCost,
short: RamCostConstants.ScriptBuySellStockRamCost,
sellShort: RamCostConstants.ScriptBuySellStockRamCost,
placeOrder: RamCostConstants.ScriptBuySellStockRamCost,
cancelOrder: RamCostConstants.ScriptBuySellStockRamCost,
getOrders: RamCostConstants.ScriptBuySellStockRamCost,
getVolatility: RamCostConstants.ScriptBuySellStockRamCost,
getForecast: RamCostConstants.ScriptBuySellStockRamCost,
purchase4SMarketData: RamCostConstants.ScriptBuySellStockRamCost,
purchase4SMarketDataTixApi: RamCostConstants.ScriptBuySellStockRamCost,
purchaseWseAccount: RamCostConstants.ScriptBuySellStockRamCost,
purchaseTixApi: RamCostConstants.ScriptBuySellStockRamCost,
},
getPurchasedServerLimit: RamCostConstants.ScriptGetPurchasedServerLimit,
getPurchasedServerMaxRam: RamCostConstants.ScriptGetPurchasedServerMaxRam,
getPurchasedServerCost: RamCostConstants.ScriptGetPurchaseServerRamCost,
@ -221,178 +413,6 @@ export const RamCosts: IMap<any> = {
getOwnedSourceFiles: RamCostConstants.ScriptGetOwnedSourceFiles,
tail: 0,
toast: 0,
// Singularity Functions
universityCourse: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
gymWorkout: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
travelToCity: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
goToLocation: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
purchaseTor: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
purchaseProgram: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
getCurrentServer: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
connect: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
manualHack: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
installBackdoor: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
getDarkwebProgramCost: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 4),
getDarkwebPrograms: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 4),
getStats: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 4),
getCharacterInformation: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 4),
hospitalize: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 4),
isBusy: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 4),
stopAction: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 2),
upgradeHomeRam: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost),
upgradeHomeCores: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost),
getUpgradeHomeRamCost: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 2),
getUpgradeHomeCoresCost: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 2),
workForCompany: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost),
applyToCompany: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost),
getCompanyRep: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 3),
getCompanyFavor: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 3),
getCompanyFavorGain: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 4),
checkFactionInvitations: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost),
joinFaction: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost),
workForFaction: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost),
getFactionRep: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 3),
getFactionFavor: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 3),
getFactionFavorGain: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 4),
donateToFaction: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
createProgram: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
commitCrime: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
getCrimeChance: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
getCrimeStats: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
getOwnedAugmentations: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
getAugmentationsFromFaction: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
getAugmentationCost: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
getAugmentationPrereq: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
getAugmentationPrice: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost / 2),
getAugmentationRepReq: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost / 2),
getAugmentationStats: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
purchaseAugmentation: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
softReset: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
installAugmentations: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
isFocused: SF4Cost(0.1),
setFocus: SF4Cost(0.1),
// Gang API
gang: {
createGang: RamCostConstants.ScriptGangApiBaseRamCost / 4,
inGang: RamCostConstants.ScriptGangApiBaseRamCost / 4,
getMemberNames: RamCostConstants.ScriptGangApiBaseRamCost / 4,
getGangInformation: RamCostConstants.ScriptGangApiBaseRamCost / 2,
getOtherGangInformation: RamCostConstants.ScriptGangApiBaseRamCost / 2,
getMemberInformation: RamCostConstants.ScriptGangApiBaseRamCost / 2,
canRecruitMember: RamCostConstants.ScriptGangApiBaseRamCost / 4,
recruitMember: RamCostConstants.ScriptGangApiBaseRamCost / 2,
getTaskNames: RamCostConstants.ScriptGangApiBaseRamCost / 4,
getTaskStats: RamCostConstants.ScriptGangApiBaseRamCost / 4,
setMemberTask: RamCostConstants.ScriptGangApiBaseRamCost / 2,
getEquipmentNames: RamCostConstants.ScriptGangApiBaseRamCost / 4,
getEquipmentCost: RamCostConstants.ScriptGangApiBaseRamCost / 2,
getEquipmentType: RamCostConstants.ScriptGangApiBaseRamCost / 2,
getEquipmentStats: RamCostConstants.ScriptGangApiBaseRamCost / 2,
purchaseEquipment: RamCostConstants.ScriptGangApiBaseRamCost,
ascendMember: RamCostConstants.ScriptGangApiBaseRamCost,
getAscensionResult: RamCostConstants.ScriptGangApiBaseRamCost / 2,
setTerritoryWarfare: RamCostConstants.ScriptGangApiBaseRamCost / 2,
getChanceToWinClash: RamCostConstants.ScriptGangApiBaseRamCost,
getBonusTime: 0,
},
// Bladeburner API
bladeburner: {
getContractNames: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 10,
getOperationNames: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 10,
getBlackOpNames: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 10,
getBlackOpRank: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 2,
getGeneralActionNames: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 10,
getSkillNames: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 10,
startAction: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
stopBladeburnerAction: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 2,
getCurrentAction: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 4,
getActionTime: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getActionEstimatedSuccessChance: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getActionRepGain: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getActionCountRemaining: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getActionMaxLevel: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getActionCurrentLevel: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getActionAutolevel: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
setActionAutolevel: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
setActionLevel: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getRank: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getSkillPoints: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getSkillLevel: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getSkillUpgradeCost: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
upgradeSkill: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getTeamSize: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
setTeamSize: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getCityEstimatedPopulation: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getCityCommunities: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getCityChaos: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getCity: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
switchCity: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getStamina: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
joinBladeburnerFaction: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
joinBladeburnerDivision: RamCostConstants.ScriptBladeburnerApiBaseRamCost,
getBonusTime: 0,
},
// Coding Contract API
codingcontract: {
attempt: RamCostConstants.ScriptCodingContractBaseRamCost,
getContractType: RamCostConstants.ScriptCodingContractBaseRamCost / 2,
getData: RamCostConstants.ScriptCodingContractBaseRamCost / 2,
getDescription: RamCostConstants.ScriptCodingContractBaseRamCost / 2,
getNumTriesRemaining: RamCostConstants.ScriptCodingContractBaseRamCost / 5,
},
// Duplicate Sleeve API
sleeve: {
getNumSleeves: RamCostConstants.ScriptSleeveBaseRamCost,
setToShockRecovery: RamCostConstants.ScriptSleeveBaseRamCost,
setToSynchronize: RamCostConstants.ScriptSleeveBaseRamCost,
setToCommitCrime: RamCostConstants.ScriptSleeveBaseRamCost,
setToUniversityCourse: RamCostConstants.ScriptSleeveBaseRamCost,
travel: RamCostConstants.ScriptSleeveBaseRamCost,
setToCompanyWork: RamCostConstants.ScriptSleeveBaseRamCost,
setToFactionWork: RamCostConstants.ScriptSleeveBaseRamCost,
setToGymWorkout: RamCostConstants.ScriptSleeveBaseRamCost,
getSleeveStats: RamCostConstants.ScriptSleeveBaseRamCost,
getTask: RamCostConstants.ScriptSleeveBaseRamCost,
getInformation: RamCostConstants.ScriptSleeveBaseRamCost,
getSleeveAugmentations: RamCostConstants.ScriptSleeveBaseRamCost,
getSleevePurchasableAugs: RamCostConstants.ScriptSleeveBaseRamCost,
purchaseSleeveAug: RamCostConstants.ScriptSleeveBaseRamCost,
},
stanek: {
giftWidth: RamCostConstants.ScriptStanekWidth,
giftHeight: RamCostConstants.ScriptStanekHeight,
chargeFragment: RamCostConstants.ScriptStanekCharge,
fragmentDefinitions: RamCostConstants.ScriptStanekFragmentDefinitions,
activeFragments: RamCostConstants.ScriptStanekPlacedFragments,
clearGift: RamCostConstants.ScriptStanekClear,
canPlaceFragment: RamCostConstants.ScriptStanekCanPlace,
placeFragment: RamCostConstants.ScriptStanekPlace,
getFragment: RamCostConstants.ScriptStanekFragmentAt,
removeFragment: RamCostConstants.ScriptStanekDeleteAt,
},
ui: {
getTheme: 0,
setTheme: 0,
resetTheme: 0,
getStyles: 0,
setStyles: 0,
resetStyles: 0,
getGameInfo: 0,
},
grafting: {
getAugmentationGraftPrice: 3.75,
getAugmentationGraftTime: 3.75,
graftAugmentation: 7.5,
},
heart: {
// Easter egg function
break: 0,

View File

@ -75,6 +75,7 @@ import { IPort } from "./NetscriptPort";
import {
NS as INS,
Singularity as ISingularity,
Player as INetscriptPlayer,
Gang as IGang,
Bladeburner as IBladeburner,
@ -498,7 +499,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
const codingcontract = NetscriptCodingContract(Player, workerScript, helper);
const corporation = NetscriptCorporation(Player, workerScript, helper);
const formulas = NetscriptFormulas(Player, workerScript, helper);
const singularity = NetscriptSingularity(Player, workerScript, helper);
const singularity = wrapAPI(helper, {}, workerScript, NetscriptSingularity(Player, workerScript), "singularity")
.singularity as unknown as ISingularity;
const stockmarket = NetscriptStockMarket(Player, workerScript, helper);
const ui = NetscriptUserInterface(Player, workerScript, helper);
const grafting = NetscriptGrafting(Player, workerScript, helper);

View File

@ -1,4 +1,3 @@
import { INetscriptHelper } from "./INetscriptHelper";
import { WorkerScript } from "../Netscript/WorkerScript";
import { IPlayer } from "../PersonObjects/IPlayer";
import { purchaseAugmentation, joinFaction, getFactionAugmentationsFiltered } from "../Faction/FactionHelpers";
@ -10,7 +9,6 @@ import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
import { killWorkerScript } from "../Netscript/killWorkerScript";
import { CONSTANTS } from "../Constants";
import { isString } from "../utils/helpers/isString";
import { getRamCost } from "../Netscript/RamCostGenerator";
import { RunningScript } from "../Script/RunningScript";
import {
@ -48,32 +46,29 @@ import { calculateHackingTime } from "../Hacking";
import { Server } from "../Server/Server";
import { netscriptCanHack } from "../Hacking/netscriptCanHack";
import { FactionInfos } from "../Faction/FactionInfo";
import { InternalAPI, NetscriptContext } from "src/Netscript/APIWrapper";
export function NetscriptSingularity(
player: IPlayer,
workerScript: WorkerScript,
helper: INetscriptHelper,
): ISingularity {
const getAugmentation = function (func: string, name: string): Augmentation {
export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript): InternalAPI<ISingularity> {
const getAugmentation = function (_ctx: NetscriptContext, name: string): Augmentation {
if (!augmentationExists(name)) {
throw helper.makeRuntimeErrorMsg(func, `Invalid augmentation: '${name}'`);
throw _ctx.helper.makeRuntimeErrorMsg(`Invalid augmentation: '${name}'`);
}
return Augmentations[name];
};
const getFaction = function (func: string, name: string): Faction {
const getFaction = function (_ctx: NetscriptContext, name: string): Faction {
if (!factionExists(name)) {
throw helper.makeRuntimeErrorMsg(func, `Invalid faction name: '${name}`);
throw _ctx.helper.makeRuntimeErrorMsg(`Invalid faction name: '${name}`);
}
return Factions[name];
};
const getCompany = function (func: string, name: string): Company {
const getCompany = function (_ctx: NetscriptContext, name: string): Company {
const company = Companies[name];
if (company == null || !(company instanceof Company)) {
throw helper.makeRuntimeErrorMsg(func, `Invalid company name: '${name}'`);
throw _ctx.helper.makeRuntimeErrorMsg(`Invalid company name: '${name}'`);
}
return company;
};
@ -96,12 +91,11 @@ export function NetscriptSingularity(
}
};
const updateRam = (funcName: string): void => helper.updateDynamicRam(funcName, getRamCost(player, funcName));
return {
getOwnedAugmentations: function (_purchased: unknown = false): string[] {
updateRam("getOwnedAugmentations");
const purchased = helper.boolean(_purchased);
helper.checkSingularityAccess("getOwnedAugmentations");
getOwnedAugmentations: (_ctx: NetscriptContext) =>
function (_purchased: unknown = false): string[] {
const purchased = _ctx.helper.boolean(_purchased);
_ctx.helper.checkSingularityAccess();
const res = [];
for (let i = 0; i < player.augmentations.length; ++i) {
res.push(player.augmentations[i].name);
@ -113,56 +107,56 @@ export function NetscriptSingularity(
}
return res;
},
getAugmentationsFromFaction: function (_facName: unknown): string[] {
updateRam("getAugmentationsFromFaction");
const facName = helper.string("getAugmentationsFromFaction", "facName", _facName);
helper.checkSingularityAccess("getAugmentationsFromFaction");
const faction = getFaction("getAugmentationsFromFaction", facName);
getAugmentationsFromFaction: (_ctx: NetscriptContext) =>
function (_facName: unknown): string[] {
const facName = _ctx.helper.string("facName", _facName);
_ctx.helper.checkSingularityAccess();
const faction = getFaction(_ctx, facName);
return getFactionAugmentationsFiltered(player, faction);
},
getAugmentationCost: function (_augName: unknown): [number, number] {
updateRam("getAugmentationCost");
const augName = helper.string("getAugmentationCost", "augName", _augName);
helper.checkSingularityAccess("getAugmentationCost");
const aug = getAugmentation("getAugmentationCost", augName);
getAugmentationCost: (_ctx: NetscriptContext) =>
function (_augName: unknown): [number, number] {
const augName = _ctx.helper.string("augName", _augName);
_ctx.helper.checkSingularityAccess();
const aug = getAugmentation(_ctx, augName);
return [aug.baseRepRequirement, aug.baseCost];
},
getAugmentationPrereq: function (_augName: unknown): string[] {
updateRam("getAugmentationPrereq");
const augName = helper.string("getAugmentationPrereq", "augName", _augName);
helper.checkSingularityAccess("getAugmentationPrereq");
const aug = getAugmentation("getAugmentationPrereq", augName);
getAugmentationPrereq: (_ctx: NetscriptContext) =>
function (_augName: unknown): string[] {
const augName = _ctx.helper.string("augName", _augName);
_ctx.helper.checkSingularityAccess();
const aug = getAugmentation(_ctx, augName);
return aug.prereqs.slice();
},
getAugmentationPrice: function (_augName: unknown): number {
updateRam("getAugmentationPrice");
const augName = helper.string("getAugmentationPrice", "augName", _augName);
helper.checkSingularityAccess("getAugmentationPrice");
const aug = getAugmentation("getAugmentationPrice", augName);
getAugmentationPrice: (_ctx: NetscriptContext) =>
function (_augName: unknown): number {
const augName = _ctx.helper.string("augName", _augName);
_ctx.helper.checkSingularityAccess();
const aug = getAugmentation(_ctx, augName);
return aug.baseCost;
},
getAugmentationRepReq: function (_augName: unknown): number {
updateRam("getAugmentationRepReq");
const augName = helper.string("getAugmentationRepReq", "augName", _augName);
helper.checkSingularityAccess("getAugmentationRepReq");
const aug = getAugmentation("getAugmentationRepReq", augName);
getAugmentationRepReq: (_ctx: NetscriptContext) =>
function (_augName: unknown): number {
const augName = _ctx.helper.string("augName", _augName);
_ctx.helper.checkSingularityAccess();
const aug = getAugmentation(_ctx, augName);
return aug.baseRepRequirement;
},
getAugmentationStats: function (_augName: unknown): AugmentationStats {
updateRam("getAugmentationStats");
const augName = helper.string("getAugmentationStats", "augName", _augName);
helper.checkSingularityAccess("getAugmentationStats");
const aug = getAugmentation("getAugmentationStats", augName);
getAugmentationStats: (_ctx: NetscriptContext) =>
function (_augName: unknown): AugmentationStats {
const augName = _ctx.helper.string("augName", _augName);
_ctx.helper.checkSingularityAccess();
const aug = getAugmentation(_ctx, augName);
return Object.assign({}, aug.mults);
},
purchaseAugmentation: function (_facName: unknown, _augName: unknown): boolean {
updateRam("purchaseAugmentation");
const facName = helper.string("purchaseAugmentation", "facName", _facName);
const augName = helper.string("purchaseAugmentation", "augName", _augName);
helper.checkSingularityAccess("purchaseAugmentation");
const fac = getFaction("purchaseAugmentation", facName);
const aug = getAugmentation("purchaseAugmentation", augName);
purchaseAugmentation: (_ctx: NetscriptContext) =>
function (_facName: unknown, _augName: unknown): boolean {
const facName = _ctx.helper.string("facName", _facName);
const augName = _ctx.helper.string("augName", _augName);
_ctx.helper.checkSingularityAccess();
const fac = getFaction(_ctx, facName);
const aug = getAugmentation(_ctx, augName);
const augs = getFactionAugmentationsFiltered(player, fac);
@ -204,10 +198,10 @@ export function NetscriptSingularity(
return false;
}
},
softReset: function (_cbScript: unknown): void {
updateRam("softReset");
const cbScript = helper.string("softReset", "cbScript", _cbScript);
helper.checkSingularityAccess("softReset");
softReset: (_ctx: NetscriptContext) =>
function (_cbScript: unknown = ""): void {
const cbScript = _ctx.helper.string("cbScript", _cbScript);
_ctx.helper.checkSingularityAccess();
workerScript.log("softReset", () => "Soft resetting. This will cause this script to be killed");
setTimeout(() => {
@ -219,10 +213,10 @@ export function NetscriptSingularity(
workerScript.running = false;
killWorkerScript(workerScript);
},
installAugmentations: function (_cbScript: unknown = ""): boolean {
updateRam("installAugmentations");
const cbScript = helper.string("installAugmentations", "cbScript", _cbScript);
helper.checkSingularityAccess("installAugmentations");
installAugmentations: (_ctx: NetscriptContext) =>
function (_cbScript: unknown = ""): boolean {
const cbScript = _ctx.helper.string("cbScript", _cbScript);
_ctx.helper.checkSingularityAccess();
if (player.queuedAugmentations.length === 0) {
workerScript.log("installAugmentations", () => "You do not have any Augmentations to be installed.");
@ -243,10 +237,10 @@ export function NetscriptSingularity(
return true;
},
goToLocation: function (_locationName: unknown): boolean {
updateRam("goToLocation");
const locationName = helper.string("goToLocation", "locationName", _locationName);
helper.checkSingularityAccess("goToLocation");
goToLocation: (_ctx: NetscriptContext) =>
function (_locationName: unknown): boolean {
const locationName = _ctx.helper.string("locationName", _locationName);
_ctx.helper.checkSingularityAccess();
const location = Object.values(Locations).find((l) => l.name === locationName);
if (!location) {
workerScript.log("goToLocation", () => `No location named ${locationName}`);
@ -260,12 +254,12 @@ export function NetscriptSingularity(
player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain / 50000);
return true;
},
universityCourse: function (_universityName: unknown, _className: unknown, _focus: unknown = true): boolean {
updateRam("universityCourse");
const universityName = helper.string("universityCourse", "universityName", _universityName);
const className = helper.string("universityCourse", "className", _className);
const focus = helper.boolean(_focus);
helper.checkSingularityAccess("universityCourse");
universityCourse: (_ctx: NetscriptContext) =>
function (_universityName: unknown, _className: unknown, _focus: unknown = true): boolean {
const universityName = _ctx.helper.string("universityName", _universityName);
const className = _ctx.helper.string("className", _className);
const focus = _ctx.helper.boolean(_focus);
_ctx.helper.checkSingularityAccess();
const wasFocusing = player.focus;
if (player.isWorking) {
const txt = player.singularityStopWork();
@ -351,12 +345,12 @@ export function NetscriptSingularity(
return true;
},
gymWorkout: function (_gymName: unknown, _stat: unknown, _focus: unknown = true): boolean {
updateRam("gymWorkout");
const gymName = helper.string("gymWorkout", "gymName", _gymName);
const stat = helper.string("gymWorkout", "stat", _stat);
const focus = helper.boolean(_focus);
helper.checkSingularityAccess("gymWorkout");
gymWorkout: (_ctx: NetscriptContext) =>
function (_gymName: unknown, _stat: unknown, _focus: unknown = true): boolean {
const gymName = _ctx.helper.string("gymName", _gymName);
const stat = _ctx.helper.string("stat", _stat);
const focus = _ctx.helper.boolean(_focus);
_ctx.helper.checkSingularityAccess();
const wasFocusing = player.focus;
if (player.isWorking) {
const txt = player.singularityStopWork();
@ -466,10 +460,10 @@ export function NetscriptSingularity(
return true;
},
travelToCity: function (_cityName: unknown): boolean {
updateRam("travelToCity");
const cityName = helper.city("travelToCity", "cityName", _cityName);
helper.checkSingularityAccess("travelToCity");
travelToCity: (_ctx: NetscriptContext) =>
function (_cityName: unknown): boolean {
const cityName = _ctx.helper.city("cityName", _cityName);
_ctx.helper.checkSingularityAccess();
switch (cityName) {
case CityName.Aevum:
@ -488,13 +482,13 @@ export function NetscriptSingularity(
player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain / 50000);
return true;
default:
throw helper.makeRuntimeErrorMsg("travelToCity", `Invalid city name: '${cityName}'.`);
throw _ctx.helper.makeRuntimeErrorMsg(`Invalid city name: '${cityName}'.`);
}
},
purchaseTor: function (): boolean {
updateRam("purchaseTor");
helper.checkSingularityAccess("purchaseTor");
purchaseTor: (_ctx: NetscriptContext) =>
function (): boolean {
_ctx.helper.checkSingularityAccess();
if (player.hasTorRouter()) {
workerScript.log("purchaseTor", () => "You already have a TOR router!");
@ -524,10 +518,10 @@ export function NetscriptSingularity(
workerScript.log("purchaseTor", () => "You have purchased a Tor router!");
return true;
},
purchaseProgram: function (_programName: unknown): boolean {
updateRam("purchaseProgram");
const programName = helper.string("purchaseProgram", "programName", _programName).toLowerCase();
helper.checkSingularityAccess("purchaseProgram");
purchaseProgram: (_ctx: NetscriptContext) =>
function (_programName: unknown): boolean {
const programName = _ctx.helper.string("programName", _programName).toLowerCase();
_ctx.helper.checkSingularityAccess();
if (!player.hasTorRouter()) {
workerScript.log("purchaseProgram", () => "You do not have the TOR router.");
@ -562,22 +556,22 @@ export function NetscriptSingularity(
player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain / 5000);
return true;
},
getCurrentServer: function (): string {
updateRam("getCurrentServer");
helper.checkSingularityAccess("getCurrentServer");
getCurrentServer: (_ctx: NetscriptContext) =>
function (): string {
_ctx.helper.checkSingularityAccess();
return player.getCurrentServer().hostname;
},
connect: function (_hostname: unknown): boolean {
updateRam("connect");
const hostname = helper.string("purchaseProgram", "hostname", _hostname);
helper.checkSingularityAccess("connect");
connect: (_ctx: NetscriptContext) =>
function (_hostname: unknown): boolean {
const hostname = _ctx.helper.string("hostname", _hostname);
_ctx.helper.checkSingularityAccess();
if (!hostname) {
throw helper.makeRuntimeErrorMsg("connect", `Invalid hostname: '${hostname}'`);
throw _ctx.helper.makeRuntimeErrorMsg(`Invalid hostname: '${hostname}'`);
}
const target = GetServer(hostname);
if (target == null) {
throw helper.makeRuntimeErrorMsg("connect", `Invalid hostname: '${hostname}'`);
throw _ctx.helper.makeRuntimeErrorMsg(`Invalid hostname: '${hostname}'`);
}
if (hostname === "home") {
@ -603,15 +597,15 @@ export function NetscriptSingularity(
return false;
},
manualHack: function (): Promise<number> {
updateRam("manualHack");
helper.checkSingularityAccess("manualHack");
manualHack: (_ctx: NetscriptContext) =>
function (): Promise<number> {
_ctx.helper.checkSingularityAccess();
const server = player.getCurrentServer();
return helper.hack(server.hostname, true);
return _ctx.helper.hack(server.hostname, true);
},
installBackdoor: function (): Promise<void> {
updateRam("installBackdoor");
helper.checkSingularityAccess("installBackdoor");
installBackdoor: (_ctx: NetscriptContext) =>
function (): Promise<void> {
_ctx.helper.checkSingularityAccess();
const baseserver = player.getCurrentServer();
if (!(baseserver instanceof Server)) {
workerScript.log("installBackdoor", () => "cannot backdoor this kind of server");
@ -623,7 +617,7 @@ export function NetscriptSingularity(
// No root access or skill level too low
const canHack = netscriptCanHack(server, player);
if (!canHack.res) {
throw helper.makeRuntimeErrorMsg("installBackdoor", canHack.msg || "");
throw _ctx.helper.makeRuntimeErrorMsg(canHack.msg || "");
}
workerScript.log(
@ -642,17 +636,17 @@ export function NetscriptSingularity(
return Promise.resolve();
});
},
isFocused: function (): boolean {
updateRam("isFocused");
helper.checkSingularityAccess("isFocused");
isFocused: (_ctx: NetscriptContext) =>
function (): boolean {
_ctx.helper.checkSingularityAccess();
return player.focus;
},
setFocus: function (_focus: unknown): boolean {
updateRam("setFocus");
const focus = helper.boolean(_focus);
helper.checkSingularityAccess("setFocus");
setFocus: (_ctx: NetscriptContext) =>
function (_focus: unknown): boolean {
const focus = _ctx.helper.boolean(_focus);
_ctx.helper.checkSingularityAccess();
if (!player.isWorking) {
throw helper.makeRuntimeErrorMsg("setFocus", "Not currently working");
throw _ctx.helper.makeRuntimeErrorMsg("Not currently working");
}
if (
!(
@ -663,7 +657,7 @@ export function NetscriptSingularity(
player.workType == CONSTANTS.WorkTypeStudyClass
)
) {
throw helper.makeRuntimeErrorMsg("setFocus", "Cannot change focus for current job");
throw _ctx.helper.makeRuntimeErrorMsg("Cannot change focus for current job");
}
if (!player.focus && focus) {
player.startFocusing();
@ -676,9 +670,9 @@ export function NetscriptSingularity(
}
return false;
},
getStats: function (): PlayerSkills {
updateRam("getStats");
helper.checkSingularityAccess("getStats");
getStats: (_ctx: NetscriptContext) =>
function (): PlayerSkills {
_ctx.helper.checkSingularityAccess();
workerScript.log("getStats", () => `getStats is deprecated, please use getplayer`);
return {
@ -691,10 +685,13 @@ export function NetscriptSingularity(
intelligence: player.intelligence,
};
},
getCharacterInformation: function (): CharacterInfo {
updateRam("getCharacterInformation");
helper.checkSingularityAccess("getCharacterInformation");
workerScript.log("getCharacterInformation", () => `getCharacterInformation is deprecated, please use getplayer`);
getCharacterInformation: (_ctx: NetscriptContext) =>
function (): CharacterInfo {
_ctx.helper.checkSingularityAccess();
workerScript.log(
"getCharacterInformation",
() => `getCharacterInformation is deprecated, please use getplayer`,
);
return {
bitnode: player.bitNodeN,
@ -741,23 +738,23 @@ export function NetscriptSingularity(
charismaExp: player.charisma_exp,
};
},
hospitalize: function (): void {
updateRam("hospitalize");
helper.checkSingularityAccess("hospitalize");
hospitalize: (_ctx: NetscriptContext) =>
function (): void {
_ctx.helper.checkSingularityAccess();
if (player.isWorking || Router.page() === Page.Infiltration || Router.page() === Page.BitVerse) {
workerScript.log("hospitalize", () => "Cannot go to the hospital because the player is busy.");
return;
}
player.hospitalize();
},
isBusy: function (): boolean {
updateRam("isBusy");
helper.checkSingularityAccess("isBusy");
isBusy: (_ctx: NetscriptContext) =>
function (): boolean {
_ctx.helper.checkSingularityAccess();
return player.isWorking || Router.page() === Page.Infiltration || Router.page() === Page.BitVerse;
},
stopAction: function (): boolean {
updateRam("stopAction");
helper.checkSingularityAccess("stopAction");
stopAction: (_ctx: NetscriptContext) =>
function (): boolean {
_ctx.helper.checkSingularityAccess();
if (player.isWorking) {
if (player.focus) {
player.stopFocusing();
@ -769,9 +766,9 @@ export function NetscriptSingularity(
}
return false;
},
upgradeHomeCores: function (): boolean {
updateRam("upgradeHomeCores");
helper.checkSingularityAccess("upgradeHomeCores");
upgradeHomeCores: (_ctx: NetscriptContext) =>
function (): boolean {
_ctx.helper.checkSingularityAccess();
// Check if we're at max cores
const homeComputer = player.getHomeComputer();
@ -799,15 +796,15 @@ export function NetscriptSingularity(
);
return true;
},
getUpgradeHomeCoresCost: function (): number {
updateRam("getUpgradeHomeCoresCost");
helper.checkSingularityAccess("getUpgradeHomeCoresCost");
getUpgradeHomeCoresCost: (_ctx: NetscriptContext) =>
function (): number {
_ctx.helper.checkSingularityAccess();
return player.getUpgradeHomeCoresCost();
},
upgradeHomeRam: function (): boolean {
updateRam("upgradeHomeRam");
helper.checkSingularityAccess("upgradeHomeRam");
upgradeHomeRam: (_ctx: NetscriptContext) =>
function (): boolean {
_ctx.helper.checkSingularityAccess();
// Check if we're at max RAM
const homeComputer = player.getHomeComputer();
@ -838,17 +835,17 @@ export function NetscriptSingularity(
);
return true;
},
getUpgradeHomeRamCost: function (): number {
updateRam("getUpgradeHomeRamCost");
helper.checkSingularityAccess("getUpgradeHomeRamCost");
getUpgradeHomeRamCost: (_ctx: NetscriptContext) =>
function (): number {
_ctx.helper.checkSingularityAccess();
return player.getUpgradeHomeRamCost();
},
workForCompany: function (_companyName: unknown, _focus: unknown = true): boolean {
updateRam("workForCompany");
let companyName = helper.string("workForCompany", "companyName", _companyName);
const focus = helper.boolean(_focus);
helper.checkSingularityAccess("workForCompany");
workForCompany: (_ctx: NetscriptContext) =>
function (_companyName: unknown, _focus: unknown = true): boolean {
let companyName = _ctx.helper.string("companyName", _companyName);
const focus = _ctx.helper.boolean(_focus);
_ctx.helper.checkSingularityAccess();
// Sanitize input
if (companyName == null) {
@ -900,12 +897,12 @@ export function NetscriptSingularity(
);
return true;
},
applyToCompany: function (_companyName: unknown, _field: unknown): boolean {
updateRam("applyToCompany");
const companyName = helper.string("applyToCompany", "companyName", _companyName);
const field = helper.string("applyToCompany", "field", _field);
helper.checkSingularityAccess("applyToCompany");
getCompany("applyToCompany", companyName);
applyToCompany: (_ctx: NetscriptContext) =>
function (_companyName: unknown, _field: unknown): boolean {
const companyName = _ctx.helper.string("companyName", _companyName);
const field = _ctx.helper.string("field", _field);
_ctx.helper.checkSingularityAccess();
getCompany(_ctx, companyName);
player.location = companyName as LocationName;
let res;
@ -972,38 +969,38 @@ export function NetscriptSingularity(
}
return res;
},
getCompanyRep: function (_companyName: unknown): number {
updateRam("getCompanyRep");
const companyName = helper.string("getCompanyRep", "companyName", _companyName);
helper.checkSingularityAccess("getCompanyRep");
const company = getCompany("getCompanyRep", companyName);
getCompanyRep: (_ctx: NetscriptContext) =>
function (_companyName: unknown): number {
const companyName = _ctx.helper.string("companyName", _companyName);
_ctx.helper.checkSingularityAccess();
const company = getCompany(_ctx, companyName);
return company.playerReputation;
},
getCompanyFavor: function (_companyName: unknown): number {
updateRam("getCompanyFavor");
const companyName = helper.string("getCompanyFavor", "companyName", _companyName);
helper.checkSingularityAccess("getCompanyFavor");
const company = getCompany("getCompanyFavor", companyName);
getCompanyFavor: (_ctx: NetscriptContext) =>
function (_companyName: unknown): number {
const companyName = _ctx.helper.string("companyName", _companyName);
_ctx.helper.checkSingularityAccess();
const company = getCompany(_ctx, companyName);
return company.favor;
},
getCompanyFavorGain: function (_companyName: unknown): number {
updateRam("getCompanyFavorGain");
const companyName = helper.string("getCompanyFavorGain", "companyName", _companyName);
helper.checkSingularityAccess("getCompanyFavorGain");
const company = getCompany("getCompanyFavorGain", companyName);
getCompanyFavorGain: (_ctx: NetscriptContext) =>
function (_companyName: unknown): number {
const companyName = _ctx.helper.string("companyName", _companyName);
_ctx.helper.checkSingularityAccess();
const company = getCompany(_ctx, companyName);
return company.getFavorGain();
},
checkFactionInvitations: function (): string[] {
helper.updateDynamicRam("checkFactionInvitations", getRamCost(player, "checkFactionInvitations"));
helper.checkSingularityAccess("checkFactionInvitations");
checkFactionInvitations: (_ctx: NetscriptContext) =>
function (): string[] {
_ctx.helper.checkSingularityAccess();
// Make a copy of player.factionInvitations
return player.factionInvitations.slice();
},
joinFaction: function (_facName: unknown): boolean {
updateRam("joinFaction");
const facName = helper.string("joinFaction", "facName", _facName);
helper.checkSingularityAccess("joinFaction");
getFaction("joinFaction", facName);
joinFaction: (_ctx: NetscriptContext) =>
function (_facName: unknown): boolean {
const facName = _ctx.helper.string("facName", _facName);
_ctx.helper.checkSingularityAccess();
getFaction(_ctx, facName);
if (!player.factionInvitations.includes(facName)) {
workerScript.log("joinFaction", () => `You have not been invited by faction '${facName}'`);
@ -1023,13 +1020,13 @@ export function NetscriptSingularity(
workerScript.log("joinFaction", () => `Joined the '${facName}' faction.`);
return true;
},
workForFaction: function (_facName: unknown, _type: unknown, _focus: unknown = true): boolean {
updateRam("workForFaction");
const facName = helper.string("workForFaction", "facName", _facName);
const type = helper.string("workForFaction", "type", _type);
const focus = helper.boolean(_focus);
helper.checkSingularityAccess("workForFaction");
getFaction("workForFaction", facName);
workForFaction: (_ctx: NetscriptContext) =>
function (_facName: unknown, _type: unknown, _focus: unknown = true): boolean {
const facName = _ctx.helper.string("facName", _facName);
const type = _ctx.helper.string("type", _type);
const focus = _ctx.helper.boolean(_focus);
_ctx.helper.checkSingularityAccess();
getFaction(_ctx, facName);
// if the player is in a gang and the target faction is any of the gang faction, fail
if (player.inGang() && AllGangs[facName] !== undefined) {
@ -1056,7 +1053,10 @@ export function NetscriptSingularity(
case "hacking contracts":
case "hackingcontracts":
if (!FactionInfos[fac.name].offerHackingWork) {
workerScript.log("workForFaction", () => `Faction '${fac.name}' do not need help with hacking contracts.`);
workerScript.log(
"workForFaction",
() => `Faction '${fac.name}' do not need help with hacking contracts.`,
);
return false;
}
player.startFactionHackWork(fac);
@ -1109,33 +1109,33 @@ export function NetscriptSingularity(
}
return true;
},
getFactionRep: function (_facName: unknown): number {
updateRam("getFactionRep");
const facName = helper.string("getFactionRep", "facName", _facName);
helper.checkSingularityAccess("getFactionRep");
const faction = getFaction("getFactionRep", facName);
getFactionRep: (_ctx: NetscriptContext) =>
function (_facName: unknown): number {
const facName = _ctx.helper.string("facName", _facName);
_ctx.helper.checkSingularityAccess();
const faction = getFaction(_ctx, facName);
return faction.playerReputation;
},
getFactionFavor: function (_facName: unknown): number {
updateRam("getFactionFavor");
const facName = helper.string("getFactionRep", "facName", _facName);
helper.checkSingularityAccess("getFactionFavor");
const faction = getFaction("getFactionFavor", facName);
getFactionFavor: (_ctx: NetscriptContext) =>
function (_facName: unknown): number {
const facName = _ctx.helper.string("facName", _facName);
_ctx.helper.checkSingularityAccess();
const faction = getFaction(_ctx, facName);
return faction.favor;
},
getFactionFavorGain: function (_facName: unknown): number {
updateRam("getFactionFavorGain");
const facName = helper.string("getFactionFavorGain", "facName", _facName);
helper.checkSingularityAccess("getFactionFavorGain");
const faction = getFaction("getFactionFavorGain", facName);
getFactionFavorGain: (_ctx: NetscriptContext) =>
function (_facName: unknown): number {
const facName = _ctx.helper.string("facName", _facName);
_ctx.helper.checkSingularityAccess();
const faction = getFaction(_ctx, facName);
return faction.getFavorGain();
},
donateToFaction: function (_facName: unknown, _amt: unknown): boolean {
updateRam("donateToFaction");
const facName = helper.string("donateToFaction", "facName", _facName);
const amt = helper.number("donateToFaction", "amt", _amt);
helper.checkSingularityAccess("donateToFaction");
const faction = getFaction("donateToFaction", facName);
donateToFaction: (_ctx: NetscriptContext) =>
function (_facName: unknown, _amt: unknown): boolean {
const facName = _ctx.helper.string("facName", _facName);
const amt = _ctx.helper.number("amt", _amt);
_ctx.helper.checkSingularityAccess();
const faction = getFaction(_ctx, facName);
if (!player.factions.includes(faction.name)) {
workerScript.log("donateToFaction", () => `You can't donate to '${facName}' because you aren't a member`);
return false;
@ -1179,11 +1179,11 @@ export function NetscriptSingularity(
);
return true;
},
createProgram: function (_programName: unknown, _focus: unknown = true): boolean {
updateRam("createProgram");
const programName = helper.string("createProgram", "programName", _programName).toLowerCase();
const focus = helper.boolean(_focus);
helper.checkSingularityAccess("createProgram");
createProgram: (_ctx: NetscriptContext) =>
function (_programName: unknown, _focus: unknown = true): boolean {
const programName = _ctx.helper.string("programName", _programName).toLowerCase();
const focus = _ctx.helper.boolean(_focus);
_ctx.helper.checkSingularityAccess();
const wasFocusing = player.focus;
if (player.isWorking) {
@ -1228,10 +1228,10 @@ export function NetscriptSingularity(
workerScript.log("createProgram", () => `Began creating program: '${programName}'`);
return true;
},
commitCrime: function (_crimeRoughName: unknown): number {
updateRam("commitCrime");
const crimeRoughName = helper.string("commitCrime", "crimeRoughName", _crimeRoughName);
helper.checkSingularityAccess("commitCrime");
commitCrime: (_ctx: NetscriptContext) =>
function (_crimeRoughName: unknown): number {
const crimeRoughName = _ctx.helper.string("crimeRoughName", _crimeRoughName);
_ctx.helper.checkSingularityAccess();
if (player.isWorking) {
const txt = player.singularityStopWork();
@ -1244,38 +1244,38 @@ export function NetscriptSingularity(
const crime = findCrime(crimeRoughName.toLowerCase());
if (crime == null) {
// couldn't find crime
throw helper.makeRuntimeErrorMsg("commitCrime", `Invalid crime: '${crimeRoughName}'`);
throw _ctx.helper.makeRuntimeErrorMsg(`Invalid crime: '${crimeRoughName}'`);
}
workerScript.log("commitCrime", () => `Attempting to commit ${crime.name}...`);
return crime.commit(Router, player, 1, workerScript);
},
getCrimeChance: function (_crimeRoughName: unknown): number {
updateRam("getCrimeChance");
const crimeRoughName = helper.string("getCrimeChance", "crimeRoughName", _crimeRoughName);
helper.checkSingularityAccess("getCrimeChance");
getCrimeChance: (_ctx: NetscriptContext) =>
function (_crimeRoughName: unknown): number {
const crimeRoughName = _ctx.helper.string("crimeRoughName", _crimeRoughName);
_ctx.helper.checkSingularityAccess();
const crime = findCrime(crimeRoughName.toLowerCase());
if (crime == null) {
throw helper.makeRuntimeErrorMsg("getCrimeChance", `Invalid crime: ${crimeRoughName}`);
throw _ctx.helper.makeRuntimeErrorMsg(`Invalid crime: ${crimeRoughName}`);
}
return crime.successRate(player);
},
getCrimeStats: function (_crimeRoughName: unknown): CrimeStats {
updateRam("getCrimeStats");
const crimeRoughName = helper.string("getCrimeStats", "crimeRoughName", _crimeRoughName);
helper.checkSingularityAccess("getCrimeStats");
getCrimeStats: (_ctx: NetscriptContext) =>
function (_crimeRoughName: unknown): CrimeStats {
const crimeRoughName = _ctx.helper.string("crimeRoughName", _crimeRoughName);
_ctx.helper.checkSingularityAccess();
const crime = findCrime(crimeRoughName.toLowerCase());
if (crime == null) {
throw helper.makeRuntimeErrorMsg("getCrimeStats", `Invalid crime: ${crimeRoughName}`);
throw _ctx.helper.makeRuntimeErrorMsg(`Invalid crime: ${crimeRoughName}`);
}
return Object.assign({}, crime);
},
getDarkwebPrograms: function (): string[] {
updateRam("getDarkwebPrograms");
helper.checkSingularityAccess("getDarkwebPrograms");
getDarkwebPrograms: (_ctx: NetscriptContext) =>
function (): string[] {
_ctx.helper.checkSingularityAccess();
// If we don't have Tor, log it and return [] (empty list)
if (!player.hasTorRouter()) {
@ -1284,10 +1284,10 @@ export function NetscriptSingularity(
}
return Object.values(DarkWebItems).map((p) => p.program);
},
getDarkwebProgramCost: function (_programName: unknown): number {
updateRam("getDarkwebProgramCost");
const programName = helper.string("getDarkwebProgramCost", "programName", _programName).toLowerCase();
helper.checkSingularityAccess("getDarkwebProgramCost");
getDarkwebProgramCost: (_ctx: NetscriptContext) =>
function (_programName: unknown): number {
const programName = _ctx.helper.string("programName", _programName).toLowerCase();
_ctx.helper.checkSingularityAccess();
// If we don't have Tor, log it and return -1
if (!player.hasTorRouter()) {
@ -1304,8 +1304,7 @@ export function NetscriptSingularity(
// doesn't exist, it's the first time they've run the script. So throw an error to let them know
// that they need to fix it.
if (item == null) {
throw helper.makeRuntimeErrorMsg(
"getDarkwebProgramCost",
throw _ctx.helper.makeRuntimeErrorMsg(
`No such exploit ('${programName}') found on the darkweb! ` +
`\nThis function is not case-sensitive. Did you perhaps forget .exe at the end?`,
);