-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
447 lines (389 loc) · 12.3 KB
/
util.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
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
var curl = require('curl')
var cheerio = require('cheerio')
var http = require('http')
exports.getCardRuneInfo = function(cardrune, callback) {
cardrune = cardrune.toLowerCase()
var url = 'http://bindingofisaacrebirth.gamepedia.com/Cards_and_Runes'
curl.get(url, null, (err, res, body) => {
const $ = cheerio.load(body)
/* Get all of the cards/runes/consumables on the page */
var cards_runes = $('tr', 'table').toArray()
var temp_cardrune = null
var index = i
/* NOTE: Indices 3-24 are tarot cards
Indices 26-34 are playing cards
Indices 36-46 are special cards
Indices 48-51 are left-pointing runes
Indices 53-57 are right-pointing runes
Index 59 is the Black Rune
Indices 61-62 are the consumables */
for (var i = 0; i < cards_runes.length; i++) {
temp_cardrune = $(cards_runes[i]).text().split('\n')
if (cardrune == temp_cardrune[1].toLowerCase().trim()) {
console.log('Found card/rune: ' + cardrune + ' @ ' + i)
index = i
break
}
}
if (temp_cardrune == null) {
callback('card/rune not found', null)
return
}
/* NOTE: [1] is the card/rune name
[3] is the ID
[7] is the message
[9] is the description/effect */
var description = temp_cardrune[9].trim()
/* Runes have slightly different table formats */
if (index >= 48 && index <= 59) {
description = temp_cardrune[11].trim()
}
var res = {
speech: description,
displayText: description,
source: 'bindingofisaacrebirth.gamepedia.com/'
}
callback(null, res)
})
}
exports.getDiceRoomInfo = function(num, callback) {
num = parseInt(num)
if (num < 1 || num > 6) {
callback('number invalid', null)
}
var url = 'http://bindingofisaacrebirth.gamepedia.com/Dice_Room'
curl.get(url, null, (err, res, body) => {
const $ = cheerio.load(body)
/* First, get the list of all of the dice rooms */
var dice_rooms = $('li', 'div .mw-content-ltr').toArray()
var text = $(dice_rooms[num+3]).text()
text = text.substring(text.indexOf('-') + 2)
/* Prepare the JSON for return */
var res = {
speech: text,
displayText: text,
source: 'bindingofisaacrebirth.gamepedia.com/',
}
callback(null, res)
return
})
}
exports.getItemInfo = function(item, callback) {
/* Convert the item to lower case and convert all ASCII-160's to ASCII-32's */
item = item.toLowerCase()
while (1) {
var new_item = item.replace(String.fromCharCode(160), ' ')
if (new_item == item) { break }
else { item = new_item }
}
/* Corner case: <3 */
if (item == 'less than 3') {
item = '<3'
console.log('Corner case: converting "less than 3" to "<3"')
}
/* Corner case: Odd Mushrooms */
if (item == 'odd mushroom large') { item = 'odd mushroom (large)'}
if (item == 'odd mushroom thin') { item = 'odd mushroom (thin)'}
var url = 'http://bindingofisaacrebirth.gamepedia.com/item'
curl.get(url, null, (err, res, body) => {
const $ = cheerio.load(body)
/* First, get the list of all of the items */
var actives = $('tr', 'table[data-description="Activated Collectibles"]').toArray()
var passives = $('tr', 'table[data-description="Passive Collectibles"]').toArray()
/* Second search through each list to find the specified item */
var index = -1
var isActive = false
var isPassive = false
/* Loop through the active items */
for (var i = 1; i < actives.length; i++) {
var temp_name = $(actives[i]).text().split('\n')[1].toLowerCase().trim()
if (item == temp_name) {
console.log('Found active item: ' + temp_name)
isActive = true
index = i
item = $(actives[index]).text().split('\n')
break
}
}
/* Loop through the passive items, if necessary */
if (!isActive) {
for (var i = 1; i < passives.length; i++) {
var temp_name = $(passives[i]).text().split('\n')[1].toLowerCase().trim()
if (item == temp_name) {
console.log('Found passive item: ' + temp_name)
isPassive = true
index = i
item = $(passives[index]).text().split('\n')
break
}
}
}
/* Return an error if the item is not found */
if (index == -1) {
callback('item (' + item + ') not found', null)
return
}
/* Prepare the JSON for return */
var res = {
speech: item[9].trim(),
displayText: item[9].trim(),
source: 'bindingofisaacrebirth.gamepedia.com/',
}
callback(null, res)
return
/* NOTE: after .text().split('\n') on a table item:
-- Name = [1]
-- ID = [3]
-- Icon = [5]
-- Quote = [7]
-- Description = [9]
-- Recharge = [11] (active items only) */
})
}
exports.getPandorasBoxInfo = function(floor, gamemode, callback) {
var message = ''
switch (gamemode) {
case 'normal':
case 'hard':
switch (floor) {
case 'basement i':
case 'cellar i':
case 'burning basement i':
case 'basement xl':
case 'cellar xl':
case 'burning basement xl':
case 'the basement':
message = 'Spawns 2 soul hearts.'
break
case 'basement ii':
case 'cellar ii':
case 'burning basement ii':
message = 'Spawns 2 keys and 2 bombs.'
break
case 'caves i':
case 'catacombs i':
case 'flooded caves i':
case 'caves xl':
case 'catacombs xl':
case 'flooded caves xl':
case 'the caves':
message = 'Spawns 1 Boss Room item.'
break
case 'caves ii':
case 'catacombs ii':
case 'flooded caves ii':
message = 'Spawns 1 Boss Room item and 2 soul hearts.'
break
case 'depths i':
case 'necropolis i':
case 'dank depths i':
case 'depths xl':
case 'necropolis xl':
case 'dank depths xl':
case 'the depths':
message = 'Spawns 4 soul hearts.'
break
case 'depths ii':
case 'necropolis ii':
case 'dank depths ii':
message = 'Spawns 20 coins.'
break
case 'womb i':
case 'utero i':
case 'scarred womb i':
case 'womb xl':
case 'utero xl':
case 'scarred womb xl':
case 'the womb':
message = 'Spawns 2 Boss Room items.'
break
case 'womb ii':
case 'utero ii':
case 'scarred womb':
message = 'Spawns The Bible.'
break
case 'sheol':
message = 'Spawns 1 Devil Room item and 1 black heart.'
break
case 'cathedral':
message = 'Spawns 1 Angel Room item and 1 eternal heart.'
break
case 'chest':
message = 'Spawns 1 coin.'
break
default:
message = 'Nothing.'
}
break
case 'greed':
case 'greedier':
switch (floor) {
case 'the basement':
message = 'Spawns 2 soul hearts.'
break
case 'the caves':
message = 'Spawns 2 keys and 2 bombs.'
break
case 'the depths':
message = 'Spawns 1 Boss Room item.'
break
case 'the womb':
message = 'Spawns 1 Boss Room item and 2 soul hearts.'
break
case 'sheol':
message = 'Spawns 4 soul hearts.'
break
case 'the shop':
message = 'Spawns 20 coins.'
break
case 'ultra greed':
message = 'Spawns 2 Boss Room items.'
break
default:
message = 'Nothing'
break
}
default:
message = 'Nothing.'
}
var response = {
speech: message,
displayTest: message,
source: 'bindingofisaacrebirth.gamepedia.com'
}
callback(null, response)
}
exports.getPillInfo = function(pill, callback) {
var url = 'http://bindingofisaacrebirth.gamepedia.com/Pills'
curl.get(url, null, (err, res, body) => {
const $ = cheerio.load(body)
/* First, get the list of all of the items */
var pills = $('tr', 'table').toArray()
var temp_pill = null
/* NOTE: Pills are indices 3-30, 32-42, 44-51 */
for (var i = 3; i < 52; i++) {
if (i == 31 || i == 43) { continue }
temp_pill = $(pills[i]).text().split('\n')
if (pill == temp_pill[1].toLowerCase().trim()) { break }
else { temp_pill = null }
}
if (!temp_pill) {
callback('pill not found', null)
return
}
/* Corner case: Amnesia */
if (pill == 'amnesia') {
temp_pill[2] = temp_pill[2].replace('?', 'question mark')
}
/* Prepare the JSON for return */
var res = {
speech: temp_pill[2],
displayText: temp_pill[2],
source: 'bindingofisaacrebirth.gamepedia.com/',
}
callback(null, res)
return
})
}
exports.getSacrificeRoomInfo = function(num, callback) {
num = parseInt(num)
if (num > 12) { num = 12 }
else if (num == 1) { num = 2 }
var message = ''
switch (num) {
case 2:
message = '50% chance of nothing. 50% chance to spawn 1 penny.'
break
case 3:
message = '33% chance of nothing. 67% chance to increase chance of receiving Angel Room over a Devil room for the current floor.'
break
case 4:
message = '50% chance of nothing. 50% chance to spawn 1 random chest.'
break
case 5:
message = '33% chance to spawn 3 coins. 67% chance to increase chance of receiving an Angel Room over a Devil room for the current floor.'
break
case 6:
message = '33% chance to teleport to the Devil or Angel Room. 67% chance to spawn 1 random chest.'
break
case 7:
message = 'If you have taken a Devil Deal, 100% chance to spawn a soul heart. If not, 33% chance to spawn one random Angel Room pedestal item and 67% chance to spawn a soul heart.'
break
case 8:
message = '100% chance to spawn 6 troll bombs.'
break
case 9:
message = '100% chance to spawn Uriel.'
break
case 10:
message = '50% chance to spawn 7 soul hearts. 50% chance to spawn 30 pennies.'
break
case 11:
message = '100% chance to spawn Gabriel.'
break
case 12:
message = '50% chance of nothing. 50% chance to teleport directly to the Dark Room.'
break
default:
message = 'Nothing.'
}
var response = {
speech: message,
displayText: message,
source: 'bindingofisaacrebirth.gamepedia.com/'
}
callback(null, response)
}
exports.getTrinketInfo = function(trinket, callback) {
/* Convert the trinket to lower case and convert all ASCII-160's to ASCII-32's */
trinket = trinket.toLowerCase()
while (1) {
var new_trinket = trinket.replace(String.fromCharCode(160), ' ')
if (new_trinket == trinket) { break }
else { trinket = new_trinket }
}
var url = 'http://bindingofisaacrebirth.gamepedia.com/trinket'
curl.get(url, null, (err, res, body) => {
const $ = cheerio.load(body)
/* First, get the list of all of the items */
var trinkets = $('tr', 'table[data-description="Trinkets"]').toArray()
/* Second search through the list to find the specified item */
var index = -1
/* Loop through the trinkets */
for (var i = 1; i < trinkets.length; i++) {
var temp_name = $(trinkets[i]).text().split('\n')[1].toLowerCase().trim()
if (trinket == temp_name) {
console.log('Found trinket: ' + temp_name)
index = i
trinket = $(trinkets[index]).text().split('\n')
break
}
}
console.log('Trinket index: ' + index)
console.log('Comparing: ' + (index == -1))
/* Return an error if the item is not found */
if (index == -1) {
console.log('No trinket found: sending error...')
callback('trinket (' + trinket + ') not found', null)
return
}
console.log('Preparing JSON to return...')
/* Prepare the JSON for return */
var res = {
speech: trinket[9].trim(),
displayText: trinket[9].trim(),
source: 'bindingofisaacrebirth.gamepedia.com/',
}
callback(null, res)
return
})
}
exports.sendError = function(err, res) {
console.error('Cannot process request', err)
res.status(400).json({
status: {
code: 400,
errorType: err.message
}
})
}