Fix minimum move count threshold and utilize baseWeights

This commit is contained in:
Sirz Benjie 2025-09-15 23:33:07 -05:00
parent 207808f37d
commit 864199a8e0
No known key found for this signature in database
GPG Key ID: 4A524B4D196C759E

View File

@ -510,11 +510,7 @@ function forceStabMove(
const chosenPool = const chosenPool =
stabMovePool.length > 0 || !forceAnyDamageIfNoStab stabMovePool.length > 0 || !forceAnyDamageIfNoStab
? stabMovePool ? stabMovePool
: filterPool( : filterPool(pool, m => allMoves[m].category !== MoveCategory.STATUS && !STAB_BLACKLIST.has(m), totalWeight);
pool,
m => allMoves[m[0]].category !== MoveCategory.STATUS && !STAB_BLACKLIST.has(m[0]),
totalWeight,
);
if (chosenPool.length > 0) { if (chosenPool.length > 0) {
let rand = randSeedInt(totalWeight.value); let rand = randSeedInt(totalWeight.value);
@ -589,7 +585,7 @@ function fillInRemainingMovesetSlots(
const tmCap = getMaxTmCount(pokemon.level); const tmCap = getMaxTmCount(pokemon.level);
const eggCap = getMaxEggMoveCount(pokemon.level); const eggCap = getMaxEggMoveCount(pokemon.level);
const remainingPoolWeight = new NumberHolder(0); const remainingPoolWeight = new NumberHolder(0);
while (remainingPool.length > pokemon.moveset.length && pokemon.moveset.length < 4) { while (pokemon.moveset.length < 4) {
const nonLevelMoveCount = tmCount.value + eggMoveCount.value; const nonLevelMoveCount = tmCount.value + eggMoveCount.value;
remainingPool = filterPool( remainingPool = filterPool(
baseWeights, baseWeights,
@ -605,6 +601,11 @@ function fillInRemainingMovesetSlots(
if (pokemon.hasTrainer()) { if (pokemon.hasTrainer()) {
filterRemainingTrainerMovePool(remainingPool, pokemon); filterRemainingTrainerMovePool(remainingPool, pokemon);
} }
// Ensure loop cannot run infinitely if there are no allowed moves left to
// fill the remaining slots
if (remainingPool.length === 0) {
return;
}
const totalWeight = remainingPool.reduce((v, m) => v + m[1], 0); const totalWeight = remainingPool.reduce((v, m) => v + m[1], 0);
let rand = randSeedInt(totalWeight); let rand = randSeedInt(totalWeight);
let index = 0; let index = 0;
@ -719,7 +720,7 @@ export function generateMoveset(pokemon: Pokemon): void {
tmCount, tmCount,
eggMoveCount, eggMoveCount,
baseWeights, baseWeights,
filterPool(baseWeights, (m: MoveId) => !pokemon.moveset.some(mo => m[0] === mo.moveId)), filterPool(baseWeights, (m: MoveId) => !pokemon.moveset.some(mo => m === mo.moveId)),
); );
} }