-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02-mid-hack.js
35 lines (33 loc) · 1.35 KB
/
02-mid-hack.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/** @param {NS} ns */
export async function main(ns) {
// Defines the "target server" to hack.
var target;
if (ns.args[0] !== undefined) {
target = ns.args[0]; // defines with optional argument
} else if (ns.hasRootAccess("joesguns")) {
target = "joesguns";
} else {
ns.exec("01-target.js", "joesguns");
target = "joesguns";
}
// Defines how much money a server should have before we hack it
// In this case, it is set to 75% of the server's max money
var moneyThresh = ns.getServerMaxMoney(target) * 0.75;
// Defines the maximum security level the target server can
// have. If the target's security level is higher than this,
// we'll weaken it before doing anything else
var securityThresh = ns.getServerMinSecurityLevel(target) + 5;
// Infinite loop that continously hacks/grows/weakens the target server
while (true) {
if (ns.getServerSecurityLevel(target) > securityThresh) {
// If the server's security level is above our threshold, weaken it
await ns.weaken(target);
} else if (ns.getServerMoneyAvailable(target) < moneyThresh) {
// If the server's money is less than our threshold, grow it
await ns.grow(target);
} else {
// Otherwise, hack it
await ns.hack(target);
}
}
}