Add check for if new programs have begun to exist
This commit is contained in:
parent
9b4042af40
commit
9bacf4f97f
@ -154,3 +154,30 @@ export async function calculateMPS(ns: NS, time: number = 5) {
|
||||
}
|
||||
return data.reduce((a, b) => a + b, 0) / time
|
||||
}
|
||||
|
||||
/**
|
||||
* Type that represents a program and whether it exists on the home server
|
||||
*/
|
||||
export type ProgramState = {
|
||||
program: string
|
||||
exists: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if any of the programs passed in now exist on the home server, and updates the exists property of the program
|
||||
* @param ns Global NS object
|
||||
* @param programs The programs to check
|
||||
* @returns true if any of the programs now exist, otherwise false
|
||||
*/
|
||||
export function checkForNewPrograms(ns: NS, programs: ProgramState[]) {
|
||||
let result = false
|
||||
for (const program of programs) {
|
||||
if (program.exists == false) {
|
||||
program.exists = ns.fileExists(program.program)
|
||||
if (program.exists) {
|
||||
result = true
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
@ -1,13 +1,22 @@
|
||||
import { recursiveHackingRequired } from "./utils"
|
||||
import { checkForNewPrograms, ProgramState, recursiveHackingRequired } from "./utils"
|
||||
|
||||
export async function main(ns: NS) {
|
||||
let levels = recursiveHackingRequired(ns)
|
||||
let hackingLevel = ns.getHackingLevel()
|
||||
|
||||
let state: ProgramState[] = [
|
||||
{ program: "BruteSSH.exe", exists: false },
|
||||
{ program: "FTPCrack.exe", exists: false },
|
||||
{ program: "relaySMTP.exe", exists: false },
|
||||
{ program: "HTTPWorm.exe", exists: false },
|
||||
{ program: "SQLInject.exe", exists: false },
|
||||
]
|
||||
|
||||
// Remove levels that are already hacked
|
||||
levels = levels.filter(level => level > hackingLevel)
|
||||
|
||||
do {
|
||||
if (Math.min(...levels) <= hackingLevel) {
|
||||
if (Math.min(...levels) <= hackingLevel || checkForNewPrograms(ns, state)) {
|
||||
ns.tprint(`Hacking level increased past ${Math.min(...levels)}}, is now ${hackingLevel}`)
|
||||
ns.tprint(`Remaining levels to hack: ${levels}`)
|
||||
// remove the level from the list, so we don't try to hack it again
|
||||
|
Loading…
Reference in New Issue
Block a user