Fix RNG issues with egg moves

pull/16/head
Flashfyre 2024-03-01 22:18:39 -05:00
parent ce60d46fd1
commit 1fed59837b
2 changed files with 61 additions and 73 deletions

View File

@ -369,25 +369,21 @@ export class EggHatchPhase extends Phase {
let ret: PlayerPokemon; let ret: PlayerPokemon;
let speciesOverride: Species; let speciesOverride: Species;
if (this.egg.isManaphyEgg()) {
this.scene.executeWithSeedOffset(() => { this.scene.executeWithSeedOffset(() => {
if (this.egg.isManaphyEgg()) {
const rand = Utils.randSeedInt(8); const rand = Utils.randSeedInt(8);
speciesOverride = rand ? Species.PHIONE : Species.MANAPHY; speciesOverride = rand ? Species.PHIONE : Species.MANAPHY;
}, this.egg.id, EGG_SEED.toString());
} else if (this.egg.tier === EggTier.MASTER } else if (this.egg.tier === EggTier.MASTER
&& this.egg.gachaType === GachaType.LEGENDARY) { && this.egg.gachaType === GachaType.LEGENDARY) {
this.scene.executeWithSeedOffset(() => {
if (!Utils.randSeedInt(2)) if (!Utils.randSeedInt(2))
speciesOverride = getLegendaryGachaSpeciesForTimestamp(this.scene, this.egg.timestamp); speciesOverride = getLegendaryGachaSpeciesForTimestamp(this.scene, this.egg.timestamp);
}, this.egg.id, EGG_SEED.toString());
} }
if (speciesOverride) { if (speciesOverride) {
this.scene.executeWithSeedOffset(() => {
const pokemonSpecies = getPokemonSpecies(speciesOverride); const pokemonSpecies = getPokemonSpecies(speciesOverride);
ret = this.scene.addPlayerPokemon(pokemonSpecies, 5, undefined, undefined, undefined, false); ret = this.scene.addPlayerPokemon(pokemonSpecies, 5, undefined, undefined, undefined, false);
}, this.egg.id, EGG_SEED.toString());
} else { } else {
let minStarterValue: integer; let minStarterValue: integer;
let maxStarterValue: integer; let maxStarterValue: integer;
@ -419,11 +415,7 @@ export class EggHatchPhase extends Phase {
.filter(s => !pokemonPrevolutions.hasOwnProperty(s) && getPokemonSpecies(s).isObtainable() && ignoredSpecies.indexOf(s) === -1); .filter(s => !pokemonPrevolutions.hasOwnProperty(s) && getPokemonSpecies(s).isObtainable() && ignoredSpecies.indexOf(s) === -1);
if (this.egg.gachaType === GachaType.TYPE) { if (this.egg.gachaType === GachaType.TYPE) {
let tryOverrideType: boolean; let tryOverrideType = !Utils.randSeedInt(2);
this.scene.executeWithSeedOffset(() => {
tryOverrideType = !Utils.randSeedInt(2);
}, this.egg.id, EGG_SEED.toString());
if (tryOverrideType) { if (tryOverrideType) {
const type = getTypeGachaTypeForTimestamp(this.scene, this.egg.timestamp); const type = getTypeGachaTypeForTimestamp(this.scene, this.egg.timestamp);
@ -447,7 +439,6 @@ export class EggHatchPhase extends Phase {
let species: Species; let species: Species;
this.scene.executeWithSeedOffset(() => {
const rand = Utils.randSeedInt(totalWeight); const rand = Utils.randSeedInt(totalWeight);
for (let s = 0; s < speciesWeights.length; s++) { for (let s = 0; s < speciesWeights.length; s++) {
if (rand < speciesWeights[s]) { if (rand < speciesWeights[s]) {
@ -459,12 +450,10 @@ export class EggHatchPhase extends Phase {
const pokemonSpecies = getPokemonSpecies(species); const pokemonSpecies = getPokemonSpecies(species);
ret = this.scene.addPlayerPokemon(pokemonSpecies, 5, undefined, undefined, undefined, false); ret = this.scene.addPlayerPokemon(pokemonSpecies, 5, undefined, undefined, undefined, false);
}, this.egg.id, EGG_SEED.toString());
} }
ret.trySetShiny(this.egg.gachaType === GachaType.SHINY ? 1024 : 512); ret.trySetShiny(this.egg.gachaType === GachaType.SHINY ? 1024 : 512);
this.scene.executeWithSeedOffset(() => {
const secondaryId = Utils.randSeedInt(4294967295); const secondaryId = Utils.randSeedInt(4294967295);
const secondaryIvs = [ const secondaryIvs = [
Utils.binToDec(Utils.decToBin(secondaryId).substring(0, 5)), Utils.binToDec(Utils.decToBin(secondaryId).substring(0, 5)),
@ -474,11 +463,10 @@ export class EggHatchPhase extends Phase {
Utils.binToDec(Utils.decToBin(secondaryId).substring(20, 25)), Utils.binToDec(Utils.decToBin(secondaryId).substring(20, 25)),
Utils.binToDec(Utils.decToBin(secondaryId).substring(25, 30)) Utils.binToDec(Utils.decToBin(secondaryId).substring(25, 30))
]; ];
for (let s = 0; s < ret.ivs.length; s++) for (let s = 0; s < ret.ivs.length; s++)
ret.ivs[s] = Math.max(ret.ivs[s], secondaryIvs[s]); ret.ivs[s] = Math.max(ret.ivs[s], secondaryIvs[s]);
}, ret.id, EGG_SEED.toString());
this.scene.executeWithSeedOffset(() => {
const rand = Utils.randSeedInt(10); const rand = Utils.randSeedInt(10);
this.eggMoveIndex = rand ? Math.floor((rand - 1) / 3) : 3; this.eggMoveIndex = rand ? Math.floor((rand - 1) / 3) : 3;

View File

@ -911,7 +911,7 @@ export class GameData {
const value = Math.pow(2, eggMoveIndex); const value = Math.pow(2, eggMoveIndex);
if (this.starterEggMoveData[speciesId] & eggMoveIndex) { if (this.starterEggMoveData[speciesId] & value) {
resolve(false); resolve(false);
return; return;
} }