Compare commits

...

2 Commits

Author SHA1 Message Date
92ad2da7b7 add program 2023-11-03 21:53:18 -03:00
a3bdb2ccd1 watcher improvements 2023-11-03 21:53:07 -03:00
3 changed files with 32 additions and 7 deletions

View File

@ -1,10 +1,13 @@
import { recursiveScan } from "./utils"
import { recursiveHackingRequired, recursiveScan } from "./utils"
export async function main(ns: NS){
switch (ns.args[0]) {
case "getServers":
getServers(ns);
break;
case "getHackingLevels":
getHackingLevels(ns);
break;
default:
ns.tprint("Invalid program name");
break;
@ -13,3 +16,6 @@ export async function main(ns: NS){
function getServers(ns: NS) {
ns.tprint(recursiveScan(ns));
}
function getHackingLevels(ns: NS) {
ns.tprint(recursiveHackingRequired(ns))
}

View File

@ -28,6 +28,21 @@ export function recursiveScan(ns: NS) {
return allServers
}
/**
* Recursively scans all servers connected to the current server for the set of all levels that hackable servers require
* @param ns
* @returns A set of every hacking level required to hack a new server
*/
export function recursiveHackingRequired(ns: NS) {
let servers = recursiveScan(ns)
let levels: number[] = []
for (let server of servers) {
levels.push(ns.getServerRequiredHackingLevel(server))
}
// remove duplicates
return [...new Set(levels)]
}
/**
* Removes files passed in from all servers
* @param ns Global NS object

View File

@ -1,16 +1,20 @@
import { recursiveHackingRequired } from "./utils"
export async function main(ns: NS) {
ns.run('hackallservers.js')
let hackingLevel = ns.getHackingLevel()
while (hackingLevel < 9999) {
let oldHackingLevel = hackingLevel
let levels = recursiveHackingRequired(ns)
let hackingLevel: number
do {
hackingLevel = ns.getHackingLevel()
if (oldHackingLevel !== hackingLevel) {
ns.tprint(`Hacking level increased from ${oldHackingLevel} to ${hackingLevel}`)
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.run('killall.js')
await ns.sleep(1000) // 1 second
ns.run('hackallservers.js')
}
// Wait 1 second before checking again
await ns.sleep(1000)
}
} while (hackingLevel < 9999)
}