Rework option select and add game stats
This commit is contained in:
1 parent
13aa20630d
commit
fcf1c4f574
14 files changed
+585
-169
No files matched your search
+38
-5
@@ -21,6 +21,7 @@ import { AES, enc } from "crypto-js";
|
||||
import { Mode } from "../ui/ui";
|
||||
import { loggedInUser, updateUserInfo } from "../account";
|
||||
import { Nature } from "../data/nature";
|
||||
import { GameStats } from "./game-stats";
|
||||
|
||||
const saveKey = 'x0i2O7WRiANTqPmZ'; // Temporary; secure encryption is not yet necessary
|
||||
|
||||
@@ -45,6 +46,7 @@ interface SystemSaveData {
|
||||
trainerId: integer;
|
||||
secretId: integer;
|
||||
dexData: DexData;
|
||||
gameStats: GameStats;
|
||||
unlocks: Unlocks;
|
||||
achvUnlocks: AchvUnlocks;
|
||||
voucherUnlocks: VoucherUnlocks;
|
||||
@@ -138,6 +140,8 @@ export class GameData {
|
||||
public dexData: DexData;
|
||||
private defaultDexData: DexData;
|
||||
|
||||
public gameStats: GameStats;
|
||||
|
||||
public unlocks: Unlocks;
|
||||
|
||||
public achvUnlocks: AchvUnlocks;
|
||||
@@ -151,6 +155,7 @@ export class GameData {
|
||||
this.loadSettings();
|
||||
this.trainerId = Utils.randSeedInt(65536);
|
||||
this.secretId = Utils.randSeedInt(65536);
|
||||
this.gameStats = new GameStats();
|
||||
this.unlocks = {
|
||||
[Unlockables.ENDLESS_MODE]: false,
|
||||
[Unlockables.MINI_BLACK_HOLE]: false,
|
||||
@@ -174,13 +179,14 @@ export class GameData {
|
||||
if (this.scene.quickStart)
|
||||
return resolve(true);
|
||||
|
||||
updateUserInfo().then(success => {
|
||||
updateUserInfo().then((success: boolean) => {
|
||||
if (!success)
|
||||
return resolve(false);
|
||||
const data: SystemSaveData = {
|
||||
trainerId: this.trainerId,
|
||||
secretId: this.secretId,
|
||||
dexData: this.dexData,
|
||||
gameStats: this.gameStats,
|
||||
unlocks: this.unlocks,
|
||||
achvUnlocks: this.achvUnlocks,
|
||||
voucherUnlocks: this.voucherUnlocks,
|
||||
@@ -233,6 +239,9 @@ export class GameData {
|
||||
this.trainerId = systemData.trainerId;
|
||||
this.secretId = systemData.secretId;
|
||||
|
||||
if (systemData.gameStats)
|
||||
this.gameStats = systemData.gameStats;
|
||||
|
||||
if (systemData.unlocks) {
|
||||
for (let key of Object.keys(systemData.unlocks)) {
|
||||
if (this.unlocks.hasOwnProperty(key))
|
||||
@@ -290,7 +299,9 @@ export class GameData {
|
||||
|
||||
private parseSystemData(dataStr: string): SystemSaveData {
|
||||
return JSON.parse(dataStr, (k: string, v: any) => {
|
||||
if (k === 'eggs') {
|
||||
if (k === 'gameStats')
|
||||
return new GameStats(v);
|
||||
else if (k === 'eggs') {
|
||||
const ret: EggData[] = [];
|
||||
if (v === null)
|
||||
v = [];
|
||||
@@ -418,6 +429,9 @@ export class GameData {
|
||||
scene.money = sessionData.money || 0;
|
||||
scene.updateMoneyText();
|
||||
|
||||
if (scene.money > this.gameStats.highestMoney)
|
||||
this.gameStats.highestMoney = scene.money;
|
||||
|
||||
const battleType = sessionData.battleType || 0;
|
||||
const battle = scene.newBattle(sessionData.waveIndex, battleType, sessionData.trainer, battleType === BattleType.TRAINER ? trainerConfigs[sessionData.trainer.trainerType].isDouble : sessionData.enemyParty.length > 1);
|
||||
|
||||
@@ -706,8 +720,12 @@ export class GameData {
|
||||
setPokemonSeen(pokemon: Pokemon, incrementCount: boolean = true): void {
|
||||
const dexEntry = this.dexData[pokemon.species.speciesId];
|
||||
dexEntry.seenAttr |= pokemon.getDexAttr();
|
||||
if (incrementCount)
|
||||
if (incrementCount) {
|
||||
dexEntry.seenCount++;
|
||||
this.gameStats.pokemonSeen++;
|
||||
if (pokemon.isShiny())
|
||||
this.gameStats.shinyPokemonSeen++;
|
||||
}
|
||||
}
|
||||
|
||||
setPokemonCaught(pokemon: Pokemon, incrementCount: boolean = true, fromEgg: boolean = false): Promise<void> {
|
||||
@@ -721,10 +739,25 @@ export class GameData {
|
||||
dexEntry.caughtAttr |= pokemon.getDexAttr();
|
||||
dexEntry.natureAttr |= Math.pow(2, pokemon.nature + 1);
|
||||
if (incrementCount) {
|
||||
if (!fromEgg)
|
||||
if (!fromEgg) {
|
||||
dexEntry.caughtCount++;
|
||||
else
|
||||
this.gameStats.pokemonCaught++;
|
||||
if (pokemon.species.pseudoLegendary || pokemon.species.legendary)
|
||||
this.gameStats.legendaryPokemonCaught++;
|
||||
else if (pokemon.species.mythical)
|
||||
this.gameStats.mythicalPokemonCaught++;
|
||||
if (pokemon.isShiny())
|
||||
this.gameStats.shinyPokemonCaught++;
|
||||
} else {
|
||||
dexEntry.hatchedCount++;
|
||||
this.gameStats.pokemonHatched++;
|
||||
if (pokemon.species.pseudoLegendary || pokemon.species.legendary)
|
||||
this.gameStats.legendaryPokemonHatched++;
|
||||
else if (pokemon.species.mythical)
|
||||
this.gameStats.mythicalPokemonHatched++;
|
||||
if (pokemon.isShiny())
|
||||
this.gameStats.shinyPokemonHatched++;
|
||||
}
|
||||
}
|
||||
|
||||
const hasPrevolution = pokemonPrevolutions.hasOwnProperty(species.speciesId);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
// public (.*?): integer;
|
||||
// this.$1 = source?.$1 || 0;
|
||||
|
||||
export class GameStats {
|
||||
public playTime: integer;
|
||||
public battles: integer;
|
||||
public classicSessionsPlayed: integer;
|
||||
public sessionsWon: integer;
|
||||
public endlessSessionsPlayed: integer;
|
||||
public highestEndlessWave: integer;
|
||||
public highestLevel: integer;
|
||||
public highestMoney: integer;
|
||||
public pokemonSeen: integer;
|
||||
public pokemonDefeated: integer;
|
||||
public pokemonCaught: integer;
|
||||
public pokemonHatched: integer;
|
||||
public legendaryPokemonSeen: integer;
|
||||
public legendaryPokemonCaught: integer;
|
||||
public legendaryPokemonHatched: integer;
|
||||
public mythicalPokemonSeen: integer;
|
||||
public mythicalPokemonCaught: integer;
|
||||
public mythicalPokemonHatched: integer;
|
||||
public shinyPokemonSeen: integer;
|
||||
public shinyPokemonCaught: integer;
|
||||
public shinyPokemonHatched: integer;
|
||||
public pokemonFused: integer;
|
||||
public trainersDefeated: integer;
|
||||
public eggsPulled: integer;
|
||||
public rareEggsPulled: integer;
|
||||
public epicEggsPulled: integer;
|
||||
public legendaryEggsPulled: integer;
|
||||
public manaphyEggsPulled: integer;
|
||||
|
||||
constructor(source?: any) {
|
||||
this.playTime = source?.playTime || 0;
|
||||
this.battles = source?.battles || 0;
|
||||
this.classicSessionsPlayed = source?.classicSessionsPlayed || 0;
|
||||
this.sessionsWon = source?.sessionsWon || 0;
|
||||
this.endlessSessionsPlayed = source?.endlessSessionsPlayed || 0;
|
||||
this.highestEndlessWave = source?.highestEndlessWave || 0;
|
||||
this.highestLevel = source?.highestLevel || 0;
|
||||
this.highestMoney = source?.highestMoney || 0;
|
||||
this.pokemonSeen = source?.pokemonSeen || 0;
|
||||
this.pokemonDefeated = source?.pokemonDefeated || 0;
|
||||
this.pokemonCaught = source?.pokemonCaught || 0;
|
||||
this.pokemonHatched = source?.pokemonHatched || 0;
|
||||
this.legendaryPokemonSeen = source?.legendaryPokemonSeen || 0;
|
||||
this.legendaryPokemonCaught = source?.legendaryPokemonCaught || 0;
|
||||
this.legendaryPokemonHatched = source?.legendaryPokemonHatched || 0;
|
||||
this.mythicalPokemonSeen = source?.mythicalPokemonSeen || 0;
|
||||
this.mythicalPokemonCaught = source?.mythicalPokemonCaught || 0;
|
||||
this.mythicalPokemonHatched = source?.mythicalPokemonCaught || 0;
|
||||
this.shinyPokemonSeen = source?.shinyPokemonSeen || 0;
|
||||
this.shinyPokemonCaught = source?.shinyPokemonCaught || 0;
|
||||
this.shinyPokemonHatched = source?.shinyPokemonHatched || 0;
|
||||
this.pokemonFused = source?.pokemonFused || 0;
|
||||
this.trainersDefeated = source?.trainersDefeated || 0;
|
||||
this.eggsPulled = source?.eggsPulled || 0;
|
||||
this.rareEggsPulled = source?.rareEggsPulled || 0;
|
||||
this.epicEggsPulled = source?.epicEggsPulled || 0;
|
||||
this.legendaryEggsPulled = source?.legendaryEggsPulled || 0;
|
||||
this.manaphyEggsPulled = source?.manaphyEggsPulled || 0;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user