hypixel-api-reborn 11.1.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 (113) hide show
  1. package/.prettierrc +3 -3
  2. package/README.md +6 -4
  3. package/eslint.config.mjs +71 -0
  4. package/package.json +21 -25
  5. package/src/API/getAchievements.js +7 -0
  6. package/src/API/getBoosters.js +1 -0
  7. package/src/API/getChallenges.js +7 -0
  8. package/src/API/getGameCounts.js +1 -0
  9. package/src/API/getGuild.js +5 -4
  10. package/src/API/getGuildAchievements.js +7 -0
  11. package/src/API/getLeaderboards.js +4 -2
  12. package/src/API/getPlayer.js +2 -1
  13. package/src/API/getQuests.js +7 -0
  14. package/src/API/getRecentGames.js +6 -10
  15. package/src/API/getServerInfo.js +42 -37
  16. package/src/API/getStatus.js +2 -1
  17. package/src/API/getWatchdogStats.js +1 -0
  18. package/src/API/index.js +28 -17
  19. package/src/API/skyblock/getAuction.js +21 -0
  20. package/src/API/skyblock/{getSkyblockAuctions.js → getAuctions.js} +19 -12
  21. package/src/API/skyblock/{getSkyblockAuctionsByPlayer.js → getAuctionsByPlayer.js} +2 -2
  22. package/src/API/skyblock/{getSkyblockBazaar.js → getBazaar.js} +1 -3
  23. package/src/API/skyblock/getBingo.js +7 -0
  24. package/src/API/skyblock/getBingoByPlayer.js +14 -0
  25. package/src/API/skyblock/{getEndedSkyblockAuctions.js → getEndedAuctions.js} +1 -0
  26. package/src/API/skyblock/getFireSales.js +7 -0
  27. package/src/API/skyblock/getGovernment.js +7 -0
  28. package/src/API/skyblock/{getSkyblockMember.js → getMember.js} +10 -3
  29. package/src/API/skyblock/getMuseum.js +15 -0
  30. package/src/API/skyblock/{getSkyblockNews.js → getNews.js} +1 -0
  31. package/src/API/skyblock/{getSkyblockProfiles.js → getProfiles.js} +14 -7
  32. package/src/Client.js +127 -25
  33. package/src/Errors.js +38 -17
  34. package/src/Private/rateLimit.js +17 -13
  35. package/src/Private/requests.js +27 -16
  36. package/src/Private/updater.js +11 -8
  37. package/src/Private/uuidCache.js +23 -30
  38. package/src/Private/validate.js +33 -22
  39. package/src/index.js +9 -0
  40. package/src/structures/APIIncident.js +4 -11
  41. package/src/structures/APIStatus.js +0 -1
  42. package/src/structures/Boosters/Booster.js +14 -13
  43. package/src/structures/Color.js +93 -48
  44. package/src/structures/Game.js +4 -2
  45. package/src/structures/Guild/Guild.js +35 -48
  46. package/src/structures/Guild/GuildMember.js +8 -8
  47. package/src/structures/Guild/GuildRank.js +2 -2
  48. package/src/structures/MiniGames/Arcade.js +242 -235
  49. package/src/structures/MiniGames/ArenaBrawl.js +11 -11
  50. package/src/structures/MiniGames/BedWars.js +262 -131
  51. package/src/structures/MiniGames/BlitzSurvivalGames.js +24 -23
  52. package/src/structures/MiniGames/CopsAndCrims.js +1 -0
  53. package/src/structures/MiniGames/Duels.js +92 -33
  54. package/src/structures/MiniGames/MegaWalls.js +3 -1
  55. package/src/structures/MiniGames/MurderMystery.js +2 -2
  56. package/src/structures/MiniGames/Pit.js +230 -2
  57. package/src/structures/MiniGames/PitInventoryItem.js +43 -0
  58. package/src/structures/MiniGames/SkyWars.js +211 -195
  59. package/src/structures/MiniGames/SmashHeroes.js +37 -35
  60. package/src/structures/MiniGames/SpeedUHC.js +17 -4
  61. package/src/structures/MiniGames/TNTGames.js +1 -1
  62. package/src/structures/MiniGames/UHC.js +33 -14
  63. package/src/structures/MiniGames/WoolWars.js +6 -5
  64. package/src/structures/Pet.js +1 -1
  65. package/src/structures/Player.js +26 -121
  66. package/src/structures/PlayerCosmetics.js +67 -12
  67. package/src/structures/ServerInfo.js +1 -1
  68. package/src/structures/SkyBlock/Auctions/Auction.js +3 -1
  69. package/src/structures/SkyBlock/Auctions/AuctionInfo.js +3 -1
  70. package/src/structures/SkyBlock/Auctions/BaseAuction.js +2 -1
  71. package/src/structures/SkyBlock/Auctions/Bid.js +1 -0
  72. package/src/structures/SkyBlock/Auctions/PartialAuction.js +1 -0
  73. package/src/structures/SkyBlock/News/SkyblockNews.js +15 -15
  74. package/src/structures/SkyBlock/PlayerBingo.js +49 -0
  75. package/src/structures/SkyBlock/SkyblockInventoryItem.js +76 -32
  76. package/src/structures/SkyBlock/SkyblockMember.js +252 -289
  77. package/src/structures/SkyBlock/SkyblockMuseum.js +60 -0
  78. package/src/structures/SkyBlock/SkyblockMuseumItem.js +54 -0
  79. package/src/structures/SkyBlock/SkyblockPet.js +3 -3
  80. package/src/structures/SkyBlock/SkyblockProfile.js +37 -23
  81. package/src/structures/SkyBlock/Static/Bingo.js +101 -0
  82. package/src/structures/SkyBlock/Static/BingoData.js +45 -0
  83. package/src/structures/SkyBlock/Static/Candidate.js +40 -0
  84. package/src/structures/SkyBlock/Static/FireSale.js +55 -0
  85. package/src/structures/SkyBlock/Static/Government.js +74 -0
  86. package/src/structures/SkyBlock/Static/Perk.js +24 -0
  87. package/src/structures/Static/Achievement.js +87 -0
  88. package/src/structures/Static/AchievementTier.js +33 -0
  89. package/src/structures/Static/Achievements.js +30 -0
  90. package/src/structures/Static/Challenges.js +29 -0
  91. package/src/structures/Static/GameAchievements.js +36 -0
  92. package/src/structures/Static/GameChallenges.js +40 -0
  93. package/src/structures/Static/GameQuests.js +24 -0
  94. package/src/structures/Static/GuildAchievements.js +34 -0
  95. package/src/structures/Static/Quest.js +66 -0
  96. package/src/structures/Static/Quests.js +31 -0
  97. package/src/structures/Status.js +2 -2
  98. package/src/utils/Constants.js +384 -543
  99. package/src/utils/{guildExp.js → Guild.js} +46 -13
  100. package/src/utils/Player.js +112 -0
  101. package/src/utils/SkyblockUtils.js +448 -186
  102. package/src/utils/arrayTools.js +1 -1
  103. package/src/utils/divide.js +1 -1
  104. package/src/utils/index.js +2 -1
  105. package/src/utils/isGuildID.js +1 -1
  106. package/src/utils/oscillation.js +4 -2
  107. package/src/utils/removeSnakeCase.js +19 -8
  108. package/src/utils/rgbToHexColor.js +1 -1
  109. package/src/utils/romanize.js +35 -4
  110. package/src/utils/toUuid.js +12 -7
  111. package/src/utils/varInt.js +2 -2
  112. package/typings/index.d.ts +1246 -446
  113. package/src/utils/toIGN.js +0 -20
@@ -1,12 +1,10 @@
1
- /* eslint-disable max-len */
2
- const divide = require('../../utils/divide');
1
+ const { duelsDivisions } = require('../../utils/Constants');
3
2
  const romanize = require('../../utils/romanize');
4
- // eslint-disable-next-line camelcase
5
- const { duels_divisions } = require('../../utils/Constants');
3
+ const divide = require('../../utils/divide');
6
4
 
7
- // eslint-disable-next-line require-jsdoc
5
+ // eslint-disable-next-line jsdoc/require-jsdoc
8
6
  function getDivision(data, mode = null) {
9
- for (const div of duels_divisions.slice().reverse()) {
7
+ for (const div of duelsDivisions.slice().reverse()) {
10
8
  const prestige = data[`${mode ? mode : 'all_modes'}_${div.key}_title_prestige`];
11
9
  if (prestige) {
12
10
  return `${div.name} ${romanize(prestige)}`;
@@ -14,14 +12,15 @@ function getDivision(data, mode = null) {
14
12
  }
15
13
  return null;
16
14
  }
17
- // eslint-disable-next-line require-jsdoc
15
+
16
+ // eslint-disable-next-line jsdoc/require-jsdoc
18
17
  function getTotalKillsDeaths(data) {
19
18
  let totalDeaths = 0;
20
19
  let totalKills = 0;
21
20
  for (const [k, v] of Object.entries(data)) {
22
- if (k.includes('deaths') && k !== 'deaths') {
21
+ if (k.includes('deaths') && 'deaths' !== k) {
23
22
  totalDeaths += v;
24
- } else if (k.includes('kills') && k !== 'kills') {
23
+ } else if (k.includes('kills') && 'kills' !== k) {
25
24
  totalKills += v;
26
25
  }
27
26
  }
@@ -39,10 +38,10 @@ class Duels {
39
38
  */
40
39
  constructor(data) {
41
40
  /**
42
- * Coins
41
+ * Tokens
43
42
  * @type {number}
44
43
  */
45
- this.coins = data.coins || 0;
44
+ this.tokens = data.coins || 0;
46
45
  /**
47
46
  * All modes division
48
47
  * @type {string|null}
@@ -102,19 +101,51 @@ class Duels {
102
101
  division: getDivision(data, 'uhc'),
103
102
  winstreak: data.current_uhc_winstreak || 0,
104
103
  bestWinstreak: data.best_uhc_winstreak || 0,
105
- kills: (data.uhc_duel_kills || 0) + (data.uhc_doubles_kills || 0) + (data.uhc_four_kills || 0) + (data.uhc_meetup_kills || 0),
106
- deaths: (data.uhc_duel_deaths || 0) + (data.uhc_doubles_deaths || 0) + (data.uhc_four_deaths || 0) + (data.uhc_meetup_deaths || 0),
104
+ kills:
105
+ (data.uhc_duel_kills || 0) +
106
+ (data.uhc_doubles_kills || 0) +
107
+ (data.uhc_four_kills || 0) +
108
+ (data.uhc_meetup_kills || 0),
109
+ deaths:
110
+ (data.uhc_duel_deaths || 0) +
111
+ (data.uhc_doubles_deaths || 0) +
112
+ (data.uhc_four_deaths || 0) +
113
+ (data.uhc_meetup_deaths || 0),
107
114
  KDRatio: divide(
108
- (data.uhc_duel_kills || 0) + (data.uhc_doubles_kills || 0) + (data.uhc_four_kills || 0) + (data.uhc_meetup_kills || 0),
109
- (data.uhc_duel_deaths || 0) + (data.uhc_doubles_deaths || 0) + (data.uhc_four_deaths || 0) + (data.uhc_meetup_deaths || 0)
115
+ (data.uhc_duel_kills || 0) +
116
+ (data.uhc_doubles_kills || 0) +
117
+ (data.uhc_four_kills || 0) +
118
+ (data.uhc_meetup_kills || 0),
119
+ (data.uhc_duel_deaths || 0) +
120
+ (data.uhc_doubles_deaths || 0) +
121
+ (data.uhc_four_deaths || 0) +
122
+ (data.uhc_meetup_deaths || 0)
110
123
  ),
111
- wins: (data.uhc_duel_wins || 0) + (data.uhc_doubles_wins || 0) + (data.uhc_four_wins || 0) + (data.uhc_meetup_wins || 0),
112
- losses: (data.uhc_duel_losses || 0) + (data.uhc_doubles_losses || 0) + (data.uhc_four_losses || 0) + (data.uhc_meetup_losses || 0),
124
+ wins:
125
+ (data.uhc_duel_wins || 0) +
126
+ (data.uhc_doubles_wins || 0) +
127
+ (data.uhc_four_wins || 0) +
128
+ (data.uhc_meetup_wins || 0),
129
+ losses:
130
+ (data.uhc_duel_losses || 0) +
131
+ (data.uhc_doubles_losses || 0) +
132
+ (data.uhc_four_losses || 0) +
133
+ (data.uhc_meetup_losses || 0),
113
134
  WLRatio: divide(
114
- (data.uhc_duel_wins || 0) + (data.uhc_doubles_wins || 0) + (data.uhc_four_wins || 0) + (data.uhc_meetup_wins || 0),
115
- (data.uhc_duel_losses || 0) + (data.uhc_doubles_losses || 0) + (data.uhc_four_losses || 0) + (data.uhc_meetup_losses || 0)
135
+ (data.uhc_duel_wins || 0) +
136
+ (data.uhc_doubles_wins || 0) +
137
+ (data.uhc_four_wins || 0) +
138
+ (data.uhc_meetup_wins || 0),
139
+ (data.uhc_duel_losses || 0) +
140
+ (data.uhc_doubles_losses || 0) +
141
+ (data.uhc_four_losses || 0) +
142
+ (data.uhc_meetup_losses || 0)
116
143
  ),
117
- playedGames: (data.uhc_duel_rounds_played || 0) + (data.uhc_doubles_rounds_played || 0) + (data.uhc_four_rounds_played || 0) + (data.uhc_meetup_rounds_played || 0)
144
+ playedGames:
145
+ (data.uhc_duel_rounds_played || 0) +
146
+ (data.uhc_doubles_rounds_played || 0) +
147
+ (data.uhc_four_rounds_played || 0) +
148
+ (data.uhc_meetup_rounds_played || 0)
118
149
  },
119
150
  '1v1': {
120
151
  division: getDivision(data, 'uhc'),
@@ -242,10 +273,16 @@ class Duels {
242
273
  bestWinstreak: data.best_op_winstreak || 0,
243
274
  kills: (data.op_duel_kills || 0) + (data.op_doubles_kills || 0),
244
275
  deaths: (data.op_duel_deaths || 0) + (data.op_doubles_deaths || 0),
245
- KDRatio: divide((data.op_duel_kills || 0) + (data.op_doubles_kills || 0), (data.op_duel_deaths || 0) + (data.op_doubles_deaths || 0)),
276
+ KDRatio: divide(
277
+ (data.op_duel_kills || 0) + (data.op_doubles_kills || 0),
278
+ (data.op_duel_deaths || 0) + (data.op_doubles_deaths || 0)
279
+ ),
246
280
  wins: (data.op_duel_wins || 0) + (data.op_doubles_wins || 0),
247
281
  losses: (data.op_duel_losses || 0) + (data.op_doubles_losses || 0),
248
- WLRatio: divide((data.op_duel_wins || 0) + (data.op_doubles_wins || 0), (data.op_duel_losses || 0) + (data.op_doubles_losses || 0)),
282
+ WLRatio: divide(
283
+ (data.op_duel_wins || 0) + (data.op_doubles_wins || 0),
284
+ (data.op_duel_losses || 0) + (data.op_doubles_losses || 0)
285
+ ),
249
286
  playedGames: (data.op_duel_rounds_played || 0) + (data.op_doubles_rounds_played || 0)
250
287
  },
251
288
  '1v1': {
@@ -284,10 +321,16 @@ class Duels {
284
321
  bestWinstreak: data.best_skywars_winstreak || 0,
285
322
  kills: (data.sw_duel_kills || 0) + (data.sw_doubles_kills || 0),
286
323
  deaths: (data.sw_duel_deaths || 0) + (data.sw_doubles_deaths || 0),
287
- KDRatio: divide((data.sw_duel_kills || 0) + (data.sw_doubles_kills || 0), (data.sw_duel_deaths || 0) + (data.sw_doubles_deaths || 0)),
324
+ KDRatio: divide(
325
+ (data.sw_duel_kills || 0) + (data.sw_doubles_kills || 0),
326
+ (data.sw_duel_deaths || 0) + (data.sw_doubles_deaths || 0)
327
+ ),
288
328
  wins: (data.sw_duel_wins || 0) + (data.sw_doubles_wins || 0),
289
329
  losses: (data.sw_duel_losses || 0) + (data.sw_doubles_losses || 0),
290
- WLRatio: divide((data.sw_duel_wins || 0) + (data.sw_doubles_wins || 0), (data.sw_duel_losses || 0) + (data.sw_doubles_losses || 0)),
330
+ WLRatio: divide(
331
+ (data.sw_duel_wins || 0) + (data.sw_doubles_wins || 0),
332
+ (data.sw_duel_losses || 0) + (data.sw_doubles_losses || 0)
333
+ ),
291
334
  playedGames: (data.sw_duel_rounds_played || 0) + (data.sw_doubles_rounds_played || 0)
292
335
  },
293
336
  '1v1': {
@@ -443,7 +486,15 @@ class Duels {
443
486
  (data.bridge_3v3v3v3_rounds_played || 0) +
444
487
  (data.bridge_four_rounds_played || 0) +
445
488
  (data.bridge_threes_bridge_rounds_played || 0) +
446
- (data.capture_threes_rounds_played || 0)
489
+ (data.capture_threes_rounds_played || 0),
490
+ goals:
491
+ (data.bridge_duel_goals || 0) +
492
+ (data.bridge_doubles_goals || 0) +
493
+ (data.bridge_2v2v2v2_goals || 0) +
494
+ (data.bridge_3v3v3v3_goals || 0) +
495
+ (data.bridge_four_goals || 0) +
496
+ (data.bridge_threes_bridge_goals || 0) +
497
+ (data.capture_threes_goals || 0)
447
498
  },
448
499
  '1v1': {
449
500
  division: getDivision(data, 'bridge'),
@@ -455,7 +506,8 @@ class Duels {
455
506
  wins: data.bridge_duel_wins || 0,
456
507
  losses: data.bridge_duel_losses || 0,
457
508
  WLRatio: divide(data.bridge_duel_wins, data.bridge_duel_losses),
458
- playedGames: data.bridge_duel_rounds_played || 0
509
+ playedGames: data.bridge_duel_rounds_played || 0,
510
+ goals: data.bridge_duel_goals || 0
459
511
  },
460
512
  '2v2': {
461
513
  division: getDivision(data, 'bridge'),
@@ -467,7 +519,8 @@ class Duels {
467
519
  wins: data.bridge_doubles_wins || 0,
468
520
  losses: data.bridge_doubles_losses || 0,
469
521
  WLRatio: divide(data.bridge_doubles_wins, data.bridge_doubles_losses),
470
- playedGames: data.bridge_doubles_rounds_played || 0
522
+ playedGames: data.bridge_doubles_rounds_played || 0,
523
+ goals: data.bridge_doubles_goals || 0
471
524
  },
472
525
  '3v3': {
473
526
  division: getDivision(data, 'bridge'),
@@ -479,7 +532,8 @@ class Duels {
479
532
  wins: data.bridge_threes_wins || 0,
480
533
  losses: data.bridge_threes_losses || 0,
481
534
  WLRatio: divide(data.bridge_threes_wins, data.bridge_threes_losses),
482
- playedGames: data.bridge_threes_rounds_played || 0
535
+ playedGames: data.bridge_threes_rounds_played || 0,
536
+ goals: data.bridge_threes_goals || 0
483
537
  },
484
538
  '2v2v2v2': {
485
539
  division: getDivision(data, 'bridge'),
@@ -491,7 +545,8 @@ class Duels {
491
545
  wins: data.bridge_2v2v2v2_wins || 0,
492
546
  losses: data.bridge_2v2v2v2_losses || 0,
493
547
  WLRatio: divide(data.bridge_2v2v2v2_wins, data.bridge_2v2v2v2_losses),
494
- playedGames: data.bridge_2v2v2v2_rounds_played || 0
548
+ playedGames: data.bridge_2v2v2v2_rounds_played || 0,
549
+ goals: data.bridge_2v2v2v2_goals || 0
495
550
  },
496
551
  '3v3v3v3': {
497
552
  division: getDivision(data, 'bridge'),
@@ -503,7 +558,8 @@ class Duels {
503
558
  wins: data.bridge_3v3v3v3_wins || 0,
504
559
  losses: data.bridge_3v3v3v3_losses || 0,
505
560
  WLRatio: divide(data.bridge_3v3v3v3_wins, data.bridge_3v3v3v3_losses),
506
- playedGames: data.bridge_3v3v3v3_rounds_played || 0
561
+ playedGames: data.bridge_3v3v3v3_rounds_played || 0,
562
+ goals: data.bridge_3v3v3v3_goals || 0
507
563
  },
508
564
  '4v4': {
509
565
  division: getDivision(data, 'bridge'),
@@ -515,9 +571,10 @@ class Duels {
515
571
  wins: data.bridge_four_wins || 0,
516
572
  losses: data.bridge_four_losses || 0,
517
573
  WLRatio: divide(data.bridge_four_wins, data.bridge_four_losses),
518
- playedGames: data.bridge_four_rounds_played || 0
574
+ playedGames: data.bridge_four_rounds_played || 0,
575
+ goals: data.bridge_four_goals || 0
519
576
  },
520
- // eslint-disable-next-line quote-props
577
+
521
578
  ctf: {
522
579
  division: getDivision(data, 'bridge'),
523
580
  kills: data.capture_threes_bridge_kills || 0,
@@ -527,7 +584,8 @@ class Duels {
527
584
  losses: data.capture_threes_losses || 0,
528
585
  WLRatio: divide(data.capture_threes_wins, data.capture_threes_losses),
529
586
  captures: data.capture_threes_captures || 0,
530
- playedGames: data.capture_threes_rounds_played || 0
587
+ playedGames: data.capture_threes_rounds_played || 0,
588
+ goals: data.capture_threes_goals || 0
531
589
  }
532
590
  };
533
591
  /**
@@ -605,6 +663,7 @@ class Duels {
605
663
  * @property {number} KDRatio Kill/Death ratio
606
664
  * @property {number} WLRatio Win/Loss ratio
607
665
  * @property {number} playedGames Played games
666
+ * @property {number} goals Goals
608
667
  */
609
668
  /**
610
669
  * @typedef {object} DuelsBowspleef
@@ -66,7 +66,9 @@ class MegaWalls {
66
66
  * Final deaths
67
67
  * @type {number}
68
68
  */
69
- this.finalDeaths = isNaN((data.final_deaths || 0) + (data.finalDeaths || 0)) ? 0 : Math.floor((data.final_deaths || 0) + (data.finalDeaths || 0));
69
+ this.finalDeaths = isNaN((data.final_deaths || 0) + (data.finalDeaths || 0))
70
+ ? 0
71
+ : Math.floor((data.final_deaths || 0) + (data.finalDeaths || 0));
70
72
  /**
71
73
  * Final Kill Death ratio
72
74
  * @type {number}
@@ -8,10 +8,10 @@ class MurderMystery {
8
8
  */
9
9
  constructor(data) {
10
10
  /**
11
- * Coins
11
+ * Tokens
12
12
  * @type {number}
13
13
  */
14
- this.coins = data.coins || 0;
14
+ this.tokens = data.coins || 0;
15
15
  /**
16
16
  * Played games
17
17
  * @type {number}
@@ -1,4 +1,10 @@
1
- /* eslint-disable max-len */
1
+ const { decode } = require('../../utils/SkyblockUtils');
2
+ const PitInventoryItem = require('./PitInventoryItem');
3
+ const { divide } = require('../../utils');
4
+ const {
5
+ pit: { Levels, Prestiges }
6
+ } = require('../../utils/Constants');
7
+
2
8
  /**
3
9
  * Pit Class
4
10
  */
@@ -8,12 +14,234 @@ class Pit {
8
14
  * @param {Record<string,unknown>} data Data from API
9
15
  */
10
16
  constructor(data) {
17
+ const stats = data.pit_stats_ptl || {};
18
+ /**
19
+ * Prestige
20
+ * @type {number}
21
+ */
22
+ this.prestige = data.profile?.prestiges?.[data.profile?.prestiges?.length - 1].index || 0;
23
+ /**
24
+ * Xp
25
+ * @type {number}
26
+ */
27
+ this.xp = data.profile?.xp || 0;
28
+ /**
29
+ * Level
30
+ * @type {number}
31
+ */
32
+ this.level =
33
+ Pit.calcLevel(this.prestige, 0 < this.prestige ? this.xp - Prestiges[this.prestige - 1].SumXp : this.xp).level ??
34
+ 0;
11
35
  /**
12
36
  * Kills
13
37
  * @type {number}
14
38
  */
15
- this.kills = data.pit_stats_ptl.kills || 0;
39
+ this.kills = stats.kills || 0;
40
+ /**
41
+ * Deaths
42
+ * @type {number}
43
+ */
44
+ this.deaths = stats.deaths || 0;
45
+ /**
46
+ * KDR
47
+ * @type {number}
48
+ */
49
+ this.KDRatio = divide(this.kills, this.deaths);
50
+ /**
51
+ * Assists
52
+ * @type {number}
53
+ */
54
+ this.assists = stats.assists || 0;
55
+ /**
56
+ * Max kill streak
57
+ * @type {number}
58
+ */
59
+ this.maxKillStreak = stats.max_streak || 0;
60
+ /**
61
+ * Playtime in SECONDS
62
+ * @type {number}
63
+ */
64
+ this.playtime = (stats.playtime_minutes || 0) * 60;
65
+ /**
66
+ * Times the played joined Pit
67
+ * @type {number}
68
+ */
69
+ this.joins = stats.joins || 0;
70
+
71
+ // Damage section (overall)
72
+ /**
73
+ * Damage received overall
74
+ * @type {number}
75
+ */
76
+ this.damageReceived = stats.damage_received || 0;
77
+ /**
78
+ * Damage dealt overall
79
+ * @type {number}
80
+ */
81
+ this.damageDealt = stats.damage_dealt || 0;
82
+ /**
83
+ * Damage dealt to damage received ratio
84
+ * @type {number}
85
+ */
86
+ this.damageRatio = divide(this.damageDealt, this.damageReceived);
87
+ // Melee damage
88
+ /**
89
+ * Damage received in melee
90
+ * @type {number}
91
+ */
92
+ this.meleeDamageReceived = stats.melee_damage_received || 0;
93
+ /**
94
+ * Damage dealt in melee
95
+ * @type {number}
96
+ */
97
+ this.meleeDamageDealt = stats.melee_damage_dealt || 0;
98
+ /**
99
+ * Sword hits
100
+ * @type {number}
101
+ */
102
+ this.swordHits = stats.sword_hits || 0;
103
+ /**
104
+ * Left Clicks (sword clicks, hit or miss)
105
+ * @type {number}
106
+ */
107
+ this.leftClicks = stats.left_clicks || 0;
108
+ /**
109
+ * Hits divided by left clicks
110
+ * @type {number}
111
+ */
112
+ this.meleeAccuracy = divide(this.swordHits, this.leftClicks);
113
+ /**
114
+ * Damage dealt to damage received ratio in melee
115
+ * @type {number}
116
+ */
117
+ this.meleeDamageRatio = divide(this.meleeDamageDealt, this.meleeDamageReceived);
118
+ // Arrow damage
119
+ /**
120
+ * Damage received by arrow
121
+ * @type {number}
122
+ */
123
+ this.bowDamageReceived = stats.bow_damage_received || 0;
124
+ /**
125
+ * Damage dealt with bow
126
+ * @type {number}
127
+ */
128
+ this.bowDamageDealt = stats.bow_damage_dealt || 0;
129
+ /**
130
+ * Arrows hit
131
+ * @type {number}
132
+ */
133
+ this.arrowsHit = stats.arrow_hits || 0;
134
+ /**
135
+ * Arrows fired (hit + missed)
136
+ * @type {number}
137
+ */
138
+ this.arrowsFired = stats.arrows_fired || 0;
139
+ /**
140
+ * Hit divided by Fired
141
+ * @type {number}
142
+ */
143
+ this.bowAccuracy = divide(this.arrowsHit, this.arrowsFired);
144
+ /**
145
+ * Damage dealt to damage received ratio in ranged (bow/arrow)
146
+ * @type {number}
147
+ */
148
+ this.bowDamageRatio = divide(this.bowDamageDealt, this.bowDamageReceived);
149
+ /**
150
+ * Golden Heads eaten
151
+ * @type {number}
152
+ */
153
+ this.goldenHeadsEaten = stats.ghead_eaten || 0;
154
+ /**
155
+ * Pit Player Inv
156
+ * @return {Promise<PitInventoryItem[]>}
157
+ */
158
+ this.getInventory = async () => {
159
+ let inventory = data.profile.inv_contents;
160
+ if (!inventory) return [];
161
+
162
+ try {
163
+ inventory = await decode(inventory.data);
164
+ const edited = [];
165
+ for (let i = 1; i < inventory.length; i++) {
166
+ if (!inventory[i].id) {
167
+ continue;
168
+ }
169
+ edited.push(new PitInventoryItem(inventory[i]));
170
+ }
171
+ return edited;
172
+ } catch {
173
+ return [];
174
+ }
175
+ };
176
+ /**
177
+ * Pit Player Ender Chest
178
+ * @return {Promise<PitInventoryItem[]>}
179
+ */
180
+ this.getEnterChest = async () => {
181
+ let chest = data.profile.inv_enderchest;
182
+ if (!chest) return [];
183
+
184
+ try {
185
+ chest = await decode(chest.data);
186
+ const edited = [];
187
+ for (let i = 1; i < chest.length; i++) {
188
+ if (!chest[i].id) {
189
+ continue;
190
+ }
191
+ edited.push(new PitInventoryItem(chest[i]));
192
+ }
193
+ return edited;
194
+ } catch {
195
+ return [];
196
+ }
197
+ };
198
+ /**
199
+ * Pit Player Armor
200
+ * @return {Promise<PitArmor>}
201
+ */
202
+ this.getArmor = async () => {
203
+ const base64 = data.profile.inv_armor;
204
+ const decoded = await decode(base64.data);
205
+ const armor = {
206
+ helmet: decoded[3].id ? new PitInventoryItem(decoded[3]) : null,
207
+ chestplate: decoded[2].id ? new PitInventoryItem(decoded[2]) : null,
208
+ leggings: decoded[1].id ? new PitInventoryItem(decoded[1]) : null,
209
+ boots: decoded[0].id ? new PitInventoryItem(decoded[0]) : null
210
+ };
211
+ return armor;
212
+ };
213
+ }
214
+ // Credit https://github.com/PitPanda/PitPandaProduction/blob/b1971f56ea1aa8c829b722cbb33247c96591c0cb/structures/Pit.js
215
+ /**
216
+ * Converts XP to Level
217
+ * @param {number} prestige Prestige Level
218
+ * @param {number} xp Current xp into the prestige
219
+ * @return {number}
220
+ */
221
+ static calcLevel(prestige, xp) {
222
+ const multiplier = Prestiges[prestige].Multiplier;
223
+ let level = 0;
224
+ while (0 < xp && 120 > level) {
225
+ const levelXp = Levels[Math.floor(level / 10)].Xp * multiplier;
226
+ if (xp >= levelXp * 10) {
227
+ xp -= levelXp * 10;
228
+ level += 10;
229
+ } else {
230
+ const gain = Math.floor(xp / levelXp);
231
+ level += gain;
232
+ xp = 0;
233
+ }
234
+ }
235
+ return level;
16
236
  }
17
237
  }
18
238
 
239
+ /**
240
+ * @typedef {object} PitArmor Equipped armor
241
+ * @property {PitInventoryItem|null} helmet Helmet
242
+ * @property {PitInventoryItem|null} chestplate Chestplate
243
+ * @property {PitInventoryItem|null} leggings Leggings
244
+ * @property {PitInventoryItem|null} boots Boots
245
+ */
246
+
19
247
  module.exports = Pit;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Item class
3
+ */
4
+ class PitInventoryItem {
5
+ /**
6
+ * @param {object} data Item data
7
+ */
8
+ constructor(data) {
9
+ /**
10
+ * Item ID
11
+ * @type {number}
12
+ */
13
+ this.itemId = data.id || 0;
14
+ /**
15
+ * Item count
16
+ * @type {number}
17
+ */
18
+ this.count = data.Count || 0;
19
+ /**
20
+ * Item name
21
+ * @type {string|null}
22
+ */
23
+ this.name = data?.tag?.display?.Name ? data.tag.display.Name.toString().replace(/§([1-9]|[a-f])|§/gm, '') : null;
24
+ /**
25
+ * Item lore
26
+ * @type {string|null}
27
+ */
28
+ this.lore = data?.tag?.display?.Lore ? data.tag.display.Lore.join('\n') : null;
29
+ /**
30
+ * Item lore
31
+ * @type {string[]}
32
+ */
33
+ this.loreArray = data?.tag?.display?.Lore ?? [];
34
+ /**
35
+ * Item Extra Attributes
36
+ * @type {object|null}
37
+ */
38
+
39
+ this.extraAttributes = data?.tag?.ExtraAttributes ?? null;
40
+ }
41
+ }
42
+
43
+ module.exports = PitInventoryItem;