This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
lib.js
1546 lines (1278 loc) · 44.6 KB
/
lib.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const fs = require('fs');
const path = require('path');
const nbt = require('prismarine-nbt');
const util = require('util');
const mcData = require("minecraft-data")("1.8.9");
const objectPath = require("object-path");
const customResources = require('./custom-resources');
const parseNbt = util.promisify(nbt.parse);
const rarity_order = ['special', 'legendary', 'epic', 'rare', 'uncommon', 'common'];
const max_souls = 190;
function replaceAll(target, search, replacement){
return target.split(search).join(replacement);
}
function getLevelByXp(xp, runecrafting){
let xp_table = runecrafting ? runecrafting_xp : leveling_xp;
if(isNaN(xp)){
return {
xp: 0,
level: 0,
xpCurrent: 0,
xpForNext: xp_table[1],
progress: 0
};
}
let xpTotal = 0;
let level = 0;
let xpForNext = Infinity;
let maxLevel = Object.keys(xp_table).sort((a, b) => Number(a) - Number(b)).map(a => Number(a)).pop();
for(let x = 1; x <= maxLevel; x++){
xpTotal += xp_table[x];
if(xpTotal > xp){
xpTotal -= xp_table[x];
break;
}else{
level = x;
}
}
let xpCurrent = Math.floor(xp - xpTotal);
if(level < maxLevel)
xpForNext = Math.ceil(xp_table[level + 1]);
let progress = Math.max(0, Math.min(xpCurrent / xpForNext, 1));
return {
xp,
level,
maxLevel,
xpCurrent,
xpForNext,
progress
};
}
function getSlayerLevel(slayer){
let { claimed_levels } = slayer;
let level = 0;
for(let level_name in claimed_levels){
let _level = parseInt(level_name.split("_").pop());
if(_level > level)
level = _level;
}
return level;
}
function getBonusStat(level, skill, max, incremention){
let skill_stats = bonus_stats[skill];
let steps = Object.keys(skill_stats).sort((a, b) => Number(a) - Number(b)).map(a => Number(a));
let bonus = Object.assign({}, stat_template);
for(let x = steps[0]; x <= max; x += incremention){
if(level < x)
break;
let skill_step = steps.slice().reverse().find(a => a <= x);
let skill_bonus = skill_stats[skill_step];
for(let skill in skill_bonus)
bonus[skill] += skill_bonus[skill];
}
return bonus;
}
// Calculate total health with defense
function getEffectiveHealth(health, defense){
if(defense <= 0)
return health;
return Math.round(health * (1 + defense / 100));
}
async function getBackpackContents(arraybuf){
let buf = Buffer.from(arraybuf);
let data = await parseNbt(buf);
data = nbt.simplify(data);
let items = data.i;
for(let item of items){
item.isInactive = true;
item.inBackpack = true;
}
return items;
}
function getId(item){
if(objectPath.has(item, 'tag.ExtraAttributes.id'))
return item.tag.ExtraAttributes.id;
return null;
}
// Process items returned by API
async function getItems(base64){
// API stores data as base64 encoded gzipped Minecraft NBT data
let buf = Buffer.from(base64, 'base64');
let data = await parseNbt(buf);
data = nbt.simplify(data);
let items = data.i;
// Check backpack contents and add them to the list of items
for(let [index, item] of items.entries()){
if(objectPath.has(item, 'tag.display.Name') && (item.tag.display.Name.endsWith('Backpack') || item.tag.display.Name.endsWith('Itchy New Year Cake Bag'))){
let keys = Object.keys(item.tag.ExtraAttributes);
let backpackData;
keys.forEach(key => {
if(key.endsWith('backpack_data') || key == 'new_year_cake_bag_data')
backpackData = item.tag.ExtraAttributes[key];
});
if(!Array.isArray(backpackData))
continue;
let backpackContents = await getBackpackContents(backpackData);
backpackContents.forEach(backpackItem => {
backpackItem.backpackIndex = index;
});
item.containsItems = [];
items.push(...backpackContents);
}
}
let index = 0;
for(let item of items){
// Set custom texture for colored leather armor
if(objectPath.has(item, 'id') && item.id >= 298 && item.id <= 301){
let types
let color = [149, 94, 59];
if(objectPath.has(item, 'tag.ExtraAttributes.color'))
color = item.tag.ExtraAttributes.color.split(":");
let type = ["leather_helmet", "leather_chestplate", "leather_leggings", "leather_boots"][item.id - 298].replace('_', '/');
item.texture_path = `/${type}/${color.join(',')}`;
}
// Set raw display name without color and formatting codes
if(objectPath.has(item, 'tag.display.Name'))
item.display_name = module.exports.getRawLore(item.tag.display.Name);
if(objectPath.has(item, 'display_name'))
if(item.display_name == 'Water Bottle')
item.Damage = 17;
const customTexture = await customResources.getTexture(item);
if(customTexture){
item.animated = customTexture.animated;
item.texture_path = '/' + customTexture.path;
item.texture_pack = customTexture.pack.config;
item.texture_pack.base_path = '/' + path.relative(path.resolve(__dirname, '..', 'public'), customTexture.pack.basePath);
}
// Resolve skull textures to their image path
if(objectPath.has(item, 'tag.SkullOwner.Properties.textures') && Array.isArray(item.tag.SkullOwner.Properties.textures) && item.tag.SkullOwner.Properties.textures.length > 0){
try{
let json = JSON.parse(Buffer.from(item.tag.SkullOwner.Properties.textures[0].Value, 'base64').toString());
let url = json.textures.SKIN.url;
let uuid = url.split("/").pop();
item.texture_path = `/head/${uuid}?v5`;
}catch(e){
}
}
let lore_raw;
// Set HTML lore to be displayed on the website
if(objectPath.has(item, 'tag.display.Lore')){
lore_raw = item.tag.display.Lore;
item.lore = '';
lore_raw.forEach((line, index) => {
item.lore += module.exports.renderLore(line);
if(index + 1 <= lore_raw.length)
item.lore += '<br>';
});
if(objectPath.has(item, 'tag.ExtraAttributes.anvil_uses')){
let { anvil_uses } = item.tag.ExtraAttributes;
let hot_potato_count = 0;
if('hot_potato_count' in item.tag.ExtraAttributes)
({ hot_potato_count } = item.tag.ExtraAttributes);
anvil_uses -= hot_potato_count;
if(anvil_uses > 0 && lore_raw)
item.lore += "<br>" + module.exports.renderLore(`§7Anvil Uses: §c${anvil_uses}`);
}
}
let lore = lore_raw ? lore_raw.map(a => a = module.exports.getRawLore(a)) : [];
let rarity, item_type;
if(lore.length > 0){
// Get item type (like "bow") and rarity (like "legendary") from last line of lore
let rarity_type = lore[lore.length - 1];
rarity_type = module.exports.splitWithTail(rarity_type, " ", 1);
rarity = rarity_type[0];
if(rarity_type.length > 1)
item_type = rarity_type[1].trim();
item.rarity = rarity.toLowerCase();
if(item_type)
item.type = item_type.toLowerCase();
item.stats = {};
// Get item stats from lore
lore.forEach(line => {
let split = line.split(":");
if(split.length < 2)
return;
let stat_type = split[0];
let stat_value = parseInt(split[1].trim().replace(/,/g, ''));
switch(stat_type){
case 'Damage':
item.stats.damage = stat_value;
break;
case 'Health':
item.stats.health = stat_value;
break;
case 'Defense':
item.stats.defense = stat_value;
break;
case 'Strength':
item.stats.strength = stat_value;
break;
case 'Speed':
item.stats.speed = stat_value;
break;
case 'Crit Chance':
item.stats.crit_chance = stat_value;
break;
case 'Crit Damage':
item.stats.crit_damage = stat_value;
break;
case 'Intelligence':
item.stats.intelligence = stat_value;
break;
}
});
// Apply Speed Talisman speed bonus
if(objectPath.has(item, 'tag.ExtraAttributes.id') && item.tag.ExtraAttributes.id == 'SPEED_TALISMAN'){
lore.forEach(line => {
if(line.startsWith('Gives')){
let split = line.split("Gives +");
if(split.length < 2)
return;
let speed = parseInt(split[1]);
if(!isNaN(speed))
item.stats.speed = speed;
}
})
}
}
// Add snow canon and blaster to weapons
if(objectPath.has(item, 'tag.ExtraAttributes.id') && ['SNOW_CANNON', 'SNOW_BLASTER'].includes(item.tag.ExtraAttributes.id))
item.type = 'bow';
// Workaround for detecting item types if another language is set by the player on Hypixel
if(objectPath.has(item, 'tag.ExtraAttributes.id') && item.tag.ExtraAttributes.id != 'ENCHANTED_BOOK'){
if(objectPath.has(item, 'tag.ExtraAttributes.enchantments')){
if('sharpness' in item.tag.ExtraAttributes.enchantments
|| 'crticial' in item.tag.ExtraAttributes.enchantments
|| 'ender_slayer' in item.tag.ExtraAttributes.enchantments
|| 'execute' in item.tag.ExtraAttributes.enchantments
|| 'first_strike' in item.tag.ExtraAttributes.enchantments
|| 'giant_killer' in item.tag.ExtraAttributes.enchantments
|| 'lethality' in item.tag.ExtraAttributes.enchantments
|| 'life_steal' in item.tag.ExtraAttributes.enchantments
|| 'looting' in item.tag.ExtraAttributes.enchantments
|| 'luck' in item.tag.ExtraAttributes.enchantments
|| 'scavenger' in item.tag.ExtraAttributes.enchantments
|| 'vampirism' in item.tag.ExtraAttributes.enchantments
|| 'bane_of_arthropods' in item.tag.ExtraAttributes.enchantments
|| 'smite' in item.tag.ExtraAttributes.enchantments)
item.type = 'sword';
if('power' in item.tag.ExtraAttributes.enchantments
|| 'aiming' in item.tag.ExtraAttributes.enchantments
|| 'dragon_hunter' in item.tag.ExtraAttributes.enchantments
|| 'infinite_quiver' in item.tag.ExtraAttributes.enchantments
|| 'power' in item.tag.ExtraAttributes.enchantments
|| 'snipe' in item.tag.ExtraAttributes.enchantments
|| 'punch' in item.tag.ExtraAttributes.enchantments
|| 'flame' in item.tag.ExtraAttributes.enchantments
|| 'piercing' in item.tag.ExtraAttributes.enchantments)
item.type = 'bow';
if('angler' in item.tag.ExtraAttributes.enchantments
|| 'blessing' in item.tag.ExtraAttributes.enchantments
|| 'caster' in item.tag.ExtraAttributes.enchantments
|| 'frail' in item.tag.ExtraAttributes.enchantments
|| 'luck_of_the_sea' in item.tag.ExtraAttributes.enchantments
|| 'lure' in item.tag.ExtraAttributes.enchantments
|| 'magnet' in item.tag.ExtraAttributes.enchantments)
item.type = 'fishing rod';
}
}
if(!objectPath.has(item, 'display_name') && objectPath.has(item, 'id')){
let vanillaItem = mcData.items[item.id];
if(vanillaItem && objectPath.has(vanillaItem, 'displayName'))
item.display_name = vanillaItem.displayName;
}
}
for(let item of items){
if(item.inBackpack){
items[item.backpackIndex].containsItems.push(Object.assign({}, item));
}
}
items = items.filter(a => !a.inBackpack);
return items;
}
// XP required for each level of a skill
const leveling_xp = {
1: 50,
2: 125,
3: 200,
4: 300,
5: 500,
6: 750,
7: 1000,
8: 1500,
9: 2000,
10: 3500,
11: 5000,
12: 7500,
13: 10000,
14: 15000,
15: 20000,
16: 30000,
17: 50000,
18: 75000,
19: 100000,
20: 200000,
21: 300000,
22: 400000,
23: 500000,
24: 600000,
25: 700000,
26: 800000,
27: 900000,
28: 1000000,
29: 1100000,
30: 1200000,
31: 1300000,
32: 1400000,
33: 1500000,
34: 1600000,
35: 1700000,
36: 1800000,
37: 1900000,
38: 2000000,
39: 2100000,
40: 2200000,
41: 2300000,
42: 2400000,
43: 2500000,
44: 2600000,
45: 2700000,
46: 2800000,
47: 3100000,
48: 3400000,
49: 3700000,
50: 4000000
};
// XP required for each level of Runecrafting
const runecrafting_xp = {
1: 50,
2: 100,
3: 125,
4: 160,
5: 200,
6: 250,
7: 315,
8: 400,
9: 500,
10: 625,
11: 785,
12: 1000,
13: 1250,
14: 1600,
15: 2000,
16: 2465,
17: 3125,
18: 4000,
19: 5000,
20: 6200,
21: 7800,
22: 9800,
23: 12200,
24: 15300
}
const slayer_xp = {
1: 5,
2: 15,
3: 200,
4: 1000,
5: 5000,
6: 20000,
7: 100000,
8: 400000
};
// Player stats on a completely new profile
const base_stats = {
damage: 0,
health: 100,
defense: 0,
effective_health: 100,
strength: 0,
damage_increase: 0,
speed: 100,
crit_chance: 20,
crit_damage: 50,
intelligence: 0
};
const stat_template = {
damage: 0,
health: 0,
defense: 0,
effective_health: 0,
strength: 0,
damage_increase: 0,
speed: 0,
crit_chance: 0,
crit_damage: 0,
intelligence: 0
};
// Object with fairy soul, skill, slayer bonuses and enchantment bonuses
const bonus_stats = {
fairy_souls: {
5: {
health: 3,
defense: 1,
strength: 1,
speed: 0
},
10: {
health: 3,
defense: 1,
strength: 1,
speed: 0
},
15: {
health: 4,
defense: 1,
strength: 1,
speed: 0
},
20: {
health: 4,
defense: 1,
strength: 1,
speed: 0
},
25: {
health: 5,
defense: 2,
strength: 2,
speed: 0
},
30: {
health: 5,
defense: 1,
strength: 1,
speed: 0
},
35: {
health: 6,
defense: 1,
strength: 1,
speed: 0
},
40: {
health: 6,
defense: 1,
strength: 1,
speed: 0
},
45: {
health: 7,
defense: 1,
strength: 1,
speed: 0
},
50: {
health: 7,
defense: 2,
strength: 2,
speed: 1
},
55: {
health: 8,
defense: 1,
strength: 1,
speed: 0
},
60: {
health: 8,
defense: 1,
strength: 1,
speed: 0
},
65: {
health: 9,
defense: 1,
strength: 1,
speed: 0
},
70: {
health: 9,
defense: 1,
strength: 1,
speed: 0
},
75: {
health: 10,
defense: 2,
strength: 2,
speed: 0
},
80: {
health: 10,
defense: 1,
strength: 1,
speed: 0
},
85: {
health: 11,
defense: 1,
strength: 1,
speed: 0
},
90: {
health: 11,
defense: 1,
strength: 1,
speed: 0
},
95: {
health: 12,
defense: 1,
strength: 1,
speed: 0
},
100: {
health: 12,
defense: 2,
strength: 2,
speed: 1
},
105: {
health: 13,
defense: 1,
strength: 1,
speed: 0
},
110: {
health: 13,
defense: 1,
strength: 1,
speed: 0
},
115: {
health: 14,
defense: 1,
strength: 1,
speed: 0
},
120: {
health: 14,
defense: 1,
strength: 1,
speed: 0
},
125: {
health: 15,
defense: 2,
strength: 2,
speed: 0
},
130: {
health: 15,
defense: 1,
strength: 1,
speed: 0
},
135: {
health: 16,
defense: 1,
strength: 1,
speed: 0
},
140: {
health: 16,
defense: 1,
strength: 1,
speed: 0
},
145: {
health: 17,
defense: 1,
strength: 1,
speed: 0
},
150: {
health: 17,
defense: 2,
strength: 2,
speed: 1
},
155: {
health: 18,
defense: 1,
strength: 1,
speed: 0
},
160: {
health: 18,
defense: 1,
strength: 1,
speed: 0
},
165: {
health: 19,
defense: 1,
strength: 1,
speed: 0
},
170: {
health: 19,
defense: 1,
strength: 1,
speed: 0
},
175: {
health: 20,
defense: 2,
strength: 2,
speed: 0
},
180: {
health: 20,
defense: 1,
strength: 1,
speed: 0
},
185: {
health: 21,
defense: 1,
strength: 1,
speed: 0
},
190: {
health: 21,
defense: 1,
strength: 1,
speed: 0
}
},
farming_skill: {
1: {
health: 2
},
15: {
health: 3
},
20: {
health: 4
},
26: {
health: 5
}
},
combat_skill: {
1: {
crit_chance: 1,
damage_increase: 0.04
}
},
mining_skill: {
1: {
defense: 1
},
15: {
defense: 2
}
},
foraging_skill: {
1: {
strength: 1
},
15: {
strength: 2
}
},
fishing_skill: {
1: {
health: 2
},
15: {
health: 3
},
20: {
health: 4
},
26: {
health: 5
}
},
enchanting_skill: {
1: {
intelligence: 1
},
15: {
intelligence: 2
}
},
alchemy_skill: {
1: {
intelligence: 1
},
15: {
intelligence: 2
}
},
carpentry_skill: {
1: {
}
},
runecrafting_skill: {
1: {
}
},
zombie_slayer: {
1: {
health: 2
},
3: {
health: 3
},
5: {
health: 4
},
7: {
health: 5
},
9: {
health: 6
}
},
spider_slayer: {
1: {
crit_damage: 1
},
5: {
crit_damage: 2
},
9: {
crit_chance: 3
}
},
wolf_slayer: {
1: {
speed: 1
},
2: {
health: 2
},
3: {
speed: 1
},
4: {
health: 2
},
5: {
crit_damage: 1
},
6: {
health: 3
},
7: {
crit_damage: 2
},
8: {
speed: 1
}
},
enchantments: {
sharpness: {
1: {
damage_multiplicator: 0.05
}
},
ender: {
1: {
damage_multiplicator: 0.12
}
},
giant_killer: {
1: {
damage_multiplicator: 0.05
}
},
cubism: {
1: {
damage_multiplicator: 0.1
}
},
impaling: {
1: {
damage_multiplicator: 0.125
}
},
critical: {
1: {
crit_damage: 10
}
},
first_strike: {
1: {
damage_multiplicator: 0.25
}
},
power: {
1: {
damage_multiplicator: 0.08
}
}
},
};
// Minecraft color and formatting codes
const minecraft_formatting = {
0: {
type: 'color',
css: 'color: #000000'
},
1: {
type: 'color',
css: 'color: #0000AA'
},
2: {
type: 'color',
css: 'color: #00AA00'
},
3: {
type: 'color',
css: 'color: #44DDDD'
},
4: {
type: 'color',
css: 'color: #CC3333'
},
5: {
type: 'color',
css: 'color: #AA00AA'
},
6: {
type: 'color',
css: 'color: #FFAA00'
},
7: {
type: 'color',
css: 'color: #AAAAAA'
},
8: {
type: 'color',
css: 'color: #777777'
},
9: {
type: 'color',
css: 'color: #8888FF'
},
a: {
type: 'color',
css: 'color: #55FF55'
},
b: {
type: 'color',
css: 'color: #55FFFF'
},
c: {
type: 'color',