Simulate evolution chain when generating movesets

pull/16/head
Flashfyre 2024-03-19 19:52:27 -04:00
parent 88e050581e
commit 6feef82fcf
4 changed files with 36 additions and 5 deletions

View File

@ -4474,7 +4474,6 @@ export const pokemonSpeciesLevelMoves: PokemonSpeciesLevelMoves = {
],
[Species.SILCOON]: [
[ 0, Moves.HARDEN ],
[ 1, Moves.HARDEN ],
],
[Species.BEAUTIFLY]: [
[ 0, Moves.GUST ],
@ -4493,7 +4492,6 @@ export const pokemonSpeciesLevelMoves: PokemonSpeciesLevelMoves = {
],
[Species.CASCOON]: [
[ 0, Moves.HARDEN ],
[ 1, Moves.HARDEN ],
],
[Species.DUSTOX]: [
[ 0, Moves.GUST ],

View File

@ -538,6 +538,27 @@ export default class PokemonSpecies extends PokemonSpeciesForm {
return prevolutionLevels;
}
// This could definitely be written better and more accurate to the getSpeciesForLevel logic, but it is only for generating movesets for evolved Pokemon
getSimulatedEvolutionChain(currentLevel: integer, forTrainer: boolean = false, isBoss: boolean = false, player: boolean = false) {
const ret = [];
if (pokemonPrevolutions.hasOwnProperty(this.speciesId)) {
const prevolutionLevels = this.getPrevolutionLevels().reverse();
const levelDiff = player ? 0 : forTrainer || isBoss ? forTrainer && isBoss ? 2.5 : 5 : 10;
ret.push([ prevolutionLevels[0][0], 1 ]);
for (let l = 1; l < prevolutionLevels.length; l++) {
const evolution = pokemonEvolutions[prevolutionLevels[l - 1][0]].find(e => e.speciesId === prevolutionLevels[l][0]);
ret.push([ prevolutionLevels[l][0], Math.min(Math.max(evolution.level + Math.round(Utils.randSeedGauss(0.5, 1 + levelDiff * 0.2) * Math.max(evolution.wildDelay, 0.5) * 5) - 1, 2, evolution.level), currentLevel - 1) ]);
}
const lastPrevolutionLevel = ret[prevolutionLevels.length - 1][1];
const evolution = pokemonEvolutions[prevolutionLevels[prevolutionLevels.length - 1][0]].find(e => e.speciesId === this.speciesId);
ret.push([ this.speciesId, Math.min(Math.max(lastPrevolutionLevel + Math.round(Utils.randSeedGauss(0.5, 1 + levelDiff * 0.2) * Math.max(evolution.wildDelay, 0.5) * 5), lastPrevolutionLevel + 1, evolution.level), currentLevel) ]);
} else {
ret.push([ this.speciesId, 1 ]);
}
return ret;
}
getCompatibleFusionSpeciesFilter(): PokemonSpeciesFilter {
const hasEvolution = pokemonEvolutions.hasOwnProperty(this.speciesId);
const hasPrevolution = pokemonPrevolutions.hasOwnProperty(this.speciesId);

View File

@ -767,11 +767,19 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
return null;
}
getLevelMoves(startingLevel?: integer, includeEvolutionMoves?: boolean): LevelMoves {
getLevelMoves(startingLevel?: integer, includeEvolutionMoves: boolean = false, simulateEvolutionChain: boolean = false): LevelMoves {
const ret: LevelMoves = [];
let levelMoves = this.getSpeciesForm().getLevelMoves();
let levelMoves: LevelMoves = [];
if (!startingLevel)
startingLevel = this.level;
if (simulateEvolutionChain) {
const evolutionChain = this.species.getSimulatedEvolutionChain(this.level, this.hasTrainer(), this.isBoss(), this.isPlayer());
for (let e = 0; e < evolutionChain.length; e++) {
const speciesLevelMoves = getPokemonSpecies(evolutionChain[e][0] as Species).getLevelMoves();
levelMoves.push(...speciesLevelMoves.filter(lm => (includeEvolutionMoves && !lm[0]) || ((!e || lm[0] >= evolutionChain[e - 1][0]) && (e === evolutionChain.length - 1 || lm[0] < evolutionChain[e + 1][0]))));
}
} else
levelMoves = this.getSpeciesForm().getLevelMoves();
if (this.fusionSpecies) {
const evolutionLevelMoves = levelMoves.slice(0, Math.max(levelMoves.findIndex(lm => !!lm[0]), 0));
const fusionLevelMoves = this.getFusionSpeciesForm().getLevelMoves();
@ -896,7 +904,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
generateAndPopulateMoveset(): void {
this.moveset = [];
const movePool = [];
const allLevelMoves = this.getLevelMoves(1);
const allLevelMoves = this.getLevelMoves(1, true, true);
if (!allLevelMoves) {
console.log(this.species.speciesId, 'ERROR')
return;

View File

@ -36,6 +36,8 @@ export function clampInt(value: integer, min: integer, max: integer): integer {
}
export function randGauss(stdev: number, mean: number = 0): number {
if (!stdev)
return 0;
const u = 1 - Math.random();
const v = Math.random();
const z = Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v);
@ -43,6 +45,8 @@ export function randGauss(stdev: number, mean: number = 0): number {
}
export function randSeedGauss(stdev: number, mean: number = 0): number {
if (!stdev)
return 0;
const u = 1 - Phaser.Math.RND.realInRange(0, 1);
const v = Phaser.Math.RND.realInRange(0, 1);
const z = Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v);