Fix RNG issues with egg moves

This commit is contained in:
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,85 +369,76 @@ 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;
switch (this.egg.tier) { switch (this.egg.tier) {
case EggTier.GREAT: case EggTier.GREAT:
minStarterValue = 4; minStarterValue = 4;
maxStarterValue = 5; maxStarterValue = 5;
break; break;
case EggTier.ULTRA: case EggTier.ULTRA:
minStarterValue = 6; minStarterValue = 6;
maxStarterValue = 7; maxStarterValue = 7;
break; break;
case EggTier.MASTER: case EggTier.MASTER:
minStarterValue = 8; minStarterValue = 8;
maxStarterValue = 9; maxStarterValue = 9;
break; break;
default: default:
minStarterValue = 1; minStarterValue = 1;
maxStarterValue = 3; maxStarterValue = 3;
break; break;
}
const ignoredSpecies = [ Species.PHIONE, Species.MANAPHY, Species.ETERNATUS ];
let speciesPool = Object.keys(speciesStarters)
.filter(s => speciesStarters[s] >= minStarterValue && speciesStarters[s] <= maxStarterValue)
.map(s => parseInt(s) as Species)
.filter(s => !pokemonPrevolutions.hasOwnProperty(s) && getPokemonSpecies(s).isObtainable() && ignoredSpecies.indexOf(s) === -1);
if (this.egg.gachaType === GachaType.TYPE) {
let tryOverrideType: boolean;
this.scene.executeWithSeedOffset(() => {
tryOverrideType = !Utils.randSeedInt(2);
}, this.egg.id, EGG_SEED.toString());
if (tryOverrideType) {
const type = getTypeGachaTypeForTimestamp(this.scene, this.egg.timestamp);
const typeFilteredSpeciesPool = speciesPool
.filter(s => getPokemonSpecies(s).isOfType(type));
if (typeFilteredSpeciesPool.length)
speciesPool = typeFilteredSpeciesPool;
} }
}
let totalWeight = 0; const ignoredSpecies = [ Species.PHIONE, Species.MANAPHY, Species.ETERNATUS ];
const speciesWeights = [];
for (let speciesId of speciesPool) {
let weight = Math.floor((((maxStarterValue - speciesStarters[speciesId]) / ((maxStarterValue - minStarterValue) + 1)) * 1.5 + 1) * 100);
const species = getPokemonSpecies(speciesId);
if (species.isRegional())
weight = Math.floor(weight / (species.isRareRegional() ? 8 : 2));
speciesWeights.push(totalWeight + weight);
totalWeight += weight;
}
let species: Species; let speciesPool = Object.keys(speciesStarters)
.filter(s => speciesStarters[s] >= minStarterValue && speciesStarters[s] <= maxStarterValue)
.map(s => parseInt(s) as Species)
.filter(s => !pokemonPrevolutions.hasOwnProperty(s) && getPokemonSpecies(s).isObtainable() && ignoredSpecies.indexOf(s) === -1);
if (this.egg.gachaType === GachaType.TYPE) {
let tryOverrideType = !Utils.randSeedInt(2);
if (tryOverrideType) {
const type = getTypeGachaTypeForTimestamp(this.scene, this.egg.timestamp);
const typeFilteredSpeciesPool = speciesPool
.filter(s => getPokemonSpecies(s).isOfType(type));
if (typeFilteredSpeciesPool.length)
speciesPool = typeFilteredSpeciesPool;
}
}
let totalWeight = 0;
const speciesWeights = [];
for (let speciesId of speciesPool) {
let weight = Math.floor((((maxStarterValue - speciesStarters[speciesId]) / ((maxStarterValue - minStarterValue) + 1)) * 1.5 + 1) * 100);
const species = getPokemonSpecies(speciesId);
if (species.isRegional())
weight = Math.floor(weight / (species.isRareRegional() ? 8 : 2));
speciesWeights.push(totalWeight + weight);
totalWeight += weight;
}
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;
} }