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.
- package/.prettierrc +3 -3
- package/README.md +6 -4
- package/eslint.config.mjs +71 -0
- package/package.json +21 -25
- package/src/API/getAchievements.js +7 -0
- package/src/API/getBoosters.js +1 -0
- package/src/API/getChallenges.js +7 -0
- package/src/API/getGameCounts.js +1 -0
- package/src/API/getGuild.js +5 -4
- package/src/API/getGuildAchievements.js +7 -0
- package/src/API/getLeaderboards.js +4 -2
- package/src/API/getPlayer.js +2 -1
- package/src/API/getQuests.js +7 -0
- package/src/API/getRecentGames.js +6 -10
- package/src/API/getServerInfo.js +42 -37
- package/src/API/getStatus.js +2 -1
- package/src/API/getWatchdogStats.js +1 -0
- package/src/API/index.js +28 -17
- package/src/API/skyblock/getAuction.js +21 -0
- package/src/API/skyblock/{getSkyblockAuctions.js → getAuctions.js} +19 -12
- package/src/API/skyblock/{getSkyblockAuctionsByPlayer.js → getAuctionsByPlayer.js} +2 -2
- package/src/API/skyblock/{getSkyblockBazaar.js → getBazaar.js} +1 -3
- package/src/API/skyblock/getBingo.js +7 -0
- package/src/API/skyblock/getBingoByPlayer.js +14 -0
- package/src/API/skyblock/{getEndedSkyblockAuctions.js → getEndedAuctions.js} +1 -0
- package/src/API/skyblock/getFireSales.js +7 -0
- package/src/API/skyblock/getGovernment.js +7 -0
- package/src/API/skyblock/{getSkyblockMember.js → getMember.js} +10 -3
- package/src/API/skyblock/getMuseum.js +15 -0
- package/src/API/skyblock/{getSkyblockNews.js → getNews.js} +1 -0
- package/src/API/skyblock/{getSkyblockProfiles.js → getProfiles.js} +14 -7
- package/src/Client.js +127 -25
- package/src/Errors.js +38 -17
- package/src/Private/rateLimit.js +17 -13
- package/src/Private/requests.js +27 -16
- package/src/Private/updater.js +11 -8
- package/src/Private/uuidCache.js +23 -30
- package/src/Private/validate.js +33 -22
- package/src/index.js +9 -0
- package/src/structures/APIIncident.js +4 -11
- package/src/structures/APIStatus.js +0 -1
- package/src/structures/Boosters/Booster.js +14 -13
- package/src/structures/Color.js +93 -48
- package/src/structures/Game.js +4 -2
- package/src/structures/Guild/Guild.js +35 -48
- package/src/structures/Guild/GuildMember.js +8 -8
- package/src/structures/Guild/GuildRank.js +2 -2
- package/src/structures/MiniGames/Arcade.js +242 -235
- package/src/structures/MiniGames/ArenaBrawl.js +11 -11
- package/src/structures/MiniGames/BedWars.js +262 -131
- package/src/structures/MiniGames/BlitzSurvivalGames.js +24 -23
- package/src/structures/MiniGames/CopsAndCrims.js +1 -0
- package/src/structures/MiniGames/Duels.js +92 -33
- package/src/structures/MiniGames/MegaWalls.js +3 -1
- package/src/structures/MiniGames/MurderMystery.js +2 -2
- package/src/structures/MiniGames/Pit.js +230 -2
- package/src/structures/MiniGames/PitInventoryItem.js +43 -0
- package/src/structures/MiniGames/SkyWars.js +211 -195
- package/src/structures/MiniGames/SmashHeroes.js +37 -35
- package/src/structures/MiniGames/SpeedUHC.js +17 -4
- package/src/structures/MiniGames/TNTGames.js +1 -1
- package/src/structures/MiniGames/UHC.js +33 -14
- package/src/structures/MiniGames/WoolWars.js +6 -5
- package/src/structures/Pet.js +1 -1
- package/src/structures/Player.js +26 -121
- package/src/structures/PlayerCosmetics.js +67 -12
- package/src/structures/ServerInfo.js +1 -1
- package/src/structures/SkyBlock/Auctions/Auction.js +3 -1
- package/src/structures/SkyBlock/Auctions/AuctionInfo.js +3 -1
- package/src/structures/SkyBlock/Auctions/BaseAuction.js +2 -1
- package/src/structures/SkyBlock/Auctions/Bid.js +1 -0
- package/src/structures/SkyBlock/Auctions/PartialAuction.js +1 -0
- package/src/structures/SkyBlock/News/SkyblockNews.js +15 -15
- package/src/structures/SkyBlock/PlayerBingo.js +49 -0
- package/src/structures/SkyBlock/SkyblockInventoryItem.js +76 -32
- package/src/structures/SkyBlock/SkyblockMember.js +252 -289
- package/src/structures/SkyBlock/SkyblockMuseum.js +60 -0
- package/src/structures/SkyBlock/SkyblockMuseumItem.js +54 -0
- package/src/structures/SkyBlock/SkyblockPet.js +3 -3
- package/src/structures/SkyBlock/SkyblockProfile.js +37 -23
- package/src/structures/SkyBlock/Static/Bingo.js +101 -0
- package/src/structures/SkyBlock/Static/BingoData.js +45 -0
- package/src/structures/SkyBlock/Static/Candidate.js +40 -0
- package/src/structures/SkyBlock/Static/FireSale.js +55 -0
- package/src/structures/SkyBlock/Static/Government.js +74 -0
- package/src/structures/SkyBlock/Static/Perk.js +24 -0
- package/src/structures/Static/Achievement.js +87 -0
- package/src/structures/Static/AchievementTier.js +33 -0
- package/src/structures/Static/Achievements.js +30 -0
- package/src/structures/Static/Challenges.js +29 -0
- package/src/structures/Static/GameAchievements.js +36 -0
- package/src/structures/Static/GameChallenges.js +40 -0
- package/src/structures/Static/GameQuests.js +24 -0
- package/src/structures/Static/GuildAchievements.js +34 -0
- package/src/structures/Static/Quest.js +66 -0
- package/src/structures/Static/Quests.js +31 -0
- package/src/structures/Status.js +2 -2
- package/src/utils/Constants.js +384 -543
- package/src/utils/{guildExp.js → Guild.js} +46 -13
- package/src/utils/Player.js +112 -0
- package/src/utils/SkyblockUtils.js +448 -186
- package/src/utils/arrayTools.js +1 -1
- package/src/utils/divide.js +1 -1
- package/src/utils/index.js +2 -1
- package/src/utils/isGuildID.js +1 -1
- package/src/utils/oscillation.js +4 -2
- package/src/utils/removeSnakeCase.js +19 -8
- package/src/utils/rgbToHexColor.js +1 -1
- package/src/utils/romanize.js +35 -4
- package/src/utils/toUuid.js +12 -7
- package/src/utils/varInt.js +2 -2
- package/typings/index.d.ts +1246 -446
- package/src/utils/toIGN.js +0 -20
|
@@ -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
|
-
|
|
4
|
-
|
|
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
|
|
@@ -59,16 +251,6 @@ class SkyWars {
|
|
|
59
251
|
* @type {number}
|
|
60
252
|
*/
|
|
61
253
|
this.wins = data.wins || 0;
|
|
62
|
-
/**
|
|
63
|
-
* Loot Chests
|
|
64
|
-
* @type {number}
|
|
65
|
-
*/
|
|
66
|
-
this.lootChests = data.skywars_chests || 0;
|
|
67
|
-
/**
|
|
68
|
-
* Opened Loot Chests
|
|
69
|
-
* @type {number}
|
|
70
|
-
*/
|
|
71
|
-
this.openedLootChests = data.SkyWars_openedChests || 0;
|
|
72
254
|
/**
|
|
73
255
|
* Heads
|
|
74
256
|
* @type {number}
|
|
@@ -113,7 +295,12 @@ class SkyWars {
|
|
|
113
295
|
* Games Played ( Total )
|
|
114
296
|
* @type {number}
|
|
115
297
|
*/
|
|
116
|
-
this.playedGames =
|
|
298
|
+
this.playedGames =
|
|
299
|
+
(data.games_solo || 0) +
|
|
300
|
+
(data.games_team || 0) +
|
|
301
|
+
(data.games_mega || 0) +
|
|
302
|
+
(data.games_mega_doubles || 0) +
|
|
303
|
+
(data.games_lab || 0);
|
|
117
304
|
/**
|
|
118
305
|
* Global Kill Death Ratio
|
|
119
306
|
* @type {number}
|
|
@@ -207,8 +394,14 @@ class SkyWars {
|
|
|
207
394
|
wins: (data.wins_mega || 0) + (data.wins_mega_doubles || 0),
|
|
208
395
|
losses: (data.losses_mega || 0) + (data.losses_mega_doubles || 0),
|
|
209
396
|
deaths: (data.deaths_mega || 0) + (data.deaths_mega_doubles || 0),
|
|
210
|
-
KDRatio: divide(
|
|
211
|
-
|
|
397
|
+
KDRatio: divide(
|
|
398
|
+
(data.kills_mega || 0) + (data.kills_mega_doubles || 0),
|
|
399
|
+
(data.deaths_mega || 0) + (data.deaths_mega_doubles || 0)
|
|
400
|
+
),
|
|
401
|
+
WLRatio: divide(
|
|
402
|
+
(data.wins_mega || 0) + (data.wins_mega_doubles || 0),
|
|
403
|
+
(data.losses_mega || 0) + (data.losses_mega_doubles || 0)
|
|
404
|
+
)
|
|
212
405
|
},
|
|
213
406
|
solo: {
|
|
214
407
|
playedGames: data.games_mega || 0,
|
|
@@ -315,8 +508,7 @@ class SkyWars {
|
|
|
315
508
|
*/
|
|
316
509
|
/**
|
|
317
510
|
* @typedef {string} PseudoDate String date, in the format of MM-YY ( YY is 20YY )
|
|
318
|
-
|
|
319
|
-
*/
|
|
511
|
+
w */
|
|
320
512
|
/**
|
|
321
513
|
* @typedef {Object} SkyWarsModeExtendedStats
|
|
322
514
|
* @property {SkyWarsTotalModeStats} overall Overall Stats
|
|
@@ -330,179 +522,3 @@ class SkyWars {
|
|
|
330
522
|
* @property {SkyWarsModeStats} doubles Mega Doubles Stats
|
|
331
523
|
*/
|
|
332
524
|
module.exports = SkyWars;
|
|
333
|
-
// eslint-disable-next-line require-jsdoc
|
|
334
|
-
function getSkyWarsPrestige(level) {
|
|
335
|
-
if (level >= 60) return 'Mythic';
|
|
336
|
-
return ['Iron', 'Iron', 'Gold', 'Diamond', 'Emerald', 'Sapphire', 'Ruby', 'Crystal', 'Opal', 'Amethyst', 'Rainbow'][Math.floor(level / 5)] || 'Iron';
|
|
337
|
-
}
|
|
338
|
-
// eslint-disable-next-line require-jsdoc
|
|
339
|
-
function getSkyWarsLevel(xp) {
|
|
340
|
-
const totalXp = [0, 2, 7, 15, 25, 50, 100, 200, 350, 600, 1000, 1500];
|
|
341
|
-
if (xp >= 15000) return Math.floor((xp - 15000) / 10000 + 12);
|
|
342
|
-
const level = totalXp.findIndex((x) => x * 10 - xp > 0);
|
|
343
|
-
return level; /* + (xp - (totalXp[level - 1] * 10 || 0)) / (totalXp[level] - totalXp[level - 1]) / 10*/
|
|
344
|
-
}
|
|
345
|
-
// eslint-disable-next-line require-jsdoc
|
|
346
|
-
function getSkyWarsLevelProgress(xp) {
|
|
347
|
-
const totalXp = [0, 2, 7, 15, 25, 50, 100, 200, 350, 600, 1000, 1500];
|
|
348
|
-
const xpToNextLvl = [0, 2, 5, 8, 10, 25, 50, 100, 150, 250, 400, 500]; // * 10
|
|
349
|
-
let percent;
|
|
350
|
-
let xpToNextLevel;
|
|
351
|
-
let currentLevelXp = xp;
|
|
352
|
-
if (xp >= 15000) {
|
|
353
|
-
currentLevelXp -= 15000;
|
|
354
|
-
if (currentLevelXp === 0) return { currentLevelXp: 0, xpToNextLevel: 10000, percent: 0, xpNextLevel: 10000 };
|
|
355
|
-
if (currentLevelXp > 10000) {
|
|
356
|
-
do {
|
|
357
|
-
currentLevelXp -= 10000;
|
|
358
|
-
} while (currentLevelXp >= 10000);
|
|
359
|
-
}
|
|
360
|
-
xpToNextLevel = 10000 - currentLevelXp;
|
|
361
|
-
percent = Math.round(currentLevelXp) / 100;
|
|
362
|
-
const percentRemaining = Math.round((100 - percent) * 100) / 100;
|
|
363
|
-
return {
|
|
364
|
-
currentLevelXp,
|
|
365
|
-
xpToNextLevel,
|
|
366
|
-
percent,
|
|
367
|
-
xpNextLevel: 10000,
|
|
368
|
-
percentRemaining
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
|
-
const totalXptoNextLevel = xpToNextLvl[totalXp.findIndex((x) => x * 10 - xp > 0)] * 10;
|
|
372
|
-
for (let i = 0; i < xpToNextLvl.length; i++) {
|
|
373
|
-
if (currentLevelXp - xpToNextLvl[i] * 10 < 0) break;
|
|
374
|
-
currentLevelXp -= xpToNextLvl[i] * 10;
|
|
375
|
-
}
|
|
376
|
-
xpToNextLevel = totalXptoNextLevel - currentLevelXp;
|
|
377
|
-
percent = Math.round((currentLevelXp / totalXptoNextLevel) * 10000) / 100;
|
|
378
|
-
return {
|
|
379
|
-
currentLevelXp,
|
|
380
|
-
xpToNextLevel,
|
|
381
|
-
percent,
|
|
382
|
-
xpNextLevel: totalXptoNextLevel
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
const ratingRegex = /^SkyWars_skywars_rating_(\d{1,2})_(\d{1,2})_(position|rating)$/;
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* Skywars Packages - parses every package player has
|
|
389
|
-
*/
|
|
390
|
-
class SkywarsPackages {
|
|
391
|
-
/**
|
|
392
|
-
* Constructor
|
|
393
|
-
* @param {string[]} data data from API
|
|
394
|
-
*/
|
|
395
|
-
constructor(data) {
|
|
396
|
-
// TODO : a lot more
|
|
397
|
-
/**
|
|
398
|
-
* Raw Packages, as received from the API
|
|
399
|
-
* @type {string[]}
|
|
400
|
-
*/
|
|
401
|
-
this.rawPackages = Array.from(data);
|
|
402
|
-
/**
|
|
403
|
-
* Cages
|
|
404
|
-
* @type {string[]}
|
|
405
|
-
*/
|
|
406
|
-
this.cages = this._parseCages();
|
|
407
|
-
/**
|
|
408
|
-
* Kits
|
|
409
|
-
* @type {SkywarsKits}
|
|
410
|
-
*/
|
|
411
|
-
this.kits = new SkywarsKits(data);
|
|
412
|
-
/**
|
|
413
|
-
* Achievements included in packages, under the form of name0
|
|
414
|
-
* @type {string[]}
|
|
415
|
-
*/
|
|
416
|
-
this.achievements = this.rawPackages
|
|
417
|
-
.map((pkg) => pkg.match(/^([A-z]+)_?achievement([0-9]?)$/))
|
|
418
|
-
.filter((x) => x)
|
|
419
|
-
.map((x) => x.slice(1).join(''));
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* Parses cages
|
|
423
|
-
* @returns {string[]}
|
|
424
|
-
*/
|
|
425
|
-
_parseCages() {
|
|
426
|
-
return this.rawPackages
|
|
427
|
-
.map((pkg) => pkg.match(/^cage_([A-z]+)-cage$/))
|
|
428
|
-
.filter((x) => x)
|
|
429
|
-
.map((x) => x[1].replace(/-[a-z]/g, (x) => x[1].toUpperCase()));
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
* Parses SkyWars Kits
|
|
435
|
-
*/
|
|
436
|
-
class SkywarsKit {
|
|
437
|
-
/**
|
|
438
|
-
* Constructor
|
|
439
|
-
* @param {string} kit Kit
|
|
440
|
-
*/
|
|
441
|
-
constructor(kit) {
|
|
442
|
-
/**
|
|
443
|
-
* Kit data
|
|
444
|
-
* @private
|
|
445
|
-
* @type {string[] | null}
|
|
446
|
-
*/
|
|
447
|
-
this._kitData = kit.match(/^kit_([a-z]+)_([a-z]+)_([a-z]+)$/);
|
|
448
|
-
/**
|
|
449
|
-
* Is this a kit
|
|
450
|
-
* @type {boolean}
|
|
451
|
-
*/
|
|
452
|
-
this.isKit = !!this._kitData;
|
|
453
|
-
if (!this._kitData) return;
|
|
454
|
-
/**
|
|
455
|
-
* Game mode the kit is for
|
|
456
|
-
* @type {KitGameModes}
|
|
457
|
-
*/
|
|
458
|
-
this.gameMode = this._kitData[2];
|
|
459
|
-
/**
|
|
460
|
-
* Kit type
|
|
461
|
-
* @type {KitType}
|
|
462
|
-
*/
|
|
463
|
-
this.kitType = this._kitData[1];
|
|
464
|
-
/**
|
|
465
|
-
* Kit name in camelCase
|
|
466
|
-
* @type {string}
|
|
467
|
-
*/
|
|
468
|
-
this.kitName = removeSnakeCaseString(this._kitData[3]);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
/**
|
|
473
|
-
* Parses SkyWars Kits
|
|
474
|
-
*/
|
|
475
|
-
class SkywarsKits {
|
|
476
|
-
/**
|
|
477
|
-
* Constructor
|
|
478
|
-
* @param {SkywarsKit[]} kits Potential Kits
|
|
479
|
-
*/
|
|
480
|
-
constructor(kits) {
|
|
481
|
-
this.kits = kits.map((kit) => new SkywarsKit(kit)).filter((kit) => kit.isKit);
|
|
482
|
-
}
|
|
483
|
-
/**
|
|
484
|
-
* Get kit by type/gameMode
|
|
485
|
-
* @param {KitGameModes} [gameMode] Kits in said game mode
|
|
486
|
-
* @param {KitType} [type] Kits corresponding to this type
|
|
487
|
-
* @returns {SkywarsKit[]}
|
|
488
|
-
*/
|
|
489
|
-
get(gameMode = '', type = '') {
|
|
490
|
-
return this.kits.filter((kit) => kit.gameMode.startsWith(gameMode) && kit.kitType.startsWith(type));
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
/**
|
|
495
|
-
* @typedef {string} KitType
|
|
496
|
-
* * basic
|
|
497
|
-
* * supporting
|
|
498
|
-
* * mining
|
|
499
|
-
* * defending
|
|
500
|
-
* * attacking
|
|
501
|
-
* * advanced
|
|
502
|
-
* * enderchest
|
|
503
|
-
*/
|
|
504
|
-
/**
|
|
505
|
-
* @typedef {string} KitGameModes
|
|
506
|
-
* * solo
|
|
507
|
-
* * team
|
|
508
|
-
*/
|
|
@@ -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
|
*/
|
|
@@ -70,7 +106,7 @@ class SmashHeroes {
|
|
|
70
106
|
* Active class
|
|
71
107
|
* @type {string}
|
|
72
108
|
*/
|
|
73
|
-
this.activeClass = data.active_class
|
|
109
|
+
this.activeClass = data.active_class ?? null;
|
|
74
110
|
/**
|
|
75
111
|
* Stats for each class
|
|
76
112
|
* @type {SmashHeroesClassStats[]|null}
|
|
@@ -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
|
-
|
|
96
|
-
|
|
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
|
-
|
|
110
|
-
|
|
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;
|
|
@@ -67,7 +67,7 @@ class TNTGames {
|
|
|
67
67
|
*/
|
|
68
68
|
this.wizards = {
|
|
69
69
|
points: data.points_capture || 0,
|
|
70
|
-
class: data.capture_class
|
|
70
|
+
class: data.capture_class ?? null,
|
|
71
71
|
kills: data.kills_capture || 0,
|
|
72
72
|
assists: data.assists_capture || 0,
|
|
73
73
|
wins: data.wins_capture || 0,
|
|
@@ -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
|
*/
|
|
@@ -52,7 +77,13 @@ class UHC {
|
|
|
52
77
|
* @type {number}
|
|
53
78
|
*/
|
|
54
79
|
this.wins =
|
|
55
|
-
(data.wins || 0) +
|
|
80
|
+
(data.wins || 0) +
|
|
81
|
+
(data.wins_solo || 0) +
|
|
82
|
+
(data['wins_red vs blue'] || 0) +
|
|
83
|
+
(data['wins_no diamonds'] || 0) +
|
|
84
|
+
(data.wins_brawl || 0) +
|
|
85
|
+
(data['wins_solo brawl'] || 0) +
|
|
86
|
+
(data['wins_duo brawl'] || 0);
|
|
56
87
|
/**
|
|
57
88
|
* Heads eaten
|
|
58
89
|
* @type {number}
|
|
@@ -142,18 +173,6 @@ class UHC {
|
|
|
142
173
|
};
|
|
143
174
|
}
|
|
144
175
|
}
|
|
145
|
-
// eslint-disable-next-line require-jsdoc
|
|
146
|
-
function getStarLevel(data) {
|
|
147
|
-
const kills =
|
|
148
|
-
(data.kills || 0) + (data.kills_solo || 0) + (data['kills_red vs blue'] || 0) + (data['kills_no diamonds'] || 0) + (data.kills_brawl || 0) + (data['kills_solo brawl'] || 0) + (data['kills_duo brawl'] || 0);
|
|
149
|
-
const wins =
|
|
150
|
-
(data.wins || 0) + (data.wins_solo || 0) + (data['wins_red vs blue'] || 0) + (data['wins_no diamonds'] || 0) + (data.wins_brawl || 0) + (data['wins_solo brawl'] || 0) + (data['wins_duo brawl'] || 0);
|
|
151
|
-
const sum = kills * 1 + wins * 10;
|
|
152
|
-
let starLevel = 1;
|
|
153
|
-
const sums = [0, 1, 6, 21, 46, 96, 171, 271, 521, 1021, 1321, 1621, 1921, 2221, 2521, Infinity];
|
|
154
|
-
starLevel += sums.map((x) => x * 10 - sum).findIndex((x) => x > 0) - 1;
|
|
155
|
-
return starLevel;
|
|
156
|
-
}
|
|
157
176
|
/**
|
|
158
177
|
* @typedef {object} UHCModeStats
|
|
159
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];
|
|
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 (
|
|
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,
|
|
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
|
-
|
|
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,
|
package/src/structures/Pet.js
CHANGED