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);
const pokemon = this.generatePokemon();
if (pokemon.fusionSpecies)
pokemon.clearFusionSpecies();
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.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.end();
});
@ -323,8 +325,8 @@ export class EggHatchPhase extends BattlePhase {
updateParticle();
}
generatePokemon(): Pokemon {
let ret: Pokemon;
generatePokemon(): PlayerPokemon {
let ret: PlayerPokemon;
let speciesOverride: Species;
if (this.egg.isManaphyEgg()) {

View File

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

View File

@ -96,6 +96,7 @@ export interface DexEntry {
caughtAttr: bigint;
seenCount: integer;
caughtCount: integer;
hatchedCount: integer;
ivs: integer[];
}
@ -236,10 +237,8 @@ export class GameData {
? 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.consolidateDexData(this.dexData);
return true;
}
@ -529,7 +528,7 @@ export class GameData {
for (let species of allSpecies) {
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++;
}
setPokemonCaught(pokemon: Pokemon, incrementCount: boolean = true): Promise<void> {
return this.setPokemonSpeciesCaught(pokemon, pokemon.species, incrementCount);
setPokemonCaught(pokemon: Pokemon, incrementCount: boolean = true, fromEgg: boolean = false): Promise<void> {
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) => {
const dexEntry = this.dexData[species.speciesId];
const caughtAttr = dexEntry.caughtAttr;
dexEntry.caughtAttr |= pokemon.getDexAttr();
if (incrementCount)
dexEntry.seenCount++;
if (incrementCount) {
if (!fromEgg)
dexEntry.caughtCount++;
else
dexEntry.hatchedCount++;
}
const hasPrevolution = pokemonPrevolutions.hasOwnProperty(species.speciesId);
const newCatch = !caughtAttr;
@ -583,7 +586,7 @@ export class GameData {
const checkPrevolution = () => {
if (hasPrevolution) {
const prevolutionSpecies = pokemonPrevolutions[species.speciesId];
return this.setPokemonSpeciesCaught(pokemon, getPokemonSpecies(prevolutionSpecies)).then(() => resolve());
return this.setPokemonSpeciesCaught(pokemon, getPokemonSpecies(prevolutionSpecies), incrementCount, fromEgg).then(() => resolve());
} else
resolve();
};
@ -648,109 +651,11 @@ export class GameData {
return BigInt(Math.pow(2, 7 + formIndex));
}
// TODO: Remove
migrateLegacyDexData(dexData: DexData, legacyDexData: object): DexData {
const newDexData: DexData = {};
for (let s of Object.keys(legacyDexData)) {
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;
}
});
consolidateDexData(dexData: DexData): void {
for (let k of Object.keys(dexData)) {
const entry = dexData[k] as DexEntry;
if (!entry.hasOwnProperty('hatchedCount'))
entry.hatchedCount = 0;
}
}
});
newEntry.seenAttr = seenAttr;
newEntry.caughtAttr = caughtAttr;
}
return newDexData;
}
}