forked from xxxsinx/bitburner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.js
201 lines (177 loc) · 5.37 KB
/
stats.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
const factions = [
'CyberSec',
'Tian Di Hui',
'Netburners',
'Sector-12',
'Aevum',
'Volhaven',
'Ishima',
'Chongqing',
'New Tokyo',
'NiteSec',
'The Black Hand',
'BitRunners',
'ECorp',
'MegaCorp',
'KuaiGong International',
'Four Sigma',
'NWO',
'Blade Industries',
'OmniTek Incorporated',
'Bachman & Associates',
'Clarke Incorporated',
'Fulcrum Secret Technologies',
'Slum Snakes',
'Tetrads',
'Silhouette',
'Speakers for the Dead',
'The Dark Army',
'The Syndicate',
'The Covenant',
'Daedalus',
'Illuminati'
];
const crimes = [
'shoplift',
'rob store',
'mug',
'larceny',
'deal drugs',
'bond forgery',
'traffick arms',
'homicide',
'grand theft auto',
'kidnap',
'assassinate',
'heist'
];
// ascensionMultiplier(points) Calculate ascension mult.
// ascensionPointsGain(exp) Calculate ascension point gain.
// moneyGain(gang, member, task) Calculate money gain per tick.
// respectGain(gang, member, task) Calculate respect gain per tick.
// wantedLevelGain(gang, member, task) Calculate wanted gain per tick.
// wantedPenalty(gang) Calculate the wanted penalty.
/** @param {NS} ns **/
export async function main(ns) {
ns.disableLog('ALL');
let player = ns.getPlayer();
if (ns.args[0] == 'best') {
ns.tprint('Best crime right now is: ' + GetBestCrime(ns, ns.getPlayer()));
return;
}
if (ns.args[0] == 'factions') {
let joined= ns.getPlayer().factions;
let missing= factions.filter(s=> !joined.includes(s));
ns.tprint('missing: ' + missing.join('\n'));
// for (const faction of factions) {
// try {
// const augs = ns.singularity.getAugmentationsFromFaction(faction);
// }
// catch {
// ns.tprint('faction ' + faction + ' is invalid maybe?');
// }
// }
return;
}
if (ns.args[0] == 'travel') {
for (; ;) {
for (let i = 0; i < 10000; i++) {
ns.singularity.travelToCity('Sector-12');
ns.singularity.travelToCity('Chongqing');
}
await ns.sleep(0);
}
return;
}
const startMoney = player.money;
while (true) {
player = ns.getPlayer();
// If we lost money, lets do some crimes to replenish the wallet
// if (player.money < startMoney) {
// await TheSecretIngredientIsCrime(ns);
// }
// else {//if (!ns.isBusy()) {
ns.print('Training stats at the gym!');
await TrainCombatStats(ns, player);
// }
SituationReport(ns, player, startMoney);
await ns.sleep(10000);
}
}
async function TrainCombatStats(ns, player) {
let stats = new Array(
{ 'stat': 'strength', 'value': player.strength },
{ 'stat': 'defense', 'value': player.defense },
{ 'stat': 'dexterity', 'value': player.dexterity },
{ 'stat': 'agility', 'value': player.agility });
// Find our lowest stat
stats = stats.sort((a, b) => a.value - b.value);
ns.print('Our lowest combat stat is ' + stats[0].stat);
if (player.className != 'training your ' + stats[0].stat + ' at a gym') {
ns.gymWorkout('Powerhouse Gym', stats[0].stat, false);
for (let i = 0; i < ns.sleeve.getNumSleeves(); i++) {
ns.sleeve.setToGymWorkout(i, 'Powerhouse Gym', 'Train ' + stats[0].stat.charAt(0).toUpperCase() + stats[0].stat.slice(1));
}
}
}
function SituationReport(ns, player, startMoney) {
ns.print('');
ns.print('Karma : ' + ns.heart.break());
ns.print('Money on script launch : ' + ns.nFormat(startMoney, "$0.000a"));
ns.print('Money : ' + ns.nFormat(player.money, "$0.000a"));
ns.print('City : ' + player.city);
ns.print('isWorking : ' + player.isWorking);
ns.print('workType : ' + player.workType);
ns.print('className : ' + player.className);
ns.print('');
}
async function TheSecretIngredientIsCrime(ns) {
const bestCrime = GetBestCrime(ns, ns.getPlayer())
if (bestCrime != undefined) {
const start = Date.now();
const time = ns.commitCrime(bestCrime);
ns.print('Committing ' + bestCrime + ' (will take approx ' + ns.tFormat(time) + ')');
while (ns.isBusy()) {
let elapsed = Date.now() - start;
if (elapsed < time * 0.8) break; // user cancelled
await ns.sleep(100);
}
ns.print(bestCrime + ' complete!');
}
}
export function GetBestCrime(ns, player) {
let bestCrime = undefined;
let bestCps = 0;
let bestKps = 0;
let bestIps = 0;
for (const crime of crimes) {
let crimeStats = ns.getCrimeStats(crime);
let chance = calculateCrimeSuccessChance(crimeStats, player) // ns.getCrimeChance(crime);
let cps = crimeStats.money / crimeStats.time * chance;
let kps = crimeStats.karma / crimeStats.time * chance;
let ips = crimeStats.intelligence_exp / crimeStats.time * chance;
//if (bestCps == 0 || (cps > bestCps && chance > 0.25)) {
//if (bestKps == 0 || (kps > bestKps/* && chance > 0.25*/)) {
if (bestIps == 0 || (ips > bestIps/* && chance > 0.25*/)) {
bestCrime = crime;
bestCps = cps;
bestKps = kps;
bestIps = ips;
}
ns.tprint(crime + ' ips: ' + ips);
}
//ns.tprint('Best crime is: ' + bestCrime);
return bestCrime;
}
function calculateCrimeSuccessChance(crimeStats, person) {
let chance =
crimeStats.hacking_success_weight * person.hacking +
crimeStats.strength_success_weight * person.strength +
crimeStats.defense_success_weight * person.defense +
crimeStats.dexterity_success_weight * person.dexterity +
crimeStats.agility_success_weight * person.agility +
crimeStats.charisma_success_weight * person.charisma
chance /= 975;
chance /= crimeStats.difficulty;
return Math.min(chance, 1)
}