forked from alainbryden/bitburner-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstanek.js.create.js
More file actions
184 lines (176 loc) · 9.1 KB
/
stanek.js.create.js
File metadata and controls
184 lines (176 loc) · 9.1 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
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
import { log, getConfiguration, getNsDataThroughFile } from './helpers.js'
const argsSchema = [
['clear', false], // If set to true, will clear whatever layout is already there and create a new one
['force-width', null], // Force the layout less than or equal to the specified width
['force-height', null], // Force the layout less than or equal to the specified height
];
export function autocomplete(data, args) {
data.flags(argsSchema);
return [];
}
/** @param {NS} ns */
export async function main(ns) {
const options = getConfiguration(ns, argsSchema);
if (!options) return;
// Check if stanek was previously placed
if (!options['clear']) {
const fragments = await getNsDataThroughFile(ns, 'ns.stanek.activeFragments()', '/Temp/stanek-activeFragments.txt');
if (fragments.length > 0)
return log(ns, `WARNING: Nothing to do, you've already populated Stanek's Gift. Exiting...`, true);
}
// Find the saved layout that best matches
const height = options['force-height'] || await getNsDataThroughFile(ns, 'ns.stanek.giftHeight()', '/Temp/stanek-giftHeight.txt');
const width = options['force-width'] || await getNsDataThroughFile(ns, 'ns.stanek.giftWidth()', '/Temp/stanek-giftWidth.txt');
const usableLayouts = layouts.filter(l => l.height <= height && l.width <= width);
const bestLayout = usableLayouts.sort((l1, l2) => // Use the layout with the least amount of unused rows/columns
(height - l1.height + width - l1.width) - (height - l2.height + width - l2.width))[0];
log(ns, `Best layout found for current Stanek grid dimentions (height: ${height} width: ${width}) ` +
`has height: ${bestLayout.height} width: ${bestLayout.width} fragments: ${bestLayout.fragments.length}`);
// Clear any prior layout if enabled
if (options['clear']) {
await getNsDataThroughFile(ns, 'ns.stanek.clearGift() || true', '/Temp/stanek-clearGift.txt');
log(ns, 'Cleared any existing stanek layout.');
}
// Place the layout
log(ns, `Placing ${bestLayout.fragments.length} fragments:\n` + JSON.stringify(bestLayout.fragments));
const result = await getNsDataThroughFile(ns,
'JSON.parse(ns.args[0]).reduce((t, f) => ns.stanek.placeFragment(f.x, f.y, f.rotation, f.id) && t, true)',
'/Temp/stanek-placeFragments.txt', [JSON.stringify(bestLayout.fragments)]);
if (result)
log(ns, `SUCCESS: Placed ${bestLayout.fragments.length} Stanek fragments.`, true, 'success');
else
log(ns, `ERROR: Failed to place one or more fragments. The layout may be invalid.`, true, 'error');
}
// DISCLAIMER: These layouts are mostly hack focused, but bring in additional important stats as there is room
const layouts = [ // NOTE: Width appears to be always the same as, or one more than height.
{
"height": 2, "width": 3, "fragments": [ // BN 13.1 is this small
{ "id": 0, "x": 0, "y": 0, "rotation": 0 } // Hacking Mult
]
}, {
"height": 3, "width": 3, "fragments": [
{ "id": 1, "x": 0, "y": 0, "rotation": 3 }, // Hacking Mult
{ "id": 25, "x": 1, "y": 0, "rotation": 3 }, // Reputation
]
}, {
"height": 3, "width": 4, "fragments": [ // Note: Possible to fit 3 fragments, see "alternative layouts" below
{ "id": 0, "x": 0, "y": 0, "rotation": 1 },
{ "id": 1, "x": 2, "y": 0, "rotation": 1 }
]
}, {
"height": 4, "width": 4, "fragments": [ // Note: Possible to fit 4 fragments, but have to sacrifice a hacking mult piece
{ "id": 0, "x": 0, "y": 0, "rotation": 0 }, // Hacking Mult
{ "id": 1, "x": 0, "y": 2, "rotation": 0 }, // Hacking Mult
{ "id": 25, "x": 2, "y": 0, "rotation": 3 } // Reputation
]
}, {
"height": 4, "width": 5, "fragments": [
{ "id": 0, "x": 0, "y": 0, "rotation": 0 }, // Hacking Mult
{ "id": 1, "x": 0, "y": 2, "rotation": 0 }, // Hacking Mult
{ "id": 25, "x": 3, "y": 1, "rotation": 3 }, // Reputation
{ "id": 104, "x": 2, "y": 0, "rotation": 0 }, // Booster
]
}, {
"height": 5, "width": 5, "fragments": [
{ "id": 0, "x": 0, "y": 0, "rotation": 0 }, // Hacking Mult
{ "id": 1, "x": 1, "y": 2, "rotation": 0 }, // Hacking Mult
{ "id": 25, "x": 3, "y": 2, "rotation": 3 }, // Reputation
{ "id": 105, "x": 0, "y": 2, "rotation": 1 }, // Booster
{ "id": 100, "x": 2, "y": 0, "rotation": 0 }, // Booster
]
}, {
// NOTE: Things get pretty subjective after this. Should we prioritize boosting hacking multi or adding more stats?
// I've decided to start by adding in Hacking Speed, Hacknet Production + Cost as 3 stats more important than just more boost
"height": 5, "width": 6, "fragments": [
{ "id": 0, "x": 3, "y": 0, "rotation": 0 }, // Hacking Mult
{ "id": 1, "x": 3, "y": 3, "rotation": 0 }, // Hacking Mult
{ "id": 5, "x": 4, "y": 1, "rotation": 1 }, // Hacking Speed
{ "id": 20, "x": 0, "y": 4, "rotation": 0 }, // Hacknet Production
{ "id": 21, "x": 0, "y": 1, "rotation": 0 }, // Hacknet Cost Reduction
{ "id": 25, "x": 0, "y": 0, "rotation": 2 }, // Reputation
{ "id": 102, "x": 0, "y": 2, "rotation": 2 } // Booster
]
}, {
"height": 6, "width": 6, "fragments": [
{ "id": 0, "x": 0, "y": 2, "rotation": 0 }, // Hacking Mult
{ "id": 1, "x": 2, "y": 2, "rotation": 1 }, // Hacking Mult
{ "id": 5, "x": 3, "y": 3, "rotation": 1 }, // Hacking Speed
{ "id": 20, "x": 5, "y": 2, "rotation": 1 }, // Hacknet Production
{ "id": 21, "x": 0, "y": 0, "rotation": 0 }, // Hacknet Cost Reduction
{ "id": 25, "x": 3, "y": 0, "rotation": 2 }, // Reputation
{ "id": 103, "x": 0, "y": 4, "rotation": 2 }, // Booster
{ "id": 104, "x": 2, "y": 0, "rotation": 1 } // Booster
]
}, {
"height": 6, "width": 7, "fragments": [
{ "id": 0, "x": 1, "y": 1, "rotation": 2 }, // Hacking Mult
{ "id": 1, "x": 1, "y": 3, "rotation": 2 }, // Hacking Mult
{ "id": 5, "x": 4, "y": 3, "rotation": 0 }, // Hacking Speed
{ "id": 6, "x": 2, "y": 0, "rotation": 0 }, // Hack power
{ "id": 7, "x": 1, "y": 4, "rotation": 0 }, // Grow power
{ "id": 20, "x": 0, "y": 2, "rotation": 3 }, // Hacknet Production
{ "id": 21, "x": 0, "y": 0, "rotation": 0 }, // Hacknet Cost Reduction
{ "id": 25, "x": 5, "y": 0, "rotation": 3 }, // Reputation
{ "id": 28, "x": 4, "y": 4, "rotation": 0 }, // Crime Money TODO: Find a way to swap this for a booster
{ "id": 105, "x": 3, "y": 1, "rotation": 2 }, // Booster
]
}, { // Note: Late BN12, as Stanek gets bigger, Bladeburner also becomes a faster win condition, so we start adding those stats
"height": 7, "width": 7, "fragments": [
{ "id": 0, "x": 1, "y": 5, "rotation": 2 }, // Hacking Mult
{ "id": 1, "x": 3, "y": 3, "rotation": 0 }, // Hacking Mult
{ "id": 5, "x": 0, "y": 4, "rotation": 3 }, // Hacking Speed
{ "id": 6, "x": 0, "y": 0, "rotation": 1 }, // Hack power
{ "id": 7, "x": 1, "y": 1, "rotation": 1 }, // Grow power
{ "id": 20, "x": 1, "y": 0, "rotation": 2 }, // Hacknet Production
{ "id": 21, "x": 3, "y": 1, "rotation": 0 }, // Hacknet Cost Reduction
{ "id": 25, "x": 5, "y": 4, "rotation": 3 }, // Reputation
{ "id": 30, "x": 3, "y": 5, "rotation": 2 }, // Bladeburner Stats
{ "id": 101, "x": 5, "y": 0, "rotation": 3 }, // Booster
{ "id": 106, "x": 1, "y": 2, "rotation": 3 }, // Booster
]
}, {
"height": 7, "width": 8, "fragments": [
{ "id": 0, "x": 4, "y": 1, "rotation": 0 }, // Hacking Mult
{ "id": 1, "x": 4, "y": 4, "rotation": 3 }, // Hacking Mult
{ "id": 5, "x": 0, "y": 2, "rotation": 0 }, // Hacking Speed
{ "id": 6, "x": 3, "y": 0, "rotation": 2 }, // Hack power
{ "id": 7, "x": 2, "y": 0, "rotation": 0 }, // Grow power
{ "id": 14, "x": 0, "y": 3, "rotation": 1 }, // Dexterity
{ "id": 16, "x": 5, "y": 5, "rotation": 2 }, // Agility
{ "id": 20, "x": 0, "y": 6, "rotation": 0 }, // Hacknet Production
{ "id": 21, "x": 0, "y": 0, "rotation": 0 }, // Hacknet Cost Reduction
{ "id": 25, "x": 6, "y": 0, "rotation": 3 }, // Reputation
{ "id": 30, "x": 2, "y": 4, "rotation": 0 }, // Bladeburner Stats
{ "id": 103, "x": 4, "y": 3, "rotation": 0 }, // Booster
{ "id": 105, "x": 1, "y": 2, "rotation": 0 }, // Booster
]
}
];
// These alternative layouts are more "well-counded", favour fitting more stat pieces vs. boosting most important stats
const alternativeLayouts = [
{
"height": 3, "width": 4, "fragments": [
{ "id": 0, "x": 1, "y": 0, "rotation": 0 }, // Hacking Chance
{ "id": 25, "x": 0, "y": 0, "rotation": 1 }, // Reputation
{ "id": 28, "x": 1, "y": 1, "rotation": 0 }, // Crime Money
]
}, {
"height": 4, "width": 4, "fragments": [
{ "id": 0, "x": 0, "y": 2, "rotation": 2 }, // Hacking Chance
{ "id": 7, "x": 2, "y": 1, "rotation": 3 }, // Grow power
{ "id": 25, "x": 0, "y": 0, "rotation": 1 }, // Reputation
{ "id": 30, "x": 1, "y": 0, "rotation": 0 }, // Bladeburner
]
}, {
"height": 6, "width": 6, "fragments": [
{ "id": 0, "x": 0, "y": 2, "rotation": 0 }, // Hacking Chance
{ "id": 1, "x": 0, "y": 4, "rotation": 0 }, // Hacking Chance
{ "id": 5, "x": 2, "y": 1, "rotation": 0 }, // Hacking Speed
{ "id": 6, "x": 2, "y": 0, "rotation": 0 }, // Hack power
{ "id": 7, "x": 2, "y": 3, "rotation": 2 }, // Grow power
{ "id": 20, "x": 5, "y": 1, "rotation": 1 }, // Hacknet Production
{ "id": 21, "x": 0, "y": 0, "rotation": 0 }, // Hacknet Cost Reduction
{ "id": 25, "x": 3, "y": 4, "rotation": 0 }, // Reputation
]
}
]