Consolidate broken variant data for players who missed 1.0.1
This commit is contained in:
parent
8faa77cfbf
commit
17eddd7b02
|
@ -2,7 +2,7 @@ export function getData() {
|
||||||
const dataStr = localStorage.getItem('data');
|
const dataStr = localStorage.getItem('data');
|
||||||
if (!dataStr)
|
if (!dataStr)
|
||||||
return null;
|
return null;
|
||||||
return JSON.parse(atob(dataStr), (k, v) => k.endsWith('Attr') && ![ 'natureAttr', 'passiveAttr', 'variantAttr' ].includes(k) ? BigInt(v) : v);
|
return JSON.parse(atob(dataStr), (k, v) => k.endsWith('Attr') && ![ 'natureAttr', 'abilityAttr', 'passiveAttr' ].includes(k) ? BigInt(v) : v);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSession() {
|
export function getSession() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import BattleScene, { PokeballCounts, bypassLogin } from "../battle-scene";
|
import BattleScene, { PokeballCounts, bypassLogin } from "../battle-scene";
|
||||||
import Pokemon, { EnemyPokemon, PlayerPokemon } from "../field/pokemon";
|
import Pokemon, { EnemyPokemon, PlayerPokemon } from "../field/pokemon";
|
||||||
import { pokemonPrevolutions } from "../data/pokemon-evolutions";
|
import { pokemonEvolutions, pokemonPrevolutions } from "../data/pokemon-evolutions";
|
||||||
import PokemonSpecies, { SpeciesFormKey, allSpecies, getPokemonSpecies, noStarterFormKeys, speciesStarters } from "../data/pokemon-species";
|
import PokemonSpecies, { SpeciesFormKey, allSpecies, getPokemonSpecies, noStarterFormKeys, speciesStarters } from "../data/pokemon-species";
|
||||||
import { Species, defaultStarterSpecies } from "../data/enums/species";
|
import { Species, defaultStarterSpecies } from "../data/enums/species";
|
||||||
import * as Utils from "../utils";
|
import * as Utils from "../utils";
|
||||||
|
@ -28,7 +28,7 @@ import { speciesEggMoves } from "../data/egg-moves";
|
||||||
import { allMoves } from "../data/move";
|
import { allMoves } from "../data/move";
|
||||||
import { TrainerVariant } from "../field/trainer";
|
import { TrainerVariant } from "../field/trainer";
|
||||||
import { OutdatedPhase, UnavailablePhase } from "#app/phases";
|
import { OutdatedPhase, UnavailablePhase } from "#app/phases";
|
||||||
import { Variant } from "#app/data/variant";
|
import { Variant, variantData } from "#app/data/variant";
|
||||||
|
|
||||||
const saveKey = 'x0i2O7WRiANTqPmZ'; // Temporary; secure encryption is not yet necessary
|
const saveKey = 'x0i2O7WRiANTqPmZ'; // Temporary; secure encryption is not yet necessary
|
||||||
|
|
||||||
|
@ -339,9 +339,12 @@ export class GameData {
|
||||||
for (let s of Object.keys(starterEggMoveData))
|
for (let s of Object.keys(starterEggMoveData))
|
||||||
this.starterData[s].eggMoves = starterEggMoveData[s];
|
this.starterData[s].eggMoves = starterEggMoveData[s];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.migrateStarterAbilities(systemData);
|
||||||
} else {
|
} else {
|
||||||
if ([ '1.0.0', '1.0.1' ].includes(systemData.gameVersion))
|
if ([ '1.0.0', '1.0.1' ].includes(systemData.gameVersion))
|
||||||
this.migrateStarterAbilities(systemData);
|
this.migrateStarterAbilities(systemData);
|
||||||
|
this.fixVariantData(systemData);
|
||||||
// Migrate ability starter data if empty for caught species
|
// Migrate ability starter data if empty for caught species
|
||||||
Object.keys(systemData.starterData).forEach(sd => {
|
Object.keys(systemData.starterData).forEach(sd => {
|
||||||
if (systemData.dexData[sd].caughtAttr && !systemData.starterData[sd].abilityAttr)
|
if (systemData.dexData[sd].caughtAttr && !systemData.starterData[sd].abilityAttr)
|
||||||
|
@ -1223,4 +1226,45 @@ export class GameData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fixVariantData(systemData: SystemSaveData): void {
|
||||||
|
const starterIds = Object.keys(this.starterData).map(s => parseInt(s) as Species);
|
||||||
|
const starterData = systemData.starterData;
|
||||||
|
const dexData = systemData.dexData;
|
||||||
|
if (starterIds.find(id => (dexData[id].caughtAttr & DexAttr.VARIANT_2 || dexData[id].caughtAttr & DexAttr.VARIANT_3) && !variantData[id])) {
|
||||||
|
for (let s of starterIds) {
|
||||||
|
const species = getPokemonSpecies(s);
|
||||||
|
if (variantData[s]) {
|
||||||
|
const tempCaughtAttr = dexData[s].caughtAttr;
|
||||||
|
let seenVariant2 = false;
|
||||||
|
let seenVariant3 = false;
|
||||||
|
let checkEvoSpecies = (es: Species) => {
|
||||||
|
seenVariant2 ||= !!(dexData[es].seenAttr & DexAttr.VARIANT_2);
|
||||||
|
seenVariant3 ||= !!(dexData[es].seenAttr & DexAttr.VARIANT_3);
|
||||||
|
if (pokemonEvolutions.hasOwnProperty(es)) {
|
||||||
|
for (let pe of pokemonEvolutions[es])
|
||||||
|
checkEvoSpecies(pe.speciesId);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
checkEvoSpecies(s);
|
||||||
|
if (dexData[s].caughtAttr & DexAttr.VARIANT_2 && !seenVariant2)
|
||||||
|
dexData[s].caughtAttr ^= DexAttr.VARIANT_2;
|
||||||
|
if (dexData[s].caughtAttr & DexAttr.VARIANT_3 && !seenVariant3)
|
||||||
|
dexData[s].caughtAttr ^= DexAttr.VARIANT_3;
|
||||||
|
starterData[s].abilityAttr = (tempCaughtAttr & DexAttr.DEFAULT_VARIANT ? AbilityAttr.ABILITY_1 : 0)
|
||||||
|
| (tempCaughtAttr & DexAttr.VARIANT_2 && species.ability2 ? AbilityAttr.ABILITY_2 : 0)
|
||||||
|
| (tempCaughtAttr & DexAttr.VARIANT_3 && species.abilityHidden ? AbilityAttr.ABILITY_HIDDEN : 0);
|
||||||
|
} else {
|
||||||
|
const tempCaughtAttr = dexData[s].caughtAttr;
|
||||||
|
if (dexData[s].caughtAttr & DexAttr.VARIANT_2)
|
||||||
|
dexData[s].caughtAttr ^= DexAttr.VARIANT_2;
|
||||||
|
if (dexData[s].caughtAttr & DexAttr.VARIANT_3)
|
||||||
|
dexData[s].caughtAttr ^= DexAttr.VARIANT_3;
|
||||||
|
starterData[s].abilityAttr = (tempCaughtAttr & DexAttr.DEFAULT_VARIANT ? AbilityAttr.ABILITY_1 : 0)
|
||||||
|
| (tempCaughtAttr & DexAttr.VARIANT_2 && species.ability2 ? AbilityAttr.ABILITY_2 : 0)
|
||||||
|
| (tempCaughtAttr & DexAttr.VARIANT_3 && species.abilityHidden ? AbilityAttr.ABILITY_HIDDEN : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue