diff --git a/src/battle-phases.ts b/src/battle-phases.ts index f3b5a0f4e06..4074a694dc2 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -111,6 +111,8 @@ export class SelectStarterPhase extends BattlePhase { const starterPokemon = new PlayerPokemon(this.scene, starter.species, startingLevel, starter.abilityIndex, starter.formIndex, starterGender, starter.shiny); if (starter.pokerus) starterPokemon.pokerus = true; + if (this.scene.gameMode === GameMode.SPLICED_ENDLESS) + starterPokemon.generateFusionSpecies(true); starterPokemon.setVisible(false); party.push(starterPokemon); loadPokemonAssets.push(starterPokemon.loadAssets()); @@ -245,7 +247,7 @@ export class EncounterPhase extends BattlePhase { if (battle.battleType === BattleType.TRAINER) battle.enemyParty[e] = battle.trainer.genPartyMember(e); else { - const enemySpecies = this.scene.randomSpecies(battle.waveIndex, level, null, true); + const enemySpecies = this.scene.randomSpecies(battle.waveIndex, level, true); battle.enemyParty[e] = new EnemyPokemon(this.scene, enemySpecies, level, false); } } diff --git a/src/battle-scene.ts b/src/battle-scene.ts index cc1e624462c..c17bbb1d4a9 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -456,7 +456,7 @@ export default class BattleScene extends Phaser.Scene { if (this.quickStart) { for (let s = 0; s < 3; s++) { - const playerSpecies = this.randomSpecies(startingWave, startingLevel, null, false); + const playerSpecies = this.randomSpecies(startingWave, startingLevel); const playerPokemon = new PlayerPokemon(this, playerSpecies, startingLevel, 0, 0); playerPokemon.setVisible(false); this.party.push(playerPokemon); @@ -815,15 +815,20 @@ export default class BattleScene extends Phaser.Scene { return Math.min(Math.ceil(baseLevel / 2) * 2 + 2, 10000); } - randomSpecies(waveIndex: integer, level: integer, speciesFilter?: PokemonSpeciesFilter, fromArenaPool?: boolean): PokemonSpecies { + randomSpecies(waveIndex: integer, level: integer, fromArenaPool?: boolean, speciesFilter?: PokemonSpeciesFilter, filterAllEvolutions?: boolean): PokemonSpecies { if (fromArenaPool) return this.arena.randomSpecies(waveIndex, level); const filteredSpecies = speciesFilter ? [...new Set(allSpecies.slice(0, -1).filter(speciesFilter).map(s => { - while (pokemonPrevolutions.hasOwnProperty(s.speciesId)) - s = getPokemonSpecies(pokemonPrevolutions[s.speciesId]); + if (!filterAllEvolutions) { + while (pokemonPrevolutions.hasOwnProperty(s.speciesId)) + s = getPokemonSpecies(pokemonPrevolutions[s.speciesId]); + } return s; }))] : allSpecies.slice(0, -1); - return getPokemonSpecies(filteredSpecies[Utils.randSeedInt(filteredSpecies.length)].getSpeciesForLevel(level, true)); + let ret = filteredSpecies[Utils.randSeedInt(filteredSpecies.length)]; + if (!filterAllEvolutions) + ret = getPokemonSpecies(ret.getSpeciesForLevel(level, true)); + return ret; } checkInput(): boolean { diff --git a/src/data/trainer-type.ts b/src/data/trainer-type.ts index 29df2ed18be..8056f23ba9e 100644 --- a/src/data/trainer-type.ts +++ b/src/data/trainer-type.ts @@ -531,7 +531,7 @@ function getSpeciesFilterRandomPartyMemberFunc(speciesFilter: PokemonSpeciesFilt const originalSpeciesFilter = speciesFilter; speciesFilter = (species: PokemonSpecies) => allowLegendaries || (!species.legendary && !species.pseudoLegendary && !species.mythical) && originalSpeciesFilter(species); return (scene: BattleScene, level: integer) => { - const ret = new EnemyPokemon(scene, scene.randomSpecies(scene.currentBattle.waveIndex, level, speciesFilter), level, true); + const ret = new EnemyPokemon(scene, scene.randomSpecies(scene.currentBattle.waveIndex, level, false, speciesFilter), level, true); if (postProcess) postProcess(ret); return ret; diff --git a/src/pokemon.ts b/src/pokemon.ts index 990a0000940..0803b53defe 100644 --- a/src/pokemon.ts +++ b/src/pokemon.ts @@ -154,22 +154,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.winCount = 0; this.pokerus = false; - if (scene.gameMode === GameMode.SPLICED_ENDLESS) { - this.fusionSpecies = scene.randomSpecies(scene.currentBattle?.waveIndex || 0, level, this.species.getCompatibleFusionSpeciesFilter(), false); - this.fusionAbilityIndex = (this.fusionSpecies.abilityHidden && hasHiddenAbility ? this.fusionSpecies.ability2 ? 2 : 1 : this.fusionSpecies.ability2 ? randAbilityIndex : 0); - this.fusionFormIndex = scene.getSpeciesFormIndex(this.fusionSpecies); - this.fusionShiny = this.shiny; - - if (this.getFusionSpeciesForm().malePercent === null) - this.fusionGender = Gender.GENDERLESS; - else { - const genderChance = (this.id % 256) * 0.390625; - if (genderChance < this.getFusionSpeciesForm().malePercent) - this.fusionGender = Gender.MALE; - else - this.fusionGender = Gender.FEMALE; - } - } + if (scene.gameMode === GameMode.SPLICED_ENDLESS) + this.generateFusionSpecies(); } if (!species.isObtainable()) @@ -597,6 +583,39 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return this.shiny; } + generateFusionSpecies(forStarter?: boolean): void { + const hiddenAbilityChance = new Utils.IntegerHolder(256); + if (!this.hasTrainer()) + this.scene.applyModifiers(HiddenAbilityRateBoosterModifier, true, hiddenAbilityChance); + + const hasHiddenAbility = !Utils.randSeedInt(hiddenAbilityChance.value); + const randAbilityIndex = Utils.randSeedInt(2); + + const filter = !forStarter ? this.species.getCompatibleFusionSpeciesFilter() + : species => { + return pokemonEvolutions.hasOwnProperty(species.speciesId) + && !pokemonPrevolutions.hasOwnProperty(species.speciesId) + && !species.pseudoLegendary + && !species.legendary + && !species.mythical + }; + + this.fusionSpecies = this.scene.randomSpecies(this.scene.currentBattle?.waveIndex || 0, this.level, false, filter, true); + this.fusionAbilityIndex = (this.fusionSpecies.abilityHidden && hasHiddenAbility ? this.fusionSpecies.ability2 ? 2 : 1 : this.fusionSpecies.ability2 ? randAbilityIndex : 0); + this.fusionFormIndex = this.scene.getSpeciesFormIndex(this.fusionSpecies); + this.fusionShiny = this.shiny; + + if (this.getFusionSpeciesForm().malePercent === null) + this.fusionGender = Gender.GENDERLESS; + else { + const genderChance = (this.id % 256) * 0.390625; + if (genderChance < this.getFusionSpeciesForm().malePercent) + this.fusionGender = Gender.MALE; + else + this.fusionGender = Gender.FEMALE; + } + } + generateAndPopulateMoveset(): void { this.moveset = []; const movePool = []; diff --git a/src/trainer.ts b/src/trainer.ts index a2e67412696..9c1dc58ebf3 100644 --- a/src/trainer.ts +++ b/src/trainer.ts @@ -153,7 +153,7 @@ export default class Trainer extends Phaser.GameObjects.Container { const tierPool = this.config.speciesPools[tier]; ret = getPokemonSpecies(getPokemonSpecies(Phaser.Math.RND.pick(tierPool)).getSpeciesForLevel(level, true)); } else - ret = getPokemonSpecies(this.scene.randomSpecies(battle.waveIndex, level, this.config.speciesFilter).getSpeciesForLevel(level)); + ret = getPokemonSpecies(this.scene.randomSpecies(battle.waveIndex, level, false, this.config.speciesFilter).getSpeciesForLevel(level)); if (template.isBalanced(battle.enemyParty.length)) { const partyMemberTypes = battle.enemyParty.map(p => p.getTypes()).flat();