-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-ores.mjs
352 lines (311 loc) · 8.24 KB
/
generate-ores.mjs
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
import Database from "better-sqlite3"
import ora from "ora"
import bz2 from "unbzip2-stream"
import fs from "fs"
import https from "https"
import tmp from "tmp"
tmp.setGracefulCleanup()
const SQLITE_FILE = tmp.tmpNameSync()
const ORE_FILE = "./src/json/ores.json"
const COLORS = new Map([
// ORES
["Arkonor", "#c9aaae"],
["Bistot", "#5bda74"],
["Crokite", "#fada6b"],
["Dark Ochre", "#f7efc6"],
["Hedbergite", "#86d4e2"],
["Hemorphite", "#a4c6dd"],
["Jaspet", "#9cc09c"],
["Kernite", "#94dbd6"],
["Plagioclase", "#c5ebc5"],
["Pyroxeres", "#f7efcb"],
["Scordite", "#c1c9bc"],
["Spodumain", "#ced77c"],
["Veldspar", "#d3b871"],
["Gneiss", "#8cfb9d"],
["Mercoxit", "#de8d63"],
["Omber", "#fffb9d"],
["Talassonite", "#c38553"],
["Rakovene", "#7da4a8"],
["Bezdnacine", "#c3bca8"],
// MOON
["Bitumens", "#beaa86"],
["Carnotite", "#4a6795"],
["Chromite", "#9a6442"],
["Cinnabar", "#56637f"],
["Cobaltite", "#688f95"],
["Coesite", "#b79f79"],
["Euxenite", "#5e7679"],
["Loparite", "#c1847f"],
["Monazite", "#b88c86"],
["Otavite", "#c69e7c"],
["Pollucite", "#375284"],
["Scheelite", "#54757d"],
["Sperrylite", "#ac8366"],
["Sylvite", "#ac9e81"],
["Titanite", "#606f6f"],
["Vanadinite", "#957e6b"],
["Xenotime", "#987874"],
["Ytterbite", "#835c57"],
["Zeolites", "#b1a28a"],
["Zircon", "#535d6c"],
// ICE
["Krystallos", "#7893a4"],
["Dark Glitter", "#a7b4bb"],
["Gelidus", "#8cbabd"],
["Glare Crust", "#92a8b3"],
["Clear Icicle", "#a8b2b8"],
["Blue Ice", "#91b5c8"],
["White Glaze", "#92a9b5"],
["Glacial Mass", "#b9cfdc"],
])
const AVAILABILITY = new Map([
// ORES
["Arkonor", ["Nullsec"]],
["Bistot", ["Nullsec"]],
["Crokite", ["Lowsec", "Nullsec"]],
["Dark Ochre", ["Lowsec"]],
["Hedbergite", ["Lowsec"]],
["Hemorphite", ["Lowsec"]],
["Jaspet", ["Lowsec"]],
["Kernite", ["Lowsec", "Nullsec"]],
["Plagioclase", ["Highsec"]],
["Pyroxeres", ["Highsec", "Lowsec", "Nullsec"]],
["Scordite", ["Highsec"]],
["Spodumain", ["Lowsec", "Triglavian"]],
["Veldspar", ["Highsec"]],
["Gneiss", ["Lowsec"]],
["Mercoxit", ["Nullsec"]],
["Omber", ["Lowsec", "Nullsec"]],
["Talassonite", ["Triglavian"]],
["Rakovene", ["Triglavian"]],
["Bezdnacine", ["Triglavian"]],
// MOON
["Bitumens", ["R4"]],
["Carnotite", ["R32"]],
["Chromite", ["R16"]],
["Cinnabar", ["R32"]],
["Cobaltite", ["R8"]],
["Coesite", ["R4"]],
["Euxenite", ["R8"]],
["Loparite", ["R64"]],
["Monazite", ["R64"]],
["Otavite", ["R16"]],
["Pollucite", ["R32"]],
["Scheelite", ["R8"]],
["Sperrylite", ["R16"]],
["Sylvite", ["R4"]],
["Titanite", ["R8"]],
["Vanadinite", ["R16"]],
["Xenotime", ["R64"]],
["Ytterbite", ["R64"]],
["Zeolites", ["R4"]],
["Zircon", ["R32"]],
// ICE
["Krystallos", ["Nullsec"]],
["Dark Glitter", ["Nullsec", "Lowsec"]],
["Gelidus", ["Nullsec"]],
["Enriched Clear Icicle", ["Nullsec", "Amarr"]],
["Thick Blue Ice", ["Nullsec", "Gallente"]],
["Pristine White Glaze", ["Nullsec", "Caldar"]],
["Smooth Glacial Mass", ["Nullsec", "Minmatar"]],
["Glare Crust", ["Nullsec", "Lowsec"]],
["Clear Icicle", ["Amarr"]],
["Blue Ice", ["Gallente"]],
["White Glaze", ["Caldari"]],
["Glacial Mass", ["Minmatar"]],
])
const ORE_GROUPS = new Map([
[450, "Arkonor"],
[451, "Bistot"],
[452, "Crokite"],
[453, "Dark Ochre"],
[454, "Hedbergite"],
[455, "Hemorphite"],
[456, "Jaspet"],
[457, "Kernite"],
[458, "Plagioclase"],
[459, "Pyroxeres"],
[460, "Scordite"],
[461, "Spodumain"],
[462, "Veldspar"],
[467, "Gneiss"],
[468, "Mercoxit"],
[469, "Omber"],
[4029, "Talassonite"],
[4030, "Rakovene"],
[4031, "Bezdnacine"],
])
const MOON_GROUPS = new Map([
[1884, "Ubiquitous Moon Asteroids"],
[1920, "Common Moon Asteroids"],
[1921, "Uncommon Moon Asteroids"],
[1922, "Rare Moon Asteroids"],
[1923, "Exceptional Moon Asteroids"],
])
const ICE_GROUPS = new Map([[465, "Ice"]])
function downloadLatestDatabase() {
return new Promise((resolve, reject) => {
const spinner = ora("Downloading latest SDE").start()
https.get(
"https://www.fuzzwork.co.uk/dump/sqlite-latest.sqlite.bz2",
{
headers: {
"User-Agent": "https://github.com/nmalaguti/eve-harvest",
},
},
(res) => {
res
.pipe(bz2())
.pipe(fs.createWriteStream(SQLITE_FILE))
.on("close", () => {
spinner.succeed()
resolve()
})
.on("error", (err) => {
spinner.fail()
reject(err)
})
},
)
})
}
async function main() {
if (!fs.existsSync(SQLITE_FILE)) {
await downloadLatestDatabase()
}
const db = new Database(SQLITE_FILE)
const getOresStmt = db.prepare(
`SELECT typeID AS id, groupID as groupId, typeName AS name, volume, portionSize AS refineAmount
FROM invTypes
WHERE groupID = ? AND marketGroupID IS NOT NULL`,
)
const compressesFromStmt = db
.prepare(
`SELECT typeID FROM dgmTypeAttributes WHERE attributeID = 1940 AND valueFloat = ?`,
)
.pluck()
const getCompressionStmt = db
.prepare(
`SELECT valueFloat
FROM dgmTypeAttributes
WHERE attributeID = 1941
AND typeID = ?`,
)
.pluck()
const oreGroupStmt = db
.prepare(
`SELECT groupName
FROM invGroups
WHERE groupID = ?`,
)
.pluck()
const oreBasicTypeStmt = db
.prepare(
`SELECT valueFloat
FROM dgmTypeAttributes
WHERE attributeID = 2711
AND typeID = ?`,
)
.pluck()
const oreTypeStmt = db
.prepare(
`SELECT valueFloat
FROM dgmTypeAttributes
WHERE attributeID = 2699
AND typeID = ?`,
)
.pluck()
const materialsStmt = db.prepare(
`SELECT m.typeID, materialTypeID, t.typeName, quantity
FROM invTypeMaterials m JOIN invTypes t ON m.materialTypeID = t.typeID
WHERE m.typeID = ?`,
)
const generateData = (groups, asteroidType, oreBonusMapper) => {
const ores = Array.from(groups.keys()).flatMap((id) => getOresStmt.all(id))
const oreNameLookup = new Map()
ores.forEach((ore) => oreNameLookup.set(ore.id, ore.name))
ores.forEach((ore) => {
ore.asteroidType = asteroidType
ore.groupName =
oreNameLookup.get(oreBasicTypeStmt.get(ore.id)) ||
oreGroupStmt.get(ore.groupId)
ore.color = COLORS.get(ore.groupName)
ore.bonus = oreBonusMapper(ore)
ore.minerals = materialsStmt.all(ore.id).reduce((obj, row) => {
obj[row.materialTypeID] = row.quantity
return obj
}, {})
ore.availableIn = AVAILABILITY.get(ore.groupName)
const compressesFrom = (ore.compressesFrom = compressesFromStmt.get(
ore.id,
))
ore.compressAmount =
(compressesFrom && getCompressionStmt.get(compressesFrom)) || 1
})
return ores
}
const ores = generateData(ORE_GROUPS, "ore", (ore) => {
let bonus
const oreType = oreTypeStmt.get(ore.id)
switch (oreType) {
case 1:
bonus = "0%"
break
case 2:
bonus = "5%"
break
case 3:
bonus = "10%"
break
case 4:
bonus = "15%"
break
}
// Hardcoding some fixes for Triglavian Ores
// TODO: remove this hack once the SDE is correct
if (ore.name.startsWith("Abyssal ") && bonus === "0%") {
bonus = "5%"
} else if (ore.name.startsWith("Hadal ") && bonus === "0%") {
bonus = "10%"
}
return bonus
}).filter((ore) => ore.bonus !== "15%") // exclude 15% ores since they no longer spawn
const moon = generateData(MOON_GROUPS, "moon", (ore) => {
let bonus
const oreType = oreTypeStmt.get(ore.id)
switch (oreType) {
case 1:
bonus = "0%"
break
case 3:
bonus = "15%"
break
case 5:
bonus = "100%"
break
}
return bonus
})
const ices = generateData(ICE_GROUPS, "ice", (ore) => {
let bonus
const oreType = oreTypeStmt.get(ore.id)
switch (oreType) {
case 1:
bonus = "0%"
break
case 4:
bonus = "Enriched"
break
}
return bonus
})
fs.writeFileSync(
ORE_FILE,
JSON.stringify([...ores, ...moon, ...ices], null, 2),
)
}
main().catch((err) => {
console.error(err)
process.exit(1)
})