nodecore-cd2025/docs/lootscrape/loot-analyze.js

45 lines
1.0 KiB
JavaScript
Raw Normal View History

2021-03-04 20:27:53 -05:00
'use strict';
const fs = require('fs');
const raw = JSON.parse(fs.readFileSync(0));
const coremods = JSON.parse(raw['*']);
delete raw['*'];
2021-03-04 20:27:53 -05:00
const stacks = {};
const items = {};
const base = 2;
Object.values(raw).forEach(v => {
const mod = v.match(/^([^:]+):*/);
if (!mod || !coremods[mod[1]]) return;
2021-03-04 20:27:53 -05:00
const m = v.match(/ (\d+)$/);
const qty = m && Number(m[1]) || 1;
v = v.replace(/ (\d+)$/, '');
stacks[v] = (stacks[v] || 0) + 1;
// Special case: collapse "boosted" infused tools into
// regular ones.
v = v.replace(/_boost$/, '');
2021-03-05 20:35:36 -05:00
// Special case: tote handles can't be packed
v = v.replace(/_full$/, '');
2021-03-04 20:27:53 -05:00
items[v] = (items[v] || 0) + qty;
});
const final = {};
Object.keys(items).forEach(k => final[k] = {
prob: stacks[k],
qty: Math.floor(items[k] / stacks[k])
});
console.log('return {');
Object.keys(items)
.sort((a, b) => stacks[b] - stacks[a])
.slice(0, 100)
.forEach(k => console.log(`\t{item = "${k}", prob = ${stacks[k]}, qty = ${
2021-03-04 20:27:53 -05:00
Math.round(items[k] / stacks[k])}},`));
console.log('}');