From 6a3ca62490fcf60dcb216403d3e33f0318f3ff17 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Sun, 5 May 2024 17:11:29 -0400 Subject: [PATCH] Add separate sub-legendary stats --- src/system/game-data.ts | 35 +++++++++++++++++++++++++++++---- src/system/game-stats.ts | 7 +++++++ src/ui/game-stats-ui-handler.ts | 13 +++++++----- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/system/game-data.ts b/src/system/game-data.ts index b828d90f5..bf5486810 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -358,8 +358,11 @@ export class GameData { this.starterData = systemData.starterData; } - if (systemData.gameStats) + if (systemData.gameStats) { + if (systemData.gameStats.legendaryPokemonCaught !== undefined && systemData.gameStats.subLegendaryPokemonCaught === undefined) + this.fixLegendaryStats(systemData); this.gameStats = systemData.gameStats; + } if (systemData.unlocks) { for (let key of Object.keys(systemData.unlocks)) { @@ -1005,7 +1008,9 @@ export class GameData { if (incrementCount) { dexEntry.seenCount++; this.gameStats.pokemonSeen++; - if (!trainer && pokemon.species.subLegendary || pokemon.species.legendary) + if (!trainer && pokemon.species.subLegendary) + this.gameStats.subLegendaryPokemonSeen++; + else if (!trainer && pokemon.species.legendary) this.gameStats.legendaryPokemonSeen++; else if (!trainer && pokemon.species.mythical) this.gameStats.mythicalPokemonSeen++; @@ -1043,7 +1048,9 @@ export class GameData { if (!fromEgg) { dexEntry.caughtCount++; this.gameStats.pokemonCaught++; - if (pokemon.species.subLegendary || pokemon.species.legendary) + if (pokemon.species.subLegendary) + this.gameStats.subLegendaryPokemonCaught++; + else if (pokemon.species.legendary) this.gameStats.legendaryPokemonCaught++; else if (pokemon.species.mythical) this.gameStats.mythicalPokemonCaught++; @@ -1052,7 +1059,9 @@ export class GameData { } else { dexEntry.hatchedCount++; this.gameStats.pokemonHatched++; - if (pokemon.species.subLegendary || pokemon.species.legendary) + if (pokemon.species.subLegendary) + this.gameStats.subLegendaryPokemonHatched++; + else if (pokemon.species.legendary) this.gameStats.legendaryPokemonHatched++; else if (pokemon.species.mythical) this.gameStats.mythicalPokemonHatched++; @@ -1311,4 +1320,22 @@ export class GameData { for (let starterId of defaultStarterSpecies) systemData.starterData[starterId].abilityAttr |= AbilityAttr.ABILITY_1; } + + fixLegendaryStats(systemData: SystemSaveData): void { + systemData.gameStats.subLegendaryPokemonSeen = 0; + systemData.gameStats.subLegendaryPokemonCaught = 0; + systemData.gameStats.subLegendaryPokemonHatched = 0; + allSpecies.filter(s => s.subLegendary).forEach(s => { + const dexEntry = systemData.dexData[s.speciesId]; + systemData.gameStats.subLegendaryPokemonSeen += dexEntry.seenCount; + systemData.gameStats.legendaryPokemonSeen = Math.max(systemData.gameStats.legendaryPokemonSeen - dexEntry.seenCount, 0); + systemData.gameStats.subLegendaryPokemonCaught += dexEntry.caughtCount; + systemData.gameStats.legendaryPokemonCaught = Math.max(systemData.gameStats.legendaryPokemonCaught - dexEntry.caughtCount, 0); + systemData.gameStats.subLegendaryPokemonHatched += dexEntry.hatchedCount; + systemData.gameStats.legendaryPokemonHatched = Math.max(systemData.gameStats.legendaryPokemonHatched - dexEntry.hatchedCount, 0); + }); + systemData.gameStats.subLegendaryPokemonSeen = Math.max(systemData.gameStats.subLegendaryPokemonSeen, systemData.gameStats.subLegendaryPokemonCaught); + systemData.gameStats.legendaryPokemonSeen = Math.max(systemData.gameStats.legendaryPokemonSeen, systemData.gameStats.legendaryPokemonCaught); + systemData.gameStats.mythicalPokemonSeen = Math.max(systemData.gameStats.mythicalPokemonSeen, systemData.gameStats.mythicalPokemonCaught); + } } \ No newline at end of file diff --git a/src/system/game-stats.ts b/src/system/game-stats.ts index 9a564b3c3..bf25b0e88 100644 --- a/src/system/game-stats.ts +++ b/src/system/game-stats.ts @@ -18,6 +18,9 @@ export class GameStats { public pokemonDefeated: integer; public pokemonCaught: integer; public pokemonHatched: integer; + public subLegendaryPokemonSeen: integer; + public subLegendaryPokemonCaught: integer; + public subLegendaryPokemonHatched: integer; public legendaryPokemonSeen: integer; public legendaryPokemonCaught: integer; public legendaryPokemonHatched: integer; @@ -52,6 +55,10 @@ export class GameStats { this.pokemonDefeated = source?.pokemonDefeated || 0; this.pokemonCaught = source?.pokemonCaught || 0; this.pokemonHatched = source?.pokemonHatched || 0; + // Currently handled by migration + this.subLegendaryPokemonSeen = source?.subLegendaryPokemonSeen; + this.subLegendaryPokemonCaught = source?.subLegendaryPokemonCaught; + this.subLegendaryPokemonHatched = source?.subLegendaryPokemonHatched; this.legendaryPokemonSeen = source?.legendaryPokemonSeen || 0; this.legendaryPokemonCaught = source?.legendaryPokemonCaught || 0; this.legendaryPokemonHatched = source?.legendaryPokemonHatched || 0; diff --git a/src/ui/game-stats-ui-handler.ts b/src/ui/game-stats-ui-handler.ts index 0b97d322e..6b067912c 100644 --- a/src/ui/game-stats-ui-handler.ts +++ b/src/ui/game-stats-ui-handler.ts @@ -64,13 +64,16 @@ const displayStats: DisplayStats = { pokemonDefeated: 'Pokémon Defeated', pokemonCaught: 'Pokémon Caught', pokemonHatched: 'Eggs Hatched', - legendaryPokemonSeen: 'Legendary Encounters?', - legendaryPokemonCaught: 'Legendaries Caught?', - legendaryPokemonHatched: 'Legendaries Hatched?', - mythicalPokemonSeen: 'Mythical Encounters?', + subLegendaryPokemonSeen: 'Sub-Legends Seen?', + subLegendaryPokemonCaught: 'Sub-Legends Caught?', + subLegendaryPokemonHatched: 'Sub-Legends Hatched?', + legendaryPokemonSeen: 'Legends Seen?', + legendaryPokemonCaught: 'Legends Caught?', + legendaryPokemonHatched: 'Legends Hatched?', + mythicalPokemonSeen: 'Mythicals Seen?', mythicalPokemonCaught: 'Mythicals Caught?', mythicalPokemonHatched: 'Mythicals Hatched?', - shinyPokemonSeen: 'Shiny Encounters?', + shinyPokemonSeen: 'Shinies Seen?', shinyPokemonCaught: 'Shinies Caught?', shinyPokemonHatched: 'Shinies Hatched?', pokemonFused: 'Pokémon Fused?',