-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhackclient.js
More file actions
53 lines (43 loc) · 1.86 KB
/
hackclient.js
File metadata and controls
53 lines (43 loc) · 1.86 KB
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
export async function hackTarget(ns, targetHostname, moneyRatio, securityDelta) {
const thisScriptName = ns.getScriptName();
let myHostname = ns.getHostname();
if( !ns.serverExists(targetHostname) ) {
return;
}
ns.tprintf("%s -> myHostname=%s | targetHostname=%s | moneyRatio=%f | securityDelta=%f", thisScriptName, myHostname, targetHostname, moneyRatio, securityDelta);
const serverMaxMoney = ns.getServerMaxMoney(targetHostname);
const serverMinSecurityLvl = ns.getServerMinSecurityLevel(targetHostname);
while(true){
let serverMoneyAvailable = ns.getServerMoneyAvailable(targetHostname);
let serverMoneyRatio = serverMoneyAvailable / serverMaxMoney;
let serverSecurityLvl = ns.getServerSecurityLevel(targetHostname);
let serverSecurityDelta = serverSecurityLvl - serverMinSecurityLvl;
let weakenCondition = (serverSecurityDelta > securityDelta) ? true : false;
let growCondition = (serverMoneyRatio < moneyRatio) ? true : false;
ns.printf("serverMoneyRatio %f %s moneyRatio %f", serverMoneyRatio, serverMoneyRatio > moneyRatio ? ">" : "<=", moneyRatio);
ns.printf("serverSecurityDelta %f %s securityDelta %f", serverSecurityDelta, serverSecurityDelta > securityDelta ? ">" : "<=", securityDelta);
if(weakenCondition) {
await ns.weaken(targetHostname);
} else if(growCondition) {
await ns.grow(targetHostname);
} else {
await ns.hack(targetHostname);
}
}
}
/** @param {NS} ns */
export async function main(ns) {
let targetHostname = "";
let thresholdMoneyRatio = 1.0;
let thresholdSecurityDelta = 0.0;
if(ns.args.length >= 1) {
targetHostname = ns.args[0];
}
if(ns.args.length >= 2) {
thresholdMoneyRatio = ns.args[1];
}
if(ns.args.length >= 3) {
thresholdSecurityDelta = ns.args[2];
}
await hackTarget(ns, targetHostname, thresholdMoneyRatio, thresholdSecurityDelta);
}