From 17eddd7b021cbfba663e0c8e3a17aefe0b04eed4 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Sat, 20 Apr 2024 22:30:28 -0400 Subject: [PATCH] Consolidate broken variant data for players who missed 1.0.1 --- src/debug.js | 2 +- src/system/game-data.ts | 48 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/debug.js b/src/debug.js index 68f95c411..b627dba65 100644 --- a/src/debug.js +++ b/src/debug.js @@ -2,7 +2,7 @@ export function getData() { const dataStr = localStorage.getItem('data'); if (!dataStr) 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() { diff --git a/src/system/game-data.ts b/src/system/game-data.ts index 15969ebd7..88fcb2ce7 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -1,6 +1,6 @@ import BattleScene, { PokeballCounts, bypassLogin } from "../battle-scene"; 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 { Species, defaultStarterSpecies } from "../data/enums/species"; import * as Utils from "../utils"; @@ -28,7 +28,7 @@ import { speciesEggMoves } from "../data/egg-moves"; import { allMoves } from "../data/move"; import { TrainerVariant } from "../field/trainer"; 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 @@ -339,9 +339,12 @@ export class GameData { for (let s of Object.keys(starterEggMoveData)) this.starterData[s].eggMoves = starterEggMoveData[s]; } + + this.migrateStarterAbilities(systemData); } else { if ([ '1.0.0', '1.0.1' ].includes(systemData.gameVersion)) this.migrateStarterAbilities(systemData); + this.fixVariantData(systemData); // Migrate ability starter data if empty for caught species Object.keys(systemData.starterData).forEach(sd => { 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); + } + } + } + } } \ No newline at end of file