Add watcher and kill all scripts

This commit is contained in:
Isaac Shoebottom 2023-11-03 15:22:12 -03:00
parent f34a37a3fb
commit 000e69a418
3 changed files with 28 additions and 0 deletions

View File

@ -9,6 +9,7 @@ export async function main(ns: NS) {
let moneyThresh = ns.getServerMaxMoney(server) * 0.75;
let securityThresh = ns.getServerMinSecurityLevel(server) + 5;
let numThreads = ns.getServerMaxRam(server) / ns.getScriptRam("hack.js")
numThreads = Math.floor(numThreads);
executeScriptOnServerFromAnother(ns, server, "hack.js", numThreads, [server, moneyThresh, securityThresh])
}
}

9
servers/home/killall.ts Normal file
View File

@ -0,0 +1,9 @@
import {NS} from "NetscriptDefinitions";
import {recursiveScan} from "./utils";
export async function main(ns: NS) {
let servers: string[] = recursiveScan(ns)
for (const server of servers) {
ns.killall(server)
}
}

18
servers/home/watcher.ts Normal file
View File

@ -0,0 +1,18 @@
import {NS} from "NetscriptDefinitions";
export async function main(ns: NS) {
let hackingLevel = ns.getHackingLevel();
while (hackingLevel < 9999) {
ns.run("hackallservers.js");
let seconds = 60 * 1000; // 1 minute
await ns.sleep(seconds)
let oldHackingLevel = hackingLevel;
hackingLevel = ns.getHackingLevel();
if(oldHackingLevel !== hackingLevel) {
ns.tprint(`Hacking level increased from ${oldHackingLevel} to ${hackingLevel}`);
ns.run("killall.js");
await ns.sleep(1000) // 1 second
ns.run("hackallservers.js");
}
}
}