Initial commit

This commit is contained in:
Snarling
2022-08-08 13:43:41 -04:00
parent 3a2e676c9b
commit 208495e269
25 changed files with 1592 additions and 1614 deletions
+55 -54
View File
@@ -6,6 +6,7 @@ import { Bladeburner as INetscriptBladeburner, BladeburnerCurAction } from "../S
import { IAction } from "src/Bladeburner/IAction";
import { InternalAPI, NetscriptContext } from "src/Netscript/APIWrapper";
import { BlackOperation } from "../Bladeburner/BlackOperation";
import { helpers } from "../Netscript/NetscriptHelpers";
export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript): InternalAPI<INetscriptBladeburner> {
const checkBladeburnerAccess = function (ctx: NetscriptContext, skipjoined = false): void {
@@ -18,13 +19,13 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
});
if (!apiAccess) {
const apiDenied = `You do not currently have access to the Bladeburner API. You must either be in BitNode-7 or have Source-File 7.`;
throw ctx.makeRuntimeErrorMsg(apiDenied);
throw helpers.makeRuntimeErrorMsg(ctx, apiDenied);
}
if (!skipjoined) {
const bladeburnerAccess = bladeburner instanceof Bladeburner;
if (!bladeburnerAccess) {
const bladeburnerDenied = `You must be a member of the Bladeburner division to use this API.`;
throw ctx.makeRuntimeErrorMsg(bladeburnerDenied);
throw helpers.makeRuntimeErrorMsg(ctx, bladeburnerDenied);
}
}
};
@@ -33,7 +34,7 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Must have joined bladeburner");
if (!bladeburner.cities.hasOwnProperty(city)) {
throw ctx.makeRuntimeErrorMsg(`Invalid city: ${city}`);
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid city: ${city}`);
}
};
@@ -42,11 +43,11 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
if (bladeburner === null) throw new Error("Must have joined bladeburner");
const actionId = bladeburner.getActionIdFromTypeAndName(type, name);
if (!actionId) {
throw ctx.makeRuntimeErrorMsg(`Invalid action type='${type}', name='${name}'`);
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid action type='${type}', name='${name}'`);
}
const actionObj = bladeburner.getActionObject(actionId);
if (!actionObj) {
throw ctx.makeRuntimeErrorMsg(`Invalid action type='${type}', name='${name}'`);
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid action type='${type}', name='${name}'`);
}
return actionObj;
@@ -74,7 +75,7 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
getBlackOpRank:
(ctx: NetscriptContext) =>
(_blackOpName: unknown): number => {
const blackOpName = ctx.helper.string("blackOpName", _blackOpName);
const blackOpName = helpers.string(ctx, "blackOpName", _blackOpName);
checkBladeburnerAccess(ctx);
const action = getBladeburnerActionObject(ctx, "blackops", blackOpName);
if (!(action instanceof BlackOperation)) throw new Error("action was not a black operation");
@@ -95,15 +96,15 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
startAction:
(ctx: NetscriptContext) =>
(_type: unknown, _name: unknown): boolean => {
const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name);
const type = helpers.string(ctx, "type", _type);
const name = helpers.string(ctx, "name", _name);
checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
try {
return bladeburner.startActionNetscriptFn(player, type, name, workerScript);
} catch (e: unknown) {
throw ctx.makeRuntimeErrorMsg(String(e));
throw helpers.makeRuntimeErrorMsg(ctx, String(e));
}
},
stopBladeburnerAction: (ctx: NetscriptContext) => (): void => {
@@ -121,8 +122,8 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
getActionTime:
(ctx: NetscriptContext) =>
(_type: unknown, _name: unknown): number => {
const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name);
const type = helpers.string(ctx, "type", _type);
const name = helpers.string(ctx, "name", _name);
checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
@@ -136,7 +137,7 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
return time;
}
} catch (e: unknown) {
throw ctx.makeRuntimeErrorMsg(String(e));
throw helpers.makeRuntimeErrorMsg(ctx, String(e));
}
},
getActionCurrentTime: (ctx: NetscriptContext) => (): number => {
@@ -149,14 +150,14 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
1000;
return timecomputed;
} catch (e: unknown) {
throw ctx.makeRuntimeErrorMsg(String(e));
throw helpers.makeRuntimeErrorMsg(ctx, String(e));
}
},
getActionEstimatedSuccessChance:
(ctx: NetscriptContext) =>
(_type: unknown, _name: unknown): [number, number] => {
const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name);
const type = helpers.string(ctx, "type", _type);
const name = helpers.string(ctx, "name", _name);
checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
@@ -170,15 +171,15 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
return chance;
}
} catch (e: unknown) {
throw ctx.makeRuntimeErrorMsg(String(e));
throw helpers.makeRuntimeErrorMsg(ctx, String(e));
}
},
getActionRepGain:
(ctx: NetscriptContext) =>
(_type: unknown, _name: unknown, _level: unknown): number => {
const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name);
const level = ctx.helper.number("level", _level);
const type = helpers.string(ctx, "type", _type);
const name = helpers.string(ctx, "name", _name);
const level = helpers.number(ctx, "level", _level);
checkBladeburnerAccess(ctx);
const action = getBladeburnerActionObject(ctx, type, name);
let rewardMultiplier;
@@ -193,22 +194,22 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
getActionCountRemaining:
(ctx: NetscriptContext) =>
(_type: unknown, _name: unknown): number => {
const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name);
const type = helpers.string(ctx, "type", _type);
const name = helpers.string(ctx, "name", _name);
checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
try {
return bladeburner.getActionCountRemainingNetscriptFn(type, name, workerScript);
} catch (e: unknown) {
throw ctx.makeRuntimeErrorMsg(String(e));
throw helpers.makeRuntimeErrorMsg(ctx, String(e));
}
},
getActionMaxLevel:
(ctx: NetscriptContext) =>
(_type: unknown, _name: unknown): number => {
const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name);
const type = helpers.string(ctx, "type", _type);
const name = helpers.string(ctx, "name", _name);
checkBladeburnerAccess(ctx);
const action = getBladeburnerActionObject(ctx, type, name);
return action.maxLevel;
@@ -216,8 +217,8 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
getActionCurrentLevel:
(ctx: NetscriptContext) =>
(_type: unknown, _name: unknown): number => {
const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name);
const type = helpers.string(ctx, "type", _type);
const name = helpers.string(ctx, "name", _name);
checkBladeburnerAccess(ctx);
const action = getBladeburnerActionObject(ctx, type, name);
return action.level;
@@ -225,8 +226,8 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
getActionAutolevel:
(ctx: NetscriptContext) =>
(_type: unknown, _name: unknown): boolean => {
const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name);
const type = helpers.string(ctx, "type", _type);
const name = helpers.string(ctx, "name", _name);
checkBladeburnerAccess(ctx);
const action = getBladeburnerActionObject(ctx, type, name);
return action.autoLevel;
@@ -234,9 +235,9 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
setActionAutolevel:
(ctx: NetscriptContext) =>
(_type: unknown, _name: unknown, _autoLevel: unknown = true): void => {
const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name);
const autoLevel = ctx.helper.boolean(_autoLevel);
const type = helpers.string(ctx, "type", _type);
const name = helpers.string(ctx, "name", _name);
const autoLevel = !!_autoLevel;
checkBladeburnerAccess(ctx);
const action = getBladeburnerActionObject(ctx, type, name);
action.autoLevel = autoLevel;
@@ -244,13 +245,13 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
setActionLevel:
(ctx: NetscriptContext) =>
(_type: unknown, _name: unknown, _level: unknown = 1): void => {
const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name);
const level = ctx.helper.number("level", _level);
const type = helpers.string(ctx, "type", _type);
const name = helpers.string(ctx, "name", _name);
const level = helpers.number(ctx, "level", _level);
checkBladeburnerAccess(ctx);
const action = getBladeburnerActionObject(ctx, type, name);
if (level < 1 || level > action.maxLevel) {
ctx.helper.makeRuntimeErrorMsg(`Level must be between 1 and ${action.maxLevel}, is ${level}`);
helpers.makeRuntimeErrorMsg(ctx, `Level must be between 1 and ${action.maxLevel}, is ${level}`);
}
action.level = level;
},
@@ -269,77 +270,77 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
getSkillLevel:
(ctx: NetscriptContext) =>
(_skillName: unknown): number => {
const skillName = ctx.helper.string("skillName", _skillName);
const skillName = helpers.string(ctx, "skillName", _skillName);
checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
try {
return bladeburner.getSkillLevelNetscriptFn(skillName, workerScript);
} catch (e: unknown) {
throw ctx.makeRuntimeErrorMsg(String(e));
throw helpers.makeRuntimeErrorMsg(ctx, String(e));
}
},
getSkillUpgradeCost:
(ctx: NetscriptContext) =>
(_skillName: unknown, _count: unknown = 1): number => {
const skillName = ctx.helper.string("skillName", _skillName);
const count = ctx.helper.number("count", _count);
const skillName = helpers.string(ctx, "skillName", _skillName);
const count = helpers.number(ctx, "count", _count);
checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
try {
return bladeburner.getSkillUpgradeCostNetscriptFn(skillName, count, workerScript);
} catch (e: unknown) {
throw ctx.makeRuntimeErrorMsg(String(e));
throw helpers.makeRuntimeErrorMsg(ctx, String(e));
}
},
upgradeSkill:
(ctx: NetscriptContext) =>
(_skillName: unknown, _count: unknown = 1): boolean => {
const skillName = ctx.helper.string("skillName", _skillName);
const count = ctx.helper.number("count", _count);
const skillName = helpers.string(ctx, "skillName", _skillName);
const count = helpers.number(ctx, "count", _count);
checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
try {
return bladeburner.upgradeSkillNetscriptFn(skillName, count, workerScript);
} catch (e: unknown) {
throw ctx.makeRuntimeErrorMsg(String(e));
throw helpers.makeRuntimeErrorMsg(ctx, String(e));
}
},
getTeamSize:
(ctx: NetscriptContext) =>
(_type: unknown, _name: unknown): number => {
const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name);
const type = helpers.string(ctx, "type", _type);
const name = helpers.string(ctx, "name", _name);
checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
try {
return bladeburner.getTeamSizeNetscriptFn(type, name, workerScript);
} catch (e: unknown) {
throw ctx.makeRuntimeErrorMsg(String(e));
throw helpers.makeRuntimeErrorMsg(ctx, String(e));
}
},
setTeamSize:
(ctx: NetscriptContext) =>
(_type: unknown, _name: unknown, _size: unknown): number => {
const type = ctx.helper.string("type", _type);
const name = ctx.helper.string("name", _name);
const size = ctx.helper.number("size", _size);
const type = helpers.string(ctx, "type", _type);
const name = helpers.string(ctx, "name", _name);
const size = helpers.number(ctx, "size", _size);
checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
try {
return bladeburner.setTeamSizeNetscriptFn(type, name, size, workerScript);
} catch (e: unknown) {
throw ctx.makeRuntimeErrorMsg(String(e));
throw helpers.makeRuntimeErrorMsg(ctx, String(e));
}
},
getCityEstimatedPopulation:
(ctx: NetscriptContext) =>
(_cityName: unknown): number => {
const cityName = ctx.helper.string("cityName", _cityName);
const cityName = helpers.string(ctx, "cityName", _cityName);
checkBladeburnerAccess(ctx);
checkBladeburnerCity(ctx, cityName);
const bladeburner = player.bladeburner;
@@ -349,7 +350,7 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
getCityCommunities:
(ctx: NetscriptContext) =>
(_cityName: unknown): number => {
const cityName = ctx.helper.string("cityName", _cityName);
const cityName = helpers.string(ctx, "cityName", _cityName);
checkBladeburnerAccess(ctx);
checkBladeburnerCity(ctx, cityName);
const bladeburner = player.bladeburner;
@@ -359,7 +360,7 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
getCityChaos:
(ctx: NetscriptContext) =>
(_cityName: unknown): number => {
const cityName = ctx.helper.string("cityName", _cityName);
const cityName = helpers.string(ctx, "cityName", _cityName);
checkBladeburnerAccess(ctx);
checkBladeburnerCity(ctx, cityName);
const bladeburner = player.bladeburner;
@@ -375,7 +376,7 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
switchCity:
(ctx: NetscriptContext) =>
(_cityName: unknown): boolean => {
const cityName = ctx.helper.string("cityName", _cityName);
const cityName = helpers.string(ctx, "cityName", _cityName);
checkBladeburnerAccess(ctx);
checkBladeburnerCity(ctx, cityName);
const bladeburner = player.bladeburner;