-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathcompile.js
976 lines (837 loc) · 32.2 KB
/
compile.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
/**
* Compile script for the json data. Basically, put all your txt files into
* the txt/ directory, and this will compile it all into json. It assumes that
* you've provided at least 'armor.txt', 'weapons.txt', 'TreasureClassEx.txt',
* 'ItemTypes.txt', and 'monstats.txt'.
*
* @todo Refactor it, since I hacked it together fairly quickly.
*/
require('./objext.js');
const fs = require('fs');
const lineEnd = /[\n\r]+/g, fieldEnd = /\t/g, full = {};
const inDir = 'txt/';
const outDir = 'json/';
const files = fs.readdirSync(inDir).filter(fn => fn.slice(-4) === '.txt').map(fn => fn.slice(0, -4));
const decimalPrecision = 15;
function keySort(obj) {
let keys = Object.keys(obj).sort(), ret = {};
keys.forEach(key => {
ret[key] = obj[key];
});
return ret;
}
const indexes = {
actinfo: 'act',
armor: 'code',
armtype: 'Token',
bodylocs: 'Code',
books: 'Name',
charstats: 'class',
colors: 'Code',
compcode: 'code',
composit: 'Name',
cubemod: 'Code',
difficultylevels: 'Name',
elemtypes: 'Code',
experience: 'Level',
events: 'event',
gems: 'code',
hirelingdesc: 'id',
hitclass: 'Code',
inventory: 'class',
itemstatcost: 'Stat',
itemtypes: 'Code',
levelgroups: 'Name',
levels: 'Id',
lvlmaze: 'Level',
lvlprest: 'Def',
lvltypes: 'Name',
misc: 'code',
misscalc: 'code',
missiles: 'Missile',
monai: 'AI',
monmode: 'code',
monprop: 'Id',
monstats: 'Id',
monstats2: 'Id',
monsounds: 'Id',
montype: 'type',
monumod: 'id',
npc: 'npc',
objmode: 'Token',
overlay: 'overlay',
pettype: 'pet type',
plrmode: 'Code',
plrtype: 'Token',
playerclass: 'Code',
properties: 'code',
runes: '*Rune Name',
setitems: 'index',
sets: 'index',
shrines: 'Code',
skillcalc: 'code',
skilldesc: 'code',
skills: '*Id',
soundenviron: 'Handle',
sounds: '*Index',
states: 'state',
storepage: 'Code',
superuniques: 'Superunique',
treasureclassex: 'Treasure Class',
uniqueitems: '*ID',
weapons: 'code',
weaponclass: 'Code',
};
const filterValues = {
'': true,
'unused': true,
'none': true,
'null': true,
};
function noDrop(e, nd, ...d) {
if (e <= 1) {
return nd | 0;
}
e = e | 0;
nd = nd | 0;
d = d.reduce((t, v) => t + v | 0, 0);
if (d < 1) {
return Infinity;
}
return (d / (((nd + d) / nd)**e - 1)) | 0;
}
files.forEach(fn => {
let data = fs.readFileSync(inDir + fn + '.txt').toString().split(lineEnd);
let header = data.shift().split(fieldEnd);
let indexColumn = header.indexOf(indexes[fn]);
let usesVersion = header.includes('version');
let expansion = false;
let maxKeyCount = 0;
if (indexColumn === -1) {
console.log('Using default Index for:', fn);
}
full[fn] = data.reduce((obj, line, index) => {
if (line.trim()) {
line = line.split(fieldEnd).map(v => v.trim());
if (line[0].toLowerCase() === 'expansion') {
expansion = true;
} else if (header.length === 1 || line.filter(Boolean).length > 1) {
let key = indexColumn >= 0 ? (line[indexColumn]) : index;
if (key !== undefined) {
if (key !== '') {
while (obj[key]) {
console.warn('Duplicate key ' + JSON.stringify(key) + ' in ' + fn);
key += ' [dup]';
}
{
let tmp = {};
for (let c = 0; c < header.length; c++) {
if (indexColumn >= 0 && c === indexColumn || !filterValues[line[c].toString().toLowerCase()]) {
tmp[header[c] || 'unknown'] = line[c] !== 'Infinity' && Number(line[c]).toString() === line[c].trim() ? Number(line[c]) : line[c];
}
}
let keyCount = Object.keys(tmp).length;
if (keyCount > 0) {
if (usesVersion) {
if (tmp.version >= 100) {
tmp.expansion = 1;
}
} else if (expansion) {
tmp.expansion = 1;
}
obj[key] = tmp;
delete obj[key]['*eol'];
delete obj[key]['*EOL'];
delete obj[key]['eol'];
delete obj[key]['EOL'];
if (indexColumn >= 0) {
obj[key].lineNumber = index;
}
}
maxKeyCount = Math.max(maxKeyCount, keyCount);
}
}
} else {
throw new Error('No viable key in: ' + fn + ' : ' + key);
}
}
}
return obj;
}, {});
if (maxKeyCount === 1) {
full[fn] = Object.values(full[fn]).map(line => Object.values(line)[0]);
console.log(fn, 'was reduced!');
}
if (fn === 'treasureclassex') {
full[fn].forEach(tc => {
let precalc = {}, nodropcalc = {
1: 0,
2: 0,
3: 0,
4: 0,
5: 0,
6: 0,
7: 0,
8: 0,
};
if (tc.Picks > 0) {
let total = 0;
for (let c = 1; c <= 9; c++) {
if (tc['Item' + c]) {
total += tc['Prob' + c] | 0;
}
}
[1, 2, 3, 4, 5, 6, 7, 8].forEach(exp => {
nodropcalc[exp] = noDrop(exp, tc.NoDrop, total);
});
for (let c = 1; c <= 9; c++) {
if (tc['Item' + c]) {
let prob = (tc['Prob' + c] | 0) / total;
precalc[tc['Item' + c]] = precalc[tc['Item' + c]] || 0;
precalc[tc['Item' + c]] += prob;
}
}
precalc = precalc.map(v => v * tc.Picks);
tc['*ItemProbTotal'] = total;
}
else if (tc.Picks < 0) {
let picksleft = -tc.Picks;
for (let c = 1; c <= 9; c++) {
if (tc['Item' + c] && picksleft > 0) {
let pickcount = Math.min(picksleft, tc['Prob' + c] | 0);
if (pickcount > 0) {
precalc[tc['Item' + c]] = precalc[tc['Item' + c]] || 0;
precalc[tc['Item' + c]] += pickcount;
picksleft -= pickcount;
}
}
}
}
tc.nodropcalc = nodropcalc;
tc.precalc = precalc;
});
}
if (fn === 'superuniques') {
full[fn]['Bishibosh'].areaId = 3;
full[fn]['Bonebreak'].areaId = 18;
full[fn]['Coldcrow'].areaId = 9;
full[fn]['Rakanishu'].areaId = 4;
full[fn]['Treehead WoodFist'].areaId = 5;
full[fn]['Griswold'].areaId = 38;
full[fn]['The Countess'].areaId = 25;
full[fn]['Pitspawn Fouldog'].areaId = 30;
full[fn]['Boneash'].areaId = 33;
full[fn]['Radament'].areaId = 49;
full[fn]['Bloodwitch the Wild'].areaId = 60;
full[fn]['Fangskin'].areaId = 61;
full[fn]['Beetleburst'].areaId = 43;
full[fn]['Leatherarm'].areaId = 59;
full[fn]['Coldworm the Burrower'].areaId = 64;
full[fn]['Fire Eye'].areaId = 54;
full[fn]['Dark Elder'].areaId = 44;
// full[fn]['The Summoner'].areaId = 74; // I don't think he spawns a superunique.
full[fn]['The Smith'].areaId = 28;
full[fn]['Web Mage the Burning'].areaId = 85;
full[fn]['Witch Doctor Endugu'].areaId = 91;
full[fn]['Stormtree'].areaId = 78;
full[fn]['Sarina the Battlemaid'].areaId = 94;
full[fn]['Icehawk Riftwing'].areaId = 92;
full[fn]['Ismail Vilehand'].areaId = 83;
full[fn]['Geleb Flamefinger'].areaId = 83;
full[fn]['Bremm Sparkfist'].areaId = 102;
full[fn]['Toorc Icefist'].areaId = 83;
full[fn]['Wyand Voidfinger'].areaId = 102;
full[fn]['Maffer Dragonhand'].areaId = 102;
full[fn]['Infector of Souls'].areaId = 108;
full[fn]['Lord De Seis'].areaId = 108;
full[fn]['Grand Vizier of Chaos'].areaId = 108;
full[fn]['The Cow King'].areaId = 39;
full[fn]['Corpsefire'].areaId = 8;
full[fn]['The Feature Creep'].areaId = 107;
full[fn]['Siege Boss'].areaId = 110;
full[fn]['Ancient Barbarian 1'].areaId = 120;
full[fn]['Ancient Barbarian 2'].areaId = 120;
full[fn]['Ancient Barbarian 3'].areaId = 120;
full[fn]['Bonesaw Breaker'].areaId = 115;
full[fn]['Dac Farren'].areaId = 110;
full[fn]['Megaflow Rectifier'].areaId = 111;
full[fn]['Eyeback Unleashed'].areaId = 111;
full[fn]['Threash Socket'].areaId = 112;
full[fn]['Pindleskin'].areaId = 121;
full[fn]['Snapchip Shatter'].areaId = 119;
full[fn]['Sharp Tooth Sayer'].areaId = 111;
full[fn]['Frozenstein'].areaId = 114;
full[fn]['Nihlathak Boss'].areaId = 124;
full[fn]['Baal Subject 1'].areaId = 131;
full[fn]['Baal Subject 2'].areaId = 131;
full[fn]['Baal Subject 3'].areaId = 131;
full[fn]['Baal Subject 4'].areaId = 131;
full[fn]['Baal Subject 5'].areaId = 131;
}
if (fn === 'monstats') {
full[fn]['bloodraven'].areaId = 17;
full[fn]['summoner'].areaId = 74;
full[fn]['andariel'].areaId = 37;
full[fn]['duriel'].areaId = 73;
full[fn]['mephisto'].areaId = 102;
full[fn]['izual'].areaId = 105;
full[fn]['diablo'].areaId = 108;
full[fn]['baalcrab'].areaId = 132;
full[fn]['ubermephisto'].areaId = 136;
full[fn]['uberdiablo'].areaId = 136;
full[fn]['uberizual'].areaId = 135;
full[fn]['uberandariel'].areaId = 133;
full[fn]['uberduriel'].areaId = 134;
full[fn]['uberbaal'].areaId = 136;
}
});
const items = {};
[
...Object.values(full.weapons).sort((a, b) => a.lineNumber - b.lineNumber),
...Object.values(full.armor).sort((a, b) => a.lineNumber - b.lineNumber),
...Object.values(full.misc).sort((a, b) => a.lineNumber - b.lineNumber),
].forEach((item, classid) => {
item.classid = classid;
items[item.code] = item;
});
let atomic = {};
let atomicTypes = {};
let atomicMax = 87;
let calcTC = x => {
let ret = Math.max(1, Math.ceil((x || 0) / 3)) * 3;
atomicMax = Math.max(ret, atomicMax);
return ret;
}
let weaponsarmor = [...Object.values(full.weapons), ...Object.values(full.armor)];
weaponsarmor.forEach(item => {
if (!item.spawnable) {
return;
}
let tc = calcTC(item.level);
function handleAtomic(itemType) {
if (full.itemtypes[itemType] && itemType !== 'tpot') {
if (full.itemtypes[itemType].TreasureClass) {
atomicTypes[itemType] = true;
atomic[itemType + tc] = atomic[itemType + tc] || [];
atomic[itemType + tc][item.lineNumber] = item.code;
}
if (full.itemtypes[itemType].Equiv1) {
handleAtomic(full.itemtypes[itemType].Equiv1);
}
if (full.itemtypes[itemType].Equiv2) {
handleAtomic(full.itemtypes[itemType].Equiv2);
}
}
}
handleAtomic(item.type);
});
atomicTypes = Object.keys(atomicTypes);
for (let c = 3; c <= atomicMax; c += 3) {
atomicTypes.forEach(type => {
atomic[type + c] = atomic[type + c] || [];
});
}
atomic.forEach((atom, atomName) => {
let precalc = {}, total = 0;
atom.forEach((itc, i) => {
let rarity = full.itemtypes[items[itc].type].Rarity | 0;
total += rarity;
atom[i] = [itc, rarity];
});
atom.forEach(([itc, chance]) => {
precalc[itc] = chance / total;
});
atomic[atomName] = precalc;
});
full.atomic = atomic;
let groupsEx = {};
full.treasureclassex.forEach((tc, key) => {
if (tc.group) {
groupsEx[tc.group] = groupsEx[tc.group] || [];
groupsEx[tc.group][tc.level|0] = key;
}
});
groupsEx = groupsEx.map(group => {
let length = group.length;
group = Object.assign({}, group);
group.length = length;
return group;
});
function avg(...nums) {
return nums.reduce((t, v) => t + v, 0) / nums.length || 0;
}
function _s(diff) {
return (str) => str + ["", "(N)", "(H)"][diff];
}
function monlevel(mon, level, diff) {
if (!diff) {
return mon["Level"] || 0;
}
let s = _s(diff),
lvl = level[s("MonLvlEx")] || 0,
mlvl = mon[s("Level")] || 0;
return (diff && !mon.boss) ? lvl : mlvl;
}
function forEachMonster(level, diff, func) {
let s = _s(diff);
[0, 1, 2].forEach((type) => {
if (type && !level[s("MonUMin")] && !level[s("MonUMax")]) {
return;
}
let m = (num) => level[(diff ? "nmon" : type ? "umon" : "mon") + num];
let totalrarity = 0;
let rarity = {};
for (let c = 1; c <= 9; c++) {
if (m(c)) {
let mon = full.monstats[m(c)];
if (mon && mon.enabled && mon.killable) {
totalrarity += mon.Rarity || 0;
rarity[mon.Id] = rarity[mon.Id] || 0;
rarity[mon.Id] += (mon.Rarity || 0);
}
}
}
for (let key in rarity) {
let mon = full.monstats[key];
if (rarity[key] > 0 && mon && mon.enabled && mon.killable) {
let mlvl = monlevel(mon, level, diff) + [0, 2, 3][type];
func(mon, mlvl, type, rarity[key] / totalrarity);
}
}
});
}
const moncountest = require('./json/moncountest.json');
let monpopulation = {};
[0, 1, 2].forEach((diff) => {
let uniqueCount = 3.5 + diff;
let champCount = 3;
let uniqueRatio = 0.8, champRatio = 0.2;
let s = _s(diff);
full.levels.forEach((level) => {
let l = (key) => level[key] || 0;
monpopulation[level.Id] = monpopulation[level.Id] || {
'normal': {},
'champion': {},
'unique': {},
'superunique': {},
'boss': {},
};
if (level.Id) {
let supers = full.superuniques.filter(s => s.areaId == level.Id || (s.hcIdx === 19 && [66, 67, 68, 69, 70, 71, 72].includes(level.Id | 0))),
bosses = full.monstats.filter((mon) => mon.areaId == level.Id),
acount = (moncountest[level.Id] && moncountest[level.Id][diff]) || 0,
scount = supers.reduce((total, sup) => {
let mon = full.monstats[sup.Class];
return (
total +
1 +
diff +
avg(
(sup["MinGrp"] || 0),
(sup["MaxGrp"] || 0)
) +
avg(
(mon["PartyMin"] || 0),
(mon["PartyMax"] || 0)
)
);
}, 0),
bcount = bosses.reduce((total, mon) => {
return (
total +
1 +
avg(
(mon["MinGrp"] || 0),
(mon["MaxGrp"] || 0)
) +
avg(
(mon["PartyMin"] || 0),
(mon["PartyMax"] || 0)
)
);
}, 0),
monucount = avg(l(s("MonUMin")), l(s("MonUMax"))),
ucount = monucount * uniqueRatio * uniqueCount,
ccount = 0;
forEachMonster(level, diff, (mon, mlvl, type, rarity) => {
if (type === 1) {
ccount += (monucount * rarity * champRatio) * (champCount + avg((mon["PartyMin"] || 0), (mon["PartyMax"] || 0)));
}
});
let count = acount - ucount - ccount - scount - bcount;
if (count > 0) {
let ratio = [{}, {}, {}, {}, {}];
forEachMonster(level, diff, (mon, mlvl, type, rarity) => {
let grp = [
avg(
(mon["MinGrp"] || 0),
(mon["MaxGrp"] || 0)
),
3,
1,
][type];
ratio[type][mon.Id] = rarity * grp +
avg(
(mon["PartyMin"] || 0),
(mon["PartyMax"] || 0)
);
});
for (let stype = 0; stype < 5; stype++) {
let totalratio = 0;
for (let skey in ratio[stype]) {
totalratio += ratio[stype][skey];
}
for (let skey in ratio[stype]) {
ratio[stype][skey] /= totalratio;
}
}
forEachMonster(level, diff, (mon, mlvl, type, rarity) => {
let mult = [
count * ratio[type][mon.Id] / (avg((mon["MinGrp"] || 0), (mon["MaxGrp"] || 0)) + avg((mon["PartyMin"] || 0), (mon["PartyMax"] || 0))),
monucount * rarity * champRatio,
monucount * rarity * uniqueRatio,
][type];
monpopulation[level.Id][['normal', 'champion', 'unique'][type]][mon.Id] = monpopulation[level.Id][['normal', 'champion', 'unique'][type]][mon.Id] || {
"mlvl": 0,
"packCount": 0,
"mlvl(N)": 0,
"packCount(N)": 0,
"mlvl(H)": 0,
"packCount(H)": 0,
};
monpopulation[level.Id][['normal', 'champion', 'unique'][type]][mon.Id][s('mlvl')] = mlvl;
monpopulation[level.Id][['normal', 'champion', 'unique'][type]][mon.Id][s('packCount')] = Math.round(mult * (10 ** decimalPrecision)) / (10 ** decimalPrecision);
});
}
supers.forEach((sup) => {
let mon = full.monstats[sup.Class],
mlvl = monlevel(mon, level, diff) + 3;
monpopulation[level.Id]['superunique'][sup.Superunique] = monpopulation[level.Id]['superunique'][sup.Superunique] || {
"mlvl": 0,
"packCount": 0,
"mlvl(N)": 0,
"packCount(N)": 0,
"mlvl(H)": 0,
"packCount(H)": 0,
"hasStaticLevel": false,
};
monpopulation[level.Id]['superunique'][sup.Superunique][s('mlvl')] = mlvl;
monpopulation[level.Id]['superunique'][sup.Superunique][s('packCount')] = sup.hcIdx === 19 ? 1 / 7 : 1;
monpopulation[level.Id]['superunique'][sup.Superunique].hasStaticLevel = Boolean(mon.boss);
});
bosses.forEach((mon) => {
let mlvl = monlevel(mon, level, diff);
monpopulation[level.Id]['boss'][mon.Id] = monpopulation[level.Id]['boss'][mon.Id] || {
"mlvl": 0,
"packCount": 0,
"mlvl(N)": 0,
"packCount(N)": 0,
"mlvl(H)": 0,
"packCount(H)": 0,
"hasStaticLevel": false,
};
monpopulation[level.Id]['boss'][mon.Id][s('mlvl')] = mlvl;
monpopulation[level.Id]['boss'][mon.Id][s('packCount')] = 1;
monpopulation[level.Id]['boss'][mon.Id].hasStaticLevel = Boolean(mon.boss);
});
}
});
});
let actprofile = {};
let montypes = ['normal', 'champion', 'unique', 'superunique', 'boss'];
let dmgtypes = [
'ResDm',
'ResMa',
'ResFi',
'ResLi',
'ResCo',
'ResPo',
];
let progressionAreas = [ // Areas that we're forced to deal with while progressing through the main quest lines.
// Act 1
2,3,4,5,6,7,10,26,27,28,29,30,31,32,33,34,35,36,
// Act 2
41,42,43,44,45,46,50,51,52,53,54,56,57,58,60,61,62,63,64,66,67,68,69,70,71,72,73,
// Act 3
76,77,78,79,80,81,82,83,85,88,89,91,92,93,100,101,
// Act 4
104,105,106,107,
// Act 5
110,111,112,113,115,117,118,120,128,129,130,
];
let bossAreas = [ // Areas that we're forced to deal with for boss farming.
37,74,102,108,131,132,
];
for (let diff of [0, 1, 2]) {
let s = str => str + ['', '(N)', '(H)'][diff];
for (let levelid in monpopulation) {
levelid = Number(levelid);
let level = full.levels[levelid];
let act = (level.Act || 0);
let pop = monpopulation[levelid];
if (levelid < 1 || levelid > 132) {
continue;
}
let category = bossAreas.indexOf(levelid) >= 0 ? 'boss' : (progressionAreas.indexOf(levelid) >= 0 ? 'progression' : 'optional');
for (let montype of montypes) {
for (let id in pop[montype]) {
let sup = undefined,
mon = undefined;
if (montype === 'superunique') {
sup = full.superuniques[id];
mon = full.monstats[sup.Class];
}
else {
mon = full.monstats[id];
}
let grp = Math.max(1, ((mon['MinGrp'] || 1) + (mon['MaxGrp'] || 1)) / 2),
party = ((mon['PartyMin'] || 0) + mon['PartyMax'] || 0) / 4,
minions = [
mon['minion1'] || undefined,
mon['minion2'] || undefined,
].filter(Boolean),
packCount = pop[montype][id][s('packCount')],
mlvl = pop[montype][id][s('mlvl')],
hp = full.monlvl[mlvl][s('HP')] *
(mon[['minHP', 'MinHP(N)', 'MinHP(H)'][diff]] + mon[['maxHP', 'MaxHP(N)', 'MaxHP(H)'][diff]]) / 200;
if ((montype === 'superunique' || montype === 'unique') && !minions.length) {
minions.push(mon.Id);
}
actprofile[act] = actprofile[act] || {};
actprofile[act][category] = actprofile[act][category] || {};
for (let dmgtype of dmgtypes) {
actprofile[act][category][s(dmgtype)] = actprofile[act][category][s(dmgtype)] || {};
}
for (let dmgtype of dmgtypes) {
let resist = mon[s(dmgtype)] || 0;
actprofile[act][category][s(dmgtype)][resist] = actprofile[act][category][s(dmgtype)][resist] || 0;
if (montype === 'superunique' || montype === 'unique') {
if (montype === 'superunique') {
grp = Math.max(1, ((sup['MinGrp'] || mon['MinGrp'] || 1) + (sup['MaxGrp'] || mon['MaxGrp'] || 1)) / 2);
}
else {
grp = Math.max(1, ((mon['MinGrp'] || 1) + (mon['MaxGrp'] || 1)) / 2);
}
actprofile[act][category][s(dmgtype)][resist] += packCount * hp * [4, 3, 2][diff];
party = 2.5 + diff;
}
else if (montype === 'champion') {
actprofile[act][category][s(dmgtype)][resist] += packCount * hp * 3 * [3, 2.5, 2][diff];
}
else {
actprofile[act][category][s(dmgtype)][resist] += packCount * hp * grp;
}
if (party > 0 && minions.length > 0) {
for (let minion of minions) {
let mmon = full.monstats[minion],
mresist = mmon[s(dmgtype)] || 0,
mmlvl = (diff ? mmon['Level'] : level[s('MonLvl')]) + (montype === 'superunique' || montype === 'unique' ? 3 : 0),
mhp = full.monlvl[mmlvl][s('HP')] *
(mmon[['minHP', 'MinHP(N)', 'MinHP(H)'][diff]] + mmon[['maxHP', 'MaxHP(N)', 'MaxHP(H)'][diff]]) / 100;
actprofile[act][category][s(dmgtype)][mresist] = actprofile[act][category][s(dmgtype)][mresist] || 0;
actprofile[act][category][s(dmgtype)][mresist] += packCount * mhp * party / minions.length;
}
}
}
}
}
}
}
(function roundValues (obj) {
for (let key in obj) {
if (typeof obj[key] === 'number') {
obj[key] = Math.round(obj[key]);
}
else if(typeof obj[key] === 'object') {
roundValues(obj[key]);
}
}
})(actprofile);
let coldmasterybreakpoints = {}, coldhpbyres = {};
for (let act of Object.values(actprofile)) {
for (let resset of Object.values(act)) {
if (resset['ResCo(H)']) {
for (let res in resset['ResCo(H)']) {
res = Number(res);
coldhpbyres[res] = coldhpbyres[res] || 0;
coldhpbyres[res] += resset['ResCo(H)'][res];
}
}
}
}
(function () {
for (let mastery = 0; mastery <= 195; mastery === 0 ? mastery = 20 : mastery ++) {
let ehp = 0;
for (let res in coldhpbyres) {
res = Number(res);
let pierce = (res >= 100 ? (mastery / 5) : mastery);
let mod = Math.min(2, 1 - (Math.min(95, res) - pierce) / 100);
ehp += coldhpbyres[res] / mod;
}
coldmasterybreakpoints[mastery] = ehp;
}
let masterylist = Object.keys(coldmasterybreakpoints);
for (let i = masterylist.length - 1; i; i--) {
coldmasterybreakpoints[masterylist[i]] = (coldmasterybreakpoints[masterylist[i - 1]] / coldmasterybreakpoints[masterylist[i]] - 1);
}
coldmasterybreakpoints[0] = 0;
for (let c = 0; c < 2; c++) {
for (let i = masterylist.length - 1; i; i--) {
coldmasterybreakpoints[masterylist[i]] = coldmasterybreakpoints[masterylist[i]] - coldmasterybreakpoints[masterylist[i - 1]];
}
}
for (let i = masterylist.length - 1; i; i--) {
coldmasterybreakpoints[masterylist[i]] = coldmasterybreakpoints[masterylist[i]] * 10000;
}
let newMasteryList = {}, mmin = Infinity;
for (let i = masterylist.length; i; i--) {
if (coldmasterybreakpoints[masterylist[i]] <= -0.5) {
mmin = Math.min(mmin, -coldmasterybreakpoints[masterylist[i]]);
newMasteryList[masterylist[i - 1]] = -coldmasterybreakpoints[masterylist[i]];
}
}
for (let key in newMasteryList) {
newMasteryList[key] = Math.round(newMasteryList[key] / mmin);
}
coldmasterybreakpoints = newMasteryList;
})();
let tcprecalc = {};
full.treasureclassex.forEach((tc, key) => {
tcprecalc[key] = tcprecalc[key] || {};
tcprecalc[key].droprate = tc.nodropcalc.map(noDrop => noDrop ? tc['*ItemProbTotal'] / (noDrop + tc['*ItemProbTotal']) : 1);
tcprecalc[key].droprateRoot = {};
tcprecalc[key].counts = tc.precalc;
delete tc['nodropcalc'];
delete tc['precalc'];
});
atomic.forEach((precalc, key) => {
tcprecalc[key] = {
droprate: {
1: 1,
2: 1,
3: 1,
4: 1,
5: 1,
6: 1,
7: 1,
8: 1,
},
droprateRoot: {},
counts: precalc,
};
});
// Formulas and coefficients for the 6 item cap are from https://github.com/realmonster/diablo2_drop_calc
// He did a lot of work figuring out the formulas that I don't care to replicate,
// so I'm taking the path of least resistance.
// Adjust droprates for TCs with 7 picks for the 6 item cap.
tcprecalc.forEach((basetc, basekey) => {
if (full.treasureclassex[basekey] && full.treasureclassex[basekey].Picks === 7) {
[1, 2, 3, 4, 5, 6, 7, 8].forEach(playerCount => {
let newvalue = basetc.droprate[playerCount] * (7 - basetc.droprate[playerCount]**6) / 7;
basetc.droprateRoot[playerCount] = newvalue;
});
} else {
basetc.droprateRoot = Object.assign({}, basetc.droprate);
}
});
[
"Duriel",
"Duriel Desecrated A",
"Duriel Desecrated B",
"Duriel Desecrated C",
"Duriel (N)",
"Duriel (N) Desecrated A",
"Duriel (N) Desecrated B",
"Duriel (N) Desecrated C",
"Duriel (H)",
"Duriel (H) Desecrated A",
"Duriel (H) Desecrated B",
"Duriel (H) Desecrated C",
"Duriel (H) Desecrated D",
"Durielq",
"Durielq (N)",
"Durielq (H)",
].forEach(tcname => {
for (let c = 1; c < 9; c++) {
tcprecalc[tcname]['droprateRoot'][c] *= 5 / 11;
}
});
tcprecalc.forEach(tc => {
if (tc['counts']['Sunder Charms']) {
delete tc['counts']['Sunder Charms'];
}
});
// Flatten and abstract countess rune TCs so we can adjust the drop rate of each via coefficient.
//tcprecalc.forEach((tc, key) => {
({
'Countess Rune': tcprecalc['Countess Rune'],
'Countess Rune (N)': tcprecalc['Countess Rune (N)'],
'Countess Rune (H)': tcprecalc['Countess Rune (H)'],
}).forEach((tc, baseName) => {
function flattenAndAbstract (tcName, mult = 1, ret = {}) {
if (tcprecalc[tcName]) {
tcprecalc[tcName].counts.forEach((submult, subtcName) => {
flattenAndAbstract(subtcName, mult * submult, ret);
});
} else {
let newtcName = `${baseName} - ${tcName}`;
if (!tcprecalc[newtcName]) {
tcprecalc[newtcName] = {
droprate: {
1: 1,
2: 1,
3: 1,
4: 1,
5: 1,
6: 1,
7: 1,
8: 1,
},
droprateRoot: {
1: 1,
2: 1,
3: 1,
4: 1,
5: 1,
6: 1,
7: 1,
8: 1,
},
counts: {
[tcName]: 1,
}
};
}
ret[newtcName] = ret[newtcName] || 0;
ret[newtcName] += mult;
}
return ret;
}
tc.counts = flattenAndAbstract(baseName);
});
//});
// Multiply the coefficients to the abstracted TCs
({
'Countess Rune': {"1":{"0.8412177979895897":["r01"],"0.8412177979895898":["r02"],"0.8279977514350507":["r03"],"0.8279977514350506":["r04"],"0.8238064081864378":["r05","r06","r07","r08"]},"2":{"0.5384142786164905":["r01","r02"],"0.4988295919434789":["r03"],"0.498829591943479":["r04"],"0.4862413242371927":["r05","r08"],"0.48624132423719274":["r06","r07"]},"3":{"0.43127418667153955":["r01","r02"],"0.38274414977638443":["r03","r04"],"0.3673191805912878":["r05","r08"],"0.3673191805912879":["r06","r07"]},"4":{"0.4019832189168574":["r01"],"0.40198321891685734":["r02"],"0.3499170812603648":["r03"],"0.34991708126036486":["r04"],"0.3333333333333333":["r05","r07","r08"],"0.33333333333333337":["r06"]},"5":{"0.4019832189168574":["r01"],"0.40198321891685734":["r02"],"0.3499170812603648":["r03"],"0.34991708126036486":["r04"],"0.3333333333333333":["r05","r07","r08"],"0.33333333333333337":["r06"]},"6":{"0.4019832189168574":["r01"],"0.40198321891685734":["r02"],"0.3499170812603648":["r03"],"0.34991708126036486":["r04"],"0.3333333333333333":["r05","r07","r08"],"0.33333333333333337":["r06"]},"7":{"0.4019832189168574":["r01"],"0.40198321891685734":["r02"],"0.3499170812603648":["r03"],"0.34991708126036486":["r04"],"0.3333333333333333":["r05","r07","r08"],"0.33333333333333337":["r06"]},"8":{"0.4019832189168574":["r01"],"0.40198321891685734":["r02"],"0.3499170812603648":["r03"],"0.34991708126036486":["r04"],"0.3333333333333333":["r05","r07","r08"],"0.33333333333333337":["r06"]}},
'Countess Rune (N)': {"1":{"0.8256244546455895":["r01","r02","r05","r06","r11","r14","r16"],"0.8256244546455894":["r03","r07","r09","r12","r13","r15"],"0.8256244546455896":["r04","r08","r10"]},"2":{"0.491703901847278":["r01","r06"],"0.4917039018472779":["r02","r03","r07","r09","r12","r15","r16"],"0.49170390184727797":["r04","r05","r08","r10","r11","r13","r14"]},"3":{"0.37401224832526186":["r01","r02","r05","r06","r11","r12","r14","r15","r16"],"0.3740122483252619":["r03","r04","r07","r08","r09","r10","r13"]},"4":{"0.34053127677806344":["r01","r02","r03","r04","r05","r06","r07","r08","r09","r10","r11"],"0.3405312767780634":["r12","r13","r14","r15","r16"]},"5":{"0.34053127677806344":["r01","r02","r03","r04","r05","r06","r07","r08","r09","r10","r11"],"0.3405312767780634":["r12","r13","r14","r15","r16"]},"6":{"0.34053127677806344":["r01","r02","r03","r04","r05","r06","r07","r08","r09","r10","r11"],"0.3405312767780634":["r12","r13","r14","r15","r16"]},"7":{"0.34053127677806344":["r01","r02","r03","r04","r05","r06","r07","r08","r09","r10","r11"],"0.3405312767780634":["r12","r13","r14","r15","r16"]},"8":{"0.34053127677806344":["r01","r02","r03","r04","r05","r06","r07","r08","r09","r10","r11"],"0.3405312767780634":["r12","r13","r14","r15","r16"]}},
'Countess Rune (H)': {"1":{"0.8219588445252253":["r01","r06"],"0.8219588445252254":["r02","r03","r04","r05","r07","r08","r09","r10","r11","r12","r13","r15","r17","r18","r19","r20","r22","r23","r24"],"0.8219588445252255":["r14","r16","r21"]},"2":{"0.4893751399649079":["r01","r02","r11","r17","r19"],"0.48937513996490795":["r03","r05","r06","r07","r09","r12","r13","r15","r16","r18","r20","r21","r22","r23","r24"],"0.489375139964908":["r04","r08","r10","r14"]},"3":{"0.3733514492176993":["r01","r17"],"0.37335144921769925":["r02","r03","r04","r05","r06","r07","r08","r09","r10","r11","r12","r14","r15","r16","r19","r20","r21","r22","r23","r24"],"0.3733514492176992":["r13","r18"]},"4":{"0.34053976872957364":["r01","r02","r03","r04","r05","r06","r07","r08","r09","r10","r12","r13","r14","r15","r16","r17","r19","r20","r23","r24"],"0.3405397687295737":["r11","r18","r21"],"0.3405397687295736":["r22"]},"5":{"0.34053976872957364":["r01","r02","r03","r04","r05","r06","r07","r08","r09","r10","r12","r13","r14","r15","r16","r17","r19","r20","r23","r24"],"0.3405397687295737":["r11","r18","r21"],"0.3405397687295736":["r22"]},"6":{"0.34053976872957364":["r01","r02","r03","r04","r05","r06","r07","r08","r09","r10","r12","r13","r14","r15","r16","r17","r19","r20","r23","r24"],"0.3405397687295737":["r11","r18","r21"],"0.3405397687295736":["r22"]},"7":{"0.34053976872957364":["r01","r02","r03","r04","r05","r06","r07","r08","r09","r10","r12","r13","r14","r15","r16","r17","r19","r20","r23","r24"],"0.3405397687295737":["r11","r18","r21"],"0.3405397687295736":["r22"]},"8":{"0.34053976872957364":["r01","r02","r03","r04","r05","r06","r07","r08","r09","r10","r12","r13","r14","r15","r16","r17","r19","r20","r23","r24"],"0.3405397687295737":["r11","r18","r21"],"0.3405397687295736":["r22"]}},
}).forEach((data, baseName) => {
[1, 2, 3, 4, 5, 6, 7, 8].forEach(players => {
data[players].forEach((runes, value) => {
value = Number(value);
runes.forEach(runeName => {
tcprecalc[baseName + ' - ' + runeName]['droprate'][players] *= value;
});
});
});
});
files.forEach(fn => {
fs.writeFileSync(outDir + fn + '.json', JSON.stringify(keySort(full[fn]), null, ' '));
});
fs.writeFileSync(outDir + 'items.json', JSON.stringify(items, null, ' '));
fs.writeFileSync(outDir + 'atomic.json', JSON.stringify(keySort(atomic), null, ' '));
fs.writeFileSync(outDir + 'treasureclassgroupsex.json', JSON.stringify(groupsEx, null, ' '));
fs.writeFileSync(outDir + 'monpopulationest.json', JSON.stringify(monpopulation, null, ' '));
fs.writeFileSync(outDir + 'tcprecalc.json', JSON.stringify(tcprecalc, null, ' '));
fs.writeFileSync(outDir + 'actprofile.json', JSON.stringify(actprofile, null, ' '));
fs.writeFileSync(outDir + 'coldmasterybreakpoints.json', JSON.stringify(coldmasterybreakpoints, null, ' '));