Added dark web functions to ns api

This commit is contained in:
Olivier Gagnon
2022-03-20 22:49:46 -04:00
parent 00d1d294ed
commit fb7c65957d
5 changed files with 139 additions and 8 deletions
+55 -6
View File
@@ -370,7 +370,8 @@ export function NetscriptSingularity(
if (player.city != CityName.Aevum) {
workerScript.log(
"gymWorkout",
() => `You cannot workout at '${LocationName.AevumCrushFitnessGym}' because you are not in '${CityName.Aevum}'.`,
() =>
`You cannot workout at '${LocationName.AevumCrushFitnessGym}' because you are not in '${CityName.Aevum}'.`,
);
return false;
}
@@ -382,7 +383,8 @@ export function NetscriptSingularity(
if (player.city != CityName.Aevum) {
workerScript.log(
"gymWorkout",
() => `You cannot workout at '${LocationName.AevumSnapFitnessGym}' because you are not in '${CityName.Aevum}'.`,
() =>
`You cannot workout at '${LocationName.AevumSnapFitnessGym}' because you are not in '${CityName.Aevum}'.`,
);
return false;
}
@@ -394,7 +396,8 @@ export function NetscriptSingularity(
if (player.city != CityName.Sector12) {
workerScript.log(
"gymWorkout",
() => `You cannot workout at '${LocationName.Sector12IronGym}' because you are not in '${CityName.Sector12}'.`,
() =>
`You cannot workout at '${LocationName.Sector12IronGym}' because you are not in '${CityName.Sector12}'.`,
);
return false;
}
@@ -406,7 +409,8 @@ export function NetscriptSingularity(
if (player.city != CityName.Sector12) {
workerScript.log(
"gymWorkout",
() => `You cannot workout at '${LocationName.Sector12PowerhouseGym}' because you are not in '${CityName.Sector12}'.`,
() =>
`You cannot workout at '${LocationName.Sector12PowerhouseGym}' because you are not in '${CityName.Sector12}'.`,
);
return false;
}
@@ -418,7 +422,8 @@ export function NetscriptSingularity(
if (player.city != CityName.Volhaven) {
workerScript.log(
"gymWorkout",
() => `You cannot workout at '${LocationName.VolhavenMilleniumFitnessGym}' because you are not in '${CityName.Volhaven}'.`,
() =>
`You cannot workout at '${LocationName.VolhavenMilleniumFitnessGym}' because you are not in '${CityName.Volhaven}'.`,
);
return false;
}
@@ -476,7 +481,7 @@ export function NetscriptSingularity(
case CityName.Volhaven:
if (player.money < CONSTANTS.TravelCost) {
workerScript.log("travelToCity", () => "Not enough money to travel.");
return false
return false;
}
player.loseMoney(CONSTANTS.TravelCost, "other");
player.city = cityname;
@@ -1325,5 +1330,49 @@ export function NetscriptSingularity(
return Object.assign({}, crime);
},
getDarkwebPrograms: function (): string[] {
helper.updateDynamicRam("getDarkwebPrograms", getRamCost(player, "getDarkwebPrograms"));
helper.checkSingularityAccess("getDarkwebPrograms");
// If we don't have Tor, log it and return [] (empty list)
if (!player.hasTorRouter()) {
workerScript.log("getDarkwebPrograms", () => "You do not have the TOR router.");
return [];
}
return Object.values(DarkWebItems).map((p) => p.program);
},
getDarkwebProgramCost: function (programName: any): any {
helper.updateDynamicRam("getDarkwebProgramCost", getRamCost(player, "getDarkwebProgramCost"));
helper.checkSingularityAccess("getDarkwebProgramCost");
// If we don't have Tor, log it and return -1
if (!player.hasTorRouter()) {
workerScript.log("getDarkwebProgramCost", () => "You do not have the TOR router.");
// returning -1 rather than throwing an error to be consistent with purchaseProgram
// which returns false if tor has
return -1;
}
programName = programName.toLowerCase();
const item = Object.values(DarkWebItems).find((i) => i.program.toLowerCase() === programName);
// If the program doesn't exist, throw an error. The reasoning here is that the 99% case is that
// the player will be using this in automation scripts, and if they're asking for a program that
// doesn't exist, it's the first time they've run the script. So throw an error to let them know
// that they need to fix it.
if (item == null) {
throw helper.makeRuntimeErrorMsg(
"getDarkwebProgramCost",
`No such exploit ('${programName}') found on the darkweb! ` +
`\nThis function is not case-sensitive. Did you perhaps forget .exe at the end?`,
);
}
if (player.hasProgram(item.program)) {
workerScript.log("getDarkwebProgramCost", () => `You already have the '${item.program}' program`);
return 0;
}
return item.price;
},
};
}