-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbase.js
50 lines (49 loc) · 1.71 KB
/
base.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
/** @param {NS} ns **/
export async function main(ns) {
ns.disableLog('getServerMoneyAvailable')
ns.disableLog('getServerSecurityLevel')
let server = ns.args[0];
let maxM = ns.args[1];
let minS = ns.args[2];
let threads = ns.args[3];
let level = ns.getServerSecurityLevel(server);
let money = ns.getServerMoneyAvailable(server);
let auxM = 0; var auxS = 0; var numM = 0; var numS = 0;
let numHack = ns.read(server + "Income.txt")
if (numHack == "") {
numHack = 0;
}
numHack = parseInt(numHack)
/*if (ns.read(server + "_log.txt") == "")
await ns.write(server + "_log.txt", money + '-' + new Date().getTime(), "w")*/
while (true) {
if (money < maxM) {
ns.print( new Date().toString())
await ns.grow(server);
money = ns.getServerMoneyAvailable(server);
//await ns.write(server + "_log.txt", money + '-' + new Date().getTime(), "a")
auxM = parseFloat(money / maxM * 100).toFixed(2);
} else if (level > minS) {
ns.print( new Date().toString())
await ns.weaken(server);
level = ns.getServerSecurityLevel(server);
auxS = parseFloat(minS / level * 100).toFixed(2);
} else {
while (money / maxM > 2 / 3 && minS / level > 2 / 3) {
try {
numHack += await ns.hack(server, { threads: Math.floor(threads / 4) });
} catch { await ns.sleep(0) }
money = ns.getServerMoneyAvailable(server);
//await ns.write(server + "_log.txt", money + '-' + new Date().getTime(), "a")
await ns.write(server + "Income.txt", numHack, "w")
}
await ns.weaken(server);
//ns.print(numHack + " stolen from " + server);
level = ns.getServerSecurityLevel(server);
}
if (numS != auxS && numM != auxM) {
numM = auxM; numS = auxS;
ns.print(numM + "% grow " + numS + "% lowSecurity");
}
}
}