@pkmn/randoms 0.5.10 → 0.5.13

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/src/gen8.ts CHANGED
@@ -103,6 +103,8 @@ export class RandomTeams {
103
103
  prng: PRNG;
104
104
  noStab: string[];
105
105
  readonly maxTeamSize: number;
106
+ readonly adjustLevel: number | null;
107
+ readonly maxMoveCount: number;
106
108
  readonly forceMonotype: string | undefined;
107
109
 
108
110
  /**
@@ -119,6 +121,8 @@ export class RandomTeams {
119
121
 
120
122
  const ruleTable = this.dex.formats.getRuleTable(format);
121
123
  this.maxTeamSize = ruleTable.maxTeamSize;
124
+ this.adjustLevel = ruleTable.adjustLevel;
125
+ this.maxMoveCount = ruleTable.maxMoveCount;
122
126
  const forceMonotype = ruleTable.valueRules.get('forcemonotype');
123
127
  this.forceMonotype = forceMonotype && this.dex.types.get(forceMonotype).exists ?
124
128
  this.dex.types.get(forceMonotype).name : undefined;
@@ -442,7 +446,7 @@ export class RandomTeams {
442
446
  }
443
447
  }
444
448
 
445
- const moves = this.multipleSamplesNoReplace(pool, 4);
449
+ const moves = this.multipleSamplesNoReplace(pool, this.maxMoveCount);
446
450
 
447
451
  // Random EVs
448
452
  const evs: StatsTable = {hp: 0, atk: 0, def: 0, spa: 0, spd: 0, spe: 0};
@@ -483,19 +487,24 @@ export class RandomTeams {
483
487
  mbst += (stats["spd"] * 2 + 31 + 21 + 100) + 5;
484
488
  mbst += (stats["spe"] * 2 + 31 + 21 + 100) + 5;
485
489
 
486
- let level = Math.floor(100 * mbstmin / mbst); // Initial level guess will underestimate
487
-
488
- while (level < 100) {
489
- mbst = Math.floor((stats["hp"] * 2 + 31 + 21 + 100) * level / 100 + 10);
490
- // Since damage is roughly proportional to level
491
- mbst += Math.floor(((stats["atk"] * 2 + 31 + 21 + 100) * level / 100 + 5) * level / 100);
492
- mbst += Math.floor((stats["def"] * 2 + 31 + 21 + 100) * level / 100 + 5);
493
- mbst += Math.floor(((stats["spa"] * 2 + 31 + 21 + 100) * level / 100 + 5) * level / 100);
494
- mbst += Math.floor((stats["spd"] * 2 + 31 + 21 + 100) * level / 100 + 5);
495
- mbst += Math.floor((stats["spe"] * 2 + 31 + 21 + 100) * level / 100 + 5);
496
-
497
- if (mbst >= mbstmin) break;
498
- level++;
490
+ let level;
491
+ if (this.adjustLevel) {
492
+ level = this.adjustLevel;
493
+ } else {
494
+ level = Math.floor(100 * mbstmin / mbst); // Initial level guess will underestimate
495
+
496
+ while (level < 100) {
497
+ mbst = Math.floor((stats["hp"] * 2 + 31 + 21 + 100) * level / 100 + 10);
498
+ // Since damage is roughly proportional to level
499
+ mbst += Math.floor(((stats["atk"] * 2 + 31 + 21 + 100) * level / 100 + 5) * level / 100);
500
+ mbst += Math.floor((stats["def"] * 2 + 31 + 21 + 100) * level / 100 + 5);
501
+ mbst += Math.floor(((stats["spa"] * 2 + 31 + 21 + 100) * level / 100 + 5) * level / 100);
502
+ mbst += Math.floor((stats["spd"] * 2 + 31 + 21 + 100) * level / 100 + 5);
503
+ mbst += Math.floor((stats["spe"] * 2 + 31 + 21 + 100) * level / 100 + 5);
504
+
505
+ if (mbst >= mbstmin) break;
506
+ level++;
507
+ }
499
508
  }
500
509
 
501
510
  // Random happiness
@@ -563,7 +572,7 @@ export class RandomTeams {
563
572
 
564
573
  banReason = ruleTable.check('basepokemon:' + toID(species.baseSpecies));
565
574
  if (banReason) continue;
566
- if (banReason !== '' || this.dex.species.get(species.baseSpecies).isNonstandard === species.isNonstandard) {
575
+ if (banReason !== '' || this.dex.species.get(species.baseSpecies).isNonstandard !== species.isNonstandard) {
567
576
  const nonexistentCheck = Tags.nonexistent.genericFilter!(species) && nonexistentBanReason;
568
577
  let tagWhitelisted = false;
569
578
  let tagBlacklisted = false;
@@ -588,10 +597,10 @@ export class RandomTeams {
588
597
  }
589
598
  }
590
599
  }
600
+ speciesPool.push(species);
591
601
  const num = species.num;
592
602
  if (pool.includes(num)) continue;
593
603
  pool.push(num);
594
- speciesPool.push(species);
595
604
  }
596
605
  }
597
606
 
@@ -825,16 +834,22 @@ export class RandomTeams {
825
834
  mbst += (stats['spa'] * 2 + 31 + 21 + 100) + 5;
826
835
  mbst += (stats['spd'] * 2 + 31 + 21 + 100) + 5;
827
836
  mbst += (stats['spe'] * 2 + 31 + 21 + 100) + 5;
828
- let level = Math.floor(100 * mbstmin / mbst);
829
- while (level < 100) {
830
- mbst = Math.floor((stats['hp'] * 2 + 31 + 21 + 100) * level / 100 + 10);
831
- mbst += Math.floor(((stats['atk'] * 2 + 31 + 21 + 100) * level / 100 + 5) * level / 100);
832
- mbst += Math.floor((stats['def'] * 2 + 31 + 21 + 100) * level / 100 + 5);
833
- mbst += Math.floor(((stats['spa'] * 2 + 31 + 21 + 100) * level / 100 + 5) * level / 100);
834
- mbst += Math.floor((stats['spd'] * 2 + 31 + 21 + 100) * level / 100 + 5);
835
- mbst += Math.floor((stats['spe'] * 2 + 31 + 21 + 100) * level / 100 + 5);
836
- if (mbst >= mbstmin) break;
837
- level++;
837
+
838
+ let level;
839
+ if (this.adjustLevel) {
840
+ level = this.adjustLevel;
841
+ } else {
842
+ level = Math.floor(100 * mbstmin / mbst);
843
+ while (level < 100) {
844
+ mbst = Math.floor((stats['hp'] * 2 + 31 + 21 + 100) * level / 100 + 10);
845
+ mbst += Math.floor(((stats['atk'] * 2 + 31 + 21 + 100) * level / 100 + 5) * level / 100);
846
+ mbst += Math.floor((stats['def'] * 2 + 31 + 21 + 100) * level / 100 + 5);
847
+ mbst += Math.floor(((stats['spa'] * 2 + 31 + 21 + 100) * level / 100 + 5) * level / 100);
848
+ mbst += Math.floor((stats['spd'] * 2 + 31 + 21 + 100) * level / 100 + 5);
849
+ mbst += Math.floor((stats['spe'] * 2 + 31 + 21 + 100) * level / 100 + 5);
850
+ if (mbst >= mbstmin) break;
851
+ level++;
852
+ }
838
853
  }
839
854
 
840
855
  // Random happiness
@@ -1965,7 +1980,7 @@ export class RandomTeams {
1965
1980
  // Random Free-For-All also uses doubles move pools, for now
1966
1981
  const allySwitch = movePool.indexOf('allyswitch');
1967
1982
  if (allySwitch > -1) {
1968
- if (movePool.length > 4) {
1983
+ if (movePool.length > this.maxMoveCount) {
1969
1984
  this.fastPop(movePool, allySwitch);
1970
1985
  } else {
1971
1986
  // Ideally, we'll never get here, but better to have a move that usually does nothing than one that always does
@@ -1993,7 +2008,7 @@ export class RandomTeams {
1993
2008
  do {
1994
2009
  // Choose next 4 moves from learnset/viable moves and add them to moves list:
1995
2010
  const pool = (movePool.length ? movePool : rejectedPool);
1996
- while (moves.size < 4 && pool.length) {
2011
+ while (moves.size < this.maxMoveCount && pool.length) {
1997
2012
  const moveid = this.sampleNoReplace(pool);
1998
2013
  if (moveid.startsWith('hiddenpower')) {
1999
2014
  if (hasHiddenPower) continue;
@@ -2100,7 +2115,7 @@ export class RandomTeams {
2100
2115
  break;
2101
2116
  }
2102
2117
  }
2103
- } while (moves.size < 4 && (movePool.length || rejectedPool.length));
2118
+ } while (moves.size < this.maxMoveCount && (movePool.length || rejectedPool.length));
2104
2119
 
2105
2120
  // for BD/SP only
2106
2121
  if (hasHiddenPower) {
@@ -2218,8 +2233,10 @@ export class RandomTeams {
2218
2233
  }
2219
2234
 
2220
2235
  let level: number;
2236
+ if (this.adjustLevel) {
2237
+ level = this.adjustLevel;
2221
2238
  // doubles levelling
2222
- if (isDoubles && species.randomDoubleBattleLevel) {
2239
+ } else if (isDoubles && species.randomDoubleBattleLevel) {
2223
2240
  level = species.randomDoubleBattleLevel;
2224
2241
  // No Dmax levelling
2225
2242
  } else if (isNoDynamax) {
@@ -2261,7 +2278,7 @@ export class RandomTeams {
2261
2278
  PUBL: 87,
2262
2279
  PU: 88, "(PU)": 88, NFE: 88,
2263
2280
  };
2264
- const customScale: {[k: string]: number} = {delibird: 100, luvdisc: 100, spinda: 100, unown: 100};
2281
+ const customScale: {[k: string]: number} = {delibird: 100, glalie: 76, luvdisc: 100, spinda: 100, unown: 100};
2265
2282
 
2266
2283
  level = customScale[species.id] || tierScale[species.tier] || 80;
2267
2284
  // Arbitrary levelling base on data files (typically winrate-influenced)
@@ -2549,11 +2566,13 @@ export class RandomTeams {
2549
2566
  item: this.sampleIfArray(setData.item) || '',
2550
2567
  ability: (this.sampleIfArray(setData.ability)),
2551
2568
  shiny: this.randomChance(1, 1024),
2569
+ level: this.adjustLevel || 100,
2552
2570
  evs: {hp: 0, atk: 0, def: 0, spa: 0, spd: 0, spe: 0, ...setData.evs},
2553
2571
  nature: setData.nature,
2554
2572
  ivs: {hp: 31, atk: 31, def: 31, spa: 31, spd: 31, spe: 31, ...setData.ivs || {}},
2555
2573
  moves: setData.moves.map((move: any) => this.sampleIfArray(move)),
2556
2574
  };
2575
+ if (this.adjustLevel) set.level = this.adjustLevel;
2557
2576
  pokemon.push(set);
2558
2577
  }
2559
2578
  return pokemon;