forked from MercuriusXeno/BitBurnerScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode-manager.js
55 lines (53 loc) · 1.95 KB
/
node-manager.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
53
54
55
// the purpose of node-manager is to handle hacknet nodes for us
// the primary reason for doing it at all is simply for netburner augs.
export async function main(ns) {
const hn = ns.hacknet;
var options = ["level", "ram", "core", "node"];
while(true) {
var maxNodes = hn.numNodes();
var needsNode = false;
if (maxNodes === 0) {
needsNode = true;
maxNodes = 1;
}
for (var i = 0; i < maxNodes; i++) {
for (var o = (needsNode ? 3 : 0); o < options.length; o++) {
var allowancePercentage = 0.00001;
var playerMoney = ns.getServerMoneyAvailable("home");
var costOfThing = 0;
switch(o) {
case 0:
costOfThing = hn.getLevelUpgradeCost(i, 1);
break;
case 1:
costOfThing = hn.getRamUpgradeCost(i, 1);
break;
case 2:
costOfThing = hn.getCoreUpgradeCost(i, 1);
break;
case 3:
costOfThing = hn.getPurchaseNodeCost();
break;
}
var shouldPurchase = playerMoney * allowancePercentage >= costOfThing;
if (shouldPurchase) {
switch(o) {
case 0:
hn.upgradeLevel(i, 1);
break;
case 1:
hn.upgradeRam(i, 1);
break;
case 2:
hn.upgradeCore(i, 1);
break;
case 3:
hn.purchaseNode()
break;
}
}
}
}
await ns.sleep(10);
}
}