Actually format + lint

This commit is contained in:
omuretsu 2022-10-12 09:54:13 -04:00
parent 7a384d53f4
commit e192ad53ec
2 changed files with 668 additions and 707 deletions

@ -202,7 +202,7 @@ const base: InternalAPI<NS> = {
},
sleep:
(ctx) =>
async (_time = 0) => {
(_time = 0) => {
const time = helpers.number(ctx, "time", _time);
if (time === undefined) {
throw helpers.makeRuntimeErrorMsg(ctx, "Takes 1 argument.");
@ -212,15 +212,16 @@ const base: InternalAPI<NS> = {
return Promise.resolve(true);
});
},
asleep: (ctx) =>
function (_time = 0) {
asleep:
(ctx) =>
(_time = 0) => {
const time = helpers.number(ctx, "time", _time);
helpers.log(ctx, () => `Sleeping for ${time} milliseconds`);
return new Promise((resolve) => setTimeout(() => resolve(true), time));
},
grow:
(ctx) =>
async (_hostname, opts = {}) => {
(_hostname, opts = {}) => {
const hostname = helpers.string(ctx, "hostname", _hostname);
const optsValidator: BasicHGWOptions = {};
assertObjectType(ctx, "opts", opts, optsValidator);
@ -384,7 +385,7 @@ const base: InternalAPI<NS> = {
const coreBonus = 1 + (cores - 1) / 16;
return CONSTANTS.ServerWeakenAmount * threads * coreBonus * BitNodeMultipliers.ServerWeakenRate;
},
share: (ctx) => async (): Promise<void> => {
share: (ctx) => () => {
helpers.log(ctx, () => "Sharing this computer.");
const end = StartSharing(
ctx.workerScript.scriptRef.threads * calculateIntelligenceBonus(Player.skills.intelligence, 2),

@ -11,11 +11,7 @@ import { isString } from "../utils/helpers/isString";
import { RunningScript } from "../Script/RunningScript";
import { calculateAchievements } from "../Achievements/Achievements";
import {
Multipliers,
CrimeStats,
Singularity as ISingularity,
} from "../ScriptEditor/NetscriptDefinitions";
import { Singularity as ISingularity } from "../ScriptEditor/NetscriptDefinitions";
import { findCrime } from "../Crime/CrimeHelpers";
import { CompanyPositions } from "../Company/CompanyPositions";
@ -97,8 +93,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
};
return {
getOwnedAugmentations: (ctx) =>
function (_purchased = false) {
getOwnedAugmentations: (ctx) => (_purchased) => {
helpers.checkSingularityAccess(ctx);
const purchased = !!_purchased;
const res: string[] = [];
@ -117,59 +112,51 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
return { n: sf.n, lvl: sf.lvl };
});
},
getAugmentationsFromFaction: (ctx) =>
function (_facName) {
getAugmentationsFromFaction: (ctx) => (_facName) => {
helpers.checkSingularityAccess(ctx);
const facName = helpers.string(ctx, "facName", _facName);
const faction = getFaction(ctx, facName);
return getFactionAugmentationsFiltered(faction);
},
getAugmentationCost: (ctx) =>
function (_augName) {
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) =>
function (_augName) {
getAugmentationPrereq: (ctx) => (_augName) => {
helpers.checkSingularityAccess(ctx);
const augName = helpers.string(ctx, "augName", _augName);
const aug = getAugmentation(ctx, augName);
return aug.prereqs.slice();
},
getAugmentationBasePrice: (ctx) =>
function (_augName) {
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) =>
function (_augName) {
getAugmentationPrice: (ctx) => (_augName) => {
helpers.checkSingularityAccess(ctx);
const augName = helpers.string(ctx, "augName", _augName);
const aug = getAugmentation(ctx, augName);
return aug.getCost().moneyCost;
},
getAugmentationRepReq: (ctx) =>
function (_augName) {
getAugmentationRepReq: (ctx) => (_augName) => {
helpers.checkSingularityAccess(ctx);
const augName = helpers.string(ctx, "augName", _augName);
const aug = getAugmentation(ctx, augName);
return aug.getCost().repCost;
},
getAugmentationStats: (ctx) =>
function (_augName): 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) =>
function (_facName, _augName) {
purchaseAugmentation: (ctx) => (_facName, _augName) => {
helpers.checkSingularityAccess(ctx);
const facName = helpers.string(ctx, "facName", _facName);
const augName = helpers.string(ctx, "augName", _augName);
@ -218,10 +205,9 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
return false;
}
},
softReset: (ctx) =>
function (_cbScript = "") {
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(() => {
@ -231,10 +217,9 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
killWorkerScript(ctx.workerScript);
},
installAugmentations: (ctx) =>
function (_cbScript = "") {
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.");
@ -251,8 +236,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
return true;
},
goToLocation: (ctx) =>
function (_locationName) {
goToLocation: (ctx) => (_locationName) => {
helpers.checkSingularityAccess(ctx);
const locationName = helpers.string(ctx, "locationName", _locationName);
const location = Object.values(Locations).find((l) => l.name === locationName);
@ -274,8 +258,9 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
Player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain / 50000);
return true;
},
universityCourse: (ctx) =>
function (_universityName, _className, _focus = true) {
universityCourse:
(ctx) =>
(_universityName, _className, _focus = true) => {
helpers.checkSingularityAccess(ctx);
const universityName = helpers.string(ctx, "universityName", _universityName);
const className = helpers.string(ctx, "className", _className);
@ -360,8 +345,9 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
return true;
},
gymWorkout: (ctx) =>
function (_gymName, _stat, _focus = true) {
gymWorkout:
(ctx) =>
(_gymName, _stat, _focus = true) => {
helpers.checkSingularityAccess(ctx);
const gymName = helpers.string(ctx, "gymName", _gymName);
const stat = helpers.string(ctx, "stat", _stat);
@ -469,8 +455,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
return true;
},
travelToCity: (ctx) =>
function (_cityName) {
travelToCity: (ctx) => (_cityName) => {
helpers.checkSingularityAccess(ctx);
const cityName = helpers.city(ctx, "cityName", _cityName);
@ -495,8 +480,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
}
},
purchaseTor: (ctx) =>
function () {
purchaseTor: (ctx) => () => {
helpers.checkSingularityAccess(ctx);
if (Player.hasTorRouter()) {
@ -519,8 +503,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
helpers.log(ctx, () => "You have purchased a Tor router!");
return true;
},
purchaseProgram: (ctx) =>
function (_programName) {
purchaseProgram: (ctx) => (_programName) => {
helpers.checkSingularityAccess(ctx);
const programName = helpers.string(ctx, "programName", _programName).toLowerCase();
@ -562,13 +545,11 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
Player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain / 5000);
return true;
},
getCurrentServer: (ctx) =>
function (): string {
getCurrentServer: (ctx) => () => {
helpers.checkSingularityAccess(ctx);
return Player.getCurrentServer().hostname;
},
connect: (ctx) =>
function (_hostname) {
connect: (ctx) => (_hostname) => {
helpers.checkSingularityAccess(ctx);
const hostname = helpers.string(ctx, "hostname", _hostname);
if (!hostname) {
@ -616,8 +597,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
//Failure case
return false;
},
manualHack: (ctx) =>
function (): Promise<number> {
manualHack: (ctx) => () => {
helpers.checkSingularityAccess(ctx);
const server = Player.getCurrentServer();
return helpers.hack(ctx, server.hostname, true);
@ -654,13 +634,11 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
return Promise.resolve();
});
},
isFocused: (ctx) =>
function () {
isFocused: (ctx) => () => {
helpers.checkSingularityAccess(ctx);
return Player.focus;
},
setFocus: (ctx) =>
function (_focus) {
setFocus: (ctx) => (_focus) => {
helpers.checkSingularityAccess(ctx);
const focus = !!_focus;
if (Player.currentWork === null) {
@ -678,8 +656,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
}
return false;
},
hospitalize: (ctx) =>
function () {
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.");
@ -687,20 +664,17 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
}
Player.hospitalize();
},
isBusy: (ctx) =>
function () {
isBusy: (ctx) => () => {
helpers.checkSingularityAccess(ctx);
return Player.currentWork !== null || Router.page() === Page.Infiltration || Router.page() === Page.BitVerse;
},
stopAction: (ctx) =>
function () {
stopAction: (ctx) => () => {
helpers.checkSingularityAccess(ctx);
const wasWorking = Player.currentWork !== null;
Player.finishWork(true);
return wasWorking;
},
upgradeHomeCores: (ctx) =>
function () {
upgradeHomeCores: (ctx) => () => {
helpers.checkSingularityAccess(ctx);
// Check if we're at max cores
@ -726,14 +700,12 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
);
return true;
},
getUpgradeHomeCoresCost: (ctx) =>
function () {
getUpgradeHomeCoresCost: (ctx) => () => {
helpers.checkSingularityAccess(ctx);
return Player.getUpgradeHomeCoresCost();
},
upgradeHomeRam: (ctx) =>
function () {
upgradeHomeRam: (ctx) => () => {
helpers.checkSingularityAccess(ctx);
// Check if we're at max RAM
@ -762,14 +734,14 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
);
return true;
},
getUpgradeHomeRamCost: (ctx) =>
function () {
getUpgradeHomeRamCost: (ctx) => () => {
helpers.checkSingularityAccess(ctx);
return Player.getUpgradeHomeRamCost();
},
workForCompany: (ctx) =>
function (_companyName, _focus = true) {
workForCompany:
(ctx) =>
(_companyName, _focus = true) => {
helpers.checkSingularityAccess(ctx);
const companyName = helpers.string(ctx, "companyName", _companyName);
const focus = !!_focus;
@ -812,8 +784,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
helpers.log(ctx, () => `Began working at '${companyName}' with position '${companyPositionName}'`);
return true;
},
applyToCompany: (ctx) =>
function (_companyName, _field) {
applyToCompany: (ctx) => (_companyName, _field) => {
helpers.checkSingularityAccess(ctx);
const companyName = helpers.string(ctx, "companyName", _companyName);
const field = helpers.string(ctx, "field", _field);
@ -881,41 +852,35 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
}
return res;
},
quitJob: (ctx) =>
function (_companyName) {
quitJob: (ctx) => (_companyName) => {
helpers.checkSingularityAccess(ctx);
const companyName = helpers.string(ctx, "companyName", _companyName);
Player.quitJob(companyName);
},
getCompanyRep: (ctx) =>
function (_companyName) {
getCompanyRep: (ctx) => (_companyName) => {
helpers.checkSingularityAccess(ctx);
const companyName = helpers.string(ctx, "companyName", _companyName);
const company = getCompany(ctx, companyName);
return company.playerReputation;
},
getCompanyFavor: (ctx) =>
function (_companyName) {
getCompanyFavor: (ctx) => (_companyName) => {
helpers.checkSingularityAccess(ctx);
const companyName = helpers.string(ctx, "companyName", _companyName);
const company = getCompany(ctx, companyName);
return company.favor;
},
getCompanyFavorGain: (ctx) =>
function (_companyName) {
getCompanyFavorGain: (ctx) => (_companyName) => {
helpers.checkSingularityAccess(ctx);
const companyName = helpers.string(ctx, "companyName", _companyName);
const company = getCompany(ctx, companyName);
return company.getFavorGain();
},
checkFactionInvitations: (ctx) =>
function () {
checkFactionInvitations: (ctx) => () => {
helpers.checkSingularityAccess(ctx);
// Make a copy of player.factionInvitations
return Player.factionInvitations.slice();
},
joinFaction: (ctx) =>
function (_facName) {
joinFaction: (ctx) => (_facName) => {
helpers.checkSingularityAccess(ctx);
const facName = helpers.string(ctx, "facName", _facName);
getFaction(ctx, facName);
@ -938,8 +903,9 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
helpers.log(ctx, () => `Joined the '${facName}' faction.`);
return true;
},
workForFaction: (ctx) =>
function (_facName, _type, _focus = true) {
workForFaction:
(ctx) =>
(_facName, _type, _focus = true) => {
helpers.checkSingularityAccess(ctx);
const facName = helpers.string(ctx, "facName", _facName);
const type = helpers.string(ctx, "type", _type);
@ -1034,29 +1000,25 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
return false;
}
},
getFactionRep: (ctx) =>
function (_facName) {
getFactionRep: (ctx) => (_facName) => {
helpers.checkSingularityAccess(ctx);
const facName = helpers.string(ctx, "facName", _facName);
const faction = getFaction(ctx, facName);
return faction.playerReputation;
},
getFactionFavor: (ctx) =>
function (_facName) {
getFactionFavor: (ctx) => (_facName) => {
helpers.checkSingularityAccess(ctx);
const facName = helpers.string(ctx, "facName", _facName);
const faction = getFaction(ctx, facName);
return faction.favor;
},
getFactionFavorGain: (ctx) =>
function (_facName) {
getFactionFavorGain: (ctx) => (_facName) => {
helpers.checkSingularityAccess(ctx);
const facName = helpers.string(ctx, "facName", _facName);
const faction = getFaction(ctx, facName);
return faction.getFavorGain();
},
donateToFaction: (ctx) =>
function (_facName, _amt) {
donateToFaction: (ctx) => (_facName, _amt) => {
helpers.checkSingularityAccess(ctx);
const facName = helpers.string(ctx, "facName", _facName);
const amt = helpers.number(ctx, "amt", _amt);
@ -1105,8 +1067,9 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
);
return true;
},
createProgram: (ctx) =>
function (_programName, _focus = true) {
createProgram:
(ctx) =>
(_programName, _focus = true) => {
helpers.checkSingularityAccess(ctx);
const programName = helpers.string(ctx, "programName", _programName).toLowerCase();
const focus = !!_focus;
@ -1152,8 +1115,9 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
helpers.log(ctx, () => `Began creating program: '${programName}'`);
return true;
},
commitCrime: (ctx) =>
function (_crimeRoughName, _focus = true) {
commitCrime:
(ctx) =>
(_crimeRoughName, _focus = true) => {
helpers.checkSingularityAccess(ctx);
const crimeRoughName = helpers.string(ctx, "crimeRoughName", _crimeRoughName);
const focus = !!_focus;
@ -1182,8 +1146,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
}
return crimeTime;
},
getCrimeChance: (ctx) =>
function (_crimeRoughName) {
getCrimeChance: (ctx) => (_crimeRoughName) => {
helpers.checkSingularityAccess(ctx);
const crimeRoughName = helpers.string(ctx, "crimeRoughName", _crimeRoughName);
@ -1194,8 +1157,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
return crime.successRate(Player);
},
getCrimeStats: (ctx) =>
function (_crimeRoughName): CrimeStats {
getCrimeStats: (ctx) => (_crimeRoughName) => {
helpers.checkSingularityAccess(ctx);
const crimeRoughName = helpers.string(ctx, "crimeRoughName", _crimeRoughName);
@ -1218,8 +1180,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
intelligence_exp: crimeStatsWithMultipliers.intExp,
});
},
getDarkwebPrograms: (ctx) =>
function () {
getDarkwebPrograms: (ctx) => () => {
helpers.checkSingularityAccess(ctx);
// If we don't have Tor, log it and return [] (empty list)
@ -1229,8 +1190,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
}
return Object.values(DarkWebItems).map((p) => p.program);
},
getDarkwebProgramCost: (ctx) =>
function (_programName) {
getDarkwebProgramCost: (ctx) => (_programName) => {
helpers.checkSingularityAccess(ctx);
const programName = helpers.string(ctx, "programName", _programName).toLowerCase();