hypixel-api-reborn 11.2.0 → 11.2.1

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 (84) hide show
  1. package/README.md +1 -1
  2. package/eslint.config.mjs +71 -0
  3. package/package.json +11 -17
  4. package/src/API/getAchievements.js +1 -0
  5. package/src/API/getBoosters.js +1 -0
  6. package/src/API/getChallenges.js +1 -0
  7. package/src/API/getGameCounts.js +1 -0
  8. package/src/API/getGuild.js +4 -3
  9. package/src/API/getGuildAchievements.js +1 -0
  10. package/src/API/getLeaderboards.js +1 -1
  11. package/src/API/getPlayer.js +1 -0
  12. package/src/API/getQuests.js +1 -0
  13. package/src/API/getRecentGames.js +5 -9
  14. package/src/API/getServerInfo.js +40 -37
  15. package/src/API/getStatus.js +1 -0
  16. package/src/API/getWatchdogStats.js +1 -0
  17. package/src/API/skyblock/getAuction.js +8 -6
  18. package/src/API/skyblock/getAuctions.js +15 -12
  19. package/src/API/skyblock/getAuctionsByPlayer.js +1 -1
  20. package/src/API/skyblock/getBazaar.js +1 -3
  21. package/src/API/skyblock/getBingo.js +1 -2
  22. package/src/API/skyblock/getBingoByPlayer.js +3 -3
  23. package/src/API/skyblock/getEndedAuctions.js +1 -0
  24. package/src/API/skyblock/getFireSales.js +1 -1
  25. package/src/API/skyblock/getGovernment.js +1 -2
  26. package/src/API/skyblock/getMember.js +1 -0
  27. package/src/API/skyblock/getMuseum.js +1 -0
  28. package/src/API/skyblock/getNews.js +1 -0
  29. package/src/API/skyblock/getProfiles.js +1 -0
  30. package/src/Client.js +42 -14
  31. package/src/Private/rateLimit.js +7 -11
  32. package/src/Private/requests.js +11 -12
  33. package/src/Private/updater.js +2 -3
  34. package/src/Private/uuidCache.js +1 -2
  35. package/src/Private/validate.js +19 -19
  36. package/src/structures/APIIncident.js +1 -2
  37. package/src/structures/APIStatus.js +0 -1
  38. package/src/structures/Boosters/Booster.js +9 -8
  39. package/src/structures/Game.js +1 -1
  40. package/src/structures/Guild/Guild.js +19 -36
  41. package/src/structures/Guild/GuildMember.js +2 -2
  42. package/src/structures/MiniGames/Arcade.js +242 -240
  43. package/src/structures/MiniGames/ArenaBrawl.js +11 -11
  44. package/src/structures/MiniGames/BedWars.js +197 -194
  45. package/src/structures/MiniGames/BlitzSurvivalGames.js +24 -23
  46. package/src/structures/MiniGames/CopsAndCrims.js +1 -0
  47. package/src/structures/MiniGames/Duels.js +9 -11
  48. package/src/structures/MiniGames/Pit.js +4 -5
  49. package/src/structures/MiniGames/SkyWars.js +197 -186
  50. package/src/structures/MiniGames/SmashHeroes.js +36 -34
  51. package/src/structures/MiniGames/SpeedUHC.js +17 -4
  52. package/src/structures/MiniGames/UHC.js +26 -25
  53. package/src/structures/MiniGames/WoolWars.js +6 -5
  54. package/src/structures/Pet.js +1 -1
  55. package/src/structures/Player.js +13 -104
  56. package/src/structures/PlayerCosmetics.js +5 -4
  57. package/src/structures/SkyBlock/Auctions/AuctionInfo.js +2 -1
  58. package/src/structures/SkyBlock/Auctions/BaseAuction.js +1 -1
  59. package/src/structures/SkyBlock/News/SkyblockNews.js +15 -15
  60. package/src/structures/SkyBlock/PlayerBingo.js +7 -14
  61. package/src/structures/SkyBlock/SkyblockInventoryItem.js +4 -28
  62. package/src/structures/SkyBlock/SkyblockMember.js +78 -223
  63. package/src/structures/SkyBlock/SkyblockPet.js +3 -4
  64. package/src/structures/SkyBlock/Static/Bingo.js +10 -11
  65. package/src/structures/SkyBlock/Static/BingoData.js +1 -1
  66. package/src/structures/Static/Achievement.js +16 -15
  67. package/src/structures/Static/AchievementTier.js +2 -2
  68. package/src/structures/Static/Quest.js +2 -2
  69. package/src/utils/Constants.js +17 -517
  70. package/src/utils/{guildExp.js → Guild.js} +42 -12
  71. package/src/utils/Player.js +112 -0
  72. package/src/utils/SkyblockUtils.js +449 -192
  73. package/src/utils/arrayTools.js +1 -1
  74. package/src/utils/divide.js +1 -1
  75. package/src/utils/index.js +2 -1
  76. package/src/utils/isGuildID.js +1 -1
  77. package/src/utils/oscillation.js +4 -2
  78. package/src/utils/removeSnakeCase.js +11 -7
  79. package/src/utils/rgbToHexColor.js +1 -1
  80. package/src/utils/romanize.js +3 -3
  81. package/src/utils/toUuid.js +4 -4
  82. package/src/utils/varInt.js +2 -2
  83. package/typings/index.d.ts +272 -162
  84. package/src/utils/toIGN.js +0 -24
@@ -1,7 +1,9 @@
1
+ const { removeSnakeCaseString } = require('../../utils/removeSnakeCase');
1
2
  const { SkyWarsPrestigeIcons } = require('../../utils/Constants');
2
3
  const divide = require('../../utils/divide');
3
- const { removeSnakeCaseString } = require('../../utils/removeSnakeCase');
4
- const generateStatsForMode = (data, mode) => {
4
+
5
+ // eslint-disable-next-line jsdoc/require-jsdoc
6
+ function generateStatsForMode(data, mode) {
5
7
  return {
6
8
  kills: data[`kills_${mode}`] || 0,
7
9
  deaths: data[`deaths_${mode}`] || 0,
@@ -10,14 +12,204 @@ const generateStatsForMode = (data, mode) => {
10
12
  KDRatio: divide(data[`kills_${mode}`], data[`deaths_${mode}`]),
11
13
  WLRatio: divide(data[`wins_${mode}`], data[`losses_${mode}`])
12
14
  };
13
- };
15
+ }
16
+
17
+ // eslint-disable-next-line jsdoc/require-jsdoc
18
+ function getSkyWarsPrestige(level) {
19
+ if (60 <= level) return 'Mythic';
20
+ return (
21
+ ['Iron', 'Iron', 'Gold', 'Diamond', 'Emerald', 'Sapphire', 'Ruby', 'Crystal', 'Opal', 'Amethyst', 'Rainbow'][
22
+ Math.floor(level / 5)
23
+ ] || 'Iron'
24
+ );
25
+ }
26
+
27
+ // eslint-disable-next-line jsdoc/require-jsdoc
28
+ function getSkyWarsLevel(xp) {
29
+ const totalXp = [0, 2, 7, 15, 25, 50, 100, 200, 350, 600, 1000, 1500];
30
+ if (15000 <= xp) return Math.floor((xp - 15000) / 10000 + 12);
31
+ const level = totalXp.findIndex((x) => 0 < x * 10 - xp);
32
+ return level;
33
+ }
34
+
35
+ // eslint-disable-next-line jsdoc/require-jsdoc
36
+ function getSkyWarsLevelProgress(xp) {
37
+ const totalXp = [0, 2, 7, 15, 25, 50, 100, 200, 350, 600, 1000, 1500];
38
+ const xpToNextLvl = [0, 2, 5, 8, 10, 25, 50, 100, 150, 250, 400, 500];
39
+ let percent;
40
+ let xpToNextLevel;
41
+ let currentLevelXp = xp;
42
+ if (15000 <= xp) {
43
+ currentLevelXp -= 15000;
44
+ if (0 === currentLevelXp) return { currentLevelXp: 0, xpToNextLevel: 10000, percent: 0, xpNextLevel: 10000 };
45
+ if (10000 < currentLevelXp) {
46
+ do {
47
+ currentLevelXp -= 10000;
48
+ } while (10000 <= currentLevelXp);
49
+ }
50
+ xpToNextLevel = 10000 - currentLevelXp;
51
+ percent = Math.round(currentLevelXp) / 100;
52
+ const percentRemaining = Math.round((100 - percent) * 100) / 100;
53
+ return {
54
+ currentLevelXp,
55
+ xpToNextLevel,
56
+ percent,
57
+ xpNextLevel: 10000,
58
+ percentRemaining
59
+ };
60
+ }
61
+ const totalXptoNextLevel = xpToNextLvl[totalXp.findIndex((x) => 0 < x * 10 - xp)] * 10;
62
+ for (let i = 0; i < xpToNextLvl.length; i++) {
63
+ if (0 > currentLevelXp - xpToNextLvl[i] * 10) break;
64
+ currentLevelXp -= xpToNextLvl[i] * 10;
65
+ }
66
+ xpToNextLevel = totalXptoNextLevel - currentLevelXp;
67
+ percent = Math.round((currentLevelXp / totalXptoNextLevel) * 10000) / 100;
68
+ return {
69
+ currentLevelXp,
70
+ xpToNextLevel,
71
+ percent,
72
+ xpNextLevel: totalXptoNextLevel
73
+ };
74
+ }
75
+
76
+ /**
77
+ * Parses SkyWars Kit
78
+ */
79
+ class SkywarsKit {
80
+ /**
81
+ * Constructor
82
+ * @param {string} kit Kit
83
+ w */
84
+ constructor(kit) {
85
+ /**
86
+ * Kit data
87
+ * @private
88
+ * @type {string[] | null}
89
+ */
90
+ this.kitData = kit.match(/^kit_([a-z]+)_([a-z]+)_([a-z]+)$/);
91
+ /**
92
+ * Is this a kit
93
+ * @type {boolean}
94
+ */
95
+ this.isKit = Boolean(this.kitData);
96
+ if (!this.kitData) return;
97
+ /**
98
+ * Game mode the kit is for
99
+ * @type {KitGameModes}
100
+ */
101
+ this.gameMode = this.kitData[2];
102
+ /**
103
+ * Kit type
104
+ * @type {KitType}
105
+ */
106
+ this.kitType = this.kitData[1];
107
+ /**
108
+ * Kit name in camelCase
109
+ * @type {string}
110
+ */
111
+ this.kitName = removeSnakeCaseString(this.kitData[3]);
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Parses SkyWars Kits
117
+ */
118
+ class SkywarsKits {
119
+ /**
120
+ * Constructor
121
+ * @param {SkywarsKit[]} kits Potential Kits
122
+ w */
123
+ constructor(kits) {
124
+ this.kits = kits.map((kit) => new SkywarsKit(kit)).filter((kit) => kit.isKit);
125
+ }
126
+ /**
127
+ * Get kit by type/gameMode
128
+ * @param {KitGameModes} [gameMode] Kits in said game mode
129
+ * @param {KitType} [type] Kits corresponding to this type
130
+ * @returns {SkywarsKit[]}
131
+ w */
132
+ get(gameMode = '', type = '') {
133
+ return this.kits.filter((kit) => kit.gameMode.startsWith(gameMode) && kit.kitType.startsWith(type));
134
+ }
135
+ }
136
+ /**
137
+ * Skywars Packages - parses every package player has
138
+ */
139
+ class SkywarsPackages {
140
+ /**
141
+ * Constructor
142
+ * @param {string[]} data data from API
143
+ w */
144
+ constructor(data) {
145
+ // TODO : a lot more
146
+ /**
147
+ * Raw Packages, as received from the API
148
+ * @type {string[]}
149
+ */
150
+ this.rawPackages = Array.from(data);
151
+ /**
152
+ * Cages
153
+ * @type {string[]}
154
+ */
155
+ this.cages = this.parseCages();
156
+ /**
157
+ * Kits
158
+ * @type {SkywarsKits}
159
+ */
160
+ this.kits = new SkywarsKits(data);
161
+ /**
162
+ * Achievements included in packages, under the form of name0
163
+ * @type {string[]}
164
+ */
165
+ this.achievements = this.rawPackages
166
+ .map((pkg) => pkg.match(/^([A-Za-z]+)_?achievement([0-9]?)$/))
167
+ .filter((x) => x)
168
+ .map((x) => x.slice(1).join(''));
169
+ }
170
+ /**
171
+ * Parses cages
172
+ * @returns {string[]}
173
+ w */
174
+ parseCages() {
175
+ return this.rawPackages
176
+ .map((pkg) => pkg.match(/^cage_([A-Za-z]+)-cage$/))
177
+ .filter((x) => x)
178
+ .map((x) => x[1].replace(/-[a-z]/g, (x) => x[1].toUpperCase()));
179
+ }
180
+ }
181
+
182
+ /**
183
+ * @typedef {string} KitType
184
+ * * basic
185
+ * * supporting
186
+ * * mining
187
+ * * defending
188
+ * * attacking
189
+ * * advanced
190
+ * * enderchest
191
+ */
192
+ /**
193
+ * @typedef {string} KitGameModes
194
+ * * solo
195
+ * * team
196
+ */
197
+
198
+ /**
199
+ * @typedef {Object} SkyWarsShardsInMode
200
+ * @property {number} solo Solo shards
201
+ * @property {number} team Team shards
202
+ * @property {number} mega Mega shards
203
+ * @property {number} lab Lab shards
204
+ */
205
+
14
206
  /**
15
207
  * SkyWars class
16
208
  */
17
209
  class SkyWars {
18
210
  /**
19
211
  * @param {object} data SkyWars data
20
- */
212
+ w */
21
213
  constructor(data) {
22
214
  /**
23
215
  * Coins
@@ -316,8 +508,7 @@ class SkyWars {
316
508
  */
317
509
  /**
318
510
  * @typedef {string} PseudoDate String date, in the format of MM-YY ( YY is 20YY )
319
- * @example `10-19` would be October 2019.
320
- */
511
+ w */
321
512
  /**
322
513
  * @typedef {Object} SkyWarsModeExtendedStats
323
514
  * @property {SkyWarsTotalModeStats} overall Overall Stats
@@ -331,183 +522,3 @@ class SkyWars {
331
522
  * @property {SkyWarsModeStats} doubles Mega Doubles Stats
332
523
  */
333
524
  module.exports = SkyWars;
334
- // eslint-disable-next-line require-jsdoc
335
- function getSkyWarsPrestige(level) {
336
- if (level >= 60) return 'Mythic';
337
- return (
338
- ['Iron', 'Iron', 'Gold', 'Diamond', 'Emerald', 'Sapphire', 'Ruby', 'Crystal', 'Opal', 'Amethyst', 'Rainbow'][
339
- Math.floor(level / 5)
340
- ] || 'Iron'
341
- );
342
- }
343
- // eslint-disable-next-line require-jsdoc
344
- function getSkyWarsLevel(xp) {
345
- const totalXp = [0, 2, 7, 15, 25, 50, 100, 200, 350, 600, 1000, 1500];
346
- if (xp >= 15000) return Math.floor((xp - 15000) / 10000 + 12);
347
- const level = totalXp.findIndex((x) => x * 10 - xp > 0);
348
- return level; /* + (xp - (totalXp[level - 1] * 10 || 0)) / (totalXp[level] - totalXp[level - 1]) / 10*/
349
- }
350
- // eslint-disable-next-line require-jsdoc
351
- function getSkyWarsLevelProgress(xp) {
352
- const totalXp = [0, 2, 7, 15, 25, 50, 100, 200, 350, 600, 1000, 1500];
353
- const xpToNextLvl = [0, 2, 5, 8, 10, 25, 50, 100, 150, 250, 400, 500]; // * 10
354
- let percent;
355
- let xpToNextLevel;
356
- let currentLevelXp = xp;
357
- if (xp >= 15000) {
358
- currentLevelXp -= 15000;
359
- if (currentLevelXp === 0) return { currentLevelXp: 0, xpToNextLevel: 10000, percent: 0, xpNextLevel: 10000 };
360
- if (currentLevelXp > 10000) {
361
- do {
362
- currentLevelXp -= 10000;
363
- } while (currentLevelXp >= 10000);
364
- }
365
- xpToNextLevel = 10000 - currentLevelXp;
366
- percent = Math.round(currentLevelXp) / 100;
367
- const percentRemaining = Math.round((100 - percent) * 100) / 100;
368
- return {
369
- currentLevelXp,
370
- xpToNextLevel,
371
- percent,
372
- xpNextLevel: 10000,
373
- percentRemaining
374
- };
375
- }
376
- const totalXptoNextLevel = xpToNextLvl[totalXp.findIndex((x) => x * 10 - xp > 0)] * 10;
377
- for (let i = 0; i < xpToNextLvl.length; i++) {
378
- if (currentLevelXp - xpToNextLvl[i] * 10 < 0) break;
379
- currentLevelXp -= xpToNextLvl[i] * 10;
380
- }
381
- xpToNextLevel = totalXptoNextLevel - currentLevelXp;
382
- percent = Math.round((currentLevelXp / totalXptoNextLevel) * 10000) / 100;
383
- return {
384
- currentLevelXp,
385
- xpToNextLevel,
386
- percent,
387
- xpNextLevel: totalXptoNextLevel
388
- };
389
- }
390
- const ratingRegex = /^SkyWars_skywars_rating_(\d{1,2})_(\d{1,2})_(position|rating)$/;
391
-
392
- /**
393
- * Skywars Packages - parses every package player has
394
- */
395
- class SkywarsPackages {
396
- /**
397
- * Constructor
398
- * @param {string[]} data data from API
399
- */
400
- constructor(data) {
401
- // TODO : a lot more
402
- /**
403
- * Raw Packages, as received from the API
404
- * @type {string[]}
405
- */
406
- this.rawPackages = Array.from(data);
407
- /**
408
- * Cages
409
- * @type {string[]}
410
- */
411
- this.cages = this._parseCages();
412
- /**
413
- * Kits
414
- * @type {SkywarsKits}
415
- */
416
- this.kits = new SkywarsKits(data);
417
- /**
418
- * Achievements included in packages, under the form of name0
419
- * @type {string[]}
420
- */
421
- this.achievements = this.rawPackages
422
- .map((pkg) => pkg.match(/^([A-z]+)_?achievement([0-9]?)$/))
423
- .filter((x) => x)
424
- .map((x) => x.slice(1).join(''));
425
- }
426
- /**
427
- * Parses cages
428
- * @returns {string[]}
429
- */
430
- _parseCages() {
431
- return this.rawPackages
432
- .map((pkg) => pkg.match(/^cage_([A-z]+)-cage$/))
433
- .filter((x) => x)
434
- .map((x) => x[1].replace(/-[a-z]/g, (x) => x[1].toUpperCase()));
435
- }
436
- }
437
-
438
- /**
439
- * Parses SkyWars Kits
440
- */
441
- class SkywarsKit {
442
- /**
443
- * Constructor
444
- * @param {string} kit Kit
445
- */
446
- constructor(kit) {
447
- /**
448
- * Kit data
449
- * @private
450
- * @type {string[] | null}
451
- */
452
- this._kitData = kit.match(/^kit_([a-z]+)_([a-z]+)_([a-z]+)$/);
453
- /**
454
- * Is this a kit
455
- * @type {boolean}
456
- */
457
- this.isKit = !!this._kitData;
458
- if (!this._kitData) return;
459
- /**
460
- * Game mode the kit is for
461
- * @type {KitGameModes}
462
- */
463
- this.gameMode = this._kitData[2];
464
- /**
465
- * Kit type
466
- * @type {KitType}
467
- */
468
- this.kitType = this._kitData[1];
469
- /**
470
- * Kit name in camelCase
471
- * @type {string}
472
- */
473
- this.kitName = removeSnakeCaseString(this._kitData[3]);
474
- }
475
- }
476
-
477
- /**
478
- * Parses SkyWars Kits
479
- */
480
- class SkywarsKits {
481
- /**
482
- * Constructor
483
- * @param {SkywarsKit[]} kits Potential Kits
484
- */
485
- constructor(kits) {
486
- this.kits = kits.map((kit) => new SkywarsKit(kit)).filter((kit) => kit.isKit);
487
- }
488
- /**
489
- * Get kit by type/gameMode
490
- * @param {KitGameModes} [gameMode] Kits in said game mode
491
- * @param {KitType} [type] Kits corresponding to this type
492
- * @returns {SkywarsKit[]}
493
- */
494
- get(gameMode = '', type = '') {
495
- return this.kits.filter((kit) => kit.gameMode.startsWith(gameMode) && kit.kitType.startsWith(type));
496
- }
497
- }
498
-
499
- /**
500
- * @typedef {string} KitType
501
- * * basic
502
- * * supporting
503
- * * mining
504
- * * defending
505
- * * attacking
506
- * * advanced
507
- * * enderchest
508
- */
509
- /**
510
- * @typedef {string} KitGameModes
511
- * * solo
512
- * * team
513
- */
@@ -1,4 +1,40 @@
1
1
  const divide = require('../../utils/divide');
2
+
3
+ // eslint-disable-next-line jsdoc/require-jsdoc
4
+ function generateModeStats(data, mode) {
5
+ return {
6
+ kills: data[`kills_${mode}`] || 0,
7
+ deaths: data[`deaths_${mode}`] || 0,
8
+ KDRatio: divide(data[`kills_${mode}`], data[`deaths_${mode}`]),
9
+ wins: data[`wins_${mode}`] || 0,
10
+ losses: data[`losses_${mode}`] || 0,
11
+ WLRatio: divide(data[`wins_${mode}`], data[`losses_${mode}`])
12
+ };
13
+ }
14
+
15
+ // eslint-disable-next-line jsdoc/require-jsdoc
16
+ function generateHeroStats(data) {
17
+ const stats = [];
18
+ for (const hero in data.class_stats) {
19
+ if (Object.prototype.hasOwnProperty.call(data.class_stats, hero)) {
20
+ stats.push({
21
+ name: hero,
22
+ level: data[`lastLevel_${hero}`] || 0,
23
+ xp: data[`xp_${hero}`] || 0,
24
+ prestige: data[`pg_${hero}`] || 0,
25
+ playedGames: data.class_stats[hero].games || 0,
26
+ kills: data.class_stats[hero].kills || 0,
27
+ deaths: data.class_stats[hero].deaths || 0,
28
+ KDRatio: divide(data.class_stats[hero].kills, data.class_stats[hero].deaths),
29
+ wins: data.class_stats[hero].wins || 0,
30
+ losses: data.class_stats[hero].losses || 0,
31
+ WLRatio: divide(data.class_stats[hero].wins, data.class_stats[hero].losses)
32
+ });
33
+ }
34
+ }
35
+ return stats;
36
+ }
37
+
2
38
  /**
3
39
  * SmashHeroes class
4
40
  */
@@ -78,40 +114,6 @@ class SmashHeroes {
78
114
  this.heroStats = data.class_stats ? generateHeroStats(data) : null;
79
115
  }
80
116
  }
81
- // eslint-disable-next-line require-jsdoc
82
- function generateModeStats(data, mode) {
83
- return {
84
- kills: data[`kills_${mode}`] || 0,
85
- deaths: data[`deaths_${mode}`] || 0,
86
- KDRatio: divide(data[`kills_${mode}`], data[`deaths_${mode}`]),
87
- wins: data[`wins_${mode}`] || 0,
88
- losses: data[`losses_${mode}`] || 0,
89
- WLRatio: divide(data[`wins_${mode}`], data[`losses_${mode}`])
90
- };
91
- }
92
- // eslint-disable-next-line require-jsdoc
93
- function generateHeroStats(data) {
94
- // eslint-disable-next-line no-useless-return
95
- const stats = [];
96
- for (const hero in data.class_stats) {
97
- if (Object.prototype.hasOwnProperty.call(data.class_stats, hero)) {
98
- stats.push({
99
- name: hero,
100
- level: data[`lastLevel_${hero}`] || 0,
101
- xp: data[`xp_${hero}`] || 0,
102
- prestige: data[`pg_${hero}`] || 0,
103
- playedGames: data.class_stats[hero].games || 0,
104
- kills: data.class_stats[hero].kills || 0,
105
- deaths: data.class_stats[hero].deaths || 0,
106
- KDRatio: divide(data.class_stats[hero].kills, data.class_stats[hero].deaths),
107
- wins: data.class_stats[hero].wins || 0,
108
- losses: data.class_stats[hero].losses || 0,
109
- WLRatio: divide(data.class_stats[hero].wins, data.class_stats[hero].losses)
110
- });
111
- }
112
- }
113
- return stats;
114
- }
115
117
  /**
116
118
  * @typedef {object} SmashHeroesModes
117
119
  * @property {SmashHeroesModeStats} '1v1v1v1' 1v1v1v1
@@ -92,8 +92,8 @@ class SpeedUHC {
92
92
  wins: data.wins_solo || 0,
93
93
  losses: data.losses_solo || 0,
94
94
  playedGames: data.games_solo || 0,
95
- winstreak: data.win_streak_solo || 0,
96
- killstreak: data.killstreak_solo || 0,
95
+ winStreak: data.win_streak_solo || 0,
96
+ killStreak: data.killstreak_solo || 0,
97
97
  assists: data.assists_solo || 0
98
98
  };
99
99
  /**
@@ -106,10 +106,23 @@ class SpeedUHC {
106
106
  wins: data.wins_team || 0,
107
107
  losses: data.losses_team || 0,
108
108
  playedGames: data.games_team || 0,
109
- winstreak: data.win_streak_team || 0,
110
- killstreak: data.killstreak_team || 0,
109
+ winStreak: data.win_streak_team || 0,
110
+ killStreak: data.killstreak_team || 0,
111
111
  assists: data.assists_team || 0
112
112
  };
113
113
  }
114
114
  }
115
+
116
+ /**
117
+ * @typedef {object} SpeedUHCModeStats
118
+ * @property {number} kills Kills
119
+ * @property {number} deaths Deaths
120
+ * @property {number} wins Wins
121
+ * @property {number} losses Losses
122
+ * @property {number} playedGames Played games
123
+ * @property {number} winStreak Win streak
124
+ * @property {number} killStreak Kill streak
125
+ * @property {number} assists Assists
126
+ */
127
+
115
128
  module.exports = SpeedUHC;
@@ -1,5 +1,30 @@
1
- /* eslint-disable max-len */
2
1
  const divide = require('../../utils/divide');
2
+
3
+ // eslint-disable-next-line jsdoc/require-jsdoc
4
+ function getStarLevel(data) {
5
+ const kills =
6
+ (data.kills || 0) +
7
+ (data.kills_solo || 0) +
8
+ (data['kills_red vs blue'] || 0) +
9
+ (data['kills_no diamonds'] || 0) +
10
+ (data.kills_brawl || 0) +
11
+ (data['kills_solo brawl'] || 0) +
12
+ (data['kills_duo brawl'] || 0);
13
+ const wins =
14
+ (data.wins || 0) +
15
+ (data.wins_solo || 0) +
16
+ (data['wins_red vs blue'] || 0) +
17
+ (data['wins_no diamonds'] || 0) +
18
+ (data.wins_brawl || 0) +
19
+ (data['wins_solo brawl'] || 0) +
20
+ (data['wins_duo brawl'] || 0);
21
+ const sum = Number(kills) + wins * 10;
22
+ let starLevel = 1;
23
+ const sums = [0, 1, 6, 21, 46, 96, 171, 271, 521, 1021, 1321, 1621, 1921, 2221, 2521, Infinity];
24
+ starLevel += sums.map((x) => x * 10 - sum).findIndex((x) => 0 < x) - 1;
25
+ return starLevel;
26
+ }
27
+
3
28
  /**
4
29
  * UHC class
5
30
  */
@@ -148,30 +173,6 @@ class UHC {
148
173
  };
149
174
  }
150
175
  }
151
- // eslint-disable-next-line require-jsdoc
152
- function getStarLevel(data) {
153
- const kills =
154
- (data.kills || 0) +
155
- (data.kills_solo || 0) +
156
- (data['kills_red vs blue'] || 0) +
157
- (data['kills_no diamonds'] || 0) +
158
- (data.kills_brawl || 0) +
159
- (data['kills_solo brawl'] || 0) +
160
- (data['kills_duo brawl'] || 0);
161
- const wins =
162
- (data.wins || 0) +
163
- (data.wins_solo || 0) +
164
- (data['wins_red vs blue'] || 0) +
165
- (data['wins_no diamonds'] || 0) +
166
- (data.wins_brawl || 0) +
167
- (data['wins_solo brawl'] || 0) +
168
- (data['wins_duo brawl'] || 0);
169
- const sum = kills * 1 + wins * 10;
170
- let starLevel = 1;
171
- const sums = [0, 1, 6, 21, 46, 96, 171, 271, 521, 1021, 1321, 1621, 1921, 2221, 2521, Infinity];
172
- starLevel += sums.map((x) => x * 10 - sum).findIndex((x) => x > 0) - 1;
173
- return starLevel;
174
- }
175
176
  /**
176
177
  * @typedef {object} UHCModeStats
177
178
  * @property {number} kills Kills
@@ -48,7 +48,6 @@ class WoolWars {
48
48
  engineer: WoolWars.generateStatsFor(data.wool_wars?.stats, 'engineer'),
49
49
  archer: WoolWars.generateStatsFor(data.wool_wars?.stats, 'archer')
50
50
  };
51
- // Misc fields ig
52
51
  /**
53
52
  * Owned Cosmetics
54
53
  * @type {string[]}
@@ -66,24 +65,26 @@ class WoolWars {
66
65
  * @return {number}
67
66
  */
68
67
  static convertXPToLevel(exp) {
69
- const minimalExp = [0, 1e3, 3e3, 6e3, 1e4, 15e3]; // NB: progression is 1k, 2k, 3k, 4k, 5k
68
+ const minimalExp = [0, 1e3, 3e3, 6e3, 1e4, 15e3];
70
69
  const baseLevel = minimalExp.length;
71
70
  const baseExp = minimalExp[minimalExp.length - 1];
72
71
  const expToLevel100 = 49e4;
73
72
  if (exp < baseExp) return minimalExp.findIndex((x) => exp < x);
74
73
  const theoreticalLevel = (exp - baseExp) / 5e3 + baseLevel;
75
- if (theoreticalLevel > 100) return 100 + this.convertXPToLevel(exp - expToLevel100);
74
+ if (100 < theoreticalLevel) return 100 + this.convertXPToLevel(exp - expToLevel100);
76
75
  return theoreticalLevel;
77
76
  }
78
77
  /**
79
78
  * Generates stats per class/overall
80
- * @param {Record<string, unknwon>} data data
79
+ * @param {Record<string, any>} data data
81
80
  * @param {string} [_class=''] Class
82
81
  * @return {WoolWarsStats}
83
82
  */
84
83
  static generateStatsFor(data, _class) {
85
84
  // N.B i called it _class instead of class because reserved keyword
86
- const workingData = (_class ? data?.['classes']?.[_class] : data) || {};
85
+
86
+ // eslint-disable-next-line no-underscore-dangle
87
+ const workingData = (_class ? data?.classes?.[_class] : data) || {};
87
88
  return {
88
89
  roundWins: workingData.wins || 0,
89
90
  gamesPlayed: workingData.games_played || 0,
@@ -29,7 +29,7 @@ class Pet {
29
29
  * Stats of the pet, if any
30
30
  * @type {object}
31
31
  */
32
- if (!stats) return; // don't parse stats because there is none.
32
+ if (!stats) return;
33
33
  /**
34
34
  * Hunger value ( 100 is highest )
35
35
  * @type {?number}