unknown-ify singularity API

This commit is contained in:
Olivier Gagnon 2022-03-29 20:05:40 -04:00
parent 725c8234c9
commit bbbaa89f74
3 changed files with 57 additions and 62 deletions

@ -742,6 +742,8 @@ export function NetscriptSingularity(
mult: { mult: {
agility: player.agility_mult, agility: player.agility_mult,
agilityExp: player.agility_exp_mult, agilityExp: player.agility_exp_mult,
charisma: player.charisma,
charismaExp: player.charisma_exp,
companyRep: player.company_rep_mult, companyRep: player.company_rep_mult,
crimeMoney: player.crime_money_mult, crimeMoney: player.crime_money_mult,
crimeSuccess: player.crime_success_mult, crimeSuccess: player.crime_success_mult,
@ -1211,7 +1213,7 @@ export function NetscriptSingularity(
); );
return true; return true;
}, },
createProgram: function (_programName: any, _focus: unknown = true): boolean { createProgram: function (_programName: unknown, _focus: unknown = true): boolean {
const programName = helper.string("createProgram", "programName", _programName).toLowerCase(); const programName = helper.string("createProgram", "programName", _programName).toLowerCase();
const focus = helper.boolean(_focus); const focus = helper.boolean(_focus);
helper.updateDynamicRam("createProgram", getRamCost(player, "createProgram")); helper.updateDynamicRam("createProgram", getRamCost(player, "createProgram"));

@ -10,10 +10,16 @@ import { Augmentations } from "../Augmentation/Augmentations";
import { CityName } from "../Locations/data/CityNames"; import { CityName } from "../Locations/data/CityNames";
import { findCrime } from "../Crime/CrimeHelpers"; import { findCrime } from "../Crime/CrimeHelpers";
import { Sleeve as ISleeve } from "../ScriptEditor/NetscriptDefinitions"; import {
AugmentPair,
Sleeve as ISleeve,
SleeveInformation,
SleeveSkills,
SleeveTask,
} from "../ScriptEditor/NetscriptDefinitions";
export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, helper: INetscriptHelper): ISleeve { export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, helper: INetscriptHelper): ISleeve {
const checkSleeveAPIAccess = function (func: any): void { const checkSleeveAPIAccess = function (func: string): void {
if (player.bitNodeN !== 10 && !SourceFileFlags[10]) { if (player.bitNodeN !== 10 && !SourceFileFlags[10]) {
throw helper.makeRuntimeErrorMsg( throw helper.makeRuntimeErrorMsg(
`sleeve.${func}`, `sleeve.${func}`,
@ -22,7 +28,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
} }
}; };
const checkSleeveNumber = function (func: any, sleeveNumber: any): void { const checkSleeveNumber = function (func: string, sleeveNumber: number): void {
if (sleeveNumber >= player.sleeves.length || sleeveNumber < 0) { if (sleeveNumber >= player.sleeves.length || sleeveNumber < 0) {
const msg = `Invalid sleeve number: ${sleeveNumber}`; const msg = `Invalid sleeve number: ${sleeveNumber}`;
workerScript.log(func, () => msg); workerScript.log(func, () => msg);
@ -30,7 +36,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
} }
}; };
const getSleeveStats = function (sleeveNumber: any): any { const getSleeveStats = function (sleeveNumber: number): SleeveSkills {
const sl = player.sleeves[sleeveNumber]; const sl = player.sleeves[sleeveNumber];
return { return {
shock: 100 - sl.shock, shock: 100 - sl.shock,
@ -42,7 +48,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
agility: sl.agility, agility: sl.agility,
charisma: sl.charisma, charisma: sl.charisma,
}; };
} };
return { return {
getNumSleeves: function (): number { getNumSleeves: function (): number {
@ -50,23 +56,23 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
checkSleeveAPIAccess("getNumSleeves"); checkSleeveAPIAccess("getNumSleeves");
return player.sleeves.length; return player.sleeves.length;
}, },
setToShockRecovery: function (asleeveNumber: any = 0): boolean { setToShockRecovery: function (_sleeveNumber: unknown): boolean {
const sleeveNumber = helper.number("setToShockRecovery", "sleeveNumber", asleeveNumber); const sleeveNumber = helper.number("setToShockRecovery", "sleeveNumber", _sleeveNumber);
helper.updateDynamicRam("setToShockRecovery", getRamCost(player, "sleeve", "setToShockRecovery")); helper.updateDynamicRam("setToShockRecovery", getRamCost(player, "sleeve", "setToShockRecovery"));
checkSleeveAPIAccess("setToShockRecovery"); checkSleeveAPIAccess("setToShockRecovery");
checkSleeveNumber("setToShockRecovery", sleeveNumber); checkSleeveNumber("setToShockRecovery", sleeveNumber);
return player.sleeves[sleeveNumber].shockRecovery(player); return player.sleeves[sleeveNumber].shockRecovery(player);
}, },
setToSynchronize: function (asleeveNumber: any = 0): boolean { setToSynchronize: function (_sleeveNumber: unknown): boolean {
const sleeveNumber = helper.number("setToSynchronize", "sleeveNumber", asleeveNumber); const sleeveNumber = helper.number("setToSynchronize", "sleeveNumber", _sleeveNumber);
helper.updateDynamicRam("setToSynchronize", getRamCost(player, "sleeve", "setToSynchronize")); helper.updateDynamicRam("setToSynchronize", getRamCost(player, "sleeve", "setToSynchronize"));
checkSleeveAPIAccess("setToSynchronize"); checkSleeveAPIAccess("setToSynchronize");
checkSleeveNumber("setToSynchronize", sleeveNumber); checkSleeveNumber("setToSynchronize", sleeveNumber);
return player.sleeves[sleeveNumber].synchronize(player); return player.sleeves[sleeveNumber].synchronize(player);
}, },
setToCommitCrime: function (asleeveNumber: any = 0, aCrimeRoughName: any = ""): boolean { setToCommitCrime: function (_sleeveNumber: unknown, _crimeRoughName: unknown): boolean {
const sleeveNumber = helper.number("setToCommitCrime", "sleeveNumber", asleeveNumber); const sleeveNumber = helper.number("setToCommitCrime", "sleeveNumber", _sleeveNumber);
const crimeRoughName = helper.string("setToCommitCrime", "crimeName", aCrimeRoughName); const crimeRoughName = helper.string("setToCommitCrime", "crimeName", _crimeRoughName);
helper.updateDynamicRam("setToCommitCrime", getRamCost(player, "sleeve", "setToCommitCrime")); helper.updateDynamicRam("setToCommitCrime", getRamCost(player, "sleeve", "setToCommitCrime"));
checkSleeveAPIAccess("setToCommitCrime"); checkSleeveAPIAccess("setToCommitCrime");
checkSleeveNumber("setToCommitCrime", sleeveNumber); checkSleeveNumber("setToCommitCrime", sleeveNumber);
@ -76,25 +82,25 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
} }
return player.sleeves[sleeveNumber].commitCrime(player, crime.name); return player.sleeves[sleeveNumber].commitCrime(player, crime.name);
}, },
setToUniversityCourse: function (asleeveNumber: any = 0, auniversityName: any = "", aclassName: any = ""): boolean { setToUniversityCourse: function (_sleeveNumber: unknown, _universityName: unknown, _className: unknown): boolean {
const sleeveNumber = helper.number("setToUniversityCourse", "sleeveNumber", asleeveNumber); const sleeveNumber = helper.number("setToUniversityCourse", "sleeveNumber", _sleeveNumber);
const universityName = helper.string("setToUniversityCourse", "universityName", auniversityName); const universityName = helper.string("setToUniversityCourse", "universityName", _universityName);
const className = helper.string("setToUniversityCourse", "className", aclassName); const className = helper.string("setToUniversityCourse", "className", _className);
helper.updateDynamicRam("setToUniversityCourse", getRamCost(player, "sleeve", "setToUniversityCourse")); helper.updateDynamicRam("setToUniversityCourse", getRamCost(player, "sleeve", "setToUniversityCourse"));
checkSleeveAPIAccess("setToUniversityCourse"); checkSleeveAPIAccess("setToUniversityCourse");
checkSleeveNumber("setToUniversityCourse", sleeveNumber); checkSleeveNumber("setToUniversityCourse", sleeveNumber);
return player.sleeves[sleeveNumber].takeUniversityCourse(player, universityName, className); return player.sleeves[sleeveNumber].takeUniversityCourse(player, universityName, className);
}, },
travel: function (asleeveNumber: any = 0, acityName: any = ""): boolean { travel: function (_sleeveNumber: unknown, _cityName: unknown): boolean {
const sleeveNumber = helper.number("travel", "sleeveNumber", asleeveNumber); const sleeveNumber = helper.number("travel", "sleeveNumber", _sleeveNumber);
const cityName = helper.string("setToUniversityCourse", "cityName", acityName); const cityName = helper.string("setToUniversityCourse", "cityName", _cityName);
helper.updateDynamicRam("travel", getRamCost(player, "sleeve", "travel")); helper.updateDynamicRam("travel", getRamCost(player, "sleeve", "travel"));
checkSleeveAPIAccess("travel"); checkSleeveAPIAccess("travel");
checkSleeveNumber("travel", sleeveNumber); checkSleeveNumber("travel", sleeveNumber);
return player.sleeves[sleeveNumber].travel(player, cityName as CityName); return player.sleeves[sleeveNumber].travel(player, cityName as CityName);
}, },
setToCompanyWork: function (asleeveNumber: any = 0, acompanyName: any = ""): boolean { setToCompanyWork: function (_sleeveNumber: unknown, acompanyName: unknown): boolean {
const sleeveNumber = helper.number("setToCompanyWork", "sleeveNumber", asleeveNumber); const sleeveNumber = helper.number("setToCompanyWork", "sleeveNumber", _sleeveNumber);
const companyName = helper.string("setToUniversityCourse", "companyName", acompanyName); const companyName = helper.string("setToUniversityCourse", "companyName", acompanyName);
helper.updateDynamicRam("setToCompanyWork", getRamCost(player, "sleeve", "setToCompanyWork")); helper.updateDynamicRam("setToCompanyWork", getRamCost(player, "sleeve", "setToCompanyWork"));
checkSleeveAPIAccess("setToCompanyWork"); checkSleeveAPIAccess("setToCompanyWork");
@ -116,10 +122,10 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
return player.sleeves[sleeveNumber].workForCompany(player, companyName); return player.sleeves[sleeveNumber].workForCompany(player, companyName);
}, },
setToFactionWork: function (asleeveNumber: any = 0, afactionName: any = "", aworkType: any = ""): boolean { setToFactionWork: function (_sleeveNumber: unknown, _factionName: unknown, _workType: unknown): boolean {
const sleeveNumber = helper.number("setToFactionWork", "sleeveNumber", asleeveNumber); const sleeveNumber = helper.number("setToFactionWork", "sleeveNumber", _sleeveNumber);
const factionName = helper.string("setToUniversityCourse", "factionName", afactionName); const factionName = helper.string("setToUniversityCourse", "factionName", _factionName);
const workType = helper.string("setToUniversityCourse", "workType", aworkType); const workType = helper.string("setToUniversityCourse", "workType", _workType);
helper.updateDynamicRam("setToFactionWork", getRamCost(player, "sleeve", "setToFactionWork")); helper.updateDynamicRam("setToFactionWork", getRamCost(player, "sleeve", "setToFactionWork"));
checkSleeveAPIAccess("setToFactionWork"); checkSleeveAPIAccess("setToFactionWork");
checkSleeveNumber("setToFactionWork", sleeveNumber); checkSleeveNumber("setToFactionWork", sleeveNumber);
@ -140,40 +146,25 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
return player.sleeves[sleeveNumber].workForFaction(player, factionName, workType); return player.sleeves[sleeveNumber].workForFaction(player, factionName, workType);
}, },
setToGymWorkout: function (asleeveNumber: any = 0, agymName: any = "", astat: any = ""): boolean { setToGymWorkout: function (_sleeveNumber: unknown, _gymName: unknown, _stat: unknown): boolean {
const sleeveNumber = helper.number("setToGymWorkout", "sleeveNumber", asleeveNumber); const sleeveNumber = helper.number("setToGymWorkout", "sleeveNumber", _sleeveNumber);
const gymName = helper.string("setToUniversityCourse", "gymName", agymName); const gymName = helper.string("setToUniversityCourse", "gymName", _gymName);
const stat = helper.string("setToUniversityCourse", "stat", astat); const stat = helper.string("setToUniversityCourse", "stat", _stat);
helper.updateDynamicRam("setToGymWorkout", getRamCost(player, "sleeve", "setToGymWorkout")); helper.updateDynamicRam("setToGymWorkout", getRamCost(player, "sleeve", "setToGymWorkout"));
checkSleeveAPIAccess("setToGymWorkout"); checkSleeveAPIAccess("setToGymWorkout");
checkSleeveNumber("setToGymWorkout", sleeveNumber); checkSleeveNumber("setToGymWorkout", sleeveNumber);
return player.sleeves[sleeveNumber].workoutAtGym(player, gymName, stat); return player.sleeves[sleeveNumber].workoutAtGym(player, gymName, stat);
}, },
getSleeveStats: function (asleeveNumber: any = 0): { getSleeveStats: function (_sleeveNumber: unknown): SleeveSkills {
shock: number; const sleeveNumber = helper.number("getSleeveStats", "sleeveNumber", _sleeveNumber);
sync: number;
hacking: number;
strength: number;
defense: number;
dexterity: number;
agility: number;
charisma: number;
} {
const sleeveNumber = helper.number("getSleeveStats", "sleeveNumber", asleeveNumber);
helper.updateDynamicRam("getSleeveStats", getRamCost(player, "sleeve", "getSleeveStats")); helper.updateDynamicRam("getSleeveStats", getRamCost(player, "sleeve", "getSleeveStats"));
checkSleeveAPIAccess("getSleeveStats"); checkSleeveAPIAccess("getSleeveStats");
checkSleeveNumber("getSleeveStats", sleeveNumber); checkSleeveNumber("getSleeveStats", sleeveNumber);
return getSleeveStats(sleeveNumber) return getSleeveStats(sleeveNumber);
}, },
getTask: function (asleeveNumber: any = 0): { getTask: function (_sleeveNumber: unknown): SleeveTask {
task: string; const sleeveNumber = helper.number("getTask", "sleeveNumber", _sleeveNumber);
crime: string;
location: string;
gymStatType: string;
factionWorkType: string;
} {
const sleeveNumber = helper.number("getTask", "sleeveNumber", asleeveNumber);
helper.updateDynamicRam("getTask", getRamCost(player, "sleeve", "getTask")); helper.updateDynamicRam("getTask", getRamCost(player, "sleeve", "getTask"));
checkSleeveAPIAccess("getTask"); checkSleeveAPIAccess("getTask");
checkSleeveNumber("getTask", sleeveNumber); checkSleeveNumber("getTask", sleeveNumber);
@ -187,14 +178,15 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
factionWorkType: FactionWorkType[sl.factionWorkType], factionWorkType: FactionWorkType[sl.factionWorkType],
}; };
}, },
getInformation: function (asleeveNumber: any = 0): any { getInformation: function (_sleeveNumber: unknown): SleeveInformation {
const sleeveNumber = helper.number("getInformation", "sleeveNumber", asleeveNumber); const sleeveNumber = helper.number("getInformation", "sleeveNumber", _sleeveNumber);
helper.updateDynamicRam("getInformation", getRamCost(player, "sleeve", "getInformation")); helper.updateDynamicRam("getInformation", getRamCost(player, "sleeve", "getInformation"));
checkSleeveAPIAccess("getInformation"); checkSleeveAPIAccess("getInformation");
checkSleeveNumber("getInformation", sleeveNumber); checkSleeveNumber("getInformation", sleeveNumber);
const sl = player.sleeves[sleeveNumber]; const sl = player.sleeves[sleeveNumber];
return { return {
tor: false,
city: sl.city, city: sl.city,
hp: sl.hp, hp: sl.hp,
jobs: Object.keys(player.jobs), // technically sleeves have the same jobs as the player. jobs: Object.keys(player.jobs), // technically sleeves have the same jobs as the player.
@ -252,8 +244,8 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
workRepGain: sl.getRepGain(player), workRepGain: sl.getRepGain(player),
}; };
}, },
getSleeveAugmentations: function (asleeveNumber: any = 0): string[] { getSleeveAugmentations: function (_sleeveNumber: unknown): string[] {
const sleeveNumber = helper.number("getSleeveAugmentations", "sleeveNumber", asleeveNumber); const sleeveNumber = helper.number("getSleeveAugmentations", "sleeveNumber", _sleeveNumber);
helper.updateDynamicRam("getSleeveAugmentations", getRamCost(player, "sleeve", "getSleeveAugmentations")); helper.updateDynamicRam("getSleeveAugmentations", getRamCost(player, "sleeve", "getSleeveAugmentations"));
checkSleeveAPIAccess("getSleeveAugmentations"); checkSleeveAPIAccess("getSleeveAugmentations");
checkSleeveNumber("getSleeveAugmentations", sleeveNumber); checkSleeveNumber("getSleeveAugmentations", sleeveNumber);
@ -264,11 +256,8 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
} }
return augs; return augs;
}, },
getSleevePurchasableAugs: function (asleeveNumber: any = 0): { getSleevePurchasableAugs: function (_sleeveNumber: unknown): AugmentPair[] {
name: string; const sleeveNumber = helper.number("getSleevePurchasableAugs", "sleeveNumber", _sleeveNumber);
cost: number;
}[] {
const sleeveNumber = helper.number("getSleevePurchasableAugs", "sleeveNumber", asleeveNumber);
helper.updateDynamicRam("getSleevePurchasableAugs", getRamCost(player, "sleeve", "getSleevePurchasableAugs")); helper.updateDynamicRam("getSleevePurchasableAugs", getRamCost(player, "sleeve", "getSleevePurchasableAugs"));
checkSleeveAPIAccess("getSleevePurchasableAugs"); checkSleeveAPIAccess("getSleevePurchasableAugs");
checkSleeveNumber("getSleevePurchasableAugs", sleeveNumber); checkSleeveNumber("getSleevePurchasableAugs", sleeveNumber);
@ -285,9 +274,9 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
return augs; return augs;
}, },
purchaseSleeveAug: function (asleeveNumber: any = 0, aaugName: any = ""): boolean { purchaseSleeveAug: function (_sleeveNumber: unknown, _augName: unknown): boolean {
const sleeveNumber = helper.number("purchaseSleeveAug", "sleeveNumber", asleeveNumber); const sleeveNumber = helper.number("purchaseSleeveAug", "sleeveNumber", _sleeveNumber);
const augName = helper.string("purchaseSleeveAug", "augName", aaugName); const augName = helper.string("purchaseSleeveAug", "augName", _augName);
helper.updateDynamicRam("purchaseSleeveAug", getRamCost(player, "sleeve", "purchaseSleeveAug")); helper.updateDynamicRam("purchaseSleeveAug", getRamCost(player, "sleeve", "purchaseSleeveAug"));
checkSleeveAPIAccess("purchaseSleeveAug"); checkSleeveAPIAccess("purchaseSleeveAug");
checkSleeveNumber("purchaseSleeveAug", sleeveNumber); checkSleeveNumber("purchaseSleeveAug", sleeveNumber);

@ -667,6 +667,10 @@ export interface CharacterMult {
agility: number; agility: number;
/** Agility exp */ /** Agility exp */
agilityExp: number; agilityExp: number;
/** Charisma stat */
charisma: number;
/** Charisma exp */
charismaExp: number;
/** Company reputation */ /** Company reputation */
companyRep: number; companyRep: number;
/** Money earned from crimes */ /** Money earned from crimes */