Fix random wild evolution logic

pull/1/head
Flashfyre 2023-05-04 20:47:41 -04:00
parent 4423f79b66
commit f33ee493bd
1 changed files with 36 additions and 20 deletions

View File

@ -227,20 +227,22 @@ export default class PokemonSpecies extends PokemonSpeciesForm {
const evolutions = pokemonEvolutions[this.speciesId]; const evolutions = pokemonEvolutions[this.speciesId];
const speciesIds: Species[] = [];
const easeInFunc = Phaser.Tweens.Builders.GetEaseFunction('Sine.easeIn'); const easeInFunc = Phaser.Tweens.Builders.GetEaseFunction('Sine.easeIn');
const easeOutFunc = Phaser.Tweens.Builders.GetEaseFunction('Sine.easeOut'); const easeOutFunc = Phaser.Tweens.Builders.GetEaseFunction('Sine.easeOut');
const evolutionPool: Map<number, Species> = new Map();
let totalWeight = 0;
let noEvolutionChance = 1;
for (let ev of evolutions) { for (let ev of evolutions) {
if (ev.level > level) if (ev.level > level)
continue; continue;
if (ev.wildDelay === SpeciesWildEvolutionDelay.NONE) { let evolutionChance: number;
speciesIds.push(ev.speciesId);
continue;
}
if (ev.wildDelay === SpeciesWildEvolutionDelay.NONE)
evolutionChance = Math.min(0.5 + easeInFunc((level - ev.level) / 40) / 2, 1);
else {
let preferredMinLevel = ev.wildDelay * 10; let preferredMinLevel = ev.wildDelay * 10;
let evolutionLevel = ev.level > 1 ? ev.level : 0; let evolutionLevel = ev.level > 1 ? ev.level : 0;
@ -250,16 +252,30 @@ export default class PokemonSpecies extends PokemonSpeciesForm {
evolutionLevel = prevolutionLevel; evolutionLevel = prevolutionLevel;
} }
const evolutionChance = 0.65 * easeInFunc((Math.min(Math.max(level - evolutionLevel, 0), preferredMinLevel) / preferredMinLevel)) + 0.35 * easeOutFunc(Math.min(level - evolutionLevel, preferredMinLevel * 2.5) / (preferredMinLevel * 2.5)); evolutionChance = Math.min(0.65 * easeInFunc((Math.min(Math.max(level - evolutionLevel, 0), preferredMinLevel) / preferredMinLevel)) + 0.35 * easeOutFunc(Math.min(level - evolutionLevel, preferredMinLevel * 2.5) / (preferredMinLevel * 2.5)), 1);
if (Math.random() <= evolutionChance)
speciesIds.push(ev.speciesId);
} }
if (speciesIds.length) { if (evolutionChance > 0) {
return speciesIds.length === 1 totalWeight += evolutionChance;
? speciesIds[0]
: speciesIds[Utils.randInt(speciesIds.length)]; evolutionPool.set(totalWeight, ev.speciesId);
if ((1 - evolutionChance) < noEvolutionChance)
noEvolutionChance = 1 - evolutionChance;
}
}
if (noEvolutionChance === 1 || Math.random() < noEvolutionChance)
return this.speciesId;
if (evolutionPool.size === 1)
return evolutionPool.values()[0];
const randValue = Math.random() * totalWeight;
for (let weight of evolutionPool.keys()) {
if (randValue < weight)
return evolutionPool.get(weight);
} }
return this.speciesId; return this.speciesId;