forked from MercuriusXeno/BitBurnerScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcascade-kill.js
49 lines (41 loc) · 1.56 KB
/
cascade-kill.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
// the purpose of cascade kill is to kill all scripts running on any server in the game
// but saving the host that you run it on for last (so that it doesn't kill itself prematurely)
export async function main(ns) {
var startingNode = ns.getHostname();
var hostsToScan = [];
hostsToScan.push(startingNode);
var serverList = [];
// assemble a server list.
while (hostsToScan.length > 0) {
var hostName = hostsToScan.pop();
if (!serverList.includes(hostName)) {
var connectedHosts = ns.scan(hostName);
for (var i = 0; i < connectedHosts.length; i++) {
hostsToScan.push(connectedHosts[i]);
}
serverList.push(hostName);
}
}
for (var s = 0; s < serverList.length; s++) {
// skip if this host, we save it for last
if (serverList[s] == startingNode)
continue;
// skip if not running anything
if (ns.ps(serverList[s]) === 0)
continue;
// kill all scripts
ns.killall(serverList[s]);
}
// idle for things to die
for (var x = 0; x < serverList.length; x++) {
// skip if this host, we save it for last
if (serverList[x] == startingNode)
continue;
// idle until they're dead, this is to avoid killing the cascade before it's finished.
while (ns.ps(serverList[x]) > 0) {
await ns.sleep(20);
}
}
// wait to kill these. This kills itself, obviously.
ns.killall(startingNode);
}