Compare commits

...

3 Commits

7 changed files with 63 additions and 20 deletions

15
servers/home/hack.ts Normal file
View File

@ -0,0 +1,15 @@
import {NS} from "NetscriptDefinitions";
export async function main(ns: NS) {
const server: string = <string>ns.args[0];
const moneyThresh: number = <number>ns.args[1];
const securityThresh: number = <number>ns.args[2];
while (true) {
if (ns.getServerSecurityLevel(server) > securityThresh) {
await ns.weaken(server);
} else if (ns.getServerMoneyAvailable(server) < moneyThresh) {
await ns.grow(server);
} else {
await ns.hack(server);
}
}
}

View File

@ -0,0 +1,15 @@
import {NS} from "NetscriptDefinitions";
import {recursiveScan} from "./utils";
import {executeScriptOnServerFromAnother} from "./utils";
export async function main(ns: NS) {
let servers: string[] = recursiveScan(ns);
for (const server of servers) {
let moneyThresh = ns.getServerMaxMoney(server) * 0.75;
let securityThresh = ns.getServerMinSecurityLevel(server) + 5;
let numThreads = ns.getServerMaxRam(server) / ns.getScriptRam("hack.js")
numThreads = Math.floor(numThreads);
executeScriptOnServerFromAnother(ns, server, "hack.js", numThreads, [server, moneyThresh, securityThresh])
}
}

9
servers/home/killall.ts Normal file
View File

@ -0,0 +1,9 @@
import {NS} from "NetscriptDefinitions";
import {recursiveScan} from "./utils";
export async function main(ns: NS) {
let servers: string[] = recursiveScan(ns)
for (const server of servers) {
ns.killall(server)
}
}

View File

@ -1,15 +0,0 @@
/** @param {NS} ns */
export async function main(ns) {
var target = ns.args[0]
var moneyThresh = ns.args[1]
var securityThresh = ns.args[2]
while (true) {
if (ns.getServerSecurityLevel(target) > securityThresh) {
await ns.weaken(target);
} else if (ns.getServerMoneyAvailable(target) < moneyThresh) {
await ns.grow(target);
} else {
await ns.hack(target);
}
}
}

View File

@ -2,5 +2,5 @@ import {NS} from "NetscriptDefinitions";
import {executeScriptOnServerFromAnother} from "./utils"; import {executeScriptOnServerFromAnother} from "./utils";
export async function main(ns: NS) { export async function main(ns: NS) {
executeScriptOnServerFromAnother(ns, "servers/home/ramcost.ts", [], "home") executeScriptOnServerFromAnother(ns, "home", "servers/home/ramcost.ts", 1, [])
} }

View File

@ -118,13 +118,14 @@ export function performFunctionIfCapable(ns: NS, server: string, func: CallableF
/** /**
* Executes a script on a server from another server * Executes a script on a server from another server
* @param ns Global NS object * @param ns Global NS object
* @param script The file path of the script to execute
* @param args The arguments to pass to the script
* @param server The server to execute the script on * @param server The server to execute the script on
* @param script The file path of the script to execute
* @param threads The number of threads to use
* @param args The arguments to pass to the script
*/ */
export function executeScriptOnServerFromAnother(ns: NS, script: string, args: any[], server: string) { export function executeScriptOnServerFromAnother(ns: NS, server: string, script: string, threads: number = 1, args: any[]) {
ns.scp(script, server); ns.scp(script, server);
performFunctionIfCapable(ns, server, ns.exec, [script, server, ...args]) performFunctionIfCapable(ns, server, ns.exec, [script, server, threads, ...args])
ns.atExit( ns.atExit(
() => { () => {
ns.rm(script, server); ns.rm(script, server);

18
servers/home/watcher.ts Normal file
View File

@ -0,0 +1,18 @@
import {NS} from "NetscriptDefinitions";
export async function main(ns: NS) {
let hackingLevel = ns.getHackingLevel();
while (hackingLevel < 9999) {
ns.run("hackallservers.js");
let seconds = 60 * 1000; // 1 minute
await ns.sleep(seconds)
let oldHackingLevel = hackingLevel;
hackingLevel = ns.getHackingLevel();
if(oldHackingLevel !== hackingLevel) {
ns.tprint(`Hacking level increased from ${oldHackingLevel} to ${hackingLevel}`);
ns.run("killall.js");
await ns.sleep(1000) // 1 second
ns.run("hackallservers.js");
}
}
}