@pkmn/randoms 0.9.22 → 0.9.23
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/index.js +63 -22
- package/build/index.js.map +1 -1
- package/build/index.mjs +63 -22
- package/build/index.mjs.map +1 -1
- package/package.json +2 -2
package/build/index.js
CHANGED
|
@@ -257,6 +257,9 @@ var RandomGen8Teams = class {
|
|
|
257
257
|
return abilities.includes("Huge Power") && movePool.includes("aquajet");
|
|
258
258
|
}
|
|
259
259
|
};
|
|
260
|
+
this.poolsCacheKey = void 0;
|
|
261
|
+
this.cachedPool = void 0;
|
|
262
|
+
this.cachedSpeciesPool = void 0;
|
|
260
263
|
}
|
|
261
264
|
setSeed(prng) {
|
|
262
265
|
this.prng = prng && !Array.isArray(prng) ? prng : new (0, _sim.PRNG)(prng);
|
|
@@ -477,20 +480,21 @@ var RandomGen8Teams = class {
|
|
|
477
480
|
shiny
|
|
478
481
|
};
|
|
479
482
|
if (this.gen === 9) {
|
|
480
|
-
set.teraType = this.sample(this.dex.types.
|
|
483
|
+
set.teraType = this.sample(this.dex.types.names());
|
|
481
484
|
}
|
|
482
485
|
team.push(set);
|
|
483
486
|
}
|
|
484
487
|
return team;
|
|
485
488
|
}
|
|
486
|
-
|
|
487
|
-
if (requiredType && !this.dex.types.get(requiredType).exists) {
|
|
488
|
-
throw new Error(`"${requiredType}" is not a valid type.`);
|
|
489
|
-
}
|
|
489
|
+
getPools(requiredType, minSourceGen, ruleTable, requireMoves = false) {
|
|
490
490
|
const isNotCustom = !ruleTable;
|
|
491
|
-
|
|
491
|
+
let pool = [];
|
|
492
492
|
let speciesPool = [];
|
|
493
|
-
|
|
493
|
+
const ck = this.poolsCacheKey;
|
|
494
|
+
if (ck && this.cachedPool && this.cachedSpeciesPool && ck[0] === requiredType && ck[1] === minSourceGen && ck[2] === ruleTable && ck[3] === requireMoves) {
|
|
495
|
+
speciesPool = this.cachedSpeciesPool.slice();
|
|
496
|
+
pool = this.cachedPool.slice();
|
|
497
|
+
} else if (isNotCustom) {
|
|
494
498
|
speciesPool = [...this.dex.species.all()];
|
|
495
499
|
for (const species of speciesPool) {
|
|
496
500
|
if (species.isNonstandard && species.isNonstandard !== "Unobtainable") continue;
|
|
@@ -504,6 +508,9 @@ var RandomGen8Teams = class {
|
|
|
504
508
|
if (num <= 0 || pool.includes(num)) continue;
|
|
505
509
|
pool.push(num);
|
|
506
510
|
}
|
|
511
|
+
this.poolsCacheKey = [requiredType, minSourceGen, ruleTable, requireMoves];
|
|
512
|
+
this.cachedPool = pool.slice();
|
|
513
|
+
this.cachedSpeciesPool = speciesPool.slice();
|
|
507
514
|
} else {
|
|
508
515
|
const EXISTENCE_TAG = ["past", "future", "lgpe", "unobtainable", "cap", "custom", "nonexistent"];
|
|
509
516
|
const nonexistentBanReason = ruleTable.check("nonexistent");
|
|
@@ -545,7 +552,18 @@ var RandomGen8Teams = class {
|
|
|
545
552
|
if (pool.includes(num)) continue;
|
|
546
553
|
pool.push(num);
|
|
547
554
|
}
|
|
555
|
+
this.poolsCacheKey = [requiredType, minSourceGen, ruleTable, requireMoves];
|
|
556
|
+
this.cachedPool = pool.slice();
|
|
557
|
+
this.cachedSpeciesPool = speciesPool.slice();
|
|
558
|
+
}
|
|
559
|
+
return { pool, speciesPool };
|
|
560
|
+
}
|
|
561
|
+
randomNPokemon(n, requiredType, minSourceGen, ruleTable, requireMoves = false) {
|
|
562
|
+
if (requiredType && !this.dex.types.get(requiredType).exists) {
|
|
563
|
+
throw new Error(`"${requiredType}" is not a valid type.`);
|
|
548
564
|
}
|
|
565
|
+
const { pool, speciesPool } = this.getPools(requiredType, minSourceGen, ruleTable, requireMoves);
|
|
566
|
+
const isNotCustom = !ruleTable;
|
|
549
567
|
const hasDexNumber = {};
|
|
550
568
|
for (let i = 0; i < n; i++) {
|
|
551
569
|
const num = this.sampleNoReplace(pool);
|
|
@@ -778,7 +796,7 @@ var RandomGen8Teams = class {
|
|
|
778
796
|
shiny
|
|
779
797
|
};
|
|
780
798
|
if (this.gen === 9) {
|
|
781
|
-
set.teraType = this.sample(this.dex.types.
|
|
799
|
+
set.teraType = this.sample(this.dex.types.names());
|
|
782
800
|
}
|
|
783
801
|
team.push(set);
|
|
784
802
|
}
|
|
@@ -2726,6 +2744,7 @@ var RandomGen7Teams = class extends RandomGen8Teams {
|
|
|
2726
2744
|
Steel: (movePool, moves, abilities, types, counter, species) => !counter.get("Steel") && species.baseStats.atk >= 100,
|
|
2727
2745
|
Water: (movePool, moves, abilities, types, counter) => !counter.get("Water")
|
|
2728
2746
|
};
|
|
2747
|
+
this.cachedStatusMoves = this.dex.moves.all().filter((move) => move.category === "Status" && move.id !== "naturepower").map((move) => move.id);
|
|
2729
2748
|
}
|
|
2730
2749
|
newQueryMoves(moves, species, preferredType, abilities) {
|
|
2731
2750
|
const counter = new MoveCounter();
|
|
@@ -2853,7 +2872,7 @@ var RandomGen7Teams = class extends RandomGen8Teams {
|
|
|
2853
2872
|
if (moves.size + movePool.length <= this.maxMoveCount) return;
|
|
2854
2873
|
}
|
|
2855
2874
|
const badWithSetup = ["defog", "dragontail", "haze", "healbell", "nuzzle", "pursuit", "rapidspin", "toxic"];
|
|
2856
|
-
const statusMoves = this.
|
|
2875
|
+
const statusMoves = this.cachedStatusMoves;
|
|
2857
2876
|
const incompatiblePairs = [
|
|
2858
2877
|
// These moves don't mesh well with other aspects of the set
|
|
2859
2878
|
[statusMoves, ["healingwish", "memento", "switcheroo", "trick"]],
|
|
@@ -4529,6 +4548,7 @@ var RandomGen6Teams = class extends RandomGen7Teams {
|
|
|
4529
4548
|
Steel: (movePool, moves, abilities, types, counter, species) => !counter.get("Steel") && species.baseStats.atk >= 100,
|
|
4530
4549
|
Water: (movePool, moves, abilities, types, counter) => !counter.get("Water")
|
|
4531
4550
|
};
|
|
4551
|
+
this.cachedStatusMoves = this.dex.moves.all().filter((move) => move.category === "Status").map((move) => move.id);
|
|
4532
4552
|
}
|
|
4533
4553
|
cullMovePool(types, moves, abilities, counter, movePool, teamDetails, species, isLead, preferredType, role) {
|
|
4534
4554
|
let hasHiddenPower = false;
|
|
@@ -4601,7 +4621,7 @@ var RandomGen6Teams = class extends RandomGen7Teams {
|
|
|
4601
4621
|
if (moves.size + movePool.length <= this.maxMoveCount) return;
|
|
4602
4622
|
}
|
|
4603
4623
|
const badWithSetup = ["defog", "dragontail", "haze", "healbell", "nuzzle", "pursuit", "rapidspin", "toxic"];
|
|
4604
|
-
const statusMoves = this.
|
|
4624
|
+
const statusMoves = this.cachedStatusMoves;
|
|
4605
4625
|
const incompatiblePairs = [
|
|
4606
4626
|
// These moves don't mesh well with other aspects of the set
|
|
4607
4627
|
[statusMoves, ["healingwish", "memento", "switcheroo", "trick"]],
|
|
@@ -5688,6 +5708,7 @@ var RandomGen5Teams = class extends RandomGen6Teams {
|
|
|
5688
5708
|
Steel: (movePool, moves, abilities, types, counter, species) => !counter.get("Steel") && ["aggron", "metagross"].includes(species.id),
|
|
5689
5709
|
Water: (movePool, moves, abilities, types, counter) => !counter.get("Water")
|
|
5690
5710
|
};
|
|
5711
|
+
this.cachedStatusMoves = this.dex.moves.all().filter((move) => move.category === "Status" && move.id !== "naturepower").map((move) => move.id);
|
|
5691
5712
|
}
|
|
5692
5713
|
cullMovePool(types, moves, abilities, counter, movePool, teamDetails, species, isLead, preferredType, role) {
|
|
5693
5714
|
let hasHiddenPower = false;
|
|
@@ -5755,7 +5776,7 @@ var RandomGen5Teams = class extends RandomGen6Teams {
|
|
|
5755
5776
|
if (moves.size + movePool.length <= this.maxMoveCount) return;
|
|
5756
5777
|
}
|
|
5757
5778
|
const badWithSetup = ["healbell", "pursuit", "toxic"];
|
|
5758
|
-
const statusMoves = this.
|
|
5779
|
+
const statusMoves = this.cachedStatusMoves;
|
|
5759
5780
|
const incompatiblePairs = [
|
|
5760
5781
|
// These moves don't mesh well with other aspects of the set
|
|
5761
5782
|
[statusMoves, ["healingwish", "switcheroo", "trick"]],
|
|
@@ -6667,6 +6688,7 @@ var RandomGen4Teams = class extends RandomGen5Teams {
|
|
|
6667
6688
|
Steel: (movePool, moves, abilities, types, counter, species) => !counter.get("Steel") && species.id === "metagross",
|
|
6668
6689
|
Water: (movePool, moves, abilities, types, counter) => !counter.get("Water")
|
|
6669
6690
|
};
|
|
6691
|
+
this.cachedStatusMoves = this.dex.moves.all().filter((move) => move.category === "Status").map((move) => move.id);
|
|
6670
6692
|
}
|
|
6671
6693
|
cullMovePool(types, moves, abilities, counter, movePool, teamDetails, species, isLead, preferredType, role) {
|
|
6672
6694
|
let hasHiddenPower = false;
|
|
@@ -6734,7 +6756,7 @@ var RandomGen4Teams = class extends RandomGen5Teams {
|
|
|
6734
6756
|
if (moves.size + movePool.length <= this.maxMoveCount) return;
|
|
6735
6757
|
}
|
|
6736
6758
|
const badWithSetup = ["pursuit", "toxic"];
|
|
6737
|
-
const statusMoves = this.
|
|
6759
|
+
const statusMoves = this.cachedStatusMoves;
|
|
6738
6760
|
const incompatiblePairs = [
|
|
6739
6761
|
// These moves don't mesh well with other aspects of the set
|
|
6740
6762
|
[statusMoves, ["healingwish", "switcheroo", "trick"]],
|
|
@@ -7515,7 +7537,7 @@ var RandomGen3Teams = class extends RandomGen4Teams {
|
|
|
7515
7537
|
if (moves.size + movePool.length <= this.maxMoveCount) return;
|
|
7516
7538
|
}
|
|
7517
7539
|
const badWithSetup = ["knockoff", "rapidspin", "toxic"];
|
|
7518
|
-
const statusMoves = this.
|
|
7540
|
+
const statusMoves = this.cachedStatusMoves;
|
|
7519
7541
|
const incompatiblePairs = [
|
|
7520
7542
|
// These moves don't mesh well with other aspects of the set
|
|
7521
7543
|
[statusMoves, "trick"],
|
|
@@ -9350,6 +9372,10 @@ var RandomTeams = class {
|
|
|
9350
9372
|
Steel: (movePool, moves, abilities, types, counter, species, teamDetails, isLead, isDoubles) => !counter.get("Steel") && (isDoubles || species.baseStats.atk >= 90 || movePool.includes("gigatonhammer") || movePool.includes("makeitrain")),
|
|
9351
9373
|
Water: (movePool, moves, abilities, types, counter) => !counter.get("Water") && !types.includes("Ground")
|
|
9352
9374
|
};
|
|
9375
|
+
this.poolsCacheKey = void 0;
|
|
9376
|
+
this.cachedPool = void 0;
|
|
9377
|
+
this.cachedSpeciesPool = void 0;
|
|
9378
|
+
this.cachedStatusMoves = this.dex.moves.all().filter((move) => move.category === "Status").map((move) => move.id);
|
|
9353
9379
|
}
|
|
9354
9380
|
setSeed(prng) {
|
|
9355
9381
|
this.prng = prng && !Array.isArray(prng) ? prng : new (0, _sim.PRNG)(prng);
|
|
@@ -9528,7 +9554,7 @@ var RandomTeams = class {
|
|
|
9528
9554
|
}
|
|
9529
9555
|
}
|
|
9530
9556
|
}
|
|
9531
|
-
const statusMoves = this.
|
|
9557
|
+
const statusMoves = this.cachedStatusMoves;
|
|
9532
9558
|
if (teamDetails.screens) {
|
|
9533
9559
|
if (movePool.includes("auroraveil")) this.fastPop(movePool, movePool.indexOf("auroraveil"));
|
|
9534
9560
|
if (movePool.length >= this.maxMoveCount + 2) {
|
|
@@ -10880,21 +10906,22 @@ var RandomTeams = class {
|
|
|
10880
10906
|
if (this.forceTeraType) {
|
|
10881
10907
|
set.teraType = this.forceTeraType;
|
|
10882
10908
|
} else {
|
|
10883
|
-
set.teraType = this.sample(this.dex.types.
|
|
10909
|
+
set.teraType = this.sample(this.dex.types.names());
|
|
10884
10910
|
}
|
|
10885
10911
|
}
|
|
10886
10912
|
team.push(set);
|
|
10887
10913
|
}
|
|
10888
10914
|
return team;
|
|
10889
10915
|
}
|
|
10890
|
-
|
|
10891
|
-
if (requiredType && !this.dex.types.get(requiredType).exists) {
|
|
10892
|
-
throw new Error(`"${requiredType}" is not a valid type.`);
|
|
10893
|
-
}
|
|
10916
|
+
getPools(requiredType, minSourceGen, ruleTable, requireMoves = false) {
|
|
10894
10917
|
const isNotCustom = !ruleTable;
|
|
10895
|
-
|
|
10918
|
+
let pool = [];
|
|
10896
10919
|
let speciesPool = [];
|
|
10897
|
-
|
|
10920
|
+
const ck = this.poolsCacheKey;
|
|
10921
|
+
if (ck && this.cachedPool && this.cachedSpeciesPool && ck[0] === requiredType && ck[1] === minSourceGen && ck[2] === ruleTable && ck[3] === requireMoves) {
|
|
10922
|
+
speciesPool = this.cachedSpeciesPool.slice();
|
|
10923
|
+
pool = this.cachedPool.slice();
|
|
10924
|
+
} else if (isNotCustom) {
|
|
10898
10925
|
speciesPool = [...this.dex.species.all()];
|
|
10899
10926
|
for (const species of speciesPool) {
|
|
10900
10927
|
if (species.isNonstandard && species.isNonstandard !== "Unobtainable") continue;
|
|
@@ -10908,6 +10935,9 @@ var RandomTeams = class {
|
|
|
10908
10935
|
if (num <= 0 || pool.includes(num)) continue;
|
|
10909
10936
|
pool.push(num);
|
|
10910
10937
|
}
|
|
10938
|
+
this.poolsCacheKey = [requiredType, minSourceGen, ruleTable, requireMoves];
|
|
10939
|
+
this.cachedPool = pool.slice();
|
|
10940
|
+
this.cachedSpeciesPool = speciesPool.slice();
|
|
10911
10941
|
} else {
|
|
10912
10942
|
const EXISTENCE_TAG = ["past", "future", "lgpe", "unobtainable", "cap", "custom", "nonexistent"];
|
|
10913
10943
|
const nonexistentBanReason = ruleTable.check("nonexistent");
|
|
@@ -10949,7 +10979,18 @@ var RandomTeams = class {
|
|
|
10949
10979
|
if (pool.includes(num)) continue;
|
|
10950
10980
|
pool.push(num);
|
|
10951
10981
|
}
|
|
10982
|
+
this.poolsCacheKey = [requiredType, minSourceGen, ruleTable, requireMoves];
|
|
10983
|
+
this.cachedPool = pool.slice();
|
|
10984
|
+
this.cachedSpeciesPool = speciesPool.slice();
|
|
10985
|
+
}
|
|
10986
|
+
return { pool, speciesPool };
|
|
10987
|
+
}
|
|
10988
|
+
randomNPokemon(n, requiredType, minSourceGen, ruleTable, requireMoves = false) {
|
|
10989
|
+
if (requiredType && !this.dex.types.get(requiredType).exists) {
|
|
10990
|
+
throw new Error(`"${requiredType}" is not a valid type.`);
|
|
10952
10991
|
}
|
|
10992
|
+
const { pool, speciesPool } = this.getPools(requiredType, minSourceGen, ruleTable, requireMoves);
|
|
10993
|
+
const isNotCustom = !ruleTable;
|
|
10953
10994
|
const hasDexNumber = {};
|
|
10954
10995
|
for (let i = 0; i < n; i++) {
|
|
10955
10996
|
const num = this.sampleNoReplace(pool);
|
|
@@ -11188,7 +11229,7 @@ var RandomTeams = class {
|
|
|
11188
11229
|
if (this.forceTeraType) {
|
|
11189
11230
|
set.teraType = this.forceTeraType;
|
|
11190
11231
|
} else {
|
|
11191
|
-
set.teraType = this.sample(this.dex.types.
|
|
11232
|
+
set.teraType = this.sample(this.dex.types.names());
|
|
11192
11233
|
}
|
|
11193
11234
|
}
|
|
11194
11235
|
team.push(set);
|