Fix various data related issues and add hatchedCount to DexEntry

This commit is contained in:
Flashfyre 2023-12-31 13:20:28 -05:00
parent db3ff7988f
commit 7a47c62535
3 changed files with 42 additions and 126 deletions

View File

@ -122,6 +122,8 @@ export class EggHatchPhase extends BattlePhase {
this.eggHatchContainer.add(this.infoContainer); this.eggHatchContainer.add(this.infoContainer);
const pokemon = this.generatePokemon(); const pokemon = this.generatePokemon();
if (pokemon.fusionSpecies)
pokemon.clearFusionSpecies();
let abilityYOffset = 5; let abilityYOffset = 5;
@ -210,7 +212,7 @@ export class EggHatchPhase extends BattlePhase {
this.scene.ui.showText(`${pokemon.name} hatched from the egg!`, null, () => { this.scene.ui.showText(`${pokemon.name} hatched from the egg!`, null, () => {
this.scene.gameData.updateSpeciesDexIvs(pokemon.species.speciesId, pokemon.ivs); this.scene.gameData.updateSpeciesDexIvs(pokemon.species.speciesId, pokemon.ivs);
this.scene.gameData.setPokemonCaught(pokemon).then(() => { this.scene.gameData.setPokemonCaught(pokemon, true, true).then(() => {
this.scene.ui.showText(null, 0); this.scene.ui.showText(null, 0);
this.end(); this.end();
}); });
@ -323,8 +325,8 @@ export class EggHatchPhase extends BattlePhase {
updateParticle(); updateParticle();
} }
generatePokemon(): Pokemon { generatePokemon(): PlayerPokemon {
let ret: Pokemon; let ret: PlayerPokemon;
let speciesOverride: Species; let speciesOverride: Species;
if (this.egg.isManaphyEgg()) { if (this.egg.isManaphyEgg()) {

View File

@ -775,6 +775,17 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
this.generateName(); this.generateName();
} }
clearFusionSpecies(): void {
this.fusionSpecies = undefined;
this.fusionFormIndex = 0;
this.fusionAbilityIndex = 0;
this.fusionShiny = false;
this.fusionGender = 0;
this.generateName();
this.calculateStats();
}
generateAndPopulateMoveset(): void { generateAndPopulateMoveset(): void {
this.moveset = []; this.moveset = [];
const movePool = []; const movePool = [];
@ -1815,6 +1826,11 @@ export class PlayerPokemon extends Pokemon {
return !!(this.fusionSpecies || (this.species.speciesId === Species.KYUREM && this.formIndex)); return !!(this.fusionSpecies || (this.species.speciesId === Species.KYUREM && this.formIndex));
} }
clearFusionSpecies(): void {
super.clearFusionSpecies();
this.generateCompatibleTms();
}
fuse(pokemon: PlayerPokemon): Promise<void> { fuse(pokemon: PlayerPokemon): Promise<void> {
return new Promise(resolve => { return new Promise(resolve => {
if (this.species.speciesId === Species.KYUREM && (pokemon.species.speciesId === Species.RESHIRAM || pokemon.species.speciesId === Species.ZEKROM)) if (this.species.speciesId === Species.KYUREM && (pokemon.species.speciesId === Species.RESHIRAM || pokemon.species.speciesId === Species.ZEKROM))
@ -1852,15 +1868,8 @@ export class PlayerPokemon extends Pokemon {
unfuse(): Promise<void> { unfuse(): Promise<void> {
return new Promise(resolve => { return new Promise(resolve => {
this.fusionSpecies = undefined; this.clearFusionSpecies();
this.fusionFormIndex = 0;
this.fusionAbilityIndex = 0;
this.fusionShiny = false;
this.fusionGender = 0;
this.generateName();
this.calculateStats();
this.generateCompatibleTms();
this.updateInfo(true).then(() => resolve()); this.updateInfo(true).then(() => resolve());
this.updateFusionPalette(); this.updateFusionPalette();
}); });

View File

@ -96,6 +96,7 @@ export interface DexEntry {
caughtAttr: bigint; caughtAttr: bigint;
seenCount: integer; seenCount: integer;
caughtCount: integer; caughtCount: integer;
hatchedCount: integer;
ivs: integer[]; ivs: integer[];
} }
@ -236,10 +237,8 @@ export class GameData {
? data.eggs.map(e => e.toEgg()) ? data.eggs.map(e => e.toEgg())
: []; : [];
if (data.dexData[1].hasOwnProperty(0))
this.migrateLegacyDexData(this.dexData, data.dexData);
else
this.dexData = Object.assign(this.dexData, data.dexData); this.dexData = Object.assign(this.dexData, data.dexData);
this.consolidateDexData(this.dexData);
return true; return true;
} }
@ -529,7 +528,7 @@ export class GameData {
for (let species of allSpecies) { for (let species of allSpecies) {
data[species.speciesId] = { data[species.speciesId] = {
seenAttr: 0n, caughtAttr: 0n, seenCount: 0, caughtCount: 0, ivs: [ 0, 0, 0, 0, 0, 0 ] seenAttr: 0n, caughtAttr: 0n, seenCount: 0, caughtCount: 0, hatchedCount: 0, ivs: [ 0, 0, 0, 0, 0, 0 ]
}; };
} }
@ -565,17 +564,21 @@ export class GameData {
dexEntry.seenCount++; dexEntry.seenCount++;
} }
setPokemonCaught(pokemon: Pokemon, incrementCount: boolean = true): Promise<void> { setPokemonCaught(pokemon: Pokemon, incrementCount: boolean = true, fromEgg: boolean = false): Promise<void> {
return this.setPokemonSpeciesCaught(pokemon, pokemon.species, incrementCount); return this.setPokemonSpeciesCaught(pokemon, pokemon.species, incrementCount, fromEgg);
} }
setPokemonSpeciesCaught(pokemon: Pokemon, species: PokemonSpecies, incrementCount?: boolean): Promise<void> { setPokemonSpeciesCaught(pokemon: Pokemon, species: PokemonSpecies, incrementCount: boolean = true, fromEgg: boolean = false): Promise<void> {
return new Promise<void>((resolve) => { return new Promise<void>((resolve) => {
const dexEntry = this.dexData[species.speciesId]; const dexEntry = this.dexData[species.speciesId];
const caughtAttr = dexEntry.caughtAttr; const caughtAttr = dexEntry.caughtAttr;
dexEntry.caughtAttr |= pokemon.getDexAttr(); dexEntry.caughtAttr |= pokemon.getDexAttr();
if (incrementCount) if (incrementCount) {
dexEntry.seenCount++; if (!fromEgg)
dexEntry.caughtCount++;
else
dexEntry.hatchedCount++;
}
const hasPrevolution = pokemonPrevolutions.hasOwnProperty(species.speciesId); const hasPrevolution = pokemonPrevolutions.hasOwnProperty(species.speciesId);
const newCatch = !caughtAttr; const newCatch = !caughtAttr;
@ -583,7 +586,7 @@ export class GameData {
const checkPrevolution = () => { const checkPrevolution = () => {
if (hasPrevolution) { if (hasPrevolution) {
const prevolutionSpecies = pokemonPrevolutions[species.speciesId]; const prevolutionSpecies = pokemonPrevolutions[species.speciesId];
return this.setPokemonSpeciesCaught(pokemon, getPokemonSpecies(prevolutionSpecies)).then(() => resolve()); return this.setPokemonSpeciesCaught(pokemon, getPokemonSpecies(prevolutionSpecies), incrementCount, fromEgg).then(() => resolve());
} else } else
resolve(); resolve();
}; };
@ -648,109 +651,11 @@ export class GameData {
return BigInt(Math.pow(2, 7 + formIndex)); return BigInt(Math.pow(2, 7 + formIndex));
} }
// TODO: Remove consolidateDexData(dexData: DexData): void {
migrateLegacyDexData(dexData: DexData, legacyDexData: object): DexData { for (let k of Object.keys(dexData)) {
const newDexData: DexData = {}; const entry = dexData[k] as DexEntry;
if (!entry.hasOwnProperty('hatchedCount'))
for (let s of Object.keys(legacyDexData)) { entry.hatchedCount = 0;
const species = getPokemonSpecies(parseInt(s));
const newEntry = dexData[parseInt(s)];
let seenAttr = 0n;
let caughtAttr = 0n;
Object.keys(legacyDexData[s]).forEach(shinyIndex => {
const shinyData = legacyDexData[s][shinyIndex];
if (species.forms?.length) {
Object.keys(shinyData).forEach(formIndex => {
const formData = shinyData[formIndex];
if (species.malePercent !== null) {
Object.keys(formData).forEach(genderIndex => {
const genderData = formData[genderIndex];
Object.keys(genderData).forEach(abilityIndex => {
const entry = genderData[abilityIndex];
if (entry.seen) {
seenAttr |= !parseInt(shinyIndex) ? DexAttr.NON_SHINY : DexAttr.SHINY;
seenAttr |= !parseInt(genderIndex) ? DexAttr.MALE : DexAttr.FEMALE;
seenAttr |= parseInt(abilityIndex) === 0 ? DexAttr.ABILITY_1 : parseInt(abilityIndex) === 1 && species.ability2 ? DexAttr.ABILITY_2 : DexAttr.ABILITY_HIDDEN;
seenAttr |= this.getFormAttr(parseInt(formIndex));
}
if (entry.caught) {
if (!caughtAttr)
newEntry.ivs = [ 10, 10, 10, 10, 10, 10 ];
caughtAttr |= !parseInt(shinyIndex) ? DexAttr.NON_SHINY : DexAttr.SHINY;
caughtAttr |= !parseInt(genderIndex) ? DexAttr.MALE : DexAttr.FEMALE;
caughtAttr |= parseInt(abilityIndex) === 0 ? DexAttr.ABILITY_1 : parseInt(abilityIndex) === 1 && species.ability2 ? DexAttr.ABILITY_2 : DexAttr.ABILITY_HIDDEN;
caughtAttr |= this.getFormAttr(parseInt(formIndex));
}
});
});
} else {
Object.keys(formData).forEach(abilityIndex => {
const entry = formData[abilityIndex];
if (entry.seen) {
seenAttr |= !parseInt(shinyIndex) ? DexAttr.NON_SHINY : DexAttr.SHINY;
seenAttr |= DexAttr.MALE;
seenAttr |= parseInt(abilityIndex) === 0 ? DexAttr.ABILITY_1 : parseInt(abilityIndex) === 1 && species.ability2 ? DexAttr.ABILITY_2 : DexAttr.ABILITY_HIDDEN;
seenAttr |= this.getFormAttr(parseInt(formIndex));
}
if (entry.caught) {
if (!caughtAttr)
newEntry.ivs = [ 10, 10, 10, 10, 10, 10 ];
caughtAttr |= !parseInt(shinyIndex) ? DexAttr.NON_SHINY : DexAttr.SHINY;
caughtAttr |= DexAttr.MALE;
caughtAttr |= parseInt(abilityIndex) === 0 ? DexAttr.ABILITY_1 : parseInt(abilityIndex) === 1 && species.ability2 ? DexAttr.ABILITY_2 : DexAttr.ABILITY_HIDDEN;
caughtAttr |= this.getFormAttr(parseInt(formIndex));
}
});
}
});
} else {
if (species.malePercent !== null) {
Object.keys(shinyData).forEach(genderIndex => {
const genderData = shinyData[genderIndex];
Object.keys(genderData).forEach(abilityIndex => {
const entry = genderData[abilityIndex];
if (entry.seen) {
seenAttr |= !parseInt(shinyIndex) ? DexAttr.NON_SHINY : DexAttr.SHINY;
seenAttr |= !parseInt(genderIndex) ? DexAttr.MALE : DexAttr.FEMALE;
seenAttr |= parseInt(abilityIndex) === 0 ? DexAttr.ABILITY_1 : parseInt(abilityIndex) === 1 && species.ability2 ? DexAttr.ABILITY_2 : DexAttr.ABILITY_HIDDEN;
seenAttr |= DexAttr.DEFAULT_FORM;
}
if (entry.caught) {
if (!caughtAttr)
newEntry.ivs = [ 10, 10, 10, 10, 10, 10 ];
caughtAttr |= !parseInt(shinyIndex) ? DexAttr.NON_SHINY : DexAttr.SHINY;
caughtAttr |= !parseInt(genderIndex) ? DexAttr.MALE : DexAttr.FEMALE;
caughtAttr |= parseInt(abilityIndex) === 0 ? DexAttr.ABILITY_1 : parseInt(abilityIndex) === 1 && species.ability2 ? DexAttr.ABILITY_2 : DexAttr.ABILITY_HIDDEN;
caughtAttr |= DexAttr.DEFAULT_FORM;
}
});
});
} else {
Object.keys(shinyData).forEach(abilityIndex => {
const entry = shinyData[abilityIndex];
if (entry.seen) {
seenAttr |= !parseInt(shinyIndex) ? DexAttr.NON_SHINY : DexAttr.SHINY;
seenAttr |= DexAttr.MALE;
seenAttr |= parseInt(abilityIndex) === 0 ? DexAttr.ABILITY_1 : parseInt(abilityIndex) === 1 && species.ability2 ? DexAttr.ABILITY_2 : DexAttr.ABILITY_HIDDEN;
seenAttr |= DexAttr.DEFAULT_FORM;
}
if (entry.caught) {
if (!caughtAttr)
newEntry.ivs = [ 10, 10, 10, 10, 10, 10 ];
caughtAttr |= !parseInt(shinyIndex) ? DexAttr.NON_SHINY : DexAttr.SHINY;
caughtAttr |= DexAttr.MALE;
caughtAttr |= parseInt(abilityIndex) === 0 ? DexAttr.ABILITY_1 : parseInt(abilityIndex) === 1 && species.ability2 ? DexAttr.ABILITY_2 : DexAttr.ABILITY_HIDDEN;
caughtAttr |= DexAttr.DEFAULT_FORM;
}
});
} }
} }
});
newEntry.seenAttr = seenAttr;
newEntry.caughtAttr = caughtAttr;
}
return newDexData;
}
} }