-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcp.js
178 lines (145 loc) · 5.29 KB
/
mcp.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
- Requires: singularity
- root servers
- backdoor faction servers
- join factions
*/
import { countPrograms } from "/libraries/root.js";
import { buyaugments, getportopeners, createexes, findavailableserver, getbesthackxp, getallservers, getserverswithram, getmostprofitable } from "/libraries/utils.js";
import { factionservers } from 'constants.js'
/** @param {NS} ns **/
export async function main(ns) {
ns.disableLog('ALL');
//ns.enableLog('exec');
ns.clearLog();
let besthackserver = "";
ns.stopAction();
mainloop:
while (true) {
await ns.sleep(100);
let allservers = getserverswithram(ns);
let targets = getallservers(ns);
// scan for contracts
ns.run('contracts/contract-scanner.js');
// buy approved augments
buyaugments(ns);
// buy ram for home if possible
ns.upgradeHomeRam();
// // hack best server for xp gain
// if (besthackserver !== getmostprofitable(ns)) {
// ns.kill('coordinator.js', 'home', besthackserver);
// ns.run('coordinator.js', 1, getmostprofitable(ns));
// besthackserver = getmostprofitable(ns);
// }
// check if ready to install augments and reset
let pendingaugs = ns.getOwnedAugmentations(true).length - ns.getOwnedAugmentations(false).length;
if (pendingaugs >= 4 && ns.gang.inGang()) {
if (ns.gang.getGangInformation().territory > .99) {
// let symbols = ns.stock.getSymbols();
// for (const sym of symbols) {
// if (ns.stock.getPosition(sym)[0] > 0 || ns.stock.getPosition(sym)[2] > 0) {
// ns.run("/stocks/selloff.js");
// continue mainloop;
// }
// ns.run("reset.js");
// }
ns.spawn("reset.js");
}
}
// if we won the war start trading stocks
if (ns.gang.inGang()) {
// if (ns.gang.getGangInformation().territory < .99 && ns.getPlayer().hasTixApiAccess && ns.getPlayer().has4SDataTixApi === false) {
if (ns.getPlayer().hasTixApiAccess && ns.getPlayer().has4SDataTixApi === false) {
ns.run('/stocks/early-stock-trader.js');
}
// if (ns.gang.getGangInformation().territory < .99 && ns.getPlayer().hasTixApiAccess && ns.getPlayer().has4SDataTixApi === true) {
if (ns.getPlayer().hasTixApiAccess && ns.getPlayer().has4SDataTixApi === true) {
ns.scriptKill('/stocks/early-stock-trader.js', 'home');
ns.run('/stocks/stock-trader.js');
}
ns.run('/stocks/manipulate.js');
}
// buy stock api
if (ns.getPlayer().hasWseAccount && ns.getPlayer().hasTixApiAccess) {
// ns.stock.purchase4SMarketData();
ns.stock.purchase4SMarketDataTixApi();
}
// if cache is getting full buy something
if (ns.getPlayer().hasCorporation) {
ns.hacknet.spendHashes('Sell for Corporation Funds');
} else {
ns.hacknet.spendHashes('Sell for Money');
}
getportopeners(ns);
// make sure critical scripts are running if they should be
if (ns.gang.inGang() === true) {
if (ns.scriptRunning('/gangs/tasks.js', 'home') === false) {
ns.print("Gang control wasn't running. Starting...");
ns.run('/gangs/tasks.js');
}
}
if (ns.scriptRunning('hudstart.js', 'home') === false) {
ns.run('hudstart.js');
}
// hacking contracts
let playerfactions = ns.getPlayer().factions;
if (ns.isBusy() === false) {
if (playerfactions.includes('Daedalus') && ns.getPlayer().bitNodeN !== 2) {
ns.run('/helpers/workforfaction.js', 1, 'Daedalus', 'Hacking');
}
if (playerfactions.includes('Sector-12') && ns.getPlayer().bitNodeN === 2) {
ns.run('/helpers/workforfaction.js', 1, 'Sector-12', 'Hacking');
}
}
// create programs - for int
//await createexes(ns);
// root servers
// backdoor faction servers
let get_root_ram = ns.getScriptRam('/helpers/get_root.js');
roottargetsloop:
for (let i = 0; i < targets.length; ++i) {
if (ns.hasRootAccess(targets[i].name) === true) {
await ns.sleep(20);
continue roottargetsloop;
}
if (ns.getHackingLevel() >= ns.getServerRequiredHackingLevel(targets[i].name)) {
rootallserversloop:
for (let j = 0; j < allservers.length; ++j) {
if (countPrograms(ns) >= ns.getServerNumPortsRequired(targets[i].name)) {
let availableram = ns.getServerMaxRam(allservers[j]) - ns.getServerUsedRam(allservers[j]);
if (availableram > get_root_ram) {
ns.exec('/helpers/get_root.js', allservers[j], 1, targets[i].name)
ns.tprint("Rooted: " + targets[i].name);
ns.print("Rooted: " + targets[i].name);
await ns.sleep(100);
// backdoor
if (factionservers.includes(targets[i].name)) {
ns.run('/helpers/backdoor.js', 1, targets[i].name);
ns.tprint("Backdoored: " + targets[i].name);
ns.print("Backdoored: " + targets[i].name);
await ns.sleep(5000);
}
break rootallserversloop;
}
}
}
}
}
// join factions
let joinfaction_ram = ns.getScriptRam('/helpers/joinfaction.js');
let factioninvites = ns.checkFactionInvitations();
if (factioninvites.length > 0) {
for (const factioninvite of factioninvites) {
factionaserversloop:
for (let i = 0; i < allservers.length; ++i) {
let availableram = ns.getServerMaxRam(allservers[i]) - ns.getServerUsedRam(allservers[i]);
if (availableram > joinfaction_ram) {
ns.exec('/helpers/joinfaction.js', allservers[i], 1, factioninvite);
ns.print('Joined: ' + factioninvite);
break factionaserversloop;
}
}
}
}
}
}