hypixel-api-reborn 9.0.3 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/.prettierrc +13 -0
  2. package/README.md +28 -16
  3. package/package.json +60 -58
  4. package/src/API/getAPIStatus.js +8 -7
  5. package/src/API/getBoosters.js +6 -5
  6. package/src/API/getGameCounts.js +6 -5
  7. package/src/API/getGuild.js +18 -17
  8. package/src/API/getLeaderboards.js +13 -12
  9. package/src/API/getPlayer.js +22 -26
  10. package/src/API/getRecentGames.js +18 -17
  11. package/src/API/getServerInfo.js +66 -77
  12. package/src/API/getStatus.js +8 -7
  13. package/src/API/getWatchdogStats.js +6 -5
  14. package/src/API/index.js +19 -9
  15. package/src/API/skyblock/getEndedSkyblockAuctions.js +10 -9
  16. package/src/API/skyblock/getSkyblockAuctions.js +64 -64
  17. package/src/API/skyblock/getSkyblockAuctionsByPlayer.js +11 -10
  18. package/src/API/skyblock/getSkyblockBazaar.js +10 -9
  19. package/src/API/skyblock/getSkyblockMember.js +28 -24
  20. package/src/API/skyblock/getSkyblockNews.js +6 -5
  21. package/src/API/skyblock/getSkyblockProfiles.js +44 -40
  22. package/src/Client.js +406 -430
  23. package/src/Errors.js +44 -38
  24. package/src/Private/defaultCache.js +77 -0
  25. package/src/Private/rateLimit.js +79 -98
  26. package/src/Private/requests.js +65 -39
  27. package/src/Private/updater.js +45 -42
  28. package/src/Private/uuidCache.js +37 -33
  29. package/src/Private/validate.js +97 -97
  30. package/src/index.js +82 -83
  31. package/src/structures/APIIncident.js +78 -78
  32. package/src/structures/APIStatus.js +47 -47
  33. package/src/structures/Boosters/Booster.js +83 -87
  34. package/src/structures/Color.js +129 -129
  35. package/src/structures/Game.js +164 -160
  36. package/src/structures/GameCounts.js +151 -151
  37. package/src/structures/Guild/Guild.js +204 -218
  38. package/src/structures/Guild/GuildMember.js +66 -66
  39. package/src/structures/Guild/GuildRank.js +48 -48
  40. package/src/structures/ItemBytes.js +33 -36
  41. package/src/structures/Leaderboard.js +31 -31
  42. package/src/structures/MiniGames/Arcade.js +567 -569
  43. package/src/structures/MiniGames/ArenaBrawl.js +52 -56
  44. package/src/structures/MiniGames/BedWars.js +423 -329
  45. package/src/structures/MiniGames/BlitzSurvivalGames.js +172 -148
  46. package/src/structures/MiniGames/BuildBattle.js +53 -53
  47. package/src/structures/MiniGames/CopsAndCrims.js +90 -90
  48. package/src/structures/MiniGames/Duels.js +694 -460
  49. package/src/structures/MiniGames/MegaWalls.js +137 -137
  50. package/src/structures/MiniGames/MurderMystery.js +93 -93
  51. package/src/structures/MiniGames/Paintball.js +67 -67
  52. package/src/structures/MiniGames/Pit.js +19 -19
  53. package/src/structures/MiniGames/Quakecraft.js +101 -101
  54. package/src/structures/MiniGames/SkyWars.js +508 -559
  55. package/src/structures/MiniGames/SmashHeroes.js +144 -151
  56. package/src/structures/MiniGames/SpeedUHC.js +115 -57
  57. package/src/structures/MiniGames/TNTGames.js +116 -116
  58. package/src/structures/MiniGames/TurboKartRacers.js +201 -71
  59. package/src/structures/MiniGames/UHC.js +164 -143
  60. package/src/structures/MiniGames/VampireZ.js +60 -60
  61. package/src/structures/MiniGames/Walls.js +52 -52
  62. package/src/structures/MiniGames/Warlords.js +62 -62
  63. package/src/structures/MiniGames/WoolWars.js +123 -0
  64. package/src/structures/Pet.js +96 -97
  65. package/src/structures/Pets.js +64 -64
  66. package/src/structures/Player.js +433 -453
  67. package/src/structures/PlayerCosmetics.js +100 -95
  68. package/src/structures/RecentGame.js +57 -57
  69. package/src/structures/ServerInfo.js +78 -78
  70. package/src/structures/SkyBlock/Auctions/Auction.js +104 -104
  71. package/src/structures/SkyBlock/Auctions/AuctionInfo.js +54 -54
  72. package/src/structures/SkyBlock/Auctions/BaseAuction.js +45 -45
  73. package/src/structures/SkyBlock/Auctions/Bid.js +48 -48
  74. package/src/structures/SkyBlock/Auctions/PartialAuction.js +25 -25
  75. package/src/structures/SkyBlock/Bazzar/Order.js +38 -38
  76. package/src/structures/SkyBlock/Bazzar/Product.js +53 -53
  77. package/src/structures/SkyBlock/News/SkyblockNews.js +60 -68
  78. package/src/structures/SkyBlock/SkyblockInventoryItem.js +124 -102
  79. package/src/structures/SkyBlock/SkyblockMember.js +820 -675
  80. package/src/structures/SkyBlock/SkyblockPet.js +71 -71
  81. package/src/structures/SkyBlock/SkyblockProfile.js +60 -60
  82. package/src/structures/Status.js +41 -41
  83. package/src/structures/Watchdog/Stats.js +36 -36
  84. package/src/utils/Constants.js +2789 -795
  85. package/src/utils/SkyblockUtils.js +208 -164
  86. package/src/utils/arrayTools.js +4 -4
  87. package/src/utils/divide.js +5 -5
  88. package/src/utils/guildExp.js +57 -67
  89. package/src/utils/index.js +13 -9
  90. package/src/utils/isGuildID.js +3 -3
  91. package/src/utils/isUUID.js +5 -5
  92. package/src/utils/oscillation.js +15 -23
  93. package/src/utils/removeSnakeCase.js +22 -35
  94. package/src/utils/rgbToHexColor.js +8 -0
  95. package/src/utils/romanize.js +11 -0
  96. package/src/utils/toIGN.js +20 -20
  97. package/src/utils/toUuid.js +19 -19
  98. package/src/utils/varInt.js +17 -21
  99. package/typings/index.d.ts +3532 -2625
  100. package/src/API/getFriends.js +0 -13
  101. package/src/API/getKeyInfo.js +0 -9
  102. package/src/API/getRankedSkyWars.js +0 -10
  103. package/src/structures/Friend.js +0 -38
  104. package/src/structures/KeyInfo.js +0 -42
  105. package/src/structures/MiniGames/SkyWarsRanked.js +0 -45
@@ -1,569 +1,567 @@
1
- // IMPORTANT : a lot of the properties from the API seem to be nonsense
2
-
3
- const divide = require('../../utils/divide');
4
- const { weekAB, monthAB } = require('../../utils/oscillation');
5
- const { removeSnakeCaseString } = require('../../utils/removeSnakeCase');
6
-
7
- /**
8
- * Arcade class
9
- */
10
- class Arcade {
11
- /**
12
- * Constructor
13
- * @param {Object} data Data from the API
14
- */
15
- constructor (data = {}) {
16
- /**
17
- * Last Tournament Advertisement as timestamp, only appears when a tournament is announced
18
- * @type {number}
19
- */
20
- this.lastTourneyAdTimestamp = data.lastTourneyAd || undefined;
21
- /**
22
- * Last Tournament Advertisement as Date, only appears when a tournament is announced
23
- * @type {Date}
24
- */
25
- this.lastTourneyAdAt = this.lastTourneyAdTimestamp ? new Date(data.lastTourneyAd) : undefined;
26
- /**
27
- * Amount of coins
28
- * @type {number}
29
- */
30
- this.coins = data.coins || 0;
31
- /**
32
- * Weekly coins
33
- * @type {number}
34
- */
35
- this.weeklyCoins = parseInt(data[`weekly_coins_${weekAB()}`] || 0, 10);
36
- /**
37
- * Monthly coins
38
- * @type {number}
39
- */
40
- this.monthlyCoins = parseInt(data[`monthly_coins_${monthAB()}`] || 0, 10);
41
- /**
42
- * Hints Disabled
43
- * @type {Boolean}
44
- */
45
- this.hintsDisabled = !data.hints;
46
- /**
47
- * Flash Disabled
48
- * @type {Boolean}
49
- */
50
- this.flashDisabled = !data.flash;
51
- /**
52
- * Draw their thing stats
53
- * @type {BaseGame}
54
- */
55
- this.drawTheirThing = new BaseGame(data, 'draw_their_thing');
56
- /**
57
- * Dragon wars "2" stats
58
- * @type {BaseGame}
59
- */
60
- this.dragonWars = new BaseGame(data, 'dragonwars2');
61
- /**
62
- * Easter Simulator stats
63
- * @type {EasterSimulator}
64
- */
65
- this.easterSimulator = new BaseGame(data, 'easter_simulator').extend('eggsFound', data.eggs_found_easter_simulator || 0);
66
- /**
67
- * Grinch Simulator stats
68
- * @type {GrinchSimulator}
69
- */
70
- this.grinchSimulator = new BaseGame(data, 'grinch_simulator_v2').extend('giftsFound', data.gifts_grinch_simulator_v2 || 0);
71
- /**
72
- * Scuba Simulator stats
73
- * @type {ScubaSimulator}
74
- */
75
- this.scubaSimulator = new BaseGame(data, 'scuba_simulator').extend('itemsFound', data.items_found_scuba_simulator || 0);
76
- /**
77
- * Santa Simulator stats
78
- * @type {SantaSimulator}
79
- */
80
- this.santaSimulator = new BaseGame(data, 'santa_simulator').extend('giftsDelivered', data.delivered_santa_simulator || 0);
81
- /**
82
- * Santa Says stats
83
- * @type {BaseGame}
84
- */
85
- this.santaSays = new BaseGame(data, 'santa_says');
86
- /**
87
- * Simon Says stats
88
- * @type {BaseGame}
89
- */
90
- this.simonSays = new BaseGame(data, 'simon_says');
91
- /**
92
- * Farm Hunt stats
93
- * @type {BaseGame}
94
- */
95
- this.farmHunt = new BaseGame(data, 'farm_hunt');
96
- /**
97
- * Hole in the Wall stats
98
- * @type {HITW}
99
- */
100
- this.holeInTheWall = new HITW(data, 'hole_in_the_wall');
101
- /**
102
- * Mini Walls stats
103
- * @type {MiniWalls}
104
- */
105
- this.miniWalls = new MiniWalls(data); // needs extension
106
- /**
107
- * Party games (1) stats
108
- * @type {BaseGame}
109
- */
110
- this.partyGames = new BaseGame(data, 'party');
111
- /**
112
- * Party Games 2 stats ( legacy )
113
- * @type {BaseGame}
114
- * @deprecated
115
- */
116
- this.partyGames2 = new BaseGame(data, 'party_2');
117
- /**
118
- * Party Games 3 stats ( legacy )
119
- * @type {BaseGame}
120
- * @deprecated
121
- */
122
- this.partyGames3 = new BaseGame(data, 'party_3');
123
- /**
124
- * Throw out stats
125
- * @type {BaseGame}
126
- */
127
- this.throwOut = new BaseGame(data, 'throw_out');
128
- /**
129
- * Soccer stats
130
- * @type {Soccer}
131
- */
132
- this.soccer = new Soccer(data);
133
- /**
134
- * Hypixel Sports stats
135
- * @type {BaseGame}
136
- * @deprecated
137
- */
138
- this.hypixelSports = new BaseGame(data, 'hypixel_sports');
139
- /**
140
- * Ender Spleef stats
141
- * @type {BaseGame}
142
- */
143
- this.enderSpleef = new BaseGame(data, 'ender');
144
- /**
145
- * Blocking dead ( previously known as DayOne ) stats
146
- * @type {BlockingDead}
147
- */
148
- this.blockingDead = new BaseGame(data, 'dayone').extend('headshots', data.headshots_dayone || 0);
149
- /**
150
- * Galaxy Wars stats
151
- * @type {GalaxyWars}
152
- */
153
- this.galaxyWars = new GalaxyWars(data);
154
- // Lenient parsing
155
- /**
156
- * OITQ / One In The Quiver stats
157
- * @type {OITQ}
158
- */
159
- this.oitq = this.oneInTheQuiver = new BaseGame(data, 'oneinthequiver').extend('bountyKills', data.bounty_kills_oneinthequiver || 0);
160
- /**
161
- * Zombies
162
- * @type {Zombies}
163
- */
164
- this.zombies = new Zombies(data);
165
- /**
166
- * Capture The Wool
167
- * @type {{kills: number, captures: number}}
168
- */
169
- this.captureTheWool = { 'kills': data.arcade_ctw_slayer || 0, 'captures': data.arcade_ctw_oh_sheep || 0 };
170
- }
171
- }
172
- /**
173
- * Most basic game class, used by all arcade games
174
- */
175
- class BaseGame {
176
- /**
177
- * @param {Object} data data
178
- * @param {string} gameName Game Name ( snake )
179
- */
180
- constructor (data, gameName) {
181
- /**
182
- * Wins
183
- * @type {?number}
184
- */
185
- this.wins = parseInt(data['wins_' + gameName], 10) || 0;
186
- /**
187
- * Kills, only available in combat games
188
- * @type {?number}
189
- */
190
- this.kills = parseInt(data['kills_' + gameName], 10) || 0;
191
- /**
192
- * Deaths, only available in combat games
193
- * @type {?number}
194
- */
195
- this.deaths = parseInt(data['deaths_' + gameName], 10) || 0;
196
- /**
197
- * Rounds Played, only available in Santa says, Simon Says, and HITW
198
- * @type {?number}
199
- */
200
- this.roundsPlayed = parseInt(data['rounds_' + gameName], 10) || 0;
201
- }
202
- /**
203
- * Extend BaseGame without creating a new class
204
- * @param {string} name Property to add
205
- * @param {*} value Corresponding value
206
- * @private
207
- * @returns {BaseGame}
208
- */
209
- extend (name, value) {
210
- this[name] = value;
211
- return this;
212
- }
213
- }
214
-
215
- /**
216
- * Galxy Wars, aka sw class, totally different from normal stats
217
- */
218
- class GalaxyWars {
219
- /**
220
- * @param {Object} data Data from API
221
- */
222
- constructor (data) {
223
- /**
224
- * Wins
225
- * @type {number}
226
- */
227
- this.wins = data.sw_game_wins || 0;
228
- /**
229
- * Kills
230
- * @type {number}
231
- */
232
- this.kills = data.sw_kills || 0;
233
- /**
234
- * Deaths
235
- * @type {number}
236
- */
237
- this.deaths = data.sw_deaths || 0;
238
- /**
239
- * Total shots fired
240
- * @type {number}
241
- */
242
- this.shotsFired = data.sw_shots_fired || 0;
243
- /**
244
- * Total weekly kills
245
- * @type {number}
246
- */
247
- this.weeklyKills = parseInt(data[`weekly_kills_${weekAB()}`] || 0, 10);
248
- /**
249
- * Total Monthly kills
250
- * @type {number}
251
- */
252
- this.monthlyKills = parseInt(data[`monthly_kills_${monthAB()}`] || 0, 10);
253
- /**
254
- * Attacker Kills
255
- * @type {number}
256
- */
257
- this.attackerKills = data.sw_rebel_kills || 0;
258
- /**
259
- * Defender Kills
260
- * @type {number}
261
- */
262
- this.defenderKills = data.sw_empire_kills || 0;
263
- }
264
- }
265
- /**
266
- * Soccer class
267
- */
268
- class Soccer {
269
- /**
270
- * @param {Object} data Data from API
271
- */
272
- constructor (data) {
273
- /**
274
- * Wins
275
- * @type {number}
276
- */
277
- this.wins = data.wins_soccer || 0;
278
- /**
279
- * Number of Kicks
280
- * @type {number}
281
- */
282
- this.kicks = data.kicks_soccer || 0;
283
- /**
284
- * Number of Powerkicks
285
- * @type {number}
286
- */
287
- this.powerKicks = data.powerkicks_soccer || 0;
288
- /**
289
- * Goals
290
- * @type {number}
291
- */
292
- this.goals = data.goals_soccer || 0;
293
- }
294
- }
295
- /**
296
- * Hole in the Wall class
297
- */
298
- class HITW extends BaseGame {
299
- /**
300
- * @param {Object} data Data From API
301
- */
302
- constructor (data) {
303
- super(data, 'hole_in_the_wall');
304
- /**
305
- * Score Record in Finals
306
- * @type {number}
307
- */
308
- this.scoreRecordFinals = data.hitw_record_f || 0;
309
- /**
310
- * Score Record in Normal
311
- * @type {number}
312
- */
313
- this.scoreRecordNormal = data.hitw_record_q || 0;
314
- /**
315
- * Score Record overall
316
- * @type {number}
317
- */
318
- this.scoreRecordOverall = this.scoreRecordFinals + this.scoreRecordNormal;
319
- }
320
- }
321
- /**
322
- * Mini Walls class
323
- */
324
- class MiniWalls extends BaseGame {
325
- /**
326
- * Constructor
327
- * @param {Object} data data from API
328
- */
329
- constructor (data) {
330
- super(data, 'mini_walls');
331
- /**
332
- * Total Arrows Hit
333
- * @type {number}
334
- */
335
- this.arrowHits = data.arrow_hits_mini_walls || 0;
336
- /**
337
- * Total Arrow shot
338
- * @type {number}
339
- */
340
- this.arrowShots = data.arrow_shots_mini_walls || 0;
341
- /**
342
- * Bow Accuracy based on hits/shots
343
- * @type {number}
344
- */
345
- this.bowAccuracy = divide(this.arrowHits, this.arrowShots);
346
- /**
347
- * Final Kills
348
- * @type {number}
349
- */
350
- this.finalKills = data.final_kills_mini_walls || 0;
351
- /**
352
- * Total damage dealt to withers
353
- * @type {number}
354
- */
355
- this.witherDamage = data.wither_damage_mini_walls || 0;
356
- /**
357
- * Wither Killed
358
- * @type {number}
359
- */
360
- this.witherKills = data.wither_kills_mini_walls || 0;
361
- }
362
- }
363
- /**
364
- * Zombies - Overall stats
365
- */
366
- class Zombies {
367
- /**
368
- * Constructor
369
- * @param {Object} data Data from API
370
- */
371
- constructor (data) {
372
- /**
373
- * Overall Stats
374
- * @type {ZombiesStats}
375
- */
376
- this.overall = new ZombiesStats(data);
377
- /**
378
- * Stats for Dead End
379
- * @type {ZombieMap}
380
- */
381
- this.deadEnd = new ZombieMap(data, 'deadend');
382
- /**
383
- * Stats for Bad Blood
384
- * @type {ZombieMap}
385
- */
386
- this.badBlood = new ZombieMap(data, 'badblood');
387
- /**
388
- * Stats for Alien Arcadium
389
- * @type {ZombieMap}
390
- */
391
- this.alienArcadium = new ZombieMap(data, 'alienarcadium');
392
- /**
393
- * Kills By Zombie
394
- * @type {Record<string,number>}
395
- */
396
- this.killsByZombie = parseZombiesKills(data);
397
- /**
398
- * Bullets Hit
399
- * @type {number}
400
- */
401
- this.bulletsHit = data.bullets_hit_zombies || 0;
402
- /**
403
- * Bullets Shot
404
- * @type {number}
405
- */
406
- this.bulletsShot = data.bullets_shot_zombies || 0;
407
- /**
408
- * Gun Accuracy
409
- * @type {number}
410
- */
411
- this.gunAccuracy = divide(this.bulletsHit, this.bulletsShot);
412
- /**
413
- * Headshots
414
- * @type {number}
415
- */
416
- this.headshots = data.headshots_zombies || 0;
417
- /**
418
- * Headshot Accuracy
419
- * @type {number}
420
- */
421
- this.headshotAccuracy = divide(this.headshots, this.bulletsShot);
422
- }
423
- }
424
- /**
425
- * Zombie stats by map
426
- */
427
- class ZombieMap {
428
- /**
429
- * Constructor
430
- * @param {Object} data Data from API
431
- * @param {string} mapName String map name
432
- */
433
- constructor (data, mapName) {
434
- /**
435
- * Normal mode
436
- * @type {ZombiesStats}
437
- */
438
- this.normal = new ZombiesStats(data, `${mapName}_normal`);
439
- /**
440
- * Hard mode ( parties only )
441
- * @type {ZombiesStats}
442
- */
443
- this.hard = new ZombiesStats(data, `${mapName}_hard`);
444
- /**
445
- * RIP mode ( parties only )
446
- * @type {ZombiesStats}
447
- */
448
- this.rip = new ZombiesStats(data, `${mapName}_rip`);
449
- /**
450
- * Overall ( 3 modes combined )
451
- * @type {ZombiesStats}
452
- */
453
- this.overall = new ZombiesStats(data, mapName);
454
- }
455
- }
456
- /**
457
- * Zombies - Stats by Map + Difficulty
458
- */
459
- class ZombiesStats {
460
- /**
461
- * Constructor
462
- * @param {Object} data Data from API
463
- * @param {string} type Map name + difficulty ( default overall )
464
- */
465
- constructor (data, type = '') {
466
- if (type) type = `_${type}`;
467
- /**
468
- * Best Round
469
- * @type {number}
470
- */
471
- this.bestRound = data[`best_round_zombies${type}`] || 0;
472
- /**
473
- * Deaths ( NOT losses )
474
- * @type {number}
475
- */
476
- this.deaths = data[`deaths_zombies${type}`] || 0;
477
- /**
478
- * Doors opened
479
- * @type {number}
480
- */
481
- this.doorsOpened = data[`doors_opened_zombies${type}`] || 0;
482
- /**
483
- * Fastest time to reach round 10 in seconds
484
- * @type {number}
485
- */
486
- this.fastestRound10 = data[`fastest_time_10_zombies${type}`] || 0;
487
- /**
488
- * Fastest time to reach round 20 in seconds
489
- * @type {number}
490
- */
491
- this.fastestRound20 = data[`fastest_time_20_zombies${type}`] || 0;
492
- /**
493
- * Fastest time to reach round 30 in seconds
494
- * @type {number}
495
- */
496
- this.fastestRound30 = data[`fastest_time_30_zombies${type}`] || 0;
497
- /**
498
- * Players revived
499
- * @type {number}
500
- */
501
- this.playersRevived = data[`players_revived_zombies${type}`] || 0;
502
- /**
503
- * Number of times player is knocked down
504
- * @type {number}
505
- */
506
- this.timesKnockedDown = data[`times_knocked_down_zombies${type}`] || 0;
507
- /**
508
- * Total amount of rounds the player survived
509
- * @type {number}
510
- */
511
- this.roundsSurvived = data[`total_rounds_survived_zombies${type}`] || 0;
512
- /**
513
- * Total amount of windows fully repaired by player
514
- * @type {number}
515
- */
516
- this.windowsRepaired = data[`windows_repaired_zombies${type}`] || 0;
517
- /**
518
- * Wins
519
- * @type {number}
520
- */
521
- this.wins = data[`wins_zombies${type}`] || 0;
522
- /**
523
- * Total Zombie Kills
524
- * @type {number}
525
- */
526
- this.zombieKills = data[`zombie_kills_zombies${type}`] || 0;
527
- }
528
- }
529
- /**
530
- * Parses Kills in Zombie and return it as an object
531
- * @param {Object} data data from API
532
- * @returns {Object}
533
- */
534
- function parseZombiesKills (data) {
535
- const matches = Array.from(Object.keys(data)).map((x) => x.match(/^([A-z]+)_zombie_kills_zombies$/)).filter((x) => x);
536
- // From entries might be broken
537
- return Object.fromEntries(matches.map((x) => [removeSnakeCaseString(x[1]), data[x[0]] || 0]));
538
- }
539
- /**
540
- * @typedef {Object} EasterSimulator
541
- * @extends BaseGame
542
- * @property {number} eggsFound Total eggs found
543
- */
544
- /**
545
- * @typedef {Object} GrinchSimulator
546
- * @extends BaseGame
547
- * @property {number} giftsFound Total gifts found and stolen
548
- */
549
- /**
550
- * @typedef {Object} ScubaSimulator
551
- * @extends BaseGame
552
- * @property {number} itemsFound Total items found
553
- */
554
- /**
555
- * @typedef {Object} SantaSimulator
556
- * @extends BaseGame
557
- * @property {number} giftsDelivered Total gifts delivered
558
- */
559
- /**
560
- * @typedef {Object} OITQ
561
- * @extends BaseGame
562
- * @property {number} bountyKills Bounty Kills
563
- */
564
- /**
565
- * @typedef {JSON} BlockingDead
566
- * @extends BaseGame
567
- * @property {number} headshots Headshots
568
- */
569
- module.exports = Arcade;
1
+ // IMPORTANT : a lot of the properties from the API seem to be nonsense
2
+
3
+ const divide = require('../../utils/divide');
4
+ const { weekAB, monthAB } = require('../../utils/oscillation');
5
+ const { removeSnakeCaseString } = require('../../utils/removeSnakeCase');
6
+
7
+ /**
8
+ * Arcade class
9
+ */
10
+ class Arcade {
11
+ /**
12
+ * Constructor
13
+ * @param {Object} data Data from the API
14
+ */
15
+ constructor(data = {}) {
16
+ /**
17
+ * Last Tournament Advertisement as timestamp, only appears when a tournament is announced
18
+ * @type {number}
19
+ */
20
+ this.lastTourneyAdTimestamp = data.lastTourneyAd || undefined;
21
+ /**
22
+ * Last Tournament Advertisement as Date, only appears when a tournament is announced
23
+ * @type {Date}
24
+ */
25
+ this.lastTourneyAdAt = this.lastTourneyAdTimestamp ? new Date(data.lastTourneyAd) : undefined;
26
+ /**
27
+ * Amount of coins
28
+ * @type {number}
29
+ */
30
+ this.coins = data.coins || 0;
31
+ /**
32
+ * Weekly coins
33
+ * @type {number}
34
+ */
35
+ this.weeklyCoins = parseInt(data[`weekly_coins_${weekAB()}`] || 0, 10);
36
+ /**
37
+ * Monthly coins
38
+ * @type {number}
39
+ */
40
+ this.monthlyCoins = parseInt(data[`monthly_coins_${monthAB()}`] || 0, 10);
41
+ /**
42
+ * Hints Disabled
43
+ * @type {Boolean}
44
+ */
45
+ this.hintsDisabled = !data.hints;
46
+ /**
47
+ * Flash Disabled
48
+ * @type {Boolean}
49
+ */
50
+ this.flashDisabled = !data.flash;
51
+ /**
52
+ * Draw their thing stats
53
+ * @type {BaseGame}
54
+ */
55
+ this.drawTheirThing = new BaseGame(data, 'draw_their_thing');
56
+ /**
57
+ * Dragon wars "2" stats
58
+ * @type {BaseGame}
59
+ */
60
+ this.dragonWars = new BaseGame(data, 'dragonwars2');
61
+ /**
62
+ * Easter Simulator stats
63
+ * @type {EasterSimulator}
64
+ */
65
+ this.easterSimulator = new BaseGame(data, 'easter_simulator').extend('eggsFound', data.eggs_found_easter_simulator || 0);
66
+ /**
67
+ * Grinch Simulator stats
68
+ * @type {GrinchSimulator}
69
+ */
70
+ this.grinchSimulator = new BaseGame(data, 'grinch_simulator_v2').extend('giftsFound', data.gifts_grinch_simulator_v2 || 0);
71
+ /**
72
+ * Scuba Simulator stats
73
+ * @type {ScubaSimulator}
74
+ */
75
+ this.scubaSimulator = new BaseGame(data, 'scuba_simulator').extend('itemsFound', data.items_found_scuba_simulator || 0);
76
+ /**
77
+ * Santa Simulator stats
78
+ * @type {SantaSimulator}
79
+ */
80
+ this.santaSimulator = new BaseGame(data, 'santa_simulator').extend('giftsDelivered', data.delivered_santa_simulator || 0);
81
+ /**
82
+ * Santa Says stats
83
+ * @type {BaseGame}
84
+ */
85
+ this.santaSays = new BaseGame(data, 'santa_says');
86
+ /**
87
+ * Simon Says stats
88
+ * @type {BaseGame}
89
+ */
90
+ this.simonSays = new BaseGame(data, 'simon_says');
91
+ /**
92
+ * Farm Hunt stats
93
+ * @type {BaseGame}
94
+ */
95
+ this.farmHunt = new BaseGame(data, 'farm_hunt');
96
+ /**
97
+ * Hole in the Wall stats
98
+ * @type {HITW}
99
+ */
100
+ this.holeInTheWall = new HITW(data, 'hole_in_the_wall');
101
+ /**
102
+ * Mini Walls stats
103
+ * @type {MiniWalls}
104
+ */
105
+ this.miniWalls = new MiniWalls(data); // needs extension
106
+ /**
107
+ * Party games (1) stats
108
+ * @type {BaseGame}
109
+ */
110
+ this.partyGames = new BaseGame(data, 'party');
111
+ /**
112
+ * Party Games 2 stats ( legacy )
113
+ * @type {BaseGame}
114
+ * @deprecated
115
+ */
116
+ this.partyGames2 = new BaseGame(data, 'party_2');
117
+ /**
118
+ * Party Games 3 stats ( legacy )
119
+ * @type {BaseGame}
120
+ * @deprecated
121
+ */
122
+ this.partyGames3 = new BaseGame(data, 'party_3');
123
+ /**
124
+ * Throw out stats
125
+ * @type {BaseGame}
126
+ */
127
+ this.throwOut = new BaseGame(data, 'throw_out');
128
+ /**
129
+ * Soccer stats
130
+ * @type {Soccer}
131
+ */
132
+ this.soccer = new Soccer(data);
133
+ /**
134
+ * Hypixel Sports stats
135
+ * @type {BaseGame}
136
+ * @deprecated
137
+ */
138
+ this.hypixelSports = new BaseGame(data, 'hypixel_sports');
139
+ /**
140
+ * Ender Spleef stats
141
+ * @type {BaseGame}
142
+ */
143
+ this.enderSpleef = new BaseGame(data, 'ender');
144
+ /**
145
+ * Blocking dead ( previously known as DayOne ) stats
146
+ * @type {BlockingDead}
147
+ */
148
+ this.blockingDead = new BaseGame(data, 'dayone').extend('headshots', data.headshots_dayone || 0);
149
+ /**
150
+ * Galaxy Wars stats
151
+ * @type {GalaxyWars}
152
+ */
153
+ this.galaxyWars = new GalaxyWars(data);
154
+ // Lenient parsing
155
+ /**
156
+ * OITQ / One In The Quiver stats
157
+ * @type {OITQ}
158
+ */
159
+ this.oitq = this.oneInTheQuiver = new BaseGame(data, 'oneinthequiver').extend('bountyKills', data.bounty_kills_oneinthequiver || 0);
160
+ /**
161
+ * Zombies
162
+ * @type {Zombies}
163
+ */
164
+ this.zombies = new Zombies(data);
165
+ /**
166
+ * Capture The Wool
167
+ * @type {{kills: number, captures: number}}
168
+ */
169
+ this.captureTheWool = { kills: data.arcade_ctw_slayer || 0, captures: data.arcade_ctw_oh_sheep || 0 };
170
+ }
171
+ }
172
+ /**
173
+ * Most basic game class, used by all arcade games
174
+ */
175
+ class BaseGame {
176
+ /**
177
+ * @param {Object} data data
178
+ * @param {string} gameName Game Name ( snake )
179
+ */
180
+ constructor(data, gameName) {
181
+ /**
182
+ * Wins
183
+ * @type {?number}
184
+ */
185
+ this.wins = parseInt(data['wins_' + gameName], 10) || 0;
186
+ /**
187
+ * Kills, only available in combat games
188
+ * @type {?number}
189
+ */
190
+ this.kills = parseInt(data['kills_' + gameName], 10) || 0;
191
+ /**
192
+ * Deaths, only available in combat games
193
+ * @type {?number}
194
+ */
195
+ this.deaths = parseInt(data['deaths_' + gameName], 10) || 0;
196
+ /**
197
+ * Rounds Played, only available in Santa says, Simon Says, and HITW
198
+ * @type {?number}
199
+ */
200
+ this.roundsPlayed = parseInt(data['rounds_' + gameName], 10) || 0;
201
+ }
202
+ /**
203
+ * Extend BaseGame without creating a new class
204
+ * @param {string} name Property to add
205
+ * @param {*} value Corresponding value
206
+ * @private
207
+ * @returns {BaseGame}
208
+ */
209
+ extend(name, value) {
210
+ this[name] = value;
211
+ return this;
212
+ }
213
+ }
214
+
215
+ /**
216
+ * Galxy Wars, aka sw class, totally different from normal stats
217
+ */
218
+ class GalaxyWars {
219
+ /**
220
+ * @param {Object} data Data from API
221
+ */
222
+ constructor(data) {
223
+ /**
224
+ * Wins
225
+ * @type {number}
226
+ */
227
+ this.wins = data.sw_game_wins || 0;
228
+ /**
229
+ * Kills
230
+ * @type {number}
231
+ */
232
+ this.kills = data.sw_kills || 0;
233
+ /**
234
+ * Deaths
235
+ * @type {number}
236
+ */
237
+ this.deaths = data.sw_deaths || 0;
238
+ /**
239
+ * Total shots fired
240
+ * @type {number}
241
+ */
242
+ this.shotsFired = data.sw_shots_fired || 0;
243
+ /**
244
+ * Total weekly kills
245
+ * @type {number}
246
+ */
247
+ this.weeklyKills = parseInt(data[`weekly_kills_${weekAB()}`] || 0, 10);
248
+ /**
249
+ * Total Monthly kills
250
+ * @type {number}
251
+ */
252
+ this.monthlyKills = parseInt(data[`monthly_kills_${monthAB()}`] || 0, 10);
253
+ /**
254
+ * Attacker Kills
255
+ * @type {number}
256
+ */
257
+ this.attackerKills = data.sw_rebel_kills || 0;
258
+ /**
259
+ * Defender Kills
260
+ * @type {number}
261
+ */
262
+ this.defenderKills = data.sw_empire_kills || 0;
263
+ }
264
+ }
265
+ /**
266
+ * Soccer class
267
+ */
268
+ class Soccer {
269
+ /**
270
+ * @param {Object} data Data from API
271
+ */
272
+ constructor(data) {
273
+ /**
274
+ * Wins
275
+ * @type {number}
276
+ */
277
+ this.wins = data.wins_soccer || 0;
278
+ /**
279
+ * Number of Kicks
280
+ * @type {number}
281
+ */
282
+ this.kicks = data.kicks_soccer || 0;
283
+ /**
284
+ * Number of Powerkicks
285
+ * @type {number}
286
+ */
287
+ this.powerKicks = data.powerkicks_soccer || 0;
288
+ /**
289
+ * Goals
290
+ * @type {number}
291
+ */
292
+ this.goals = data.goals_soccer || 0;
293
+ }
294
+ }
295
+ /**
296
+ * Hole in the Wall class
297
+ */
298
+ class HITW extends BaseGame {
299
+ /**
300
+ * @param {Object} data Data From API
301
+ */
302
+ constructor(data) {
303
+ super(data, 'hole_in_the_wall');
304
+ /**
305
+ * Score Record in Finals
306
+ * @type {number}
307
+ */
308
+ this.scoreRecordFinals = data.hitw_record_f || 0;
309
+ /**
310
+ * Score Record in Normal
311
+ * @type {number}
312
+ */
313
+ this.scoreRecordNormal = data.hitw_record_q || 0;
314
+ /**
315
+ * Score Record overall
316
+ * @type {number}
317
+ */
318
+ this.scoreRecordOverall = this.scoreRecordFinals + this.scoreRecordNormal;
319
+ }
320
+ }
321
+ /**
322
+ * Mini Walls class
323
+ */
324
+ class MiniWalls extends BaseGame {
325
+ /**
326
+ * Constructor
327
+ * @param {Object} data data from API
328
+ */
329
+ constructor(data) {
330
+ super(data, 'mini_walls');
331
+ /**
332
+ * Total Arrow Hits
333
+ * @type {number}
334
+ */
335
+ this.arrowHits = data.arrows_hit_mini_walls || 0;
336
+ /**
337
+ * Total Arrow shots
338
+ * @type {number}
339
+ */
340
+ this.arrowShots = data.arrows_shot_mini_walls || 0;
341
+ /**
342
+ * Bow Accuracy based on hits/shots
343
+ * @type {number}
344
+ */
345
+ this.bowAccuracy = divide(this.arrowHits, this.arrowShots);
346
+ /**
347
+ * Final Kills
348
+ * @type {number}
349
+ */
350
+ this.finalKills = data.final_kills_mini_walls || 0;
351
+ /**
352
+ * Total damage dealt to withers
353
+ * @type {number}
354
+ */
355
+ this.witherDamage = data.wither_damage_mini_walls || 0;
356
+ /**
357
+ * Wither Killed
358
+ * @type {number}
359
+ */
360
+ this.witherKills = data.wither_kills_mini_walls || 0;
361
+ }
362
+ }
363
+ /**
364
+ * Zombies - Overall stats
365
+ */
366
+ class Zombies {
367
+ /**
368
+ * Constructor
369
+ * @param {Object} data Data from API
370
+ */
371
+ constructor(data) {
372
+ /**
373
+ * Overall Stats
374
+ * @type {ZombiesStats}
375
+ */
376
+ this.overall = new ZombiesStats(data);
377
+ /**
378
+ * Stats for Dead End
379
+ * @type {ZombieMap}
380
+ */
381
+ this.deadEnd = new ZombieMap(data, 'deadend');
382
+ /**
383
+ * Stats for Bad Blood
384
+ * @type {ZombieMap}
385
+ */
386
+ this.badBlood = new ZombieMap(data, 'badblood');
387
+ /**
388
+ * Stats for Alien Arcadium
389
+ * @type {ZombieMap}
390
+ */
391
+ this.alienArcadium = new ZombieMap(data, 'alienarcadium');
392
+ /**
393
+ * Kills By Zombie
394
+ * @type {Record<string,number>}
395
+ */
396
+ this.killsByZombie = parseZombiesKills(data);
397
+ /**
398
+ * Bullets Hit
399
+ * @type {number}
400
+ */
401
+ this.bulletsHit = data.bullets_hit_zombies || 0;
402
+ /**
403
+ * Bullets Shot
404
+ * @type {number}
405
+ */
406
+ this.bulletsShot = data.bullets_shot_zombies || 0;
407
+ /**
408
+ * Gun Accuracy
409
+ * @type {number}
410
+ */
411
+ this.gunAccuracy = divide(this.bulletsHit, this.bulletsShot);
412
+ /**
413
+ * Headshots
414
+ * @type {number}
415
+ */
416
+ this.headshots = data.headshots_zombies || 0;
417
+ /**
418
+ * Headshot Accuracy
419
+ * @type {number}
420
+ */
421
+ this.headshotAccuracy = divide(this.headshots, this.bulletsShot);
422
+ }
423
+ }
424
+ /**
425
+ * Zombie stats by map
426
+ */
427
+ class ZombieMap {
428
+ /**
429
+ * Constructor
430
+ * @param {Object} data Data from API
431
+ * @param {string} mapName String map name
432
+ */
433
+ constructor(data, mapName) {
434
+ /**
435
+ * Normal mode
436
+ * @type {ZombiesStats}
437
+ */
438
+ this.normal = new ZombiesStats(data, `${mapName}_normal`);
439
+ /**
440
+ * Hard mode ( parties only )
441
+ * @type {ZombiesStats}
442
+ */
443
+ this.hard = new ZombiesStats(data, `${mapName}_hard`);
444
+ /**
445
+ * RIP mode ( parties only )
446
+ * @type {ZombiesStats}
447
+ */
448
+ this.rip = new ZombiesStats(data, `${mapName}_rip`);
449
+ /**
450
+ * Overall ( 3 modes combined )
451
+ * @type {ZombiesStats}
452
+ */
453
+ this.overall = new ZombiesStats(data, mapName);
454
+ }
455
+ }
456
+ /**
457
+ * Zombies - Stats by Map + Difficulty
458
+ */
459
+ class ZombiesStats {
460
+ /**
461
+ * Constructor
462
+ * @param {Object} data Data from API
463
+ * @param {string} type Map name + difficulty ( default overall )
464
+ */
465
+ constructor(data, type = '') {
466
+ if (type) type = `_${type}`;
467
+ /**
468
+ * Best Round
469
+ * @type {number}
470
+ */
471
+ this.bestRound = data[`best_round_zombies${type}`] || 0;
472
+ /**
473
+ * Deaths ( NOT losses )
474
+ * @type {number}
475
+ */
476
+ this.deaths = data[`deaths_zombies${type}`] || 0;
477
+ /**
478
+ * Doors opened
479
+ * @type {number}
480
+ */
481
+ this.doorsOpened = data[`doors_opened_zombies${type}`] || 0;
482
+ /**
483
+ * Fastest time to reach round 10 in seconds
484
+ * @type {number}
485
+ */
486
+ this.fastestRound10 = data[`fastest_time_10_zombies${type}`] || 0;
487
+ /**
488
+ * Fastest time to reach round 20 in seconds
489
+ * @type {number}
490
+ */
491
+ this.fastestRound20 = data[`fastest_time_20_zombies${type}`] || 0;
492
+ /**
493
+ * Fastest time to reach round 30 in seconds
494
+ * @type {number}
495
+ */
496
+ this.fastestRound30 = data[`fastest_time_30_zombies${type}`] || 0;
497
+ /**
498
+ * Players revived
499
+ * @type {number}
500
+ */
501
+ this.playersRevived = data[`players_revived_zombies${type}`] || 0;
502
+ /**
503
+ * Number of times player is knocked down
504
+ * @type {number}
505
+ */
506
+ this.timesKnockedDown = data[`times_knocked_down_zombies${type}`] || 0;
507
+ /**
508
+ * Total amount of rounds the player survived
509
+ * @type {number}
510
+ */
511
+ this.roundsSurvived = data[`total_rounds_survived_zombies${type}`] || 0;
512
+ /**
513
+ * Total amount of windows fully repaired by player
514
+ * @type {number}
515
+ */
516
+ this.windowsRepaired = data[`windows_repaired_zombies${type}`] || 0;
517
+ /**
518
+ * Wins
519
+ * @type {number}
520
+ */
521
+ this.wins = data[`wins_zombies${type}`] || 0;
522
+ /**
523
+ * Total Zombie Kills
524
+ * @type {number}
525
+ */
526
+ this.zombieKills = data[`zombie_kills_zombies${type}`] || 0;
527
+ }
528
+ }
529
+ // eslint-disable-next-line require-jsdoc
530
+ function parseZombiesKills(data) {
531
+ const matches = Array.from(Object.keys(data))
532
+ .map((x) => x.match(/^([A-z]+)_zombie_kills_zombies$/))
533
+ .filter((x) => x);
534
+ // From entries might be broken
535
+ return Object.fromEntries(matches.map((x) => [removeSnakeCaseString(x[1]), data[x[0]] || 0]));
536
+ }
537
+ /**
538
+ * @typedef {Object} EasterSimulator
539
+ * @extends BaseGame
540
+ * @property {number} eggsFound Total eggs found
541
+ */
542
+ /**
543
+ * @typedef {Object} GrinchSimulator
544
+ * @extends BaseGame
545
+ * @property {number} giftsFound Total gifts found and stolen
546
+ */
547
+ /**
548
+ * @typedef {Object} ScubaSimulator
549
+ * @extends BaseGame
550
+ * @property {number} itemsFound Total items found
551
+ */
552
+ /**
553
+ * @typedef {Object} SantaSimulator
554
+ * @extends BaseGame
555
+ * @property {number} giftsDelivered Total gifts delivered
556
+ */
557
+ /**
558
+ * @typedef {Object} OITQ
559
+ * @extends BaseGame
560
+ * @property {number} bountyKills Bounty Kills
561
+ */
562
+ /**
563
+ * @typedef {JSON} BlockingDead
564
+ * @extends BaseGame
565
+ * @property {number} headshots Headshots
566
+ */
567
+ module.exports = Arcade;