diff --git a/src/arena.ts b/src/arena.ts index 4f9f53c6e35..c4d298d7d88 100644 --- a/src/arena.ts +++ b/src/arena.ts @@ -25,7 +25,7 @@ export class Arena { this.pokemonPool = biomePools[biome]; } - randomSpecies(waveIndex: integer, level: integer): PokemonSpecies { + randomSpecies(waveIndex: integer, level: integer, attempt?: integer): PokemonSpecies { const isBoss = (waveIndex >= 100 || waveIndex % 10 === 0) && !!this.pokemonPool[BiomePoolTier.BOSS].length; const tierValue = Utils.randInt(!isBoss ? 512 : 64); let tier = !isBoss @@ -38,6 +38,7 @@ export class Arena { } const tierPool = this.pokemonPool[tier]; let ret: PokemonSpecies; + let regen = false; if (!tierPool.length) ret = this.scene.randomSpecies(waveIndex, level); else { @@ -61,7 +62,30 @@ export class Arena { } ret = getPokemonSpecies(species); + + if (ret.legendary || ret.pseudoLegendary || ret.mythical) { + switch (true) { + case (ret.baseTotal >= 720): + regen = level < 90; + break; + case (ret.baseTotal >= 670): + regen = level < 70; + break; + case (ret.baseTotal >= 580): + regen = level < 50; + break; + default: + regen = level < 30; + break; + } + } } + + if (regen && (attempt || 0) < 10) { + console.log('Incompatible level: regenerating...'); + return this.randomSpecies(waveIndex, level, (attempt || 0) + 1); + } + const newSpeciesId = ret.getSpeciesForLevel(level); if (newSpeciesId !== ret.speciesId) { console.log('Replaced', Species[ret.speciesId], 'with', Species[newSpeciesId]); @@ -102,8 +126,6 @@ export class Arena { if (this.weather?.weatherType === (weather || undefined)) return false; - console.log('set weather', WeatherType[weather]); - const oldWeatherType = this.weather?.weatherType || WeatherType.NONE; this.weather = weather ? new Weather(weather, viaMove ? 5 : 0) : null; diff --git a/src/battle-info.ts b/src/battle-info.ts index 261448ad8e9..327ec8d5a64 100644 --- a/src/battle-info.ts +++ b/src/battle-info.ts @@ -239,6 +239,10 @@ export default class BattleInfo extends Phaser.GameObjects.Container { } }, onComplete: () => { + if (!this.scene) { + resolve(); + return; + } if (duration) this.scene.sound.stopByKey('exp'); if (ratio === 1) { @@ -270,7 +274,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { } setHpNumbers(hp: integer, maxHp: integer) { - if (!this.player) + if (!this.player || !this.scene) return; this.hpNumbersContainer.removeAll(true); const hpStr = hp.toString();