diff --git a/servers/home/watcher.ts b/servers/home/watcher.ts index 399ed44..c48e72c 100644 --- a/servers/home/watcher.ts +++ b/servers/home/watcher.ts @@ -2,17 +2,21 @@ import { recursiveHackingRequired } from "./utils" export async function main(ns: NS) { let levels = recursiveHackingRequired(ns) - let hackingLevel: number + let hackingLevel = ns.getHackingLevel() + // Remove levels that are already hacked + levels = levels.filter(level => level > hackingLevel) + do { - hackingLevel = ns.getHackingLevel() if (levels.includes(hackingLevel)) { // remove the level from the list, so we don't try to hack it again levels.splice(levels.indexOf(hackingLevel), 1) ns.tprint(`Hacking level increased to ${hackingLevel}`) + ns.tprint(`Remaining levels to hack: ${levels}`) ns.run("killall.js") await ns.sleep(1000) // 1 second ns.run("hackallservers.js") } + hackingLevel = ns.getHackingLevel() // Wait 1 second before checking again await ns.sleep(1000) } while (hackingLevel <= Math.max(...levels))