@blizzhackers/d2data 2.7.8 → 2.7.10

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/compile.js CHANGED
@@ -13,6 +13,7 @@ const lineEnd = /[\n\r]+/g, fieldEnd = /\t/g, full = {};
13
13
  const inDir = 'txt/';
14
14
  const outDir = 'json/';
15
15
  const files = fs.readdirSync(inDir).filter(fn => fn.slice(-4) === '.txt').map(fn => fn.slice(0, -4));
16
+ const decimalPrecision = 15;
16
17
 
17
18
  function keySort(obj) {
18
19
  let keys = Object.keys(obj).sort(), ret = {};
@@ -443,17 +444,30 @@ function forEachMonster(level, diff, func) {
443
444
 
444
445
  let m = (num) => level[(diff ? "nmon" : type ? "umon" : "mon") + num];
445
446
 
447
+ let totalrarity = 0;
448
+ let rarity = {};
449
+
446
450
  for (let c = 1; c <= 9; c++) {
447
451
  if (m(c)) {
448
452
  let mon = full.monstats[m(c)];
449
453
 
450
454
  if (mon && mon.enabled && mon.killable) {
451
- let mlvl = monlevel(mon, level, diff) + [0, 2, 3][type];
452
-
453
- func(mon, mlvl, type);
455
+ totalrarity += mon.Rarity || 0;
456
+ rarity[mon.Id] = rarity[mon.Id] || 0;
457
+ rarity[mon.Id] += (mon.Rarity || 0);
454
458
  }
455
459
  }
456
460
  }
461
+
462
+ for (let key in rarity) {
463
+ let mon = full.monstats[key];
464
+
465
+ if (rarity[key] > 0 && mon && mon.enabled && mon.killable) {
466
+ let mlvl = monlevel(mon, level, diff) + [0, 2, 3][type];
467
+
468
+ func(mon, mlvl, type, rarity[key] / totalrarity);
469
+ }
470
+ }
457
471
  });
458
472
  }
459
473
 
@@ -512,35 +526,54 @@ let monpopulation = {};
512
526
  )
513
527
  );
514
528
  }, 0),
515
- ucount = avg(l(s("MonUMin")), l(s("MonUMax"))) * uniqueRatio * uniqueCount,
516
- ccount = avg(l(s("MonUMin")), l(s("MonUMax"))) * champRatio * champCount,
517
- count = acount - ucount - ccount - scount - bcount;
529
+ monucount = avg(l(s("MonUMin")), l(s("MonUMax"))),
530
+ ucount = monucount * uniqueRatio * uniqueCount,
531
+ ccount = 0;
532
+
533
+ forEachMonster(level, diff, (mon, mlvl, type, rarity) => {
534
+ if (type === 1) {
535
+ ccount += (monucount * rarity * champRatio) * (champCount + avg((mon["PartyMin"] || 0), (mon["PartyMax"] || 0)));
536
+ }
537
+ });
538
+
539
+ let count = acount - ucount - ccount - scount - bcount;
518
540
 
519
541
  if (count > 0) {
520
- let totalpackssize = 0,
521
- udiv = 0;
522
-
523
- forEachMonster(level, diff, (mon, mlvl, type) => {
524
- if (!type) {
525
- let m = (key) => mon[key] || 0;
526
- let packsize = avg(
527
- m("PartyMin") + m("PartyMax"),
528
- m("MinGrp") + m("MaxGrp")
529
- );
530
-
531
- totalpackssize += packsize;
542
+ let ratio = [{}, {}, {}, {}, {}];
543
+
544
+ forEachMonster(level, diff, (mon, mlvl, type, rarity) => {
545
+ let grp = [
546
+ avg(
547
+ (mon["MinGrp"] || 0),
548
+ (mon["MaxGrp"] || 0)
549
+ ),
550
+ 3,
551
+ 1,
552
+ ][type];
553
+ ratio[type][mon.Id] = rarity * grp +
554
+ avg(
555
+ (mon["PartyMin"] || 0),
556
+ (mon["PartyMax"] || 0)
557
+ );
558
+ });
559
+
560
+ for (let stype = 0; stype < 5; stype++) {
561
+ let totalratio = 0;
562
+
563
+ for (let skey in ratio[stype]) {
564
+ totalratio += ratio[stype][skey];
532
565
  }
533
566
 
534
- if (type === 2) {
535
- udiv++;
567
+ for (let skey in ratio[stype]) {
568
+ ratio[stype][skey] /= totalratio;
536
569
  }
537
- });
570
+ }
538
571
 
539
- forEachMonster(level, diff, (mon, mlvl, type) => {
572
+ forEachMonster(level, diff, (mon, mlvl, type, rarity) => {
540
573
  let mult = [
541
- count / totalpackssize,
542
- ccount / champCount / udiv,
543
- ucount / uniqueCount / udiv,
574
+ count * ratio[type][mon.Id] / (avg((mon["MinGrp"] || 0), (mon["MaxGrp"] || 0)) + avg((mon["PartyMin"] || 0), (mon["PartyMax"] || 0))),
575
+ monucount * rarity * champRatio,
576
+ monucount * rarity * uniqueRatio,
544
577
  ][type];
545
578
  monpopulation[level.Id][['normal', 'champion', 'unique'][type]][mon.Id] = monpopulation[level.Id][['normal', 'champion', 'unique'][type]][mon.Id] || {
546
579
  "mlvl": 0,
@@ -551,7 +584,7 @@ let monpopulation = {};
551
584
  "packCount(H)": 0,
552
585
  };
553
586
  monpopulation[level.Id][['normal', 'champion', 'unique'][type]][mon.Id][s('mlvl')] = mlvl;
554
- monpopulation[level.Id][['normal', 'champion', 'unique'][type]][mon.Id][s('packCount')] = mult;
587
+ monpopulation[level.Id][['normal', 'champion', 'unique'][type]][mon.Id][s('packCount')] = Math.round(mult * (10 ** decimalPrecision)) / (10 ** decimalPrecision);
555
588
  });
556
589
  }
557
590
 
package/generatecsv.js ADDED
@@ -0,0 +1,64 @@
1
+ const monpopulationest = require('./json/monpopulationest.json');
2
+ const superuniques = require('./json/superuniques.json');
3
+ const monstats = require('./json/monstats.json');
4
+ const levels = require('./json/levels.json');
5
+ const localestrings = require('./json/localestrings-eng.json');
6
+ const fs = require('fs');
7
+
8
+ let diffs = ['', '(N)', '(H)'];
9
+
10
+ for (let diff in diffs) {
11
+ let rows = [
12
+ [
13
+ 'Name',
14
+ 'Difficulty',
15
+ 'Is Super?',
16
+ 'Is Boss?',
17
+ 'Area Level',
18
+ 'Base Monster Level',
19
+ 'Actual Monster Level',
20
+ 'Area',
21
+ 'Area ID',
22
+ ],
23
+ ];
24
+
25
+ let diffstr = diffs[diff];
26
+
27
+ function addRow(level, mlvls, mon, sup) {
28
+ rows[rows.length] = [
29
+ localestrings[sup ? sup.Name : mon.NameStr],
30
+ ['normal', 'nightmare', 'hell'][diff],
31
+ sup ? 'yes' : 'no',
32
+ mon.boss ? 'yes' : 'no',
33
+ level['MonLvlEx' + diffstr],
34
+ mon['Level' + diffstr],
35
+ mlvls[diff],
36
+ localestrings[level.LevelName],
37
+ level.Id,
38
+ ];
39
+ }
40
+
41
+ for (let levelId in monpopulationest) {
42
+ let pop = monpopulationest[levelId];
43
+ let level = levels[levelId];
44
+
45
+ for (let superid in pop['superunique']) {
46
+ addRow(level, [
47
+ pop['superunique'][superid]['mlvl'],
48
+ pop['superunique'][superid]['mlvl(N)'],
49
+ pop['superunique'][superid]['mlvl(H)'],
50
+ ], monstats[superuniques[superid].Class], superuniques[superid]);
51
+ }
52
+
53
+ for (let monid in pop['boss']) {
54
+ addRow(level, [
55
+ pop['boss'][monid]['mlvl'],
56
+ pop['boss'][monid]['mlvl(N)'],
57
+ pop['boss'][monid]['mlvl(H)'],
58
+ ], monstats[monid]);
59
+ }
60
+ }
61
+
62
+ let data = rows.map(row => row.map(col => JSON.stringify(col)).join(',')).join('\n');
63
+ fs.writeFileSync(['superboss_normal.csv', 'superboss_nightmare.csv', 'superboss_hell.csv'][diff], data);
64
+ }