@pkmn/randoms 0.7.5 → 0.7.6
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 +18 -5
- package/build/index.js.map +1 -1
- package/build/index.mjs +21 -8
- package/build/index.mjs.map +1 -1
- package/package.json +2 -2
package/build/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import {
|
|
3
|
-
Dex
|
|
3
|
+
Dex
|
|
4
4
|
} from "@pkmn/sim";
|
|
5
5
|
|
|
6
6
|
// src/utils.ts
|
|
@@ -377,16 +377,20 @@ var RandomTeams = class {
|
|
|
377
377
|
const team = [];
|
|
378
378
|
const natures = this.dex.natures.all();
|
|
379
379
|
const items = this.dex.items.all();
|
|
380
|
-
const randomN = this.randomNPokemon(this.maxTeamSize, this.forceMonotype);
|
|
380
|
+
const randomN = this.randomNPokemon(this.maxTeamSize, this.forceMonotype, void 0, void 0, true);
|
|
381
381
|
for (let forme of randomN) {
|
|
382
382
|
let species = dex.species.get(forme);
|
|
383
383
|
if (species.isNonstandard)
|
|
384
384
|
species = dex.species.get(species.baseSpecies);
|
|
385
385
|
let item = "";
|
|
386
|
+
let isIllegalItem;
|
|
387
|
+
let isBadItem;
|
|
386
388
|
if (this.gen >= 2) {
|
|
387
389
|
do {
|
|
388
390
|
item = this.sample(items).name;
|
|
389
|
-
|
|
391
|
+
isIllegalItem = this.dex.items.get(item).gen > this.gen || this.dex.items.get(item).isNonstandard;
|
|
392
|
+
isBadItem = item.startsWith("TR") || this.dex.items.get(item).isPokeball;
|
|
393
|
+
} while (isIllegalItem || isBadItem && this.randomChance(19, 20));
|
|
390
394
|
}
|
|
391
395
|
if (species.battleOnly) {
|
|
392
396
|
if (typeof species.battleOnly === "string") {
|
|
@@ -501,7 +505,7 @@ var RandomTeams = class {
|
|
|
501
505
|
}
|
|
502
506
|
return team;
|
|
503
507
|
}
|
|
504
|
-
randomNPokemon(n, requiredType, minSourceGen, ruleTable) {
|
|
508
|
+
randomNPokemon(n, requiredType, minSourceGen, ruleTable, requireMoves = false) {
|
|
505
509
|
const last = [0, 151, 251, 386, 493, 649, 721, 807, 898, 1010][this.gen];
|
|
506
510
|
if (n <= 0 || n > last)
|
|
507
511
|
throw new Error(`n must be a number between 1 and ${last} (got ${n})`);
|
|
@@ -516,6 +520,11 @@ var RandomTeams = class {
|
|
|
516
520
|
for (const species of speciesPool) {
|
|
517
521
|
if (species.isNonstandard && species.isNonstandard !== "Unobtainable")
|
|
518
522
|
continue;
|
|
523
|
+
if (requireMoves) {
|
|
524
|
+
const hasMovesInCurrentGen = Object.values(this.dex.species.getLearnset(species.id) || {}).some((sources) => sources.some((source) => source.startsWith("9")));
|
|
525
|
+
if (!hasMovesInCurrentGen)
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
519
528
|
if (requiredType && !species.types.includes(requiredType))
|
|
520
529
|
continue;
|
|
521
530
|
if (minSourceGen && species.gen < minSourceGen)
|
|
@@ -753,9 +762,13 @@ var RandomTeams = class {
|
|
|
753
762
|
const species = this.dex.species.get(forme);
|
|
754
763
|
let item = "";
|
|
755
764
|
let itemData;
|
|
765
|
+
let isBadItem;
|
|
756
766
|
if (doItemsExist) {
|
|
757
|
-
|
|
758
|
-
|
|
767
|
+
do {
|
|
768
|
+
itemData = this.sampleNoReplace(itemPool);
|
|
769
|
+
item = itemData == null ? void 0 : itemData.name;
|
|
770
|
+
isBadItem = item.startsWith("TR") || itemData.isPokeball;
|
|
771
|
+
} while (isBadItem && this.randomChance(19, 20) && itemPool.length > this.maxTeamSize);
|
|
759
772
|
}
|
|
760
773
|
let ability = "No Ability";
|
|
761
774
|
let abilityData;
|
|
@@ -8030,7 +8043,7 @@ var GENERATORS = {
|
|
|
8030
8043
|
};
|
|
8031
8044
|
var TeamGenerators = new class {
|
|
8032
8045
|
getTeamGenerator(format, seed = null) {
|
|
8033
|
-
format =
|
|
8046
|
+
format = Dex.formats.get(format);
|
|
8034
8047
|
if (!format.exists)
|
|
8035
8048
|
throw new Error(`Unknown format '${format.name}' - does not exist`);
|
|
8036
8049
|
if (format.team !== "random")
|
|
@@ -8038,7 +8051,7 @@ var TeamGenerators = new class {
|
|
|
8038
8051
|
const Generator = format.mod && GENERATORS[format.mod];
|
|
8039
8052
|
if (!Generator)
|
|
8040
8053
|
throw new Error(`Unknown format '${format.name}' - cannot find generator`);
|
|
8041
|
-
return new Generator(
|
|
8054
|
+
return new Generator(Dex.mod(format.mod), format, seed);
|
|
8042
8055
|
}
|
|
8043
8056
|
}();
|
|
8044
8057
|
export {
|