mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-19 07:48:37 +02:00
work on making the netscript api tighter
This commit is contained in:
@@ -4,7 +4,7 @@ import { IPlayer } from "../PersonObjects/IPlayer";
|
||||
import { Bladeburner } from "../Bladeburner/Bladeburner";
|
||||
import { getRamCost } from "../Netscript/RamCostGenerator";
|
||||
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
|
||||
import { Bladeburner as INetscriptBladeburner } from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { Bladeburner as INetscriptBladeburner, BladeburnerCurAction } from "../ScriptEditor/NetscriptDefinitions";
|
||||
|
||||
export function NetscriptBladeburner(
|
||||
player: IPlayer,
|
||||
@@ -56,48 +56,48 @@ export function NetscriptBladeburner(
|
||||
};
|
||||
|
||||
return {
|
||||
getContractNames: function (): any {
|
||||
getContractNames: function (): string[] {
|
||||
helper.updateDynamicRam("getContractNames", getRamCost("bladeburner", "getContractNames"));
|
||||
checkBladeburnerAccess("getContractNames");
|
||||
const bladeburner = player.bladeburner;
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
return bladeburner.getContractNamesNetscriptFn();
|
||||
},
|
||||
getOperationNames: function (): any {
|
||||
getOperationNames: function (): string[] {
|
||||
helper.updateDynamicRam("getOperationNames", getRamCost("bladeburner", "getOperationNames"));
|
||||
checkBladeburnerAccess("getOperationNames");
|
||||
const bladeburner = player.bladeburner;
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
return bladeburner.getOperationNamesNetscriptFn();
|
||||
},
|
||||
getBlackOpNames: function (): any {
|
||||
getBlackOpNames: function (): string[] {
|
||||
helper.updateDynamicRam("getBlackOpNames", getRamCost("bladeburner", "getBlackOpNames"));
|
||||
checkBladeburnerAccess("getBlackOpNames");
|
||||
const bladeburner = player.bladeburner;
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
return bladeburner.getBlackOpNamesNetscriptFn();
|
||||
},
|
||||
getBlackOpRank: function (name: any = ""): any {
|
||||
getBlackOpRank: function (name: any = ""): number {
|
||||
helper.updateDynamicRam("getBlackOpRank", getRamCost("bladeburner", "getBlackOpRank"));
|
||||
checkBladeburnerAccess("getBlackOpRank");
|
||||
const action: any = getBladeburnerActionObject("getBlackOpRank", "blackops", name);
|
||||
return action.reqdRank;
|
||||
},
|
||||
getGeneralActionNames: function (): any {
|
||||
getGeneralActionNames: function (): string[] {
|
||||
helper.updateDynamicRam("getGeneralActionNames", getRamCost("bladeburner", "getGeneralActionNames"));
|
||||
checkBladeburnerAccess("getGeneralActionNames");
|
||||
const bladeburner = player.bladeburner;
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
return bladeburner.getGeneralActionNamesNetscriptFn();
|
||||
},
|
||||
getSkillNames: function (): any {
|
||||
getSkillNames: function (): string[] {
|
||||
helper.updateDynamicRam("getSkillNames", getRamCost("bladeburner", "getSkillNames"));
|
||||
checkBladeburnerAccess("getSkillNames");
|
||||
const bladeburner = player.bladeburner;
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
return bladeburner.getSkillNamesNetscriptFn();
|
||||
},
|
||||
startAction: function (type: any = "", name: any = ""): any {
|
||||
startAction: function (type: any = "", name: any = ""): boolean {
|
||||
helper.updateDynamicRam("startAction", getRamCost("bladeburner", "startAction"));
|
||||
checkBladeburnerAccess("startAction");
|
||||
const bladeburner = player.bladeburner;
|
||||
@@ -108,21 +108,21 @@ export function NetscriptBladeburner(
|
||||
throw helper.makeRuntimeErrorMsg("bladeburner.startAction", e);
|
||||
}
|
||||
},
|
||||
stopBladeburnerAction: function (): any {
|
||||
stopBladeburnerAction: function (): void {
|
||||
helper.updateDynamicRam("stopBladeburnerAction", getRamCost("bladeburner", "stopBladeburnerAction"));
|
||||
checkBladeburnerAccess("stopBladeburnerAction");
|
||||
const bladeburner = player.bladeburner;
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
return bladeburner.resetAction();
|
||||
},
|
||||
getCurrentAction: function (): any {
|
||||
getCurrentAction: function (): BladeburnerCurAction {
|
||||
helper.updateDynamicRam("getCurrentAction", getRamCost("bladeburner", "getCurrentAction"));
|
||||
checkBladeburnerAccess("getCurrentAction");
|
||||
const bladeburner = player.bladeburner;
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
return bladeburner.getTypeAndNameFromActionId(bladeburner.action);
|
||||
},
|
||||
getActionTime: function (type: any = "", name: any = ""): any {
|
||||
getActionTime: function (type: any = "", name: any = ""): number {
|
||||
helper.updateDynamicRam("getActionTime", getRamCost("bladeburner", "getActionTime"));
|
||||
checkBladeburnerAccess("getActionTime");
|
||||
const bladeburner = player.bladeburner;
|
||||
@@ -133,7 +133,7 @@ export function NetscriptBladeburner(
|
||||
throw helper.makeRuntimeErrorMsg("bladeburner.getActionTime", e);
|
||||
}
|
||||
},
|
||||
getActionEstimatedSuccessChance: function (type: any = "", name: any = ""): any {
|
||||
getActionEstimatedSuccessChance: function (type: any = "", name: any = ""): [number, number] {
|
||||
helper.updateDynamicRam(
|
||||
"getActionEstimatedSuccessChance",
|
||||
getRamCost("bladeburner", "getActionEstimatedSuccessChance"),
|
||||
@@ -147,7 +147,7 @@ export function NetscriptBladeburner(
|
||||
throw helper.makeRuntimeErrorMsg("bladeburner.getActionEstimatedSuccessChance", e);
|
||||
}
|
||||
},
|
||||
getActionRepGain: function (type: any = "", name: any = "", level: any): any {
|
||||
getActionRepGain: function (type: any = "", name: any = "", level: any): number {
|
||||
helper.updateDynamicRam("getActionRepGain", getRamCost("bladeburner", "getActionRepGain"));
|
||||
checkBladeburnerAccess("getActionRepGain");
|
||||
const action = getBladeburnerActionObject("getActionRepGain", type, name);
|
||||
@@ -160,7 +160,7 @@ export function NetscriptBladeburner(
|
||||
|
||||
return action.rankGain * rewardMultiplier * BitNodeMultipliers.BladeburnerRank;
|
||||
},
|
||||
getActionCountRemaining: function (type: any = "", name: any = ""): any {
|
||||
getActionCountRemaining: function (type: any = "", name: any = ""): number {
|
||||
helper.updateDynamicRam("getActionCountRemaining", getRamCost("bladeburner", "getActionCountRemaining"));
|
||||
checkBladeburnerAccess("getActionCountRemaining");
|
||||
const bladeburner = player.bladeburner;
|
||||
@@ -171,31 +171,31 @@ export function NetscriptBladeburner(
|
||||
throw helper.makeRuntimeErrorMsg("bladeburner.getActionCountRemaining", e);
|
||||
}
|
||||
},
|
||||
getActionMaxLevel: function (type: any = "", name: any = ""): any {
|
||||
getActionMaxLevel: function (type: any = "", name: any = ""): number {
|
||||
helper.updateDynamicRam("getActionMaxLevel", getRamCost("bladeburner", "getActionMaxLevel"));
|
||||
checkBladeburnerAccess("getActionMaxLevel");
|
||||
const action = getBladeburnerActionObject("getActionMaxLevel", type, name);
|
||||
return action.maxLevel;
|
||||
},
|
||||
getActionCurrentLevel: function (type: any = "", name: any = ""): any {
|
||||
getActionCurrentLevel: function (type: any = "", name: any = ""): number {
|
||||
helper.updateDynamicRam("getActionCurrentLevel", getRamCost("bladeburner", "getActionCurrentLevel"));
|
||||
checkBladeburnerAccess("getActionCurrentLevel");
|
||||
const action = getBladeburnerActionObject("getActionCurrentLevel", type, name);
|
||||
return action.level;
|
||||
},
|
||||
getActionAutolevel: function (type: any = "", name: any = ""): any {
|
||||
getActionAutolevel: function (type: any = "", name: any = ""): boolean {
|
||||
helper.updateDynamicRam("getActionAutolevel", getRamCost("bladeburner", "getActionAutolevel"));
|
||||
checkBladeburnerAccess("getActionAutolevel");
|
||||
const action = getBladeburnerActionObject("getActionCurrentLevel", type, name);
|
||||
return action.autoLevel;
|
||||
},
|
||||
setActionAutolevel: function (type: any = "", name: any = "", autoLevel: any = true): any {
|
||||
setActionAutolevel: function (type: any = "", name: any = "", autoLevel: any = true): void {
|
||||
helper.updateDynamicRam("setActionAutolevel", getRamCost("bladeburner", "setActionAutolevel"));
|
||||
checkBladeburnerAccess("setActionAutolevel");
|
||||
const action = getBladeburnerActionObject("setActionAutolevel", type, name);
|
||||
action.autoLevel = autoLevel;
|
||||
},
|
||||
setActionLevel: function (type: any = "", name: any = "", level: any = 1): any {
|
||||
setActionLevel: function (type: any = "", name: any = "", level: any = 1): void {
|
||||
helper.updateDynamicRam("setActionLevel", getRamCost("bladeburner", "setActionLevel"));
|
||||
checkBladeburnerAccess("setActionLevel");
|
||||
const action = getBladeburnerActionObject("setActionLevel", type, name);
|
||||
@@ -207,21 +207,21 @@ export function NetscriptBladeburner(
|
||||
}
|
||||
action.level = level;
|
||||
},
|
||||
getRank: function (): any {
|
||||
getRank: function (): number {
|
||||
helper.updateDynamicRam("getRank", getRamCost("bladeburner", "getRank"));
|
||||
checkBladeburnerAccess("getRank");
|
||||
const bladeburner = player.bladeburner;
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
return bladeburner.rank;
|
||||
},
|
||||
getSkillPoints: function (): any {
|
||||
getSkillPoints: function (): number {
|
||||
helper.updateDynamicRam("getSkillPoints", getRamCost("bladeburner", "getSkillPoints"));
|
||||
checkBladeburnerAccess("getSkillPoints");
|
||||
const bladeburner = player.bladeburner;
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
return bladeburner.skillPoints;
|
||||
},
|
||||
getSkillLevel: function (skillName: any = ""): any {
|
||||
getSkillLevel: function (skillName: any = ""): number {
|
||||
helper.updateDynamicRam("getSkillLevel", getRamCost("bladeburner", "getSkillLevel"));
|
||||
checkBladeburnerAccess("getSkillLevel");
|
||||
const bladeburner = player.bladeburner;
|
||||
@@ -232,7 +232,7 @@ export function NetscriptBladeburner(
|
||||
throw helper.makeRuntimeErrorMsg("bladeburner.getSkillLevel", e);
|
||||
}
|
||||
},
|
||||
getSkillUpgradeCost: function (skillName: any = ""): any {
|
||||
getSkillUpgradeCost: function (skillName: any = ""): number {
|
||||
helper.updateDynamicRam("getSkillUpgradeCost", getRamCost("bladeburner", "getSkillUpgradeCost"));
|
||||
checkBladeburnerAccess("getSkillUpgradeCost");
|
||||
const bladeburner = player.bladeburner;
|
||||
@@ -243,7 +243,7 @@ export function NetscriptBladeburner(
|
||||
throw helper.makeRuntimeErrorMsg("bladeburner.getSkillUpgradeCost", e);
|
||||
}
|
||||
},
|
||||
upgradeSkill: function (skillName: any): any {
|
||||
upgradeSkill: function (skillName: any): boolean {
|
||||
helper.updateDynamicRam("upgradeSkill", getRamCost("bladeburner", "upgradeSkill"));
|
||||
checkBladeburnerAccess("upgradeSkill");
|
||||
const bladeburner = player.bladeburner;
|
||||
@@ -254,7 +254,7 @@ export function NetscriptBladeburner(
|
||||
throw helper.makeRuntimeErrorMsg("bladeburner.upgradeSkill", e);
|
||||
}
|
||||
},
|
||||
getTeamSize: function (type: any = "", name: any = ""): any {
|
||||
getTeamSize: function (type: any = "", name: any = ""): number {
|
||||
helper.updateDynamicRam("getTeamSize", getRamCost("bladeburner", "getTeamSize"));
|
||||
checkBladeburnerAccess("getTeamSize");
|
||||
const bladeburner = player.bladeburner;
|
||||
@@ -265,7 +265,7 @@ export function NetscriptBladeburner(
|
||||
throw helper.makeRuntimeErrorMsg("bladeburner.getTeamSize", e);
|
||||
}
|
||||
},
|
||||
setTeamSize: function (type: any = "", name: any = "", size: any): any {
|
||||
setTeamSize: function (type: any = "", name: any = "", size: any): number {
|
||||
helper.updateDynamicRam("setTeamSize", getRamCost("bladeburner", "setTeamSize"));
|
||||
checkBladeburnerAccess("setTeamSize");
|
||||
const bladeburner = player.bladeburner;
|
||||
@@ -276,7 +276,7 @@ export function NetscriptBladeburner(
|
||||
throw helper.makeRuntimeErrorMsg("bladeburner.setTeamSize", e);
|
||||
}
|
||||
},
|
||||
getCityEstimatedPopulation: function (cityName: any): any {
|
||||
getCityEstimatedPopulation: function (cityName: any): number {
|
||||
helper.updateDynamicRam("getCityEstimatedPopulation", getRamCost("bladeburner", "getCityEstimatedPopulation"));
|
||||
checkBladeburnerAccess("getCityEstimatedPopulation");
|
||||
checkBladeburnerCity("getCityEstimatedPopulation", cityName);
|
||||
@@ -284,7 +284,7 @@ export function NetscriptBladeburner(
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
return bladeburner.cities[cityName].popEst;
|
||||
},
|
||||
getCityCommunities: function (cityName: any): any {
|
||||
getCityCommunities: function (cityName: any): number {
|
||||
helper.updateDynamicRam("getCityCommunities", getRamCost("bladeburner", "getCityCommunities"));
|
||||
checkBladeburnerAccess("getCityCommunities");
|
||||
checkBladeburnerCity("getCityCommunities", cityName);
|
||||
@@ -292,7 +292,7 @@ export function NetscriptBladeburner(
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
return bladeburner.cities[cityName].comms;
|
||||
},
|
||||
getCityChaos: function (cityName: any): any {
|
||||
getCityChaos: function (cityName: any): number {
|
||||
helper.updateDynamicRam("getCityChaos", getRamCost("bladeburner", "getCityChaos"));
|
||||
checkBladeburnerAccess("getCityChaos");
|
||||
checkBladeburnerCity("getCityChaos", cityName);
|
||||
@@ -300,14 +300,14 @@ export function NetscriptBladeburner(
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
return bladeburner.cities[cityName].chaos;
|
||||
},
|
||||
getCity: function (): any {
|
||||
getCity: function (): string {
|
||||
helper.updateDynamicRam("getCity", getRamCost("bladeburner", "getCity"));
|
||||
checkBladeburnerAccess("getCityChaos");
|
||||
const bladeburner = player.bladeburner;
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
return bladeburner.city;
|
||||
},
|
||||
switchCity: function (cityName: any): any {
|
||||
switchCity: function (cityName: any): boolean {
|
||||
helper.updateDynamicRam("switchCity", getRamCost("bladeburner", "switchCity"));
|
||||
checkBladeburnerAccess("switchCity");
|
||||
checkBladeburnerCity("switchCity", cityName);
|
||||
@@ -315,21 +315,21 @@ export function NetscriptBladeburner(
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
return (bladeburner.city = cityName);
|
||||
},
|
||||
getStamina: function (): any {
|
||||
getStamina: function (): [number, number] {
|
||||
helper.updateDynamicRam("getStamina", getRamCost("bladeburner", "getStamina"));
|
||||
checkBladeburnerAccess("getStamina");
|
||||
const bladeburner = player.bladeburner;
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
return [bladeburner.stamina, bladeburner.maxStamina];
|
||||
},
|
||||
joinBladeburnerFaction: function (): any {
|
||||
joinBladeburnerFaction: function (): boolean {
|
||||
helper.updateDynamicRam("joinBladeburnerFaction", getRamCost("bladeburner", "joinBladeburnerFaction"));
|
||||
checkBladeburnerAccess("joinBladeburnerFaction", true);
|
||||
const bladeburner = player.bladeburner;
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
return bladeburner.joinBladeburnerFactionNetscriptFn(workerScript);
|
||||
},
|
||||
joinBladeburnerDivision: function (): any {
|
||||
joinBladeburnerDivision: function (): boolean {
|
||||
helper.updateDynamicRam("joinBladeburnerDivision", getRamCost("bladeburner", "joinBladeburnerDivision"));
|
||||
if (player.bitNodeN === 7 || player.sourceFileLvl(7) > 0) {
|
||||
if (player.bitNodeN === 8) {
|
||||
@@ -355,8 +355,9 @@ export function NetscriptBladeburner(
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
getBonusTime: function (): any {
|
||||
getBonusTime: function (): number {
|
||||
helper.updateDynamicRam("getBonusTime", getRamCost("bladeburner", "getBonusTime"));
|
||||
checkBladeburnerAccess("getBonusTime");
|
||||
const bladeburner = player.bladeburner;
|
||||
|
||||
@@ -22,7 +22,12 @@ export function NetscriptCodingContract(
|
||||
};
|
||||
|
||||
return {
|
||||
attempt: function (answer: any, fn: any, ip: any = workerScript.hostname, { returnReward }: any = {}): any {
|
||||
attempt: function (
|
||||
answer: any,
|
||||
fn: any,
|
||||
ip: any = workerScript.hostname,
|
||||
{ returnReward }: any = {},
|
||||
): boolean | string {
|
||||
helper.updateDynamicRam("attempt", getRamCost("codingcontract", "attempt"));
|
||||
const contract = getCodingContract("attempt", ip, fn);
|
||||
|
||||
@@ -63,7 +68,7 @@ export function NetscriptCodingContract(
|
||||
return returnReward ? "" : false;
|
||||
}
|
||||
},
|
||||
getContractType: function (fn: any, ip: any = workerScript.hostname): any {
|
||||
getContractType: function (fn: any, ip: any = workerScript.hostname): string {
|
||||
helper.updateDynamicRam("getContractType", getRamCost("codingcontract", "getContractType"));
|
||||
const contract = getCodingContract("getContractType", ip, fn);
|
||||
return contract.getType();
|
||||
@@ -88,12 +93,12 @@ export function NetscriptCodingContract(
|
||||
return data;
|
||||
}
|
||||
},
|
||||
getDescription: function (fn: any, ip: any = workerScript.hostname): any {
|
||||
getDescription: function (fn: any, ip: any = workerScript.hostname): string {
|
||||
helper.updateDynamicRam("getDescription", getRamCost("codingcontract", "getDescription"));
|
||||
const contract = getCodingContract("getDescription", ip, fn);
|
||||
return contract.getDescription();
|
||||
},
|
||||
getNumTriesRemaining: function (fn: any, ip: any = workerScript.hostname): any {
|
||||
getNumTriesRemaining: function (fn: any, ip: any = workerScript.hostname): number {
|
||||
helper.updateDynamicRam("getNumTriesRemaining", getRamCost("codingcontract", "getNumTriesRemaining"));
|
||||
const contract = getCodingContract("getNumTriesRemaining", ip, fn);
|
||||
return contract.getMaxNumTries() - contract.tries;
|
||||
|
||||
@@ -9,7 +9,15 @@ import { WorkerScript } from "../Netscript/WorkerScript";
|
||||
import { GangMember } from "../Gang/GangMember";
|
||||
import { GangMemberTask } from "../Gang/GangMemberTask";
|
||||
|
||||
import { Gang as IGang } from "../ScriptEditor/NetscriptDefinitions";
|
||||
import {
|
||||
Gang as IGang,
|
||||
GangGenInfo,
|
||||
GangOtherInfo,
|
||||
GangMemberInfo,
|
||||
GangMemberAscension,
|
||||
EquipmentStats,
|
||||
GangTaskStats,
|
||||
} from "../ScriptEditor/NetscriptDefinitions";
|
||||
|
||||
export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helper: INetscriptHelper): IGang {
|
||||
const checkGangApiAccess = function (func: string): void {
|
||||
@@ -58,18 +66,18 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
|
||||
player.startGang(faction, isHacking);
|
||||
return true;
|
||||
},
|
||||
inGang: function (): any {
|
||||
inGang: function (): boolean {
|
||||
helper.updateDynamicRam("inGang", getRamCost("gang", "inGang"));
|
||||
return player.inGang();
|
||||
},
|
||||
getMemberNames: function (): any {
|
||||
getMemberNames: function (): string[] {
|
||||
helper.updateDynamicRam("getMemberNames", getRamCost("gang", "getMemberNames"));
|
||||
checkGangApiAccess("getMemberNames");
|
||||
const gang = player.gang;
|
||||
if (gang === null) throw new Error("Should not be called without Gang");
|
||||
return gang.members.map((member) => member.name);
|
||||
},
|
||||
getGangInformation: function (): any {
|
||||
getGangInformation: function (): GangGenInfo {
|
||||
helper.updateDynamicRam("getGangInformation", getRamCost("gang", "getGangInformation"));
|
||||
checkGangApiAccess("getGangInformation");
|
||||
const gang = player.gang;
|
||||
@@ -88,7 +96,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
|
||||
wantedLevelGainRate: gang.wantedGainRate,
|
||||
};
|
||||
},
|
||||
getOtherGangInformation: function (): any {
|
||||
getOtherGangInformation: function (): GangOtherInfo {
|
||||
helper.updateDynamicRam("getOtherGangInformation", getRamCost("gang", "getOtherGangInformation"));
|
||||
checkGangApiAccess("getOtherGangInformation");
|
||||
const cpy: any = {};
|
||||
@@ -98,7 +106,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
|
||||
|
||||
return cpy;
|
||||
},
|
||||
getMemberInformation: function (name: any): any {
|
||||
getMemberInformation: function (name: any): GangMemberInfo {
|
||||
helper.updateDynamicRam("getMemberInformation", getRamCost("gang", "getMemberInformation"));
|
||||
checkGangApiAccess("getMemberInformation");
|
||||
const member = getGangMember("getMemberInformation", name);
|
||||
@@ -145,14 +153,14 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
|
||||
augmentations: member.augmentations.slice(),
|
||||
};
|
||||
},
|
||||
canRecruitMember: function (): any {
|
||||
canRecruitMember: function (): boolean {
|
||||
helper.updateDynamicRam("canRecruitMember", getRamCost("gang", "canRecruitMember"));
|
||||
checkGangApiAccess("canRecruitMember");
|
||||
const gang = player.gang;
|
||||
if (gang === null) throw new Error("Should not be called without Gang");
|
||||
return gang.canRecruitMember();
|
||||
},
|
||||
recruitMember: function (name: any): any {
|
||||
recruitMember: function (name: any): boolean {
|
||||
helper.updateDynamicRam("recruitMember", getRamCost("gang", "recruitMember"));
|
||||
checkGangApiAccess("recruitMember");
|
||||
const gang = player.gang;
|
||||
@@ -166,7 +174,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
|
||||
|
||||
return recruited;
|
||||
},
|
||||
getTaskNames: function (): any {
|
||||
getTaskNames: function (): string[] {
|
||||
helper.updateDynamicRam("getTaskNames", getRamCost("gang", "getTaskNames"));
|
||||
checkGangApiAccess("getTaskNames");
|
||||
const gang = player.gang;
|
||||
@@ -175,7 +183,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
|
||||
tasks.unshift("Unassigned");
|
||||
return tasks;
|
||||
},
|
||||
setMemberTask: function (memberName: any, taskName: any): any {
|
||||
setMemberTask: function (memberName: any, taskName: any): boolean {
|
||||
helper.updateDynamicRam("setMemberTask", getRamCost("gang", "setMemberTask"));
|
||||
checkGangApiAccess("setMemberTask");
|
||||
const member = getGangMember("setMemberTask", memberName);
|
||||
@@ -191,7 +199,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
|
||||
|
||||
return success;
|
||||
},
|
||||
getTaskStats: function (taskName: any): any {
|
||||
getTaskStats: function (taskName: any): GangTaskStats {
|
||||
helper.updateDynamicRam("getTaskStats", getRamCost("gang", "getTaskStats"));
|
||||
checkGangApiAccess("getTaskStats");
|
||||
const task = getGangTask("getTaskStats", taskName);
|
||||
@@ -199,12 +207,12 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
|
||||
copy.territory = Object.assign({}, task.territory);
|
||||
return copy;
|
||||
},
|
||||
getEquipmentNames: function (): any {
|
||||
getEquipmentNames: function (): string[] {
|
||||
helper.updateDynamicRam("getEquipmentNames", getRamCost("gang", "getEquipmentNames"));
|
||||
checkGangApiAccess("getEquipmentNames");
|
||||
return Object.keys(GangMemberUpgrades);
|
||||
},
|
||||
getEquipmentCost: function (equipName: any): any {
|
||||
getEquipmentCost: function (equipName: any): number {
|
||||
helper.updateDynamicRam("getEquipmentCost", getRamCost("gang", "getEquipmentCost"));
|
||||
checkGangApiAccess("getEquipmentCost");
|
||||
const gang = player.gang;
|
||||
@@ -213,23 +221,24 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
|
||||
if (upg === null) return Infinity;
|
||||
return gang.getUpgradeCost(upg);
|
||||
},
|
||||
getEquipmentType: function (equipName: any): any {
|
||||
getEquipmentType: function (equipName: any): string {
|
||||
helper.updateDynamicRam("getEquipmentType", getRamCost("gang", "getEquipmentType"));
|
||||
checkGangApiAccess("getEquipmentType");
|
||||
const upg = GangMemberUpgrades[equipName];
|
||||
if (upg == null) return "";
|
||||
return upg.getType();
|
||||
},
|
||||
getEquipmentStats: function (equipName: any): any {
|
||||
getEquipmentStats: function (equipName: any): EquipmentStats {
|
||||
helper.updateDynamicRam("getEquipmentStats", getRamCost("gang", "getEquipmentStats"));
|
||||
checkGangApiAccess("getEquipmentStats");
|
||||
const equipment = GangMemberUpgrades[equipName];
|
||||
if (!equipment) {
|
||||
throw helper.makeRuntimeErrorMsg("getEquipmentStats", `Invalid equipment: ${equipName}`);
|
||||
}
|
||||
return Object.assign({}, equipment.mults);
|
||||
const typecheck: EquipmentStats = equipment.mults;
|
||||
return Object.assign({}, typecheck) as any;
|
||||
},
|
||||
purchaseEquipment: function (memberName: any, equipName: any): any {
|
||||
purchaseEquipment: function (memberName: any, equipName: any): boolean {
|
||||
helper.updateDynamicRam("purchaseEquipment", getRamCost("gang", "purchaseEquipment"));
|
||||
checkGangApiAccess("purchaseEquipment");
|
||||
const gang = player.gang;
|
||||
@@ -246,7 +255,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
|
||||
|
||||
return res;
|
||||
},
|
||||
ascendMember: function (name: any): any {
|
||||
ascendMember: function (name: any): GangMemberAscension | undefined {
|
||||
helper.updateDynamicRam("ascendMember", getRamCost("gang", "ascendMember"));
|
||||
checkGangApiAccess("ascendMember");
|
||||
const gang = player.gang;
|
||||
@@ -268,7 +277,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
|
||||
workerScript.log("setTerritoryWarfare", "Disengaging in Gang Territory Warfare");
|
||||
}
|
||||
},
|
||||
getChanceToWinClash: function (otherGang: any): any {
|
||||
getChanceToWinClash: function (otherGang: any): number {
|
||||
helper.updateDynamicRam("getChanceToWinClash", getRamCost("gang", "getChanceToWinClash"));
|
||||
checkGangApiAccess("getChanceToWinClash");
|
||||
const gang = player.gang;
|
||||
@@ -282,7 +291,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
|
||||
|
||||
return playerPower / (otherPower + playerPower);
|
||||
},
|
||||
getBonusTime: function (): any {
|
||||
getBonusTime: function (): number {
|
||||
helper.updateDynamicRam("getBonusTime", getRamCost("gang", "getBonusTime"));
|
||||
checkGangApiAccess("getBonusTime");
|
||||
const gang = player.gang;
|
||||
|
||||
@@ -18,7 +18,7 @@ import { HacknetServer } from "../Hacknet/HacknetServer";
|
||||
import { HacknetNode } from "../Hacknet/HacknetNode";
|
||||
import { GetServer } from "../Server/AllServers";
|
||||
|
||||
import { Hacknet as IHacknet } from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { Hacknet as IHacknet, NodeStats } from "../ScriptEditor/NetscriptDefinitions";
|
||||
|
||||
export function NetscriptHacknet(player: IPlayer, workerScript: WorkerScript, helper: INetscriptHelper): IHacknet {
|
||||
// Utility function to get Hacknet Node object
|
||||
@@ -51,26 +51,26 @@ export function NetscriptHacknet(player: IPlayer, workerScript: WorkerScript, he
|
||||
};
|
||||
|
||||
return {
|
||||
numNodes: function (): any {
|
||||
numNodes: function (): number {
|
||||
return player.hacknetNodes.length;
|
||||
},
|
||||
maxNumNodes: function (): any {
|
||||
maxNumNodes: function (): number {
|
||||
if (hasHacknetServers(player)) {
|
||||
return HacknetServerConstants.MaxServers;
|
||||
}
|
||||
return Infinity;
|
||||
},
|
||||
purchaseNode: function (): any {
|
||||
purchaseNode: function (): number {
|
||||
return purchaseHacknet(player);
|
||||
},
|
||||
getPurchaseNodeCost: function (): any {
|
||||
getPurchaseNodeCost: function (): number {
|
||||
if (hasHacknetServers(player)) {
|
||||
return getCostOfNextHacknetServer(player);
|
||||
} else {
|
||||
return getCostOfNextHacknetNode(player);
|
||||
}
|
||||
},
|
||||
getNodeStats: function (i: any): any {
|
||||
getNodeStats: function (i: any): NodeStats {
|
||||
const node = getHacknetNode(i, "getNodeStats");
|
||||
const hasUpgraded = hasHacknetServers(player);
|
||||
const res: any = {
|
||||
@@ -90,19 +90,19 @@ export function NetscriptHacknet(player: IPlayer, workerScript: WorkerScript, he
|
||||
|
||||
return res;
|
||||
},
|
||||
upgradeLevel: function (i: any, n: any): any {
|
||||
upgradeLevel: function (i: any, n: any): boolean {
|
||||
const node = getHacknetNode(i, "upgradeLevel");
|
||||
return purchaseLevelUpgrade(player, node, n);
|
||||
},
|
||||
upgradeRam: function (i: any, n: any): any {
|
||||
upgradeRam: function (i: any, n: any): boolean {
|
||||
const node = getHacknetNode(i, "upgradeRam");
|
||||
return purchaseRamUpgrade(player, node, n);
|
||||
},
|
||||
upgradeCore: function (i: any, n: any): any {
|
||||
upgradeCore: function (i: any, n: any): boolean {
|
||||
const node = getHacknetNode(i, "upgradeCore");
|
||||
return purchaseCoreUpgrade(player, node, n);
|
||||
},
|
||||
upgradeCache: function (i: any, n: any): any {
|
||||
upgradeCache: function (i: any, n: any): boolean {
|
||||
if (!hasHacknetServers(player)) {
|
||||
return false;
|
||||
}
|
||||
@@ -117,19 +117,19 @@ export function NetscriptHacknet(player: IPlayer, workerScript: WorkerScript, he
|
||||
}
|
||||
return res;
|
||||
},
|
||||
getLevelUpgradeCost: function (i: any, n: any): any {
|
||||
getLevelUpgradeCost: function (i: any, n: any): number {
|
||||
const node = getHacknetNode(i, "upgradeLevel");
|
||||
return node.calculateLevelUpgradeCost(n, player.hacknet_node_level_cost_mult);
|
||||
},
|
||||
getRamUpgradeCost: function (i: any, n: any): any {
|
||||
getRamUpgradeCost: function (i: any, n: any): number {
|
||||
const node = getHacknetNode(i, "upgradeRam");
|
||||
return node.calculateRamUpgradeCost(n, player.hacknet_node_ram_cost_mult);
|
||||
},
|
||||
getCoreUpgradeCost: function (i: any, n: any): any {
|
||||
getCoreUpgradeCost: function (i: any, n: any): number {
|
||||
const node = getHacknetNode(i, "upgradeCore");
|
||||
return node.calculateCoreUpgradeCost(n, player.hacknet_node_core_cost_mult);
|
||||
},
|
||||
getCacheUpgradeCost: function (i: any, n: any): any {
|
||||
getCacheUpgradeCost: function (i: any, n: any): number {
|
||||
if (!hasHacknetServers(player)) {
|
||||
return Infinity;
|
||||
}
|
||||
@@ -140,47 +140,47 @@ export function NetscriptHacknet(player: IPlayer, workerScript: WorkerScript, he
|
||||
}
|
||||
return node.calculateCacheUpgradeCost(n);
|
||||
},
|
||||
numHashes: function (): any {
|
||||
numHashes: function (): number {
|
||||
if (!hasHacknetServers(player)) {
|
||||
return 0;
|
||||
}
|
||||
return player.hashManager.hashes;
|
||||
},
|
||||
hashCapacity: function (): any {
|
||||
hashCapacity: function (): number {
|
||||
if (!hasHacknetServers(player)) {
|
||||
return 0;
|
||||
}
|
||||
return player.hashManager.capacity;
|
||||
},
|
||||
hashCost: function (upgName: any): any {
|
||||
hashCost: function (upgName: any): number {
|
||||
if (!hasHacknetServers(player)) {
|
||||
return Infinity;
|
||||
}
|
||||
|
||||
return player.hashManager.getUpgradeCost(upgName);
|
||||
},
|
||||
spendHashes: function (upgName: any, upgTarget: any): any {
|
||||
spendHashes: function (upgName: any, upgTarget: any): boolean {
|
||||
if (!hasHacknetServers(player)) {
|
||||
return false;
|
||||
}
|
||||
return purchaseHashUpgrade(player, upgName, upgTarget);
|
||||
},
|
||||
getHashUpgradeLevel: function (upgName: any): any {
|
||||
getHashUpgradeLevel: function (upgName: any): number {
|
||||
const level = player.hashManager.upgrades[upgName];
|
||||
if (level === undefined) {
|
||||
throw helper.makeRuntimeErrorMsg("hacknet.hashUpgradeLevel", `Invalid Hash Upgrade: ${upgName}`);
|
||||
}
|
||||
return level;
|
||||
},
|
||||
getStudyMult: function (): any {
|
||||
getStudyMult: function (): number {
|
||||
if (!hasHacknetServers(player)) {
|
||||
return false;
|
||||
return 1;
|
||||
}
|
||||
return player.hashManager.getStudyMult();
|
||||
},
|
||||
getTrainingMult: function (): any {
|
||||
getTrainingMult: function (): number {
|
||||
if (!hasHacknetServers(player)) {
|
||||
return false;
|
||||
return 1;
|
||||
}
|
||||
return player.hashManager.getTrainingMult();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user