Add starter select ability selection

This commit is contained in:
Flashfyre committed 2023-04-26 12:50:21 -04:00
1 parent bb86ab6250
commit 592ccc7c6a
9 files changed
+190 -47

No files matched your search

+90 -23
View File
@@ -2,7 +2,7 @@ import BattleScene from "../battle-scene";
import { Gender } from "../data/gender";
import Pokemon from "../pokemon";
import { pokemonPrevolutions } from "../data/pokemon-evolutions";
import PokemonSpecies, { allSpecies } from "../data/pokemon-species";
import PokemonSpecies, { allSpecies, getPokemonSpecies } from "../data/pokemon-species";
import { Species } from "../data/species";
import * as Utils from "../utils";
@@ -10,6 +10,7 @@ interface SaveData {
trainerId: integer;
secretId: integer;
dexData: DexData;
timestamp: integer
}
export interface DexData {
@@ -25,6 +26,7 @@ export interface DexEntryDetails {
shiny: boolean;
formIndex: integer;
female: boolean;
abilityIndex: integer;
entry: DexEntry;
}
@@ -32,6 +34,7 @@ export interface StarterDexUnlockTree {
shiny: boolean | Map<boolean, StarterDexUnlockTree>
formIndex: integer | Map<integer, StarterDexUnlockTree>
female: boolean | Map<boolean, StarterDexUnlockTree>
abilityIndex: integer | Map<integer, StarterDexUnlockTree>
key: string,
entry: DexEntry
}
@@ -59,7 +62,8 @@ export class GameData {
const data: SaveData = {
trainerId: this.trainerId,
secretId: this.secretId,
dexData: this.dexData
dexData: this.dexData,
timestamp: new Date().getTime()
};
localStorage.setItem('data', btoa(JSON.stringify(data)));
@@ -78,6 +82,9 @@ export class GameData {
this.secretId = data.secretId;
this.dexData = data.dexData;
if (data.timestamp === undefined)
this.convertDexData(data.dexData);
return true;
}
@@ -108,12 +115,15 @@ export class GameData {
for (let species of allSpecies) {
data[species.speciesId] = {};
const abilityCount = species.getAbilityCount();
if (species.forms?.length)
initDexSubData(data[species.speciesId] as DexData, 2).map(sd => species.malePercent !== null ? initDexSubData(sd, species.forms.length).map(fd => initDexEntries(fd, 2)) : initDexEntries(sd, species.forms.length));
initDexSubData(data[species.speciesId] as DexData, 2).map(sd => species.malePercent !== null
? initDexSubData(sd, species.forms.length).map(fd => initDexSubData(fd, 2).map(gd => initDexEntries(gd, abilityCount)))
: initDexSubData(sd, species.forms.length).map(fd => initDexEntries(fd, abilityCount)));
else if (species.malePercent !== null)
initDexSubData(data[species.speciesId] as DexData, 2).map(sd => initDexEntries(sd, 2));
initDexSubData(data[species.speciesId] as DexData, 2).map(sd => initDexSubData(sd, 2).map(gd => initDexEntries(gd, abilityCount)));
else
initDexEntries(data[species.speciesId] as DexData, 2)
initDexSubData(data[species.speciesId] as DexData, 2).map(sd => initDexEntries(sd, abilityCount))
}
const defaultStarters: Species[] = [
@@ -125,7 +135,7 @@ export class GameData {
];
for (let ds of defaultStarters) {
let entry = data[ds][0][Gender.MALE] as DexEntry;
let entry = data[ds][0][Gender.MALE][0] as DexEntry;
entry.seen = true;
entry.caught = true;
}
@@ -162,31 +172,37 @@ export class GameData {
}
getPokemonDexEntry(pokemon: Pokemon) {
return this.getDexEntry(pokemon.species, pokemon.shiny, pokemon.formIndex, pokemon.gender === Gender.FEMALE);
return this.getDexEntry(pokemon.species, pokemon.shiny, pokemon.formIndex, pokemon.gender === Gender.FEMALE, pokemon.abilityIndex);
}
getDexEntry(species: PokemonSpecies, shiny: boolean, formIndex: integer, female: boolean): DexEntry {
getDexEntry(species: PokemonSpecies, shiny: boolean, formIndex: integer, female: boolean, abilityIndex: integer): DexEntry {
const shinyIndex = !shiny ? 0 : 1;
const genderIndex = !female ? 0 : 1;
const data = this.dexData[species.speciesId];
if (species.forms?.length) {
if (species.malePercent !== null)
return data[shinyIndex][formIndex][genderIndex];
return data[shinyIndex][formIndex];
return data[shinyIndex][formIndex][genderIndex][abilityIndex];
return data[shinyIndex][formIndex][abilityIndex];
} else if (species.malePercent !== null)
return data[shinyIndex][genderIndex];
return data[shinyIndex] as DexEntry;
return data[shinyIndex][genderIndex][abilityIndex];
return data[shinyIndex][abilityIndex] as DexEntry;
}
getDefaultDexEntry(species: PokemonSpecies, forceShiny?: boolean, forceFormIndex?: integer, forceFemale?: boolean): DexEntryDetails {
getDefaultDexEntry(species: PokemonSpecies, forceShiny?: boolean, forceFormIndex?: integer, forceFemale?: boolean, forceAbilityIndex?: integer): DexEntryDetails {
const hasForms = !!species.forms?.length;
const hasGender = species.malePercent !== null;
let shiny = false;
let formIndex = 0;
let female = false;
let abilityIndex = 0;
let entry = null;
const traverseData = (data: DexData, level: integer) => {
const keys = Object.keys(data);
if ((!hasForms && level === 1) || (!hasGender && level === 2)) {
traverseData(data, level + 1);
return;
}
keys.forEach((key: string, k: integer) => {
if (entry)
return;
@@ -207,13 +223,18 @@ export class GameData {
if (forceFemale !== undefined && female !== forceFemale)
return
break;
case 3:
abilityIndex = k;
if (forceAbilityIndex !== undefined && abilityIndex !== forceAbilityIndex)
return;
break;
}
if ('caught' in data[key]) {
if (data[key].caught)
entry = data[key] as DexEntry;
} else
traverseData(data[key] as DexData, level + (hasForms ? 1 : 2));
traverseData(data[key] as DexData, level + 1);
});
};
@@ -224,6 +245,7 @@ export class GameData {
shiny: shiny,
formIndex: formIndex,
female: female,
abilityIndex: abilityIndex,
entry: entry
};
}
@@ -240,13 +262,14 @@ export class GameData {
case 'shiny':
const shinyMap = new Map<boolean, StarterDexUnlockTree>();
for (let s = 0; s < 2; s++) {
const props = { shiny: !!s, formIndex: null };
const props = { shiny: !!s };
shinyMap.set(!!s, {
shiny: !!s,
formIndex: hasForms ? getTreeOrValueMap('formIndex', props as StarterDexUnlockTree) : null,
female: !hasForms && hasGender ? getTreeOrValueMap('female', props as StarterDexUnlockTree) : null,
key: hasForms ? 'formIndex' : hasGender ? 'female' : 'entry',
entry: hasForms || hasGender ? null : this.dexData[species.speciesId][!s ? 0 : 1]
abilityIndex: !hasForms && !hasGender ? getTreeOrValueMap('abilityIndex', props as StarterDexUnlockTree) : null,
key: hasForms ? 'formIndex' : hasGender ? 'female' : 'abilityIndex',
entry: null,
});
}
return shinyMap;
@@ -258,25 +281,46 @@ export class GameData {
shiny: parent.shiny,
formIndex: f,
female: hasGender ? getTreeOrValueMap('female', props as StarterDexUnlockTree) : null,
key: hasGender ? 'female' : 'entry',
entry: hasGender ? null : this.dexData[species.speciesId][!parent.shiny ? 0 : 1][f]
abilityIndex: !hasGender ? getTreeOrValueMap('abilityIndex', props as StarterDexUnlockTree) : null,
key: hasGender ? 'female' : 'abilityIndex',
entry: null
});
}
return formMap;
case 'female':
const genderMap = new Map<boolean, StarterDexUnlockTree>();
for (let g = 0; g < 2; g++) {
const props = { shiny: parent.shiny, formIndex: parent.formIndex, female: !!g };
genderMap.set(!!g, {
shiny: parent.shiny,
formIndex: parent.formIndex,
female: !!g,
key: 'entry',
entry: hasForms
? this.dexData[species.speciesId][!parent.shiny ? 0 : 1][parent.formIndex as integer][g]
: this.dexData[species.speciesId][!parent.shiny ? 0 : 1][g]
abilityIndex: getTreeOrValueMap('abilityIndex', props as StarterDexUnlockTree),
key: 'abilityIndex',
entry: null
});
}
return genderMap;
case 'abilityIndex':
const abilityMap = new Map<integer, StarterDexUnlockTree>();
const abilityCount = species.getAbilityCount();
for (let a = 0; a < abilityCount; a++) {
abilityMap.set(a, {
shiny: parent.shiny,
formIndex: parent.formIndex,
female: parent.female,
abilityIndex: a,
key: 'entry',
entry: hasForms
? hasGender
? this.dexData[species.speciesId][!parent.shiny ? 0 : 1][parent.formIndex as integer][!parent.female ? 0 : 1][a]
: this.dexData[species.speciesId][!parent.shiny ? 0 : 1][parent.formIndex as integer][a]
: hasGender
? this.dexData[species.speciesId][!parent.shiny ? 0 : 1][!parent.female ? 0 : 1][a]
: this.dexData[species.speciesId][!parent.shiny ? 0 : 1][a]
});
}
return abilityMap;
}
};
@@ -284,10 +328,33 @@ export class GameData {
shiny: getTreeOrValueMap('shiny'),
formIndex: null,
female: null,
abilityIndex: null,
key: 'shiny',
entry: null
};
return root;
}
convertDexData(dexData: DexData): void {
const traverseData = (speciesId: Species, data: DexData) => {
const keys = Object.keys(data);
keys.forEach((key: string, k: integer) => {
if ('caught' in data[key]) {
const abilityCount = getPokemonSpecies(speciesId).getAbilityCount();
data[key] = {
0: data[key]
};
for (let a = 1; a < abilityCount; a++)
data[key][a] = { seen: false, caught: false };
} else
traverseData(speciesId, data[key]);
});
}
Object.keys(dexData).forEach((species: string, s: integer) => {
const speciesId = parseInt(species);
traverseData(speciesId, dexData[species]);
});
}
}