hypixel-api-reborn 11.3.3 → 11.3.4

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.
@@ -1,12 +1,12 @@
1
1
  /* eslint-disable jsdoc/require-jsdoc */
2
+ const { parse, simplify } = require('prismarine-nbt');
2
3
  const constants = require('./Constants');
3
4
 
4
5
  async function decode(base64, isBuffer = false) {
5
- const nbt = require('prismarine-nbt');
6
- const parseNbt = require('util').promisify(nbt.parse);
6
+ // Credit: https://github.com/SkyCryptWebsite/SkyCryptv2/blob/3b5b3ae4fe77c60eff90691797f09024baf68872/src/lib/server/stats/items/processing.ts#L215-L218
7
7
  const buffer = isBuffer ? base64 : Buffer.from(base64, 'base64');
8
- let data = await parseNbt(buffer);
9
- data = nbt.simplify(data);
8
+ let data = await parse(buffer);
9
+ data = simplify(data.parsed);
10
10
  const newdata = [];
11
11
  for (let i = 0; i < data.i.length; i++) {
12
12
  newdata.push(data.i[i]);
@@ -180,7 +180,7 @@ function getTrophyFishRank(level) {
180
180
  } else if (4 === level) {
181
181
  return 'Diamond';
182
182
  }
183
- return 'Bronze';
183
+ return null;
184
184
  }
185
185
 
186
186
  function getSkills(data) {
@@ -273,66 +273,173 @@ function getSlayer(data) {
273
273
  };
274
274
  }
275
275
 
276
- function getKuudra(data) {
277
- if (!data?.kuudra_completed_tiers) return null;
276
+ function getScore(points) {
277
+ if (1000 <= points) {
278
+ return 'S';
279
+ } else if (800 <= points) {
280
+ return 'A';
281
+ } else if (600 <= points) {
282
+ return 'B';
283
+ } else if (400 <= points) {
284
+ return 'C';
285
+ } else if (200 <= points) {
286
+ return 'D';
287
+ }
288
+ return 'F';
289
+ }
290
+
291
+ function getBelt(points) {
292
+ if (7000 <= points) {
293
+ return 'Black';
294
+ } else if (6000 <= points) {
295
+ return 'Brown';
296
+ } else if (4000 <= points) {
297
+ return 'Blue';
298
+ } else if (2000 <= points) {
299
+ return 'Green';
300
+ } else if (1000 <= points) {
301
+ return 'Yellow';
302
+ }
303
+ return 'White';
304
+ }
305
+
306
+ function getCrimson(data) {
278
307
  return {
279
- none: data.kuudra_completed_tiers?.none ?? 0,
280
- hot: data.kuudra_completed_tiers?.hot ?? 0,
281
- burning: data.kuudra_completed_tiers?.burning ?? 0,
282
- fiery: data.kuudra_completed_tiers?.fiery ?? 0,
283
- highestWaveHot: data.kuudra_completed_tiers?.highest_wave_hot ?? 0,
284
- highestWaveFiery: data.kuudra_completed_tiers?.highest_wave_fiery ?? 0,
285
- infernal: data.kuudra_completed_tiers?.infernal ?? 0,
286
- highestWaveInfernal: data.kuudra_completed_tiers?.highest_wave_infernal ?? 0,
287
- highestWaveBurning: data.kuudra_completed_tiers?.highest_wave_burning ?? 0
308
+ faction: data?.nether_island_player_data?.selected_faction || null,
309
+ reputation: {
310
+ barbarians: data?.nether_island_player_data?.barbarians_reputation ?? 0,
311
+ mages: data?.nether_island_player_data?.mages_reputation ?? 0
312
+ },
313
+ trophyFish: {
314
+ rank: getTrophyFishRank((data?.trophy_fish?.rewards ?? [])?.length),
315
+ caught: {
316
+ total: data?.trophy_fish?.total_caught ?? 0,
317
+ bronze: Object.keys(data?.trophy_fish ?? {}).filter((key) => key.endsWith('_bronze'))?.length,
318
+ silver: Object.keys(data?.trophy_fish ?? {}).filter((key) => key.endsWith('_silver'))?.length,
319
+ gold: Object.keys(data?.trophy_fish ?? {}).filter((key) => key.endsWith('_gold'))?.length,
320
+ diamond: Object.keys(data?.trophy_fish ?? {}).filter((key) => key.endsWith('_diamond'))?.length
321
+ }
322
+ },
323
+ dojo: {
324
+ belt: getBelt(
325
+ Object.keys(data?.nether_island_player_data?.dojo ?? {})
326
+ .filter((key) => key?.startsWith('dojo_points'))
327
+ .reduce((acc, key) => acc + (data?.nether_island_player_data?.dojo[key] ?? 0), 0)
328
+ ),
329
+ force: {
330
+ points: data?.nether_island_player_data?.dojo?.dojo_points_mob_kb ?? 0,
331
+ rank: getScore(data?.nether_island_player_data?.dojo?.dojo_points_mob_kb ?? 0)
332
+ },
333
+ stamina: {
334
+ points: data?.nether_island_player_data?.dojo?.dojo_points_wall_jump ?? 0,
335
+ rank: getScore(data?.nether_island_player_data?.dojo?.dojo_points_wall_jump ?? 0)
336
+ },
337
+ mastery: {
338
+ points: data?.nether_island_player_data?.dojo?.dojo_points_archer ?? 0,
339
+ rank: getScore(data?.nether_island_player_data?.dojo?.dojo_points_archer ?? 0)
340
+ },
341
+ discipline: {
342
+ points: data?.nether_island_player_data?.dojo?.dojo_points_sword_swap ?? 0,
343
+ rank: getScore(data?.nether_island_player_data?.dojo?.dojo_points_sword_swap ?? 0)
344
+ },
345
+ swiftness: {
346
+ points: data?.nether_island_player_data?.dojo?.dojo_points_snake ?? 0,
347
+ rank: getScore(data?.nether_island_player_data?.dojo?.dojo_points_snake ?? 0)
348
+ },
349
+ control: {
350
+ points: data?.nether_island_player_data?.dojo?.dojo_points_lock_head ?? 0,
351
+ rank: getScore(data?.nether_island_player_data?.dojo?.dojo_points_lock_head ?? 0)
352
+ },
353
+ tenacity: {
354
+ points: data?.nether_island_player_data?.dojo?.dojo_points_fireball ?? 0,
355
+ rank: getScore(data?.nether_island_player_data?.dojo?.dojo_points_fireball ?? 0)
356
+ }
357
+ },
358
+ kuudra: {
359
+ none: data?.nether_island_player_data?.kuudra_completed_tiers?.none ?? 0,
360
+ hot: data?.nether_island_player_data?.kuudra_completed_tiers?.hot ?? 0,
361
+ burning: data?.nether_island_player_data?.kuudra_completed_tiers?.burning ?? 0,
362
+ fiery: data?.nether_island_player_data?.kuudra_completed_tiers?.fiery ?? 0,
363
+ highestWaveHot: data?.nether_island_player_data?.kuudra_completed_tiers?.highest_wave_hot ?? 0,
364
+ highestWaveFiery: data?.nether_island_player_data?.kuudra_completed_tiers?.highest_wave_fiery ?? 0,
365
+ infernal: data?.nether_island_player_data?.kuudra_completed_tiers?.infernal ?? 0,
366
+ highestWaveInfernal: data?.nether_island_player_data?.kuudra_completed_tiers?.highest_wave_infernal ?? 0,
367
+ highestWaveBurning: data?.nether_island_player_data?.kuudra_completed_tiers?.highest_wave_burning ?? 0
368
+ }
288
369
  };
289
370
  }
290
371
 
291
372
  function getCompletions(data) {
292
- const completions = {};
373
+ const completions = {
374
+ total: 0
375
+ };
293
376
 
294
377
  for (const tier in data) {
378
+ if ('total' === tier) continue;
295
379
  completions[`Floor_${tier}`] = data[tier];
380
+ completions.total += data[tier];
296
381
  }
297
382
 
298
383
  return completions;
299
384
  }
300
385
 
386
+ function getDungeonsFloor(data, type, floor) {
387
+ return {
388
+ fastestRun: (data?.dungeons?.dungeon_types?.[type]?.best_runs?.[floor] ?? []).sort(
389
+ (a, b) => a?.elapsed_time - b?.elapsed_time
390
+ )[0],
391
+ fastestSRun: (data?.dungeons?.dungeon_types?.[type]?.best_runs?.[floor] ?? [])
392
+ .filter((run) => 270 >= run?.score_exploration + run?.score_speed + run?.score_skill + run?.score_bonus)
393
+ .sort((a, b) => a?.elapsed_time - b?.elapsed_time)[0],
394
+ fastestSPlusRun: (data?.dungeons?.dungeon_types?.[type]?.best_runs?.[floor] ?? [])
395
+ .filter((run) => 300 >= run?.score_exploration + run?.score_speed + run?.score_skill + run?.score_bonus)
396
+ .sort((a, b) => a?.elapsed_time - b?.elapsed_time)[0],
397
+ completions: data?.dungeonXp?.dungeon_types?.[type]?.tier_completions[floor] ?? 0
398
+ };
399
+ }
400
+
301
401
  function getDungeons(data) {
302
402
  return {
303
- types: {
304
- catacombs: {
305
- experience: getLevelByXp(
306
- data.dungeons?.dungeon_types?.catacombs ? data.dungeons.dungeon_types.catacombs.experience : null,
307
- 'dungeons'
308
- ),
309
- completions: getCompletions(data.dungeons?.dungeon_types?.catacombs?.tier_completions)
310
- },
311
- masterCatacombs: {
312
- completions: getCompletions(data.dungeons?.dungeon_types?.master_catacombs?.tier_completions)
313
- }
403
+ experience: getLevelByXp(data?.dungeons?.dungeon_types?.catacombs?.experience ?? 0, 'dungeons'),
404
+ secrets: data?.dungeons?.secrets ?? 0,
405
+ completions: {
406
+ catacombs: getCompletions(data?.dungeons?.dungeon_types?.catacombs?.tier_completions),
407
+ masterCatacombs: getCompletions(data?.dungeons?.dungeon_types?.master_catacombs?.tier_completions)
408
+ },
409
+ floors: {
410
+ entrance: getDungeonsFloor(data, 'catacombs', '0'),
411
+ floor1: getDungeonsFloor(data, 'catacombs', '1'),
412
+ floor2: getDungeonsFloor(data, 'catacombs', '2'),
413
+ floor3: getDungeonsFloor(data, 'catacombs', '3'),
414
+ floor4: getDungeonsFloor(data, 'catacombs', '4'),
415
+ floor5: getDungeonsFloor(data, 'catacombs', '5'),
416
+ floor6: getDungeonsFloor(data, 'catacombs', '6'),
417
+ floor7: getDungeonsFloor(data, 'catacombs', '7'),
418
+ masterCatacombs1: getDungeonsFloor(data, 'master_catacombs', '1'),
419
+ masterCatacombs2: getDungeonsFloor(data, 'master_catacombs', '2'),
420
+ masterCatacombs3: getDungeonsFloor(data, 'master_catacombs', '3'),
421
+ masterCatacombs4: getDungeonsFloor(data, 'master_catacombs', '4'),
422
+ masterCatacombs5: getDungeonsFloor(data, 'master_catacombs', '5'),
423
+ masterCatacombs6: getDungeonsFloor(data, 'master_catacombs', '6'),
424
+ masterCatacombs7: getDungeonsFloor(data, 'master_catacombs', '7')
314
425
  },
315
426
  classes: {
316
- healer: getLevelByXp(
317
- data.dungeons?.player_classes?.healer ? data.dungeons.player_classes.healer.experience : null,
318
- 'dungeons'
319
- ),
320
- mage: getLevelByXp(
321
- data.dungeons?.player_classes?.mage ? data.dungeons.player_classes.mage.experience : null,
322
- 'dungeons'
323
- ),
324
- berserk: getLevelByXp(
325
- data.dungeons?.player_classes?.berserk ? data.dungeons.player_classes.berserk.experience : null,
326
- 'dungeons'
327
- ),
328
- archer: getLevelByXp(
329
- data.dungeons?.player_classes?.archer ? data.dungeons.player_classes.archer.experience : null,
330
- 'dungeons'
331
- ),
332
- tank: getLevelByXp(
333
- data.dungeons?.player_classes?.tank ? data.dungeons.player_classes.tank.experience : null,
334
- 'dungeons'
335
- )
427
+ healer: getLevelByXp(data?.dungeons?.player_classes?.healer?.experience ?? 0, 'dungeons'),
428
+ mage: getLevelByXp(data?.dungeons?.player_classes?.mage?.experience ?? 0, 'dungeons'),
429
+ berserk: getLevelByXp(data?.dungeons?.player_classes?.berserk?.experience ?? 0, 'dungeons'),
430
+ archer: getLevelByXp(data?.dungeons?.player_classes?.archer?.experience ?? 0, 'dungeons'),
431
+ tank: getLevelByXp(data?.dungeons?.player_classes?.tank?.experience ?? 0, 'dungeons'),
432
+ selected: data?.dungeons?.selected_dungeon_class ?? 'mage'
433
+ },
434
+ essence: {
435
+ diamond: data?.currencies?.essence?.DIAMOND?.current || 0,
436
+ dragon: data?.currencies?.essence?.DRAGON?.current || 0,
437
+ spider: data?.currencies?.essence?.SPIDER?.current || 0,
438
+ wither: data?.currencies?.essence?.WITHER?.current || 0,
439
+ undead: data?.currencies?.essence?.UNDEAD?.current || 0,
440
+ gold: data?.currencies?.essence?.GOLD?.current || 0,
441
+ ice: data?.currencies?.essence?.ICE?.current || 0,
442
+ crimson: data?.currencies?.essence?.CRIMSON?.current || 0
336
443
  }
337
444
  };
338
445
  }
@@ -516,6 +623,30 @@ function populateGoals(achieved, all) {
516
623
  return populatedAchieved;
517
624
  }
518
625
 
626
+ function getHOTM(data) {
627
+ return {
628
+ experience: getLevelByXp(data.mining_core?.experience, 'hotm'),
629
+ ability: data.mining_core?.selected_pickaxe_ability || 'none',
630
+ powder: {
631
+ mithril: {
632
+ spent: data?.mining_core?.powder_spent_mithril || 0,
633
+ current: data?.mining_core?.powder_mithril || 0,
634
+ total: data?.mining_core?.powder_spent_mithril || 0 + data?.mining_core?.powder_mithril || 0
635
+ },
636
+ gemstone: {
637
+ spent: data?.mining_core?.powder_spent_gemstone || 0,
638
+ current: data?.mining_core?.powder_gemstone || 0,
639
+ total: data?.mining_core?.powder_spent_gemstone || 0 + data?.mining_core?.powder_gemstone || 0
640
+ },
641
+ glacite: {
642
+ spent: data?.mining_core?.powder_spent_glacite || 0,
643
+ current: data?.mining_core?.powder_glacite || 0,
644
+ total: data?.mining_core?.powder_spent_glacite || 0 + data?.mining_core?.powder_glacite || 0
645
+ }
646
+ }
647
+ };
648
+ }
649
+
519
650
  module.exports = {
520
651
  decode,
521
652
  getLevelByXp,
@@ -524,12 +655,13 @@ module.exports = {
524
655
  getSkills,
525
656
  getBestiaryLevel,
526
657
  getSlayer,
527
- getKuudra,
658
+ getCrimson,
528
659
  getDungeons,
529
660
  getJacobData,
530
661
  getChocolateFactory,
531
662
  getPetLevel,
532
663
  parseRarity,
533
664
  parseGearScore,
534
- populateGoals
665
+ populateGoals,
666
+ getHOTM
535
667
  };