@pkmn/randoms 0.5.9 → 0.5.12

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/build/gen8.js CHANGED
@@ -62,6 +62,8 @@ class RandomTeams {
62
62
  this.noStab = NoStab;
63
63
  const ruleTable = this.dex.formats.getRuleTable(format);
64
64
  this.maxTeamSize = ruleTable.maxTeamSize;
65
+ this.adjustLevel = ruleTable.adjustLevel;
66
+ this.maxMoveCount = ruleTable.maxMoveCount;
65
67
  const forceMonotype = ruleTable.valueRules.get('forcemonotype');
66
68
  this.forceMonotype = forceMonotype && this.dex.types.get(forceMonotype).exists ?
67
69
  this.dex.types.get(forceMonotype).name : undefined;
@@ -351,7 +353,7 @@ class RandomTeams {
351
353
  pool = [...new Set(pool.concat(basePool))];
352
354
  }
353
355
  }
354
- const moves = this.multipleSamplesNoReplace(pool, 4);
356
+ const moves = this.multipleSamplesNoReplace(pool, this.maxMoveCount);
355
357
  // Random EVs
356
358
  const evs = { hp: 0, atk: 0, def: 0, spa: 0, spd: 0, spe: 0 };
357
359
  const s = ["hp", "atk", "def", "spa", "spd", "spe"];
@@ -386,18 +388,24 @@ class RandomTeams {
386
388
  mbst += (stats["spa"] * 2 + 31 + 21 + 100) + 5;
387
389
  mbst += (stats["spd"] * 2 + 31 + 21 + 100) + 5;
388
390
  mbst += (stats["spe"] * 2 + 31 + 21 + 100) + 5;
389
- let level = Math.floor(100 * mbstmin / mbst); // Initial level guess will underestimate
390
- while (level < 100) {
391
- mbst = Math.floor((stats["hp"] * 2 + 31 + 21 + 100) * level / 100 + 10);
392
- // Since damage is roughly proportional to level
393
- mbst += Math.floor(((stats["atk"] * 2 + 31 + 21 + 100) * level / 100 + 5) * level / 100);
394
- mbst += Math.floor((stats["def"] * 2 + 31 + 21 + 100) * level / 100 + 5);
395
- mbst += Math.floor(((stats["spa"] * 2 + 31 + 21 + 100) * level / 100 + 5) * level / 100);
396
- mbst += Math.floor((stats["spd"] * 2 + 31 + 21 + 100) * level / 100 + 5);
397
- mbst += Math.floor((stats["spe"] * 2 + 31 + 21 + 100) * level / 100 + 5);
398
- if (mbst >= mbstmin)
399
- break;
400
- level++;
391
+ let level;
392
+ if (this.adjustLevel) {
393
+ level = this.adjustLevel;
394
+ }
395
+ else {
396
+ level = Math.floor(100 * mbstmin / mbst); // Initial level guess will underestimate
397
+ while (level < 100) {
398
+ mbst = Math.floor((stats["hp"] * 2 + 31 + 21 + 100) * level / 100 + 10);
399
+ // Since damage is roughly proportional to level
400
+ mbst += Math.floor(((stats["atk"] * 2 + 31 + 21 + 100) * level / 100 + 5) * level / 100);
401
+ mbst += Math.floor((stats["def"] * 2 + 31 + 21 + 100) * level / 100 + 5);
402
+ mbst += Math.floor(((stats["spa"] * 2 + 31 + 21 + 100) * level / 100 + 5) * level / 100);
403
+ mbst += Math.floor((stats["spd"] * 2 + 31 + 21 + 100) * level / 100 + 5);
404
+ mbst += Math.floor((stats["spe"] * 2 + 31 + 21 + 100) * level / 100 + 5);
405
+ if (mbst >= mbstmin)
406
+ break;
407
+ level++;
408
+ }
401
409
  }
402
410
  // Random happiness
403
411
  const happiness = this.random(256);
@@ -466,7 +474,7 @@ class RandomTeams {
466
474
  banReason = ruleTable.check('basepokemon:' + (0, sim_1.toID)(species.baseSpecies));
467
475
  if (banReason)
468
476
  continue;
469
- if (banReason !== '' || this.dex.species.get(species.baseSpecies).isNonstandard === species.isNonstandard) {
477
+ if (banReason !== '' || this.dex.species.get(species.baseSpecies).isNonstandard !== species.isNonstandard) {
470
478
  const nonexistentCheck = sim_1.Tags.nonexistent.genericFilter(species) && nonexistentBanReason;
471
479
  let tagWhitelisted = false;
472
480
  let tagBlacklisted = false;
@@ -495,11 +503,11 @@ class RandomTeams {
495
503
  }
496
504
  }
497
505
  }
506
+ speciesPool.push(species);
498
507
  const num = species.num;
499
508
  if (pool.includes(num))
500
509
  continue;
501
510
  pool.push(num);
502
- speciesPool.push(species);
503
511
  }
504
512
  }
505
513
  const hasDexNumber = {};
@@ -741,17 +749,23 @@ class RandomTeams {
741
749
  mbst += (stats['spa'] * 2 + 31 + 21 + 100) + 5;
742
750
  mbst += (stats['spd'] * 2 + 31 + 21 + 100) + 5;
743
751
  mbst += (stats['spe'] * 2 + 31 + 21 + 100) + 5;
744
- let level = Math.floor(100 * mbstmin / mbst);
745
- while (level < 100) {
746
- mbst = Math.floor((stats['hp'] * 2 + 31 + 21 + 100) * level / 100 + 10);
747
- mbst += Math.floor(((stats['atk'] * 2 + 31 + 21 + 100) * level / 100 + 5) * level / 100);
748
- mbst += Math.floor((stats['def'] * 2 + 31 + 21 + 100) * level / 100 + 5);
749
- mbst += Math.floor(((stats['spa'] * 2 + 31 + 21 + 100) * level / 100 + 5) * level / 100);
750
- mbst += Math.floor((stats['spd'] * 2 + 31 + 21 + 100) * level / 100 + 5);
751
- mbst += Math.floor((stats['spe'] * 2 + 31 + 21 + 100) * level / 100 + 5);
752
- if (mbst >= mbstmin)
753
- break;
754
- level++;
752
+ let level;
753
+ if (this.adjustLevel) {
754
+ level = this.adjustLevel;
755
+ }
756
+ else {
757
+ level = Math.floor(100 * mbstmin / mbst);
758
+ while (level < 100) {
759
+ mbst = Math.floor((stats['hp'] * 2 + 31 + 21 + 100) * level / 100 + 10);
760
+ mbst += Math.floor(((stats['atk'] * 2 + 31 + 21 + 100) * level / 100 + 5) * level / 100);
761
+ mbst += Math.floor((stats['def'] * 2 + 31 + 21 + 100) * level / 100 + 5);
762
+ mbst += Math.floor(((stats['spa'] * 2 + 31 + 21 + 100) * level / 100 + 5) * level / 100);
763
+ mbst += Math.floor((stats['spd'] * 2 + 31 + 21 + 100) * level / 100 + 5);
764
+ mbst += Math.floor((stats['spe'] * 2 + 31 + 21 + 100) * level / 100 + 5);
765
+ if (mbst >= mbstmin)
766
+ break;
767
+ level++;
768
+ }
755
769
  }
756
770
  // Random happiness
757
771
  const happiness = this.random(256);
@@ -1794,7 +1808,7 @@ class RandomTeams {
1794
1808
  // Random Free-For-All also uses doubles move pools, for now
1795
1809
  const allySwitch = movePool.indexOf('allyswitch');
1796
1810
  if (allySwitch > -1) {
1797
- if (movePool.length > 4) {
1811
+ if (movePool.length > this.maxMoveCount) {
1798
1812
  this.fastPop(movePool, allySwitch);
1799
1813
  }
1800
1814
  else {
@@ -1820,7 +1834,7 @@ class RandomTeams {
1820
1834
  do {
1821
1835
  // Choose next 4 moves from learnset/viable moves and add them to moves list:
1822
1836
  const pool = (movePool.length ? movePool : rejectedPool);
1823
- while (moves.size < 4 && pool.length) {
1837
+ while (moves.size < this.maxMoveCount && pool.length) {
1824
1838
  const moveid = this.sampleNoReplace(pool);
1825
1839
  if (moveid.startsWith('hiddenpower')) {
1826
1840
  if (hasHiddenPower)
@@ -1913,7 +1927,7 @@ class RandomTeams {
1913
1927
  break;
1914
1928
  }
1915
1929
  }
1916
- } while (moves.size < 4 && (movePool.length || rejectedPool.length));
1930
+ } while (moves.size < this.maxMoveCount && (movePool.length || rejectedPool.length));
1917
1931
  // for BD/SP only
1918
1932
  if (hasHiddenPower) {
1919
1933
  let hpType;
@@ -2038,8 +2052,11 @@ class RandomTeams {
2038
2052
  forme = 'Pikachu' + this.sample(['', '-Original', '-Hoenn', '-Sinnoh', '-Unova', '-Kalos', '-Alola', '-Partner', '-World']);
2039
2053
  }
2040
2054
  let level;
2041
- // doubles levelling
2042
- if (isDoubles && species.randomDoubleBattleLevel) {
2055
+ if (this.adjustLevel) {
2056
+ level = this.adjustLevel;
2057
+ // doubles levelling
2058
+ }
2059
+ else if (isDoubles && species.randomDoubleBattleLevel) {
2043
2060
  level = species.randomDoubleBattleLevel;
2044
2061
  // No Dmax levelling
2045
2062
  }
@@ -2083,7 +2100,7 @@ class RandomTeams {
2083
2100
  PUBL: 87,
2084
2101
  PU: 88, "(PU)": 88, NFE: 88,
2085
2102
  };
2086
- const customScale = { delibird: 100, luvdisc: 100, spinda: 100, unown: 100 };
2103
+ const customScale = { delibird: 100, glalie: 76, luvdisc: 100, spinda: 100, unown: 100 };
2087
2104
  level = customScale[species.id] || tierScale[species.tier] || 80;
2088
2105
  // Arbitrary levelling base on data files (typically winrate-influenced)
2089
2106
  }
@@ -2388,11 +2405,14 @@ class RandomTeams {
2388
2405
  item: this.sampleIfArray(setData.item) || '',
2389
2406
  ability: (this.sampleIfArray(setData.ability)),
2390
2407
  shiny: this.randomChance(1, 1024),
2408
+ level: this.adjustLevel || 100,
2391
2409
  evs: Object.assign({ hp: 0, atk: 0, def: 0, spa: 0, spd: 0, spe: 0 }, setData.evs),
2392
2410
  nature: setData.nature,
2393
2411
  ivs: Object.assign({ hp: 31, atk: 31, def: 31, spa: 31, spd: 31, spe: 31 }, setData.ivs || {}),
2394
2412
  moves: setData.moves.map((move) => this.sampleIfArray(move)),
2395
2413
  };
2414
+ if (this.adjustLevel)
2415
+ set.level = this.adjustLevel;
2396
2416
  pokemon.push(set);
2397
2417
  }
2398
2418
  return pokemon;