Improve watcher slightly

This commit is contained in:
Isaac Shoebottom 2023-11-04 16:48:17 -03:00
parent 12d9165162
commit f52af72140

View File

@ -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))