Formatted/linted (There are some errors, but they aren't mine afaik)

This commit is contained in:
Undeemiss 2022-05-28 21:35:20 -05:00
parent 8b026f606b
commit f8f3c099e0
18 changed files with 293 additions and 292 deletions

@ -671,15 +671,15 @@ export class Bladeburner implements IBladeburner {
this.postToConsole("Automation: " + (this.automateEnabled ? "enabled" : "disabled")); this.postToConsole("Automation: " + (this.automateEnabled ? "enabled" : "disabled"));
this.postToConsole( this.postToConsole(
"When your stamina drops to " + "When your stamina drops to " +
formatNumber(this.automateThreshLow, 0) + formatNumber(this.automateThreshLow, 0) +
", you will automatically switch to " + ", you will automatically switch to " +
this.automateActionLow.name + this.automateActionLow.name +
". When your stamina recovers to " + ". When your stamina recovers to " +
formatNumber(this.automateThreshHigh, 0) + formatNumber(this.automateThreshHigh, 0) +
", you will automatically " + ", you will automatically " +
"switch to " + "switch to " +
this.automateActionHigh.name + this.automateActionHigh.name +
".", ".",
); );
} else if (flag.toLowerCase().includes("en")) { } else if (flag.toLowerCase().includes("en")) {
if ( if (
@ -974,8 +974,8 @@ export class Bladeburner implements IBladeburner {
if (this.logging.events) { if (this.logging.events) {
this.log( this.log(
"Intelligence indicates that a large number of Synthoids migrated from " + "Intelligence indicates that a large number of Synthoids migrated from " +
sourceCityName + sourceCityName +
" to some other city", " to some other city",
); );
} }
} else if (chance <= 0.7) { } else if (chance <= 0.7) {
@ -1314,19 +1314,19 @@ export class Bladeburner implements IBladeburner {
if (isOperation && this.logging.ops) { if (isOperation && this.logging.ops) {
this.log( this.log(
`${person.whoAmI()}: ` + `${person.whoAmI()}: ` +
action.name + action.name +
" successfully completed! Gained " + " successfully completed! Gained " +
formatNumber(gain, 3) + formatNumber(gain, 3) +
" rank", " rank",
); );
} else if (!isOperation && this.logging.contracts) { } else if (!isOperation && this.logging.contracts) {
this.log( this.log(
`${person.whoAmI()}: ` + `${person.whoAmI()}: ` +
action.name + action.name +
" contract successfully completed! Gained " + " contract successfully completed! Gained " +
formatNumber(gain, 3) + formatNumber(gain, 3) +
" rank and " + " rank and " +
numeralWrapper.formatMoney(moneyGain), numeralWrapper.formatMoney(moneyGain),
); );
} }
} }
@ -1432,12 +1432,12 @@ export class Bladeburner implements IBladeburner {
if (this.logging.blackops) { if (this.logging.blackops) {
this.log( this.log(
`${person.whoAmI()}: ` + `${person.whoAmI()}: ` +
action.name + action.name +
" failed! Lost " + " failed! Lost " +
formatNumber(rankLoss, 1) + formatNumber(rankLoss, 1) +
" rank and took " + " rank and took " +
formatNumber(damage, 0) + formatNumber(damage, 0) +
" damage", " damage",
); );
} }
} }
@ -1482,17 +1482,17 @@ export class Bladeburner implements IBladeburner {
if (this.logging.general) { if (this.logging.general) {
this.log( this.log(
`${person.whoAmI()}: ` + `${person.whoAmI()}: ` +
"Training completed. Gained: " + "Training completed. Gained: " +
formatNumber(strExpGain, 1) + formatNumber(strExpGain, 1) +
" str exp, " + " str exp, " +
formatNumber(defExpGain, 1) + formatNumber(defExpGain, 1) +
" def exp, " + " def exp, " +
formatNumber(dexExpGain, 1) + formatNumber(dexExpGain, 1) +
" dex exp, " + " dex exp, " +
formatNumber(agiExpGain, 1) + formatNumber(agiExpGain, 1) +
" agi exp, " + " agi exp, " +
formatNumber(staminaGain, 3) + formatNumber(staminaGain, 3) +
" max stamina", " max stamina",
); );
} }
break; break;
@ -1519,9 +1519,9 @@ export class Bladeburner implements IBladeburner {
if (this.logging.general) { if (this.logging.general) {
this.log( this.log(
`${person.whoAmI()}: ` + `${person.whoAmI()}: ` +
`Field analysis completed. Gained ${formatNumber(rankGain, 2)} rank, ` + `Field analysis completed. Gained ${formatNumber(rankGain, 2)} rank, ` +
`${formatNumber(hackingExpGain, 1)} hacking exp, and ` + `${formatNumber(hackingExpGain, 1)} hacking exp, and ` +
`${formatNumber(charismaExpGain, 1)} charisma exp`, `${formatNumber(charismaExpGain, 1)} charisma exp`,
); );
} }
break; break;
@ -1536,9 +1536,9 @@ export class Bladeburner implements IBladeburner {
if (this.logging.general) { if (this.logging.general) {
this.log( this.log(
`${person.whoAmI()}: ` + `${person.whoAmI()}: ` +
"Successfully recruited a team member! Gained " + "Successfully recruited a team member! Gained " +
formatNumber(expGain, 1) + formatNumber(expGain, 1) +
" charisma exp", " charisma exp",
); );
} }
} else { } else {
@ -1547,9 +1547,9 @@ export class Bladeburner implements IBladeburner {
if (this.logging.general) { if (this.logging.general) {
this.log( this.log(
`${person.whoAmI()}: ` + `${person.whoAmI()}: ` +
"Failed to recruit a team member. Gained " + "Failed to recruit a team member. Gained " +
formatNumber(expGain, 1) + formatNumber(expGain, 1) +
" charisma exp", " charisma exp",
); );
} }
} }
@ -1577,7 +1577,8 @@ export class Bladeburner implements IBladeburner {
this.stamina = Math.min(this.maxStamina, this.stamina + staminaGain); this.stamina = Math.min(this.maxStamina, this.stamina + staminaGain);
if (this.logging.general) { if (this.logging.general) {
this.log( this.log(
`${person.whoAmI()}: Rested in Hyperbolic Regeneration Chamber. Restored ${BladeburnerConstants.HrcHpGain `${person.whoAmI()}: Rested in Hyperbolic Regeneration Chamber. Restored ${
BladeburnerConstants.HrcHpGain
} HP and gained ${numeralWrapper.formatStamina(staminaGain)} stamina`, } HP and gained ${numeralWrapper.formatStamina(staminaGain)} stamina`,
); );
} }

@ -136,20 +136,19 @@ export class Skill {
calculateCost(currentLevel: number, count = 1): number { calculateCost(currentLevel: number, count = 1): number {
if (count == 1) { if (count == 1) {
return Math.floor((this.baseCost + currentLevel * this.costInc) * BitNodeMultipliers.BladeburnerSkillCost); return Math.floor((this.baseCost + currentLevel * this.costInc) * BitNodeMultipliers.BladeburnerSkillCost);
} } else if (count < 0 || isNaN(count)) {
else if (count < 0 || isNaN(count)) {
throw new Error(`Attempted to find cost of ${count} BB upgrades`); throw new Error(`Attempted to find cost of ${count} BB upgrades`);
} } else if (count < 100) {
else if (count < 100) { const thisUpgrade = Math.floor(
const thisUpgrade = Math.floor((this.baseCost + currentLevel * this.costInc) * BitNodeMultipliers.BladeburnerSkillCost); (this.baseCost + currentLevel * this.costInc) * BitNodeMultipliers.BladeburnerSkillCost,
);
return this.calculateCost(currentLevel + 1, count - 1) + thisUpgrade; return this.calculateCost(currentLevel + 1, count - 1) + thisUpgrade;
} } else {
else {
//unFloored is roughly equivalent to //unFloored is roughly equivalent to
//(this.baseCost + currentLevel * this.costInc) * BitNodeMultipliers.BladeburnerSkillCost //(this.baseCost + currentLevel * this.costInc) * BitNodeMultipliers.BladeburnerSkillCost
//being repeated for increasing currentLevel //being repeated for increasing currentLevel
const preMult = count * ((2 * this.baseCost) + this.costInc * (2 * currentLevel + count + 1)) / 2; const preMult = (count * (2 * this.baseCost + this.costInc * (2 * currentLevel + count + 1))) / 2;
const unFloored = (preMult * BitNodeMultipliers.BladeburnerSkillCost) - count / 2; const unFloored = preMult * BitNodeMultipliers.BladeburnerSkillCost - count / 2;
return Math.floor(unFloored); return Math.floor(unFloored);
} }
} }

@ -74,7 +74,7 @@ export function GeneralActionElem(props: IProps): React.ReactElement {
<CopyableText value={props.action.name} /> <CopyableText value={props.action.name} />
<StartButton <StartButton
bladeburner={props.bladeburner} bladeburner={props.bladeburner}
type={ActionTypes[props.action.name ]} type={ActionTypes[props.action.name]}
name={props.action.name} name={props.action.name}
rerender={rerender} rerender={rerender}
/> />

@ -22,7 +22,7 @@ export function Augmentations(props: IProps): React.ReactElement {
const [augmentation, setAugmentation] = useState("Augmented Targeting I"); const [augmentation, setAugmentation] = useState("Augmented Targeting I");
function setAugmentationDropdown(event: SelectChangeEvent<string>): void { function setAugmentationDropdown(event: SelectChangeEvent<string>): void {
setAugmentation(event.target.value ); setAugmentation(event.target.value);
} }
function queueAug(): void { function queueAug(): void {
props.player.queueAugmentation(augmentation); props.player.queueAugmentation(augmentation);

@ -15,7 +15,7 @@ import { CodingContractTypes } from "../../CodingContracts";
export function CodingContracts(): React.ReactElement { export function CodingContracts(): React.ReactElement {
const [codingcontract, setCodingcontract] = useState("Find Largest Prime Factor"); const [codingcontract, setCodingcontract] = useState("Find Largest Prime Factor");
function setCodingcontractDropdown(event: SelectChangeEvent<string>): void { function setCodingcontractDropdown(event: SelectChangeEvent<string>): void {
setCodingcontract(event.target.value ); setCodingcontract(event.target.value);
} }
function specificContract(): void { function specificContract(): void {

@ -18,7 +18,7 @@ const bigNumber = 1e12;
export function Companies(): React.ReactElement { export function Companies(): React.ReactElement {
const [company, setCompany] = useState(FactionNames.ECorp as string); const [company, setCompany] = useState(FactionNames.ECorp as string);
function setCompanyDropdown(event: SelectChangeEvent<string>): void { function setCompanyDropdown(event: SelectChangeEvent<string>): void {
setCompany(event.target.value ); setCompany(event.target.value);
} }
function resetCompanyRep(): void { function resetCompanyRep(): void {
AllCompanies[company].playerReputation = 0; AllCompanies[company].playerReputation = 0;

@ -29,7 +29,7 @@ export function Factions(props: IProps): React.ReactElement {
const [faction, setFaction] = useState(FactionNames.Illuminati as string); const [faction, setFaction] = useState(FactionNames.Illuminati as string);
function setFactionDropdown(event: SelectChangeEvent<string>): void { function setFactionDropdown(event: SelectChangeEvent<string>): void {
setFaction(event.target.value ); setFaction(event.target.value);
} }
function receiveInvite(): void { function receiveInvite(): void {

@ -19,7 +19,7 @@ interface IProps {
export function Programs(props: IProps): React.ReactElement { export function Programs(props: IProps): React.ReactElement {
const [program, setProgram] = useState("NUKE.exe"); const [program, setProgram] = useState("NUKE.exe");
function setProgramDropdown(event: SelectChangeEvent<string>): void { function setProgramDropdown(event: SelectChangeEvent<string>): void {
setProgram(event.target.value ); setProgram(event.target.value);
} }
function addProgram(): void { function addProgram(): void {
if (!props.player.hasProgram(program)) { if (!props.player.hasProgram(program)) {

@ -15,7 +15,7 @@ import MenuItem from "@mui/material/MenuItem";
export function Servers(): React.ReactElement { export function Servers(): React.ReactElement {
const [server, setServer] = useState("home"); const [server, setServer] = useState("home");
function setServerDropdown(event: SelectChangeEvent<string>): void { function setServerDropdown(event: SelectChangeEvent<string>): void {
setServer(event.target.value ); setServer(event.target.value);
} }
function rootServer(): void { function rootServer(): void {
const s = GetServer(server); const s = GetServer(server);

@ -8,8 +8,8 @@ export function Unclickable(): React.ReactElement {
function unclickable(event: React.MouseEvent<HTMLDivElement>): void { function unclickable(event: React.MouseEvent<HTMLDivElement>): void {
if (!event.target || !(event.target instanceof Element)) return; if (!event.target || !(event.target instanceof Element)) return;
const display = getComputedStyle(event.target ).display; const display = getComputedStyle(event.target).display;
const visibility = getComputedStyle(event.target ).visibility; const visibility = getComputedStyle(event.target).visibility;
if (display === "none" && visibility === "hidden" && event.isTrusted) player.giveExploit(Exploit.Unclickable); if (display === "none" && visibility === "hidden" && event.isTrusted) player.giveExploit(Exploit.Unclickable);
} }

@ -54,7 +54,7 @@ export function HacknetNodeElem(props: IProps): React.ReactElement {
multiplier = getMaxNumberLevelUpgrades(props.player, node, HacknetNodeConstants.MaxLevel); multiplier = getMaxNumberLevelUpgrades(props.player, node, HacknetNodeConstants.MaxLevel);
} else { } else {
const levelsToMax = HacknetNodeConstants.MaxLevel - node.level; const levelsToMax = HacknetNodeConstants.MaxLevel - node.level;
multiplier = Math.min(levelsToMax, purchaseMult ); multiplier = Math.min(levelsToMax, purchaseMult);
} }
const increase = const increase =
@ -94,7 +94,7 @@ export function HacknetNodeElem(props: IProps): React.ReactElement {
multiplier = getMaxNumberRamUpgrades(props.player, node, HacknetNodeConstants.MaxRam); multiplier = getMaxNumberRamUpgrades(props.player, node, HacknetNodeConstants.MaxRam);
} else { } else {
const levelsToMax = Math.round(Math.log2(HacknetNodeConstants.MaxRam / node.ram)); const levelsToMax = Math.round(Math.log2(HacknetNodeConstants.MaxRam / node.ram));
multiplier = Math.min(levelsToMax, purchaseMult ); multiplier = Math.min(levelsToMax, purchaseMult);
} }
const increase = const increase =
@ -144,7 +144,7 @@ export function HacknetNodeElem(props: IProps): React.ReactElement {
multiplier = getMaxNumberCoreUpgrades(props.player, node, HacknetNodeConstants.MaxCores); multiplier = getMaxNumberCoreUpgrades(props.player, node, HacknetNodeConstants.MaxCores);
} else { } else {
const levelsToMax = HacknetNodeConstants.MaxCores - node.cores; const levelsToMax = HacknetNodeConstants.MaxCores - node.cores;
multiplier = Math.min(levelsToMax, purchaseMult ); multiplier = Math.min(levelsToMax, purchaseMult);
} }
const increase = const increase =

@ -72,12 +72,12 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
}, },
getBlackOpRank: getBlackOpRank:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_blackOpName: unknown): number => { (_blackOpName: unknown): number => {
const blackOpName = ctx.helper.string("blackOpName", _blackOpName); const blackOpName = ctx.helper.string("blackOpName", _blackOpName);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const action: any = getBladeburnerActionObject(ctx, "blackops", blackOpName); const action: any = getBladeburnerActionObject(ctx, "blackops", blackOpName);
return action.reqdRank; return action.reqdRank;
}, },
getGeneralActionNames: (ctx: NetscriptContext) => (): string[] => { getGeneralActionNames: (ctx: NetscriptContext) => (): string[] => {
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
@ -92,18 +92,18 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
}, },
startAction: startAction:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_type: unknown, _name: unknown): boolean => { (_type: unknown, _name: unknown): boolean => {
const type = ctx.helper.string("type", _type); const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name); const name = ctx.helper.string("name", _name);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
try { try {
return bladeburner.startActionNetscriptFn(player, type, name, workerScript); return bladeburner.startActionNetscriptFn(player, type, name, workerScript);
} catch (e: any) { } catch (e: any) {
throw ctx.makeRuntimeErrorMsg(e); throw ctx.makeRuntimeErrorMsg(e);
} }
}, },
stopBladeburnerAction: (ctx: NetscriptContext) => (): void => { stopBladeburnerAction: (ctx: NetscriptContext) => (): void => {
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
@ -118,25 +118,25 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
}, },
getActionTime: getActionTime:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_type: unknown, _name: unknown): number => { (_type: unknown, _name: unknown): number => {
const type = ctx.helper.string("type", _type); const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name); const name = ctx.helper.string("name", _name);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
try { try {
const time = bladeburner.getActionTimeNetscriptFn(player, type, name); const time = bladeburner.getActionTimeNetscriptFn(player, type, name);
if (typeof time === "string") { if (typeof time === "string") {
const errorLogText = `Invalid action: type='${type}' name='${name}'`; const errorLogText = `Invalid action: type='${type}' name='${name}'`;
ctx.log(() => errorLogText); ctx.log(() => errorLogText);
return -1; return -1;
} else { } else {
return time; return time;
}
} catch (e: any) {
throw ctx.makeRuntimeErrorMsg(e);
} }
}, } catch (e: any) {
throw ctx.makeRuntimeErrorMsg(e);
}
},
getActionCurrentTime: (ctx: NetscriptContext) => (): number => { getActionCurrentTime: (ctx: NetscriptContext) => (): number => {
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
@ -152,106 +152,106 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
}, },
getActionEstimatedSuccessChance: getActionEstimatedSuccessChance:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_type: unknown, _name: unknown): [number, number] => { (_type: unknown, _name: unknown): [number, number] => {
const type = ctx.helper.string("type", _type); const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name); const name = ctx.helper.string("name", _name);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
try { try {
const chance = bladeburner.getActionEstimatedSuccessChanceNetscriptFn(player, type, name); const chance = bladeburner.getActionEstimatedSuccessChanceNetscriptFn(player, type, name);
if (typeof chance === "string") { if (typeof chance === "string") {
const errorLogText = `Invalid action: type='${type}' name='${name}'`; const errorLogText = `Invalid action: type='${type}' name='${name}'`;
ctx.log(() => errorLogText); ctx.log(() => errorLogText);
return [-1, -1]; return [-1, -1];
} else { } else {
return chance; return chance;
}
} catch (e: any) {
throw ctx.makeRuntimeErrorMsg(e);
} }
}, } catch (e: any) {
throw ctx.makeRuntimeErrorMsg(e);
}
},
getActionRepGain: getActionRepGain:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_type: unknown, _name: unknown, _level: unknown): number => { (_type: unknown, _name: unknown, _level: unknown): number => {
const type = ctx.helper.string("type", _type); const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name); const name = ctx.helper.string("name", _name);
const level = ctx.helper.number("level", _level); const level = ctx.helper.number("level", _level);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const action = getBladeburnerActionObject(ctx, type, name); const action = getBladeburnerActionObject(ctx, type, name);
let rewardMultiplier; let rewardMultiplier;
if (level == null || isNaN(level)) { if (level == null || isNaN(level)) {
rewardMultiplier = Math.pow(action.rewardFac, action.level - 1); rewardMultiplier = Math.pow(action.rewardFac, action.level - 1);
} else { } else {
rewardMultiplier = Math.pow(action.rewardFac, level - 1); rewardMultiplier = Math.pow(action.rewardFac, level - 1);
} }
return action.rankGain * rewardMultiplier * BitNodeMultipliers.BladeburnerRank; return action.rankGain * rewardMultiplier * BitNodeMultipliers.BladeburnerRank;
}, },
getActionCountRemaining: getActionCountRemaining:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_type: unknown, _name: unknown): number => { (_type: unknown, _name: unknown): number => {
const type = ctx.helper.string("type", _type); const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name); const name = ctx.helper.string("name", _name);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
try { try {
return bladeburner.getActionCountRemainingNetscriptFn(type, name, workerScript); return bladeburner.getActionCountRemainingNetscriptFn(type, name, workerScript);
} catch (e: any) { } catch (e: any) {
throw ctx.makeRuntimeErrorMsg(e); throw ctx.makeRuntimeErrorMsg(e);
} }
}, },
getActionMaxLevel: getActionMaxLevel:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_type: unknown, _name: unknown): number => { (_type: unknown, _name: unknown): number => {
const type = ctx.helper.string("type", _type); const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name); const name = ctx.helper.string("name", _name);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const action = getBladeburnerActionObject(ctx, type, name); const action = getBladeburnerActionObject(ctx, type, name);
return action.maxLevel; return action.maxLevel;
}, },
getActionCurrentLevel: getActionCurrentLevel:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_type: unknown, _name: unknown): number => { (_type: unknown, _name: unknown): number => {
const type = ctx.helper.string("type", _type); const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name); const name = ctx.helper.string("name", _name);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const action = getBladeburnerActionObject(ctx, type, name); const action = getBladeburnerActionObject(ctx, type, name);
return action.level; return action.level;
}, },
getActionAutolevel: getActionAutolevel:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_type: unknown, _name: unknown): boolean => { (_type: unknown, _name: unknown): boolean => {
const type = ctx.helper.string("type", _type); const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name); const name = ctx.helper.string("name", _name);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const action = getBladeburnerActionObject(ctx, type, name); const action = getBladeburnerActionObject(ctx, type, name);
return action.autoLevel; return action.autoLevel;
}, },
setActionAutolevel: setActionAutolevel:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_type: unknown, _name: unknown, _autoLevel: unknown = true): void => { (_type: unknown, _name: unknown, _autoLevel: unknown = true): void => {
const type = ctx.helper.string("type", _type); const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name); const name = ctx.helper.string("name", _name);
const autoLevel = ctx.helper.boolean(_autoLevel); const autoLevel = ctx.helper.boolean(_autoLevel);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const action = getBladeburnerActionObject(ctx, type, name); const action = getBladeburnerActionObject(ctx, type, name);
action.autoLevel = autoLevel; action.autoLevel = autoLevel;
}, },
setActionLevel: setActionLevel:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_type: unknown, _name: unknown, _level: unknown = 1): void => { (_type: unknown, _name: unknown, _level: unknown = 1): void => {
const type = ctx.helper.string("type", _type); const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name); const name = ctx.helper.string("name", _name);
const level = ctx.helper.number("level", _level); const level = ctx.helper.number("level", _level);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const action = getBladeburnerActionObject(ctx, type, name); const action = getBladeburnerActionObject(ctx, type, name);
if (level < 1 || level > action.maxLevel) { if (level < 1 || level > action.maxLevel) {
ctx.helper.makeRuntimeErrorMsg(`Level must be between 1 and ${action.maxLevel}, is ${level}`); ctx.helper.makeRuntimeErrorMsg(`Level must be between 1 and ${action.maxLevel}, is ${level}`);
} }
action.level = level; action.level = level;
}, },
getRank: (ctx: NetscriptContext) => (): number => { getRank: (ctx: NetscriptContext) => (): number => {
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
@ -266,107 +266,106 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
}, },
getSkillLevel: getSkillLevel:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_skillName: unknown): number => { (_skillName: unknown): number => {
const skillName = ctx.helper.string("skillName", _skillName); const skillName = ctx.helper.string("skillName", _skillName);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
try { try {
return bladeburner.getSkillLevelNetscriptFn(skillName, workerScript); return bladeburner.getSkillLevelNetscriptFn(skillName, workerScript);
} catch (e: any) { } catch (e: any) {
throw ctx.makeRuntimeErrorMsg(e); throw ctx.makeRuntimeErrorMsg(e);
} }
}, },
getSkillUpgradeCost: getSkillUpgradeCost:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_skillName: unknown): number => { (_skillName: unknown): number => {
const skillName = ctx.helper.string("skillName", _skillName); const skillName = ctx.helper.string("skillName", _skillName);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
try { try {
return bladeburner.getSkillUpgradeCostNetscriptFn(skillName, workerScript); return bladeburner.getSkillUpgradeCostNetscriptFn(skillName, workerScript);
} catch (e: any) { } catch (e: any) {
throw ctx.makeRuntimeErrorMsg(e); throw ctx.makeRuntimeErrorMsg(e);
} }
}, },
upgradeSkill: upgradeSkill:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_skillName: unknown, count = 1): number => { (_skillName: unknown, count = 1): number => {
const skillName = ctx.helper.string("skillName", _skillName); const skillName = ctx.helper.string("skillName", _skillName);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
try { try {
if(bladeburner.upgradeSkillNetscriptFn(skillName, count, workerScript)){ if (bladeburner.upgradeSkillNetscriptFn(skillName, count, workerScript)) {
return count; return count;
} } else {
else{ return 0;
return 0;
}
} catch (e: any) {
throw ctx.makeRuntimeErrorMsg(e);
} }
}, } catch (e: any) {
throw ctx.makeRuntimeErrorMsg(e);
}
},
getTeamSize: getTeamSize:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_type: unknown, _name: unknown): number => { (_type: unknown, _name: unknown): number => {
const type = ctx.helper.string("type", _type); const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name); const name = ctx.helper.string("name", _name);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
try { try {
return bladeburner.getTeamSizeNetscriptFn(type, name, workerScript); return bladeburner.getTeamSizeNetscriptFn(type, name, workerScript);
} catch (e: any) { } catch (e: any) {
throw ctx.makeRuntimeErrorMsg(e); throw ctx.makeRuntimeErrorMsg(e);
} }
}, },
setTeamSize: setTeamSize:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_type: unknown, _name: unknown, _size: unknown): number => { (_type: unknown, _name: unknown, _size: unknown): number => {
const type = ctx.helper.string("type", _type); const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name); const name = ctx.helper.string("name", _name);
const size = ctx.helper.number("size", _size); const size = ctx.helper.number("size", _size);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
try { try {
return bladeburner.setTeamSizeNetscriptFn(type, name, size, workerScript); return bladeburner.setTeamSizeNetscriptFn(type, name, size, workerScript);
} catch (e: any) { } catch (e: any) {
throw ctx.makeRuntimeErrorMsg(e); throw ctx.makeRuntimeErrorMsg(e);
} }
}, },
getCityEstimatedPopulation: getCityEstimatedPopulation:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_cityName: unknown): number => { (_cityName: unknown): number => {
const cityName = ctx.helper.string("cityName", _cityName); const cityName = ctx.helper.string("cityName", _cityName);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
checkBladeburnerCity(ctx, cityName); checkBladeburnerCity(ctx, cityName);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
return bladeburner.cities[cityName].popEst; return bladeburner.cities[cityName].popEst;
}, },
getCityCommunities: getCityCommunities:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_cityName: unknown): number => { (_cityName: unknown): number => {
const cityName = ctx.helper.string("cityName", _cityName); const cityName = ctx.helper.string("cityName", _cityName);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
checkBladeburnerCity(ctx, cityName); checkBladeburnerCity(ctx, cityName);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
return bladeburner.cities[cityName].comms; return bladeburner.cities[cityName].comms;
}, },
getCityChaos: getCityChaos:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_cityName: unknown): number => { (_cityName: unknown): number => {
const cityName = ctx.helper.string("cityName", _cityName); const cityName = ctx.helper.string("cityName", _cityName);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
checkBladeburnerCity(ctx, cityName); checkBladeburnerCity(ctx, cityName);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
return bladeburner.cities[cityName].chaos; return bladeburner.cities[cityName].chaos;
}, },
getCity: (ctx: NetscriptContext) => (): string => { getCity: (ctx: NetscriptContext) => (): string => {
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
@ -375,15 +374,15 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
}, },
switchCity: switchCity:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_cityName: unknown): boolean => { (_cityName: unknown): boolean => {
const cityName = ctx.helper.string("cityName", _cityName); const cityName = ctx.helper.string("cityName", _cityName);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
checkBladeburnerCity(ctx, cityName); checkBladeburnerCity(ctx, cityName);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
bladeburner.city = cityName; bladeburner.city = cityName;
return true; return true;
}, },
getStamina: (ctx: NetscriptContext) => (): [number, number] => { getStamina: (ctx: NetscriptContext) => (): [number, number] => {
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;

@ -257,7 +257,7 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript
function getMaterial(divisionName: string, cityName: string, materialName: string): Material { function getMaterial(divisionName: string, cityName: string, materialName: string): Material {
const warehouse = getWarehouse(divisionName, cityName); const warehouse = getWarehouse(divisionName, cityName);
const matName = (materialName ).replace(/ /g, ""); const matName = materialName.replace(/ /g, "");
const material = warehouse.materials[matName]; const material = warehouse.materials[matName];
if (material === undefined) throw new Error(`Invalid material name: '${materialName}'`); if (material === undefined) throw new Error(`Invalid material name: '${materialName}'`);
return material; return material;
@ -725,9 +725,11 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript
const employeeName = ctx.helper.string("employeeName", _employeeName); const employeeName = ctx.helper.string("employeeName", _employeeName);
const job = ctx.helper.string("job", _job); const job = ctx.helper.string("job", _job);
const employee = getEmployee(divisionName, cityName, employeeName); const employee = getEmployee(divisionName, cityName, employeeName);
return netscriptDelay(["Training", "Unassigned"].includes(employee.pos) ? 0 : 1000, workerScript).then(function () { return netscriptDelay(["Training", "Unassigned"].includes(employee.pos) ? 0 : 1000, workerScript).then(
return Promise.resolve(AssignJob(employee, job)); function () {
}); return Promise.resolve(AssignJob(employee, job));
},
);
}, },
hireEmployee: hireEmployee:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>

@ -693,7 +693,7 @@ export function Root(props: IProps): React.ReactElement {
if (server === null) throw new Error(`Server '${closingScript.hostname}' should not be null, but it is.`); if (server === null) throw new Error(`Server '${closingScript.hostname}' should not be null, but it is.`);
const serverScriptIndex = server.scripts.findIndex((script) => script.filename === closingScript.fileName); const serverScriptIndex = server.scripts.findIndex((script) => script.filename === closingScript.fileName);
if (serverScriptIndex === -1 || savedScriptCode !== server.scripts[serverScriptIndex ].code) { if (serverScriptIndex === -1 || savedScriptCode !== server.scripts[serverScriptIndex].code) {
PromptEvent.emit({ PromptEvent.emit({
txt: `Do you want to save changes to ${closingScript.fileName} on ${closingScript.hostname}?`, txt: `Do you want to save changes to ${closingScript.fileName} on ${closingScript.hostname}?`,
resolve: (result: boolean | string) => { resolve: (result: boolean | string) => {

@ -36,7 +36,7 @@ function toNumber(n: number | IMinMaxRange): number {
return n; return n;
} }
case "object": { case "object": {
const range = n ; const range = n;
value = getRandomInt(range.min, range.max); value = getRandomInt(range.min, range.max);
break; break;
} }

@ -68,7 +68,7 @@ export function placeOrder(
// Process to see if it should be executed immediately // Process to see if it should be executed immediately
const processOrderRefs = { const processOrderRefs = {
stockMarket: StockMarket , stockMarket: StockMarket,
symbolToStockMap: SymbolToStockMap, symbolToStockMap: SymbolToStockMap,
}; };
processOrders(stock, order.type, order.pos, processOrderRefs); processOrders(stock, order.type, order.pos, processOrderRefs);

@ -84,7 +84,7 @@ export function mv(
script.filename = destPath; script.filename = destPath;
} else if (srcFile instanceof TextFile) { } else if (srcFile instanceof TextFile) {
const textFile = srcFile ; const textFile = srcFile;
if (!dest.endsWith(".txt")) { if (!dest.endsWith(".txt")) {
terminal.error(`Source and destination files must have the same type`); terminal.error(`Source and destination files must have the same type`);
return; return;

@ -121,7 +121,7 @@ export function getTextFile(fn: string, server: BaseServer): TextFile | null {
filename = removeLeadingSlash(filename); filename = removeLeadingSlash(filename);
} }
for (const file of server.textFiles ) { for (const file of server.textFiles) {
if (file.fn === filename) { if (file.fn === filename) {
return file; return file;
} }