-
Notifications
You must be signed in to change notification settings - Fork 3
/
get_bases.js
310 lines (278 loc) · 7.9 KB
/
get_bases.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
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
var request = require("request");
var rp = require('request-promise');
var jsonfile = require('jsonfile');
var fs = require('fs');
var sleep = require('sleep');
var waitUntil = require('wait-until');
const util = require('util');
/* wiki item properties:
* http://pathofexile.gamepedia.com/Special:Browse/Soul_Taker
* http://pathofexile.gamepedia.com/Special:Browse/Abberath%27s_Hooves
* */
//var regex_hiddenmods = /(<br>)?.*\(Hidden\)(<br>)/i;
var regex_hiddenmods = /.*\(Hidden\).*/i;
var regex_wikilinks = /\[\[([^\]\|]*)\]\]|\[\[[^\]\|]*\|([^\]\|]*)\]\]/;
/*
matches formats "[[mod]]" or "[[wikipage|mod]] and stores "mod" as capture group 1 or 2, respectively.
Since only one capture group is filled each time, using both together in a replacement like r'\1\2' turns
both match variants into "mod".
*/
var regex_wiki_page_disamb = /([^\(]+) \([^\)]+\)/;
var regex_wiki_page_disamb_replace = /\s?\(.*\)$/;
/*
matches items named "item name (disambiguation)" and stores "item name" as capture group 1.
this format is used in the wiki to distinguish style variants of items, giving each variant its own page.
since the style variants ingame all have the same name, we want to filter these out and
put in a manually prepared version that covers all styles in one overview.
*/
var regex_single_range = /\+?\(((-?[\d\.]+)-([\d\.]+))\)%?/;
var regex_single_range_replace = /\((-?[\d\.]+-[\d\.]+)\)/;
/*
matches variants of the wiki's "(num-num)" format including the possibly leading "+" and trailing "%", such as:
(10-20)
+(10-20)
(10-20)%
(0.6-1)%
(0.6-0.8)%
(-40-40)% format found in ventor's gamble's rarity and some "flask charge used" mods
+(-25-50)% ventor's gamble again, now with resistances
The "num-num" part inside the brakets is stored as capture group 1
It intentionally leaves the leading "-" of mods like "-(20-10) Physical Damage Taken from Attacks"
The initial matching of double range damage mods like "Adds (10-20) to (30-40) Type Damage" is done
with another expression.
*/
var regex_double_range = /\(?(\d+)(?:-(\d+)\))? to \(?(\d+)(?:-(\d+)\))?/;
var regex_double_range_replace = /\(?(\d+)(?:-(\d+)\))? to \(?(\d+)(?:-(\d+)\))?/;
/*
matches the relevant variants for double range damage mods
(10-20) to (30-40)
15 to (30-40)
(10-20) to 35
15 to 35
Four named capture groups are used: lowmin, lowmax, highmin and highmax (numbers 10, 20, 30 and 40 above)
lowmax and/or highmax is None if the part is only a number and not a number range (cases 2-4 above; numbers 15 and 35)
*/
getItemBases();
function getItemBases() {
var url = "https://pathofexile.gamepedia.com/index.php?title=Special:CargoExport" +
'&format=json' +
'&limit=4000' +
'&tables=items, flasks, amulets' +
'&fields=items.name, items.class, items.size_x, items.size_y, ' +
'items.required_strength, items.required_intelligence, items.required_dexterity, items.required_level, items.drop_level, items._pageName = item_name, ' +
'flasks._pageName = flask_name, amulets._pageName = amulet_name' +
'&where=(flasks._pageName <> "" or amulets._pageName <> "") and items.rarity="Normal"' +
'&join_on=items._pageName=flasks._pageName, items._pageName=amulets._pageName';
url = encodeURI(url);
//console.log(url)
var options = {
uri: url,
headers: {
'User-Agent': 'Request-Promise'
},
json: true
};
rp(options)
.then(function (result) {
var bases = {};
result.forEach(function(base) {
var tmp = get_item_stats(base);
bases[base.name] = tmp;
});
write_data_to_file('item_bases', bases);
})
.catch(function (err) {
console.log(err)
});
}
function write_data_to_file(file, data) {
var file_name = 'output/' + file + '.json';
try {
fs.unlinkSync(file_name);
} catch (err) {}
var out = {};
out[file] = data;
jsonfile.writeFile(file_name, out, function(err) {
if(err){
console.error(err)
}
else {
console.log('file ' + file_name + ' saved.');
}
})
}
function get_item_stats(list) {
var stats = {};
var tmp = {};
var value;
/* sub type/class */
value = list["class"];
if (typeof value !== "undefined" && value) {
if (value > 0 || value.length) {
stats["Item Class"] = value;
}
}
/* defense */
// evasion
value = list["evasion"];
if (typeof value !== "undefined" && value) {
if (value > 0 || value.length) {
stats["Evasion Rating"] = value;
}
}
// energy shield
value = list["energy shield"];
if (typeof value !== "undefined" && value) {
if (value > 0 || value.length) {
stats["Energy Shield"] = value;
}
}
// armour
value = list["armour"];
if (typeof value !== "undefined" && value) {
if (value > 0 || value.length) {
stats["Armour"] = value;
}
}
// block
value = list["block"];
if (typeof value !== "undefined" && value) {
if (value > 0 || value.length) {
stats["Block"] = value;
}
}
// class
value = list["item class"];
if (typeof value !== "undefined" && value) {
if (value > 0 || value.length) {
stats["Item Class"] = value.replace(/Thrusting\s?/, '');
}
}
/* requirements */
// dexterity
value = list["required dexterity"];
if (typeof value !== "undefined" && value) {
if (value > 0 || value.length) {
stats["Dexterity"] = value;
}
}
// intelligence
value = list["required intelligence"];
if (typeof value !== "undefined" && value) {
if (value > 0 || value.length) {
stats["Intelligence"] = value;
}
}
// strength
value = list["required strength"];
if (typeof value !== "undefined" && value) {
if (value > 0 || value.length) {
stats["Strength"] = value;
}
}
// level
value = list["required level"];
if (typeof value !== "undefined" && value) {
if (value > 0 || value.length) {
stats["Level"] = value;
}
}
/* offense */
// attack speed
value = list["attack speed"];
if (typeof value !== "undefined" && value) {
if (value > 0 || value.length) {
stats["Attack Speed"] = value;
}
}
// crit chance
value = list["critical strike chance"];
if (typeof value !== "undefined" && value) {
if (value > 0 || value.length) {
stats["Critical Strike Chance"] = value;
}
}
// min phys dmg
value = list["physical damage min"];
if (typeof value !== "undefined" && value) {
if (value > 0 || value.length) {
stats["Minimum Physical Damage"] = value;
}
}
// max phys dmg
value = list["physical damage max"];
if (typeof value !== "undefined" && value) {
if (value > 0 || value.length) {
stats["Maximum Physical Damage"] = value;
}
}
// weapon range
value = list["range"];
if (typeof value !== "undefined" && value) {
if (value > 0 || value.length) {
stats["Weapon Range"] = value;
}
}
/* others */
// drop level
value = list["drop level"];
if (typeof value !== "undefined" && value) {
if (value > 0 || value.length) {
stats["Drop Level"] = value;
}
}
// width
value = list["size x"];
if (typeof value !== "undefined" && value) {
if (value > 0 || value.length) {
stats["Width"] = value;
}
}
// height
value = list["size y"];
if (typeof value !== "undefined" && value) {
if (value > 0 || value.length) {
stats["Height"] = value;
}
}
return stats
}
function cleanModString(string) {
string = remove_hidden_mods(string);
return string;
}
function remove_wiki_formats(text) {
if (typeof text === "undefined") {
return
}
while (text.match(regex_wikilinks)) {
text = text.replace(regex_wikilinks, '$1$2');
}
text = text.replace('<em class="tc -corrupted">Corrupted</em>', '');
text = text.replace('<', '<').replace('>', '>');
return text;
}
function remove_hidden_mods(text) {
if (typeof text === "undefined") {
return
}
return text.replace(regex_hiddenmods, '');
}
function item_exists(name, items) {
var i = 0;
items.forEach(function(element, index) {
if (element.name == name) {
i = index;
}
});
return i
}
Array.prototype.clean = function(deleteValue) {
for (var i = 0; i < this.length; i++) {
if (this[i] == deleteValue) {
this.splice(i, 1);
i--;
}
}
return this;
};