forked from Rplus/PokemonGo-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter-pokemon-stats.js
86 lines (70 loc) · 1.92 KB
/
filter-pokemon-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
let fs = require('fs');
let contents = fs.readFileSync('GAME_MASTER.json', 'utf8');
let allData = JSON.parse(contents);
if (allData.result) {
allData = allData.itemTemplates;
}
let pmData = allData.filter(d => d.pokemonSettings);
console.log(`All pm data length: ${pmData.length}`);
let props = [
'pokemonId',
'stats',
'familyId',
'rarity',
];
if (process.argv[2] === 'filter=true') {
pmData = pmData.map(pm => {
let _pm = {
templateId: pm.templateId,
};
for (const prop in pm.pokemonSettings) {
if (props.includes(prop)) {
_pm[prop] = pm.pokemonSettings[prop];
}
}
let isotope = _pm.templateId.split(_pm.pokemonId)[1];
if (isotope) {
_pm.isotope = isotope.replace(/^\_/, '');
}
_pm.types = [
pm.pokemonSettings.type,
pm.pokemonSettings.type2
].filter(Boolean);
_pm.pokedex = +(pm.templateId.match(/V(\d{4})/)[1]);
return _pm;
});
}
let outputJSON = (json = {}, fileName = '', jsonSpace = 2) => {
let fileContent = JSON.stringify(json, null, jsonSpace);
fs.writeFileSync(fileName, fileContent);
console.log(`JSON saved as ${fileName}! ( ${fileContent.length / 1000} kb )`);
};
outputJSON(pmData, 'pm-data.json');
pmData = pmData.reduce((all, pm) => {
all[pm.pokedex] = all[pm.pokedex] || [];
all[pm.pokedex].push(pm);
return all;
}, {});
outputJSON(pmData, 'pm-data-by-dex.json');
fileContent = JSON.stringify(pmData, null, 2);
((d) => {
var arr = [];
for (let dex in d) {
let a = [...d[dex]];
if (d[dex].length !== 1) {
a = a.filter(pm => pm.isotope);
}
a.forEach(i => {
let ads = `${i.stats.baseAttack}-${i.stats.baseDefense}-${i.stats.baseStamina}`;
let o = {
dex: +dex,
ads: ads.split('-').map(Number),
};
if (i.isotope) {
o.isotope = i.isotope.toLowerCase();
}
arr.push(o);
});
}
outputJSON(arr, 'pm-data-with-ads.json', 2);
})(pmData);