updated scan-analyze.ts to use string concatenation
This commit is contained in:
parent
f75ef84f95
commit
374d46daa1
|
|
@ -1,7 +1,7 @@
|
|||
import { ezgame } from "@/ezgame";
|
||||
import { getNormalServer } from "@/ezgame/get-normal-server";
|
||||
import { utils } from "@/utils/utils";
|
||||
import { NS } from "@ns";
|
||||
import { formulas } from ".";
|
||||
|
||||
interface TestCase {
|
||||
name: string;
|
||||
|
|
@ -23,7 +23,7 @@ const gangTests = (ns: NS, serverName: string): TestCase[] => [
|
|||
name: "gang.ascensionMultiplier",
|
||||
fn: (ns, serverName) => {
|
||||
const points = utils.randomNumber(0, 1e9);
|
||||
const testResult = roundTo5Decimals(ezgame.formulas.gang.ascensionMultiplier(points));
|
||||
const testResult = roundTo5Decimals(formulas.gang.ascensionMultiplier(points));
|
||||
const actualResult = roundTo5Decimals(ns.formulas.gang.ascensionMultiplier(points));
|
||||
if (testResult !== actualResult) {
|
||||
throw new Error(`expected ${actualResult}, got ${testResult}`);
|
||||
|
|
@ -34,7 +34,7 @@ const gangTests = (ns: NS, serverName: string): TestCase[] => [
|
|||
name: "gang.ascensionPointsGain",
|
||||
fn: (ns, serverName) => {
|
||||
const exp = utils.randomNumber(0, 1e9);
|
||||
const testResult = roundTo5Decimals(ezgame.formulas.gang.ascensionPointsGain(exp));
|
||||
const testResult = roundTo5Decimals(formulas.gang.ascensionPointsGain(exp));
|
||||
const actualResult = roundTo5Decimals(ns.formulas.gang.ascensionPointsGain(exp));
|
||||
if (testResult !== actualResult) {
|
||||
throw new Error(`expected ${actualResult}, got ${testResult}`);
|
||||
|
|
@ -56,7 +56,7 @@ const hackingTests = (ns: NS, serverName: string): TestCase[] => [
|
|||
const player = ns.getPlayer();
|
||||
const threads = utils.randomNumber(1, 100);
|
||||
const cores = utils.randomNumber(1, 16);
|
||||
const testResult = roundTo5Decimals(ezgame.formulas.hacking.growAmount(server, player, threads, cores));
|
||||
const testResult = roundTo5Decimals(formulas.hacking.growAmount(server, player, threads, cores));
|
||||
const actualResult = roundTo5Decimals(ns.formulas.hacking.growAmount(server, player, threads, cores));
|
||||
if (testResult !== actualResult) {
|
||||
throw new Error(`expected ${actualResult}, got ${testResult}`);
|
||||
|
|
@ -70,7 +70,7 @@ const hackingTests = (ns: NS, serverName: string): TestCase[] => [
|
|||
const threads = utils.randomNumber(1, 100);
|
||||
const player = ns.getPlayer();
|
||||
const cores = utils.randomNumber(1, 16);
|
||||
const testResult = roundTo5Decimals(ezgame.formulas.hacking.growPercent(server, threads, player, cores));
|
||||
const testResult = roundTo5Decimals(formulas.hacking.growPercent(server, threads, player, cores));
|
||||
const actualResult = roundTo5Decimals(ns.formulas.hacking.growPercent(server, threads, player, cores));
|
||||
if (testResult !== actualResult) {
|
||||
throw new Error(`expected ${actualResult}, got ${testResult}`);
|
||||
|
|
@ -86,7 +86,7 @@ const hackingTests = (ns: NS, serverName: string): TestCase[] => [
|
|||
// anyways if it is above moneyMax, the function should clamp it to the max (hopefully)
|
||||
const targetMoney = server.moneyMax ?? 1e120;
|
||||
const cores = utils.randomNumber(1, 16);
|
||||
const testResult = roundTo5Decimals(ezgame.formulas.hacking.growThreads(server, player, targetMoney, cores));
|
||||
const testResult = roundTo5Decimals(formulas.hacking.growThreads(server, player, targetMoney, cores));
|
||||
const actualResult = roundTo5Decimals(ns.formulas.hacking.growThreads(server, player, targetMoney, cores));
|
||||
if (testResult !== actualResult) {
|
||||
throw new Error(`expected ${actualResult}, got ${testResult}`);
|
||||
|
|
@ -98,7 +98,7 @@ const hackingTests = (ns: NS, serverName: string): TestCase[] => [
|
|||
fn: (ns, serverName) => {
|
||||
const server = getNormalServer(ns, serverName);
|
||||
const player = ns.getPlayer();
|
||||
const testResult = roundTo5Decimals(ezgame.formulas.hacking.growTime(server, player));
|
||||
const testResult = roundTo5Decimals(formulas.hacking.growTime(server, player));
|
||||
const actualResult = roundTo5Decimals(ns.formulas.hacking.growTime(server, player));
|
||||
if (testResult !== actualResult) {
|
||||
throw new Error(`expected ${actualResult}, got ${testResult}`);
|
||||
|
|
@ -110,7 +110,7 @@ const hackingTests = (ns: NS, serverName: string): TestCase[] => [
|
|||
fn: (ns, serverName) => {
|
||||
const server = getNormalServer(ns, serverName);
|
||||
const player = ns.getPlayer();
|
||||
const testResult = roundTo5Decimals(ezgame.formulas.hacking.hackChance(server, player));
|
||||
const testResult = roundTo5Decimals(formulas.hacking.hackChance(server, player));
|
||||
const actualResult = roundTo5Decimals(ns.formulas.hacking.hackChance(server, player));
|
||||
if (testResult !== actualResult) {
|
||||
throw new Error(`expected ${actualResult}, got ${testResult}`);
|
||||
|
|
@ -122,7 +122,7 @@ const hackingTests = (ns: NS, serverName: string): TestCase[] => [
|
|||
fn: (ns, serverName) => {
|
||||
const server = getNormalServer(ns, serverName);
|
||||
const player = ns.getPlayer();
|
||||
const testResult = roundTo5Decimals(ezgame.formulas.hacking.hackExp(server, player));
|
||||
const testResult = roundTo5Decimals(formulas.hacking.hackExp(server, player));
|
||||
const actualResult = roundTo5Decimals(ns.formulas.hacking.hackExp(server, player));
|
||||
if (testResult !== actualResult) {
|
||||
throw new Error(`expected ${actualResult}, got ${testResult}`);
|
||||
|
|
@ -134,7 +134,7 @@ const hackingTests = (ns: NS, serverName: string): TestCase[] => [
|
|||
fn: (ns, serverName) => {
|
||||
const server = getNormalServer(ns, serverName);
|
||||
const player = ns.getPlayer();
|
||||
const testResult = roundTo5Decimals(ezgame.formulas.hacking.hackPercent(server, player));
|
||||
const testResult = roundTo5Decimals(formulas.hacking.hackPercent(server, player));
|
||||
const actualResult = roundTo5Decimals(ns.formulas.hacking.hackPercent(server, player));
|
||||
if (testResult !== actualResult) {
|
||||
throw new Error(`expected ${actualResult}, got ${testResult}`);
|
||||
|
|
@ -146,7 +146,7 @@ const hackingTests = (ns: NS, serverName: string): TestCase[] => [
|
|||
fn: (ns, serverName) => {
|
||||
const server = getNormalServer(ns, serverName);
|
||||
const player = ns.getPlayer();
|
||||
const testResult = roundTo5Decimals(ezgame.formulas.hacking.hackTime(server, player));
|
||||
const testResult = roundTo5Decimals(formulas.hacking.hackTime(server, player));
|
||||
const actualResult = roundTo5Decimals(ns.formulas.hacking.hackTime(server, player));
|
||||
if (testResult !== actualResult) {
|
||||
throw new Error(`expected ${actualResult}, got ${testResult}`);
|
||||
|
|
@ -158,7 +158,7 @@ const hackingTests = (ns: NS, serverName: string): TestCase[] => [
|
|||
fn: (ns, serverName) => {
|
||||
const server = getNormalServer(ns, serverName);
|
||||
const player = ns.getPlayer();
|
||||
const testResult = roundTo5Decimals(ezgame.formulas.hacking.weakenTime(server, player));
|
||||
const testResult = roundTo5Decimals(formulas.hacking.weakenTime(server, player));
|
||||
const actualResult = roundTo5Decimals(ns.formulas.hacking.weakenTime(server, player));
|
||||
if (testResult !== actualResult) {
|
||||
throw new Error(`expected ${actualResult}, got ${testResult}`);
|
||||
|
|
|
|||
|
|
@ -49,8 +49,10 @@ export const scanAnalyze = (ns: NS, options: ScanAnalyzeOptions = {}): Map<strin
|
|||
}
|
||||
|
||||
if (!options.quiet) {
|
||||
const lines: string[] = [""];
|
||||
// we are sure that home is always in the tree since its the starting point
|
||||
printTree(ns, tree.get("home") as ServerNode, tree);
|
||||
printTree(ns, lines, tree.get("home") as ServerNode, tree);
|
||||
ns.tprint(lines.join("\n"));
|
||||
}
|
||||
|
||||
return tree;
|
||||
|
|
@ -58,6 +60,7 @@ export const scanAnalyze = (ns: NS, options: ScanAnalyzeOptions = {}): Map<strin
|
|||
|
||||
const printTree = (
|
||||
ns: NS,
|
||||
lines: string[],
|
||||
node: ServerNode,
|
||||
tree: Map<string, ServerNode>,
|
||||
prefix: string[] = [" "],
|
||||
|
|
@ -71,14 +74,14 @@ const printTree = (
|
|||
const titlePrefix = prefix.slice(0, prefix.length - 1).join("") + (isLast ? "┗ " : "┣ ");
|
||||
const infoPrefix = prefix.join("") + (node.children.length > 0 ? "┃ " : " ");
|
||||
|
||||
ns.tprint(`* ${titlePrefix}${node.hostname}`);
|
||||
ns.tprint(
|
||||
`* ${infoPrefix}Root Access: ${server.hasAdminRights ? "YES" : "NO"}, Required hacking skill: ${
|
||||
lines.push(`${titlePrefix}${node.hostname}`);
|
||||
lines.push(
|
||||
`${infoPrefix}Root Access: ${server.hasAdminRights ? "YES" : "NO"}, Required hacking skill: ${
|
||||
server.requiredHackingSkill ?? 0
|
||||
}`,
|
||||
);
|
||||
ns.tprint(`* ${infoPrefix}Number of open ports required to NUKE: ${server.numOpenPortsRequired ?? 0}`);
|
||||
ns.tprint(`* ${infoPrefix}RAM: ${utils.format.ram(server.maxRam)}, Player purchased: ${server.purchasedByPlayer}`);
|
||||
lines.push(`${infoPrefix}Number of open ports required to NUKE: ${server.numOpenPortsRequired ?? 0}`);
|
||||
lines.push(`${infoPrefix}RAM: ${utils.format.ram(server.maxRam)}, Player purchased: ${server.purchasedByPlayer}`);
|
||||
|
||||
// recursive
|
||||
node.children.forEach((childName, i) => {
|
||||
|
|
@ -88,7 +91,7 @@ const printTree = (
|
|||
throw new Error(`Child node ${childName} not found in tree`);
|
||||
}
|
||||
const childIsLast = i === node.children.length - 1;
|
||||
printTree(ns, childNode, tree, [...prefix, childIsLast ? " " : "┃ "], childIsLast);
|
||||
printTree(ns, lines, childNode, tree, [...prefix, childIsLast ? " " : "┃ "], childIsLast);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,6 @@ export const scriptPropagator = (ns: NS) => {
|
|||
return rootedHosts;
|
||||
};
|
||||
|
||||
// export const main = (ns: NS) => {
|
||||
// scriptPropagator(ns);
|
||||
// };
|
||||
export const main = (ns: NS) => {
|
||||
scriptPropagator(ns);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -40,7 +40,11 @@ export const startall = (ns: NS, scriptName: string, options: StartOptions = {})
|
|||
}
|
||||
|
||||
if (threadsToUse > 0) {
|
||||
ns.exec(scriptName, host, threadsToUse, ...args);
|
||||
const pid = ns.exec(scriptName, host, threadsToUse, ...args);
|
||||
if (pid === 0) {
|
||||
ns.tprint(`${host}: Process not started. Did you check if the script exists on the server?`);
|
||||
return;
|
||||
}
|
||||
ns.tprint(`Started ${scriptName} on ${host} with ${threadsToUse} threads`);
|
||||
totalThreadsStarted += threadsToUse;
|
||||
hostsStartedOn++;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { NS } from "@ns";
|
||||
|
||||
export const main = async (ns: NS) => {
|
||||
const bruh = await ns.prompt("hello", { type: "text", choices: ["asdf1", "asdf2"] });
|
||||
console.log(bruh);
|
||||
const electron = eval(`require("electron")`);
|
||||
ns.tprint(JSON.stringify(Object.keys(electron)));
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue