Compare commits
No commits in common. "92ad2da7b758d5925abd962c6026c158bea8cb17" and "677f23ea8d3e3fdba5da176b2ad15ba3708af304" have entirely different histories.
92ad2da7b7
...
677f23ea8d
@ -1,13 +1,10 @@
|
|||||||
import { recursiveHackingRequired, recursiveScan } from "./utils"
|
import { recursiveScan } from "./utils"
|
||||||
|
|
||||||
export async function main(ns: NS){
|
export async function main(ns: NS){
|
||||||
switch (ns.args[0]) {
|
switch (ns.args[0]) {
|
||||||
case "getServers":
|
case "getServers":
|
||||||
getServers(ns);
|
getServers(ns);
|
||||||
break;
|
break;
|
||||||
case "getHackingLevels":
|
|
||||||
getHackingLevels(ns);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
ns.tprint("Invalid program name");
|
ns.tprint("Invalid program name");
|
||||||
break;
|
break;
|
||||||
@ -16,6 +13,3 @@ export async function main(ns: NS){
|
|||||||
function getServers(ns: NS) {
|
function getServers(ns: NS) {
|
||||||
ns.tprint(recursiveScan(ns));
|
ns.tprint(recursiveScan(ns));
|
||||||
}
|
}
|
||||||
function getHackingLevels(ns: NS) {
|
|
||||||
ns.tprint(recursiveHackingRequired(ns))
|
|
||||||
}
|
|
||||||
|
@ -28,21 +28,6 @@ export function recursiveScan(ns: NS) {
|
|||||||
return allServers
|
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
|
* Removes files passed in from all servers
|
||||||
* @param ns Global NS object
|
* @param ns Global NS object
|
||||||
|
@ -1,20 +1,16 @@
|
|||||||
import { recursiveHackingRequired } from "./utils"
|
|
||||||
|
|
||||||
export async function main(ns: NS) {
|
export async function main(ns: NS) {
|
||||||
ns.run('hackallservers.js')
|
ns.run('hackallservers.js')
|
||||||
let levels = recursiveHackingRequired(ns)
|
let hackingLevel = ns.getHackingLevel()
|
||||||
let hackingLevel: number
|
while (hackingLevel < 9999) {
|
||||||
do {
|
let oldHackingLevel = hackingLevel
|
||||||
hackingLevel = ns.getHackingLevel()
|
hackingLevel = ns.getHackingLevel()
|
||||||
if (levels.includes(hackingLevel)) {
|
if (oldHackingLevel !== hackingLevel) {
|
||||||
// remove the level from the list, so we don't try to hack it again
|
ns.tprint(`Hacking level increased from ${oldHackingLevel} to ${hackingLevel}`)
|
||||||
levels.splice(levels.indexOf(hackingLevel), 1)
|
|
||||||
ns.tprint(`Hacking level increased to ${hackingLevel}`)
|
|
||||||
ns.run('killall.js')
|
ns.run('killall.js')
|
||||||
await ns.sleep(1000) // 1 second
|
await ns.sleep(1000) // 1 second
|
||||||
ns.run('hackallservers.js')
|
ns.run('hackallservers.js')
|
||||||
}
|
}
|
||||||
// Wait 1 second before checking again
|
// Wait 1 second before checking again
|
||||||
await ns.sleep(1000)
|
await ns.sleep(1000)
|
||||||
} while (hackingLevel < 9999)
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user