From 23e3bdc9600b1d58dbac839283febea7114bb3f2 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Fri, 29 Mar 2024 00:03:54 -0400 Subject: [PATCH] Bosses generate with higher IVs --- src/battle-scene.ts | 6 ++++++ src/egg-hatch-phase.ts | 10 +--------- src/field/pokemon.ts | 9 +-------- src/phases.ts | 2 +- src/utils.ts | 11 +++++++++++ 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index a37990af5..4e8b06c4a 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -758,6 +758,12 @@ export default class BattleScene extends Phaser.Scene { addEnemyPokemon(species: PokemonSpecies, level: integer, trainerSlot: TrainerSlot, boss: boolean = false, dataSource?: PokemonData, postProcess?: (enemyPokemon: EnemyPokemon) => void): EnemyPokemon { const pokemon = new EnemyPokemon(this, species, level, trainerSlot, boss, dataSource); + if (boss) { + const secondaryIvs = Utils.getIvsFromId(Utils.randSeedInt(4294967295)); + + for (let s = 0; s < pokemon.ivs.length; s++) + pokemon.ivs[s] = Math.round(Phaser.Math.Linear(Math.min(pokemon.ivs[s], secondaryIvs[s]), Math.max(pokemon.ivs[s], secondaryIvs[s]), 0.75)); + } if (postProcess) postProcess(pokemon); pokemon.init(); diff --git a/src/egg-hatch-phase.ts b/src/egg-hatch-phase.ts index 34d95835f..3f38a5f4c 100644 --- a/src/egg-hatch-phase.ts +++ b/src/egg-hatch-phase.ts @@ -382,15 +382,7 @@ export class EggHatchPhase extends Phase { ret.trySetShiny(this.egg.gachaType === GachaType.SHINY ? 1024 : 512); - const secondaryId = Utils.randSeedInt(4294967295); - const secondaryIvs = [ - Utils.binToDec(Utils.decToBin(secondaryId).substring(0, 5)), - Utils.binToDec(Utils.decToBin(secondaryId).substring(5, 10)), - Utils.binToDec(Utils.decToBin(secondaryId).substring(10, 15)), - Utils.binToDec(Utils.decToBin(secondaryId).substring(15, 20)), - Utils.binToDec(Utils.decToBin(secondaryId).substring(20, 25)), - Utils.binToDec(Utils.decToBin(secondaryId).substring(25, 30)) - ]; + const secondaryIvs = Utils.getIvsFromId(Utils.randSeedInt(4294967295)); for (let s = 0; s < ret.ivs.length; s++) ret.ivs[s] = Math.max(ret.ivs[s], secondaryIvs[s]); diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index dea7ebe4e..86bdd280d 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -145,14 +145,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.fusionGender = dataSource.fusionGender; } else { this.id = Utils.randSeedInt(4294967296); - this.ivs = ivs || [ - Utils.binToDec(Utils.decToBin(this.id).substring(0, 5)), - Utils.binToDec(Utils.decToBin(this.id).substring(5, 10)), - Utils.binToDec(Utils.decToBin(this.id).substring(10, 15)), - Utils.binToDec(Utils.decToBin(this.id).substring(15, 20)), - Utils.binToDec(Utils.decToBin(this.id).substring(20, 25)), - Utils.binToDec(Utils.decToBin(this.id).substring(25, 30)) - ]; + this.ivs = ivs || Utils.getIvsFromId(this.id); if (this.gender === undefined) { if (this.species.malePercent === null) diff --git a/src/phases.ts b/src/phases.ts index 67e4612bf..4351f089a 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -645,7 +645,7 @@ export class EncounterPhase extends BattlePhase { this.scene.field.add(enemyPokemon); battle.seenEnemyPartyMemberIds.add(enemyPokemon.id); const playerPokemon = this.scene.getPlayerPokemon(); - if (playerPokemon.visible) + if (playerPokemon?.visible) this.scene.field.moveBelow(enemyPokemon as Pokemon, playerPokemon); enemyPokemon.tint(0, 0.5); } else if (battle.battleType === BattleType.TRAINER) { diff --git a/src/utils.ts b/src/utils.ts index e96d27969..15ef65587 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -149,6 +149,17 @@ export function decToBin(input: integer): string { return bin; } +export function getIvsFromId(id: integer): integer[] { + return [ + binToDec(decToBin(id).substring(0, 5)), + binToDec(decToBin(id).substring(5, 10)), + binToDec(decToBin(id).substring(10, 15)), + binToDec(decToBin(id).substring(15, 20)), + binToDec(decToBin(id).substring(20, 25)), + binToDec(decToBin(id).substring(25, 30)) + ]; +} + export function formatLargeNumber(count: integer, threshold: integer): string { if (count < threshold) return count.toString();