-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheasy-hack.js
52 lines (43 loc) · 1.48 KB
/
easy-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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/** Baby's first hack script.
* Used by low RAM servers that don't have 8GB or more for our hack-daemon.
* Because it's simple, it's dumb and does not report to the coordinator.
* Written By: Zharay
* URL: https://github.com/Zharay/BitburnerBotnet
**/
/** @param {NS} ns */
export async function main(ns) {
var threshModifier = 0.8;
// Get targets from coordinator
var gTargets = ns.getPortHandle(1);
while (gTargets.peek() == "NULL PORT DATA") {
ns.print("Waiting for targets to be added by coordinator...")
await ns.sleep(1000);
}
var randWait = 1000 * Math.floor((Math.random() * 30) + 3);
ns.print("Waiting for [" + (randWait / 1000) + "] seconds");
await ns.sleep(randWait);
var jTargets = JSON.parse(gTargets.peek());
var jExp = JSON.parse(ns.peek(5));
var target = "";
if (jTargets.length != 0) target = jTargets[0].target;
else if (jExp.length != 0) target = jExp[0].target;
else {
ns.print("Nothing I can do :(");
return;
}
var moneyThreshold = ns.getServerMaxMoney(target) * threshModifier;
var securityThreshold = ns.getServerMinSecurityLevel(target) + 5;
var fKill = ns.getPortHandle(20);
while (fKill.peek() == "NULL PORT DATA") {
if (ns.getServerSecurityLevel(target) > securityThreshold) {
ns.print("Weakening defenses...");
await ns.weaken(target);
} else if (ns.getServerMoneyAvailable(target) < moneyThreshold) {
ns.print("Growing money...");
await ns.grow(target);
} else {
ns.print("Hacking...");
await ns.hack(target);
}
}
}