diff --git a/src/battle-phases.ts b/src/battle-phases.ts index 2f0b20c3f..c0c7a167e 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -246,7 +246,7 @@ export class EncounterPhase extends BattlePhase { battle.enemyParty[e] = battle.trainer.genPartyMember(e); else { const enemySpecies = this.scene.randomSpecies(battle.waveIndex, level, null, true); - battle.enemyParty[e] = new EnemyPokemon(this.scene, enemySpecies, level); + battle.enemyParty[e] = new EnemyPokemon(this.scene, enemySpecies, level, false); } } const enemyPokemon = this.scene.getEnemyParty()[e]; diff --git a/src/data/trainer-type.ts b/src/data/trainer-type.ts index 8eebf9cf7..61bfabb3f 100644 --- a/src/data/trainer-type.ts +++ b/src/data/trainer-type.ts @@ -521,7 +521,7 @@ function getGymLeaderPartyTemplate(scene: BattleScene) { function getRandomPartyMemberFunc(speciesPool: Species[], postProcess?: (enemyPokemon: EnemyPokemon) => void): PartyMemberFunc { return (scene: BattleScene, level: integer) => { const species = getPokemonSpecies(Phaser.Math.RND.pick(speciesPool)).getSpeciesForLevel(level, true); - const ret = new EnemyPokemon(scene, getPokemonSpecies(species), level); + const ret = new EnemyPokemon(scene, getPokemonSpecies(species), level, true); if (postProcess) postProcess(ret); return ret; @@ -532,7 +532,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); + const ret = new EnemyPokemon(scene, scene.randomSpecies(scene.currentBattle.waveIndex, level, speciesFilter), level, true); if (postProcess) postProcess(ret); return ret; diff --git a/src/pokemon.ts b/src/pokemon.ts index 5498a1933..4ee9b2941 100644 --- a/src/pokemon.ts +++ b/src/pokemon.ts @@ -125,23 +125,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } } - const rand1 = Utils.binToDec(Utils.decToBin(this.id).substring(0, 16)); - const rand2 = Utils.binToDec(Utils.decToBin(this.id).substring(16, 32)); - - const E = this.scene.gameData.trainerId ^ this.scene.gameData.secretId; - const F = rand1 ^ rand2; - - if (this.shiny === undefined) { - let shinyThreshold = new Utils.IntegerHolder(32); - this.scene.applyModifiers(ShinyRateBoosterModifier, true, shinyThreshold); - console.log(shinyThreshold.value); - - this.shiny = (E ^ F) < shinyThreshold.value; - if ((E ^ F) < 32) - console.log('REAL SHINY!!'); - if (this.shiny) - console.log((E ^ F), shinyThreshold.value); - } + if (this.shiny === undefined) + this.trySetShiny(); this.winCount = 0; this.pokerus = false; @@ -207,6 +192,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { abstract isPlayer(): boolean; + abstract hasTrainer(): boolean; + abstract getFieldIndex(): integer; abstract getBattlerIndex(): BattlerIndex; @@ -507,6 +494,26 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.summonData.moveset[moveIndex] = move; } + trySetShiny(): boolean { + const rand1 = Utils.binToDec(Utils.decToBin(this.id).substring(0, 16)); + const rand2 = Utils.binToDec(Utils.decToBin(this.id).substring(16, 32)); + + const E = this.scene.gameData.trainerId ^ this.scene.gameData.secretId; + const F = rand1 ^ rand2; + + let shinyThreshold = new Utils.IntegerHolder(32); + if (!this.hasTrainer()) { + this.scene.applyModifiers(ShinyRateBoosterModifier, true, shinyThreshold); + console.log(shinyThreshold.value); + } + + this.shiny = (E ^ F) < shinyThreshold.value; + if ((E ^ F) < 32) + console.log('REAL SHINY!!'); + + return this.shiny; + } + generateAndPopulateMoveset(): void { this.moveset = []; const movePool = []; @@ -1097,6 +1104,10 @@ export class PlayerPokemon extends Pokemon { return true; } + hasTrainer(): boolean { + return true; + } + getFieldIndex(): integer { return this.scene.getPlayerField().indexOf(this); } @@ -1165,12 +1176,15 @@ export class PlayerPokemon extends Pokemon { } export class EnemyPokemon extends Pokemon { + public trainer: boolean; public aiType: AiType; - constructor(scene: BattleScene, species: PokemonSpecies, level: integer, dataSource?: PokemonData) { + constructor(scene: BattleScene, species: PokemonSpecies, level: integer, trainer: boolean, dataSource?: PokemonData) { super(scene, 236, 84, species, level, dataSource?.abilityIndex, dataSource ? dataSource.formIndex : scene.arena.getFormIndex(species), dataSource?.gender, dataSource?.shiny, dataSource); + this.trainer = trainer; + if (!dataSource) { let prevolution: Species; let speciesId = species.speciesId; @@ -1323,6 +1337,10 @@ export class EnemyPokemon extends Pokemon { return false; } + hasTrainer(): boolean { + return this.trainer; + } + getFieldIndex(): integer { return this.scene.getEnemyField().indexOf(this); } diff --git a/src/system/game-data.ts b/src/system/game-data.ts index 28ba02c4d..fc988fa8f 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -253,7 +253,7 @@ export class GameData { scene.newArena(sessionData.arena.biome, true); sessionData.enemyParty.forEach((enemyData, e) => { - const enemyPokemon = enemyData.toPokemon(scene) as EnemyPokemon; + const enemyPokemon = enemyData.toPokemon(scene, battleType) as EnemyPokemon; battle.enemyParty[e] = enemyPokemon; if (battleType === BattleType.WILD) battle.seenEnemyPartyMemberIds.add(enemyPokemon.id); diff --git a/src/system/pokemon-data.ts b/src/system/pokemon-data.ts index 5c89fd5f7..5c768e020 100644 --- a/src/system/pokemon-data.ts +++ b/src/system/pokemon-data.ts @@ -1,3 +1,4 @@ +import { BattleType } from "../battle"; import BattleScene from "../battle-scene"; import { Gender } from "../data/gender"; import { PokeballType } from "../data/pokeball"; @@ -69,10 +70,10 @@ export default class PokemonData { } } - toPokemon(scene: BattleScene): Pokemon { + toPokemon(scene: BattleScene, battleType?: BattleType): Pokemon { const species = getPokemonSpecies(this.species); if (this.player) return new PlayerPokemon(scene, species, this.level, this.abilityIndex, this.formIndex, this.gender, this.shiny, this); - return new EnemyPokemon(scene, species, this.level, this); + return new EnemyPokemon(scene, species, this.level, battleType === BattleType.TRAINER, this); } } \ No newline at end of file diff --git a/src/trainer.ts b/src/trainer.ts index d901b482f..a2e674126 100644 --- a/src/trainer.ts +++ b/src/trainer.ts @@ -131,7 +131,7 @@ export default class Trainer extends Phaser.GameObjects.Container { ? getPokemonSpecies(battle.enemyParty[offset].species.getSpeciesForLevel(level)) : this.genNewPartyMemberSpecies(level); - ret = new EnemyPokemon(this.scene, species, level); + ret = new EnemyPokemon(this.scene, species, level, true); }, this.config.hasStaticParty ? this.config.getDerivedType() + ((index + 1) << 8) : this.scene.currentBattle.waveIndex + (this.config.getDerivedType() << 10) + ((index + 1) << 8)); return ret;