Add persistent data for catches

This commit is contained in:
Flashfyre 2023-04-18 01:32:26 -04:00
parent 00ad27247c
commit fcdd7c421e
8 changed files with 196 additions and 85 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -4,6 +4,7 @@ import * as Utils from './utils';
import { addTextObject, TextStyle } from './text';
import { getGenderSymbol, getGenderColor } from './gender';
import { StatusEffect } from './status-effect';
import BattleScene from './battle-scene';
export default class BattleInfo extends Phaser.GameObjects.Container {
private player: boolean;
@ -18,6 +19,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
private nameText: Phaser.GameObjects.Text;
private genderText: Phaser.GameObjects.Text;
private ownedIcon: Phaser.GameObjects.Image;
private statusIndicator: Phaser.GameObjects.Sprite;
private levelContainer: Phaser.GameObjects.Container;
private hpBar: Phaser.GameObjects.Image;
@ -53,6 +55,14 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
this.genderText.setPositionRelative(this.nameText, 0, 2);
this.add(this.genderText);
if (!this.player) {
this.ownedIcon = this.scene.add.image(0, 0, 'icon_owned');
this.ownedIcon.setVisible(false);
this.ownedIcon.setOrigin(0, 0);
this.ownedIcon.setPositionRelative(this.nameText, 0, 11.5);
this.add(this.ownedIcon);
}
this.statusIndicator = this.scene.add.sprite(0, 0, 'statuses');
this.statusIndicator.setVisible(false);
this.statusIndicator.setOrigin(0, 0);
@ -97,6 +107,13 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
this.genderText.setColor(getGenderColor(pokemon.gender));
this.genderText.setPositionRelative(this.nameText, nameTextWidth, 0);
if (!this.player) {
const speciesOwned = !!pokemon.scene.gameData.getDefaultDexEntry(pokemon.species)?.entry?.caught;
this.ownedIcon.setVisible(speciesOwned);
if (!pokemon.scene.gameData.getPokemonDexEntry(pokemon).caught)
this.ownedIcon.setTint(0x808080);
}
this.hpBar.setScale(pokemon.getHpRatio(), 1);
if (this.player)
this.setHpNumbers(pokemon.hp, pokemon.getMaxHp());
@ -138,6 +155,9 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
if (this.lastStatus !== StatusEffect.NONE)
this.statusIndicator.setFrame(StatusEffect[this.lastStatus].toLowerCase());
this.statusIndicator.setVisible(!!this.lastStatus);
if (!this.player && this.ownedIcon.visible)
this.ownedIcon.setAlpha(this.statusIndicator.visible ? 0 : 1);
}
const updatePokemonHp = () => {

View File

@ -72,6 +72,8 @@ export class EncounterPhase extends BattlePhase {
const enemyPokemon = this.scene.getEnemyPokemon();
enemyPokemon.resetSummonData();
this.scene.gameData.setPokemonSeen(enemyPokemon);
console.log(enemyPokemon.species.name, enemyPokemon.species.speciesId, enemyPokemon.stats);
enemyPokemon.loadAssets().then(() => {
@ -1258,8 +1260,7 @@ export class LevelUpPhase extends PartyMemberPokemonPhase {
const prevStats = pokemon.stats.slice(0);
pokemon.calculateStats();
pokemon.updateInfo();
this.scene.pauseBgm();
this.scene.sound.play('level_up_fanfare');
this.scene.playSoundWithoutBgm('level_up_fanfare', 1500);
this.scene.ui.showText(`${this.getPokemon().name} grew to\nLV. ${this.level}!`, null, () => this.scene.ui.getMessageHandler().promptLevelUpStats(prevStats, false, () => this.end()), null, true);
const levelMoves = this.getPokemon().getLevelMoves(this.lastLevel + 1);
for (let lm of levelMoves)
@ -1267,7 +1268,6 @@ export class LevelUpPhase extends PartyMemberPokemonPhase {
const evolution = pokemon.getEvolution();
if (evolution)
this.scene.unshiftPhase(new EvolutionPhase(this.scene, this.partyMemberIndex, evolution, this.lastLevel));
this.scene.time.delayedCall(1500, () => this.scene.resumeBgm());
}
}
@ -1307,10 +1307,8 @@ export class LearnMovePhase extends PartyMemberPokemonPhase {
loadMoveAnimAssets(this.scene, [ this.moveId ], true)
.then(() => {
this.scene.ui.setMode(messageMode).then(() => {
this.scene.pauseBgm();
this.scene.sound.play('level_up_fanfare');
this.scene.playSoundWithoutBgm('level_up_fanfare', 1500);
this.scene.ui.showText(`${pokemon.name} learned\n${Utils.toPokemonUpperCase(move.name)}!`, null, () => this.end(), messageMode === Mode.EVOLUTION_SCENE ? 1000 : null, true);
this.scene.time.delayedCall(1500, () => this.scene.resumeBgm());
});
});
});
@ -1548,6 +1546,7 @@ export class AttemptCapturePhase extends BattlePhase {
else
end();
};
this.scene.gameData.setPokemonCaught(pokemon).then(() => {
if (this.scene.getParty().length === 6) {
const promptRelease = () => {
this.scene.ui.showText(`Your party is full.\nRelease a POKéMON to make room for ${pokemon.name}?`, null, () => {
@ -1570,6 +1569,7 @@ export class AttemptCapturePhase extends BattlePhase {
promptRelease();
} else
addToParty();
});
}, 0, true);
}

View File

@ -14,7 +14,7 @@ import { initCommonAnims, loadCommonAnimAssets, populateAnims } from './battle-a
import { BattlePhase } from './battle-phase';
import { initGameSpeed } from './game-speed';
import { Arena } from './arena';
import { SaveData } from './data';
import { GameData } from './game-data';
import StarterSelectUiHandler from './ui/starter-select-ui-handler';
const enableAuto = true;
@ -41,7 +41,7 @@ export default class BattleScene extends Phaser.Scene {
public gameSpeed: integer = 1;
public quickStart: boolean;
public saveData: SaveData;
public gameData: GameData;
private phaseQueue: BattlePhase[];
private phaseQueuePrepend: BattlePhase[];
@ -68,6 +68,7 @@ export default class BattleScene extends Phaser.Scene {
//public spritePipeline: SpritePipeline;
private bgm: Phaser.Sound.BaseSound;
private bgmResumeTimer: Phaser.Time.TimerEvent;
private buttonKeys: Phaser.Input.Keyboard.Key[][];
@ -76,7 +77,7 @@ export default class BattleScene extends Phaser.Scene {
constructor() {
super('battle');
this.saveData = new SaveData(this);
this.gameData = new GameData(this);
this.phaseQueue = [];
this.phaseQueuePrepend = [];
@ -135,6 +136,7 @@ export default class BattleScene extends Phaser.Scene {
this.loadAtlas('numbers', 'ui');
this.loadAtlas('overlay_hp', 'ui');
this.loadImage('overlay_exp', 'ui');
this.loadImage('icon_owned', 'ui');
this.loadImage('level_up_stats', 'ui');
this.loadImage('ball_window', 'ui');
this.loadImage('boolean_window', 'ui');
@ -521,6 +523,18 @@ export default class BattleScene extends Phaser.Scene {
this.arena.fadeOutBgm(500, destroy);
}
playSoundWithoutBgm(soundName: string, pauseDuration?: integer): void {
this.pauseBgm();
this.sound.play(soundName);
const sound = this.sound.get(soundName);
if (this.bgmResumeTimer)
this.bgmResumeTimer.destroy();
this.bgmResumeTimer = this.time.delayedCall((pauseDuration || (sound.totalDuration * 1000)), () => {
this.resumeBgm();
this.bgmResumeTimer = null;
});
}
getCurrentPhase(): BattlePhase {
return this.currentPhase;
}

View File

@ -1,9 +1,16 @@
import BattleScene from "./battle-scene";
import { Gender } from "./gender";
import Pokemon from "./pokemon";
import PokemonSpecies, { allSpecies } from "./pokemon-species";
import { Species } from "./species";
import * as Utils from "./utils";
interface SaveData {
trainerId: integer;
secretId: integer;
dexData: DexData;
}
export interface DexData {
[key: integer]: DexData | DexEntry
}
@ -13,7 +20,7 @@ export interface DexEntry {
caught: boolean;
}
export interface StarterDexEntry {
export interface DexEntryDetails {
shiny: boolean;
formIndex: integer;
female: boolean;
@ -28,7 +35,7 @@ export interface StarterDexUnlockTree {
entry: DexEntry
}
export class SaveData {
export class GameData {
private scene: BattleScene;
public trainerId: integer;
@ -39,19 +46,38 @@ export class SaveData {
constructor(scene: BattleScene) {
this.scene = scene;
this.trainerId = Utils.randInt(65536);
this.secretId = Utils.randInt(65536)
this.secretId = Utils.randInt(65536);
if (!this.load())
this.initDexData();
}
save() {
private save(): boolean {
const data: SaveData = {
trainerId: this.trainerId,
secretId: this.secretId,
dexData: this.dexData
};
localStorage.setItem('data', btoa(JSON.stringify(data)));
return true;
}
load() {
private load(): boolean {
if (!localStorage.getItem('data'))
return false;
const data = JSON.parse(atob(localStorage.getItem('data'))) as SaveData;
console.log(data);
this.trainerId = data.trainerId;
this.secretId = data.secretId;
this.dexData = data.dexData;
return true;
}
initDexData() {
private initDexData() {
const data: DexData = {};
const initDexSubData = (dexData: DexData, count: integer): DexData[] => {
@ -68,7 +94,7 @@ export class SaveData {
const initDexEntries = (dexData: DexData, count: integer): DexEntry[] => {
const ret: DexEntry[] = [];
for (let i = 0; i < count; i++) {
const entry: DexEntry = { seen: true, caught: true };
const entry: DexEntry = { seen: false, caught: false };
dexData[i] = entry;
ret.push(entry);
}
@ -98,20 +124,46 @@ export class SaveData {
let entry = data[ds][0][Gender.MALE] as DexEntry;
entry.seen = true;
entry.caught = true;
entry = data[ds][0][Gender.FEMALE] as DexEntry;
entry.seen = true;
entry.caught = true;
entry = data[ds][1][Gender.FEMALE] as DexEntry;
entry.seen = true;
entry.caught = true;
}
data[Species.SHAYMIN][1][1].caught = true;
this.dexData = data;
}
getDexEntry(species: PokemonSpecies, shiny: boolean, formIndex: integer, female: boolean) : DexEntry {
setPokemonSeen(pokemon: Pokemon): void {
const dexEntry = this.getPokemonDexEntry(pokemon);
if (!dexEntry.seen) {
dexEntry.seen = true;
this.save();
}
}
setPokemonCaught(pokemon: Pokemon): Promise<void> {
return new Promise(resolve => {
const dexEntry = this.getPokemonDexEntry(pokemon);
if (!dexEntry.caught) {
const newCatch = !this.getDefaultDexEntry(pokemon.species);
dexEntry.caught = true;
this.save();
if (newCatch && !pokemon.species.getPrevolutionLevels(true).length) {
this.scene.playSoundWithoutBgm('level_up_fanfare', 1500);
this.scene.ui.showText(`${pokemon.name} has been\nadded as a starter!`, null, () => resolve(), null, true);
return;
}
}
resolve();
});
}
getPokemonDexEntry(pokemon: Pokemon) {
return this.getDexEntry(pokemon.species, pokemon.shiny, pokemon.formIndex, pokemon.gender === Gender.FEMALE);
}
getDexEntry(species: PokemonSpecies, shiny: boolean, formIndex: integer, female: boolean): DexEntry {
const shinyIndex = !shiny ? 0 : 1;
const genderIndex = !female ? 0 : 1;
const data = this.dexData[species.speciesId];
@ -124,7 +176,7 @@ export class SaveData {
return data[shinyIndex] as DexEntry;
}
getDefaultStarterDexEntry(species: PokemonSpecies, forceShiny?: boolean, forceFormIndex?: integer, forceFemale?: boolean): StarterDexEntry {
getDefaultDexEntry(species: PokemonSpecies, forceShiny?: boolean, forceFormIndex?: integer, forceFemale?: boolean): DexEntryDetails {
const hasForms = !!species.forms?.length;
let shiny = false;
let formIndex = 0;

View File

@ -525,9 +525,9 @@ export const pokemonEvolutions: PokemonEvolutions = {
],
[Species.BURMY]: [
new SpeciesEvolution(Species.MOTHIM, 20, null, new SpeciesEvolutionCondition((p: Pokemon) => p.gender, true)),
new SpeciesEvolution(Species.WORMADAM, 20, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.gender && p.scene.arena.biomeType === Biome.FOREST, true)),
new SpeciesEvolution(Species.WORMADAM, 20, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.gender && p.scene.arena.biomeType === Biome.CAVE, true)),
new SpeciesEvolution(Species.WORMADAM, 20, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.gender && p.scene.arena.biomeType === Biome.CITY, true))
new SpeciesEvolution(Species.WORMADAM, 20, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.gender && p.scene.arena?.biomeType === Biome.FOREST, true)),
new SpeciesEvolution(Species.WORMADAM, 20, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.gender && p.scene.arena?.biomeType === Biome.CAVE, true)),
new SpeciesEvolution(Species.WORMADAM, 20, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.gender && p.scene.arena?.biomeType === Biome.CITY, true))
],
[Species.COMBEE]: [
new SpeciesEvolution(Species.VESPIQUEN, 21, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.gender, true))
@ -802,8 +802,8 @@ export const pokemonEvolutions: PokemonEvolutions = {
new SpeciesEvolution(Species.STARMIE, 1, EvolutionItem.WATER_STONE, null, SpeciesWildEvolutionDelay.MEDIUM)
],
[Species.EEVEE]: [
new SpeciesEvolution(Species.ESPEON, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10 && p.scene.arena.isDaytime()), SpeciesWildEvolutionDelay.MEDIUM),
new SpeciesEvolution(Species.UMBREON, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10 && !p.scene.arena.isDaytime()), SpeciesWildEvolutionDelay.MEDIUM),
new SpeciesEvolution(Species.ESPEON, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10 && p.scene.arena?.isDaytime()), SpeciesWildEvolutionDelay.MEDIUM),
new SpeciesEvolution(Species.UMBREON, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10 && !p.scene.arena?.isDaytime()), SpeciesWildEvolutionDelay.MEDIUM),
new SpeciesEvolution(Species.VAPOREON, 1, EvolutionItem.WATER_STONE, null, SpeciesWildEvolutionDelay.MEDIUM),
new SpeciesEvolution(Species.JOLTEON, 1, EvolutionItem.THUNDER_STONE, null, SpeciesWildEvolutionDelay.MEDIUM),
new SpeciesEvolution(Species.FLAREON, 1, EvolutionItem.FIRE_STONE, null, SpeciesWildEvolutionDelay.MEDIUM),
@ -829,10 +829,10 @@ export const pokemonEvolutions: PokemonEvolutions = {
new SpeciesEvolution(Species.MISMAGIUS, 1, EvolutionItem.DUSK_STONE, null, SpeciesWildEvolutionDelay.VERY_LONG)
],
[Species.GLIGAR]: [
new SpeciesEvolution(Species.GLISCOR, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.scene.arena.isDaytime() /* Razor fang at night*/), SpeciesWildEvolutionDelay.LONG)
new SpeciesEvolution(Species.GLISCOR, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.scene.arena?.isDaytime() /* Razor fang at night*/), SpeciesWildEvolutionDelay.LONG)
],
[Species.SNEASEL]: [
new SpeciesEvolution(Species.WEAVILE, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.scene.arena.isDaytime() /* Razor claw at night*/), SpeciesWildEvolutionDelay.LONG)
new SpeciesEvolution(Species.WEAVILE, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.scene.arena?.isDaytime() /* Razor claw at night*/), SpeciesWildEvolutionDelay.LONG)
],
[Species.PILOSWINE]: [
new SpeciesEvolution(Species.MAMOSWINE, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.moveset.filter(m => m.moveId === Moves.ANCIENT_POWER).length), SpeciesWildEvolutionDelay.VERY_LONG)
@ -975,16 +975,16 @@ export const pokemonEvolutions: PokemonEvolutions = {
new SpeciesEvolution(Species.MARILL, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10), SpeciesWildEvolutionDelay.SHORT)
],
[Species.BUDEW]: [
new SpeciesEvolution(Species.ROSELIA, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount > 10 && p.scene.arena.isDaytime()), SpeciesWildEvolutionDelay.SHORT)
new SpeciesEvolution(Species.ROSELIA, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount > 10 && p.scene.arena?.isDaytime()), SpeciesWildEvolutionDelay.SHORT)
],
[Species.CHINGLING]: [
new SpeciesEvolution(Species.CHIMECHO, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10 && !p.scene.arena.isDaytime()), SpeciesWildEvolutionDelay.MEDIUM)
new SpeciesEvolution(Species.CHIMECHO, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10 && !p.scene.arena?.isDaytime()), SpeciesWildEvolutionDelay.MEDIUM)
],
[Species.BUNEARY]: [
new SpeciesEvolution(Species.LOPUNNY, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10), SpeciesWildEvolutionDelay.MEDIUM)
],
[Species.RIOLU]: [
new SpeciesEvolution(Species.LUCARIO, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10 && p.scene.arena.isDaytime()), SpeciesWildEvolutionDelay.MEDIUM)
new SpeciesEvolution(Species.LUCARIO, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10 && p.scene.arena?.isDaytime()), SpeciesWildEvolutionDelay.MEDIUM)
],
[Species.WOOBAT]: [
new SpeciesEvolution(Species.SWOOBAT, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10), SpeciesWildEvolutionDelay.MEDIUM)

View File

@ -103,7 +103,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
const rand1 = Utils.binToDec(Utils.decToBin(this.id).substring(0, 16));
const rand2 = Utils.binToDec(Utils.decToBin(this.id).substring(16, 32));
const E = this.scene.saveData.trainerId ^ this.scene.saveData.secretId;
const E = this.scene.gameData.trainerId ^ this.scene.gameData.secretId;
const F = rand1 ^ rand2;
if (this.shiny === undefined) {
@ -777,7 +777,7 @@ export default interface Pokemon {
export class PlayerPokemon extends Pokemon {
public compatibleTms: Moves[];
constructor(scene: BattleScene, species: PokemonSpecies, level: integer, formIndex: integer, gender: Gender, shiny: boolean, dataSource?: Pokemon) {
constructor(scene: BattleScene, species: PokemonSpecies, level: integer, formIndex: integer, gender?: Gender, shiny?: boolean, dataSource?: Pokemon) {
super(scene, 106, 148, species, level, formIndex, gender, shiny, dataSource);
this.getSpeciesForm().generateIconAnim(scene, this.gender === Gender.FEMALE, formIndex);
@ -816,6 +816,8 @@ export class PlayerPokemon extends Pokemon {
this.getSpeciesForm().generateIconAnim(this.scene, this.gender === Gender.FEMALE, this.formIndex);
this.compatibleTms.splice(0, this.compatibleTms.length);
this.generateCompatibleTms();
this.scene.gameData.setPokemonSeen(this);
this.scene.gameData.setPokemonCaught(this);
this.loadAssets().then(() => {
this.calculateStats();
this.updateInfo().then(() => resolve());

View File

@ -5,7 +5,8 @@ import { TextStyle, addTextObject } from "../text";
import { Mode } from "./ui";
import * as Utils from "../utils";
import MessageUiHandler from "./message-ui-handler";
import { StarterDexEntry, StarterDexUnlockTree } from "../data";
import { DexEntryDetails, StarterDexUnlockTree } from "../game-data";
import { Gender, getGenderColor, getGenderSymbol } from "../gender";
export type StarterSelectCallback = (starters: Starter[]) => void;
@ -22,6 +23,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
private pokemonNumberText: Phaser.GameObjects.Text;
private pokemonSprite: Phaser.GameObjects.Sprite;
private pokemonNameText: Phaser.GameObjects.Text;
private pokemonGenderText: Phaser.GameObjects.Text;
private instructionsText: Phaser.GameObjects.Text;
private starterSelectMessageBoxContainer: Phaser.GameObjects.Container;
@ -37,7 +39,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
private starterGens: integer[] = [];
private starterCursors: integer[] = [];
private starterDetails: [boolean, integer, boolean][] = [];
private speciesStarterDexEntry: StarterDexEntry;
private speciesStarterDexEntry: DexEntryDetails;
private speciesStarterDexTree: StarterDexUnlockTree;
private canCycleShiny: boolean;
private canCycleForm: boolean;
@ -79,6 +81,10 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
this.pokemonNameText.setOrigin(0, 0);
this.starterSelectContainer.add(this.pokemonNameText);
this.pokemonGenderText = addTextObject(this.scene, 96, 112, '', TextStyle.SUMMARY);
this.pokemonGenderText.setOrigin(0, 0);
this.starterSelectContainer.add(this.pokemonGenderText);
const genText = addTextObject(this.scene, 115, 6, 'I\nII\nIII\nIV\nV', TextStyle.WINDOW);
genText.setLineSpacing(16);
this.starterSelectContainer.add(genText);
@ -121,7 +127,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
continue;
this.speciesLoaded.set(species.speciesId, false);
this.genSpecies[g].push(species);
const dexEntry = this.scene.saveData.getDefaultStarterDexEntry(species);
const dexEntry = this.scene.gameData.getDefaultDexEntry(species);
species.generateIconAnim(this.scene, dexEntry?.female, dexEntry?.formIndex);
const x = (s % 9) * 18;
const y = Math.floor(s / 9) * 18;
@ -259,6 +265,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
});
}
success = true;
this.updateInstructions();
} else
ui.playError();
}
@ -266,6 +273,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
if (this.starterCursors.length) {
this.popStarter();
success = true;
this.updateInstructions();
} else
ui.playError();
} else {
@ -275,16 +283,24 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
switch (button) {
case Button.CYCLE_SHINY:
if (this.canCycleShiny) {
this.setSpeciesDetails(this.lastSpecies, !this.shinyCursor, this.formCursor, !!this.genderCursor);
this.setSpeciesDetails(this.lastSpecies, !this.shinyCursor, undefined, undefined);
if (this.shinyCursor)
this.scene.sound.play('sparkle');
else
success = true;
}
break;
case Button.CYCLE_FORM:
if (this.canCycleForm)
this.setSpeciesDetails(this.lastSpecies, !!this.shinyCursor, (this.formCursor + 1) % this.lastSpecies.forms.length, !!this.genderCursor);
if (this.canCycleForm) {
this.setSpeciesDetails(this.lastSpecies, undefined, (this.formCursor + 1) % this.lastSpecies.forms.length, undefined);
success = true;
}
break;
case Button.CYCLE_GENDER:
if (this.canCycleGender)
this.setSpeciesDetails(this.lastSpecies, !!this.shinyCursor, this.formCursor, !this.genderCursor);
if (this.canCycleGender) {
this.setSpeciesDetails(this.lastSpecies, undefined, undefined, !this.genderCursor);
success = true;
}
break;
case Button.UP:
if (row)
@ -382,11 +398,11 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
}
setSpecies(species: PokemonSpecies) {
this.speciesStarterDexEntry = species ? this.scene.saveData.getDefaultStarterDexEntry(species) : null;
this.speciesStarterDexTree = this.speciesStarterDexEntry ? this.scene.saveData.getStarterDexUnlockTree(species) : null;
this.speciesStarterDexEntry = species ? this.scene.gameData.getDefaultDexEntry(species) : null;
this.speciesStarterDexTree = this.speciesStarterDexEntry ? this.scene.gameData.getStarterDexUnlockTree(species) : null;
if (this.lastSpecies) {
const defaultStarterDexEntry = this.scene.saveData.getDefaultStarterDexEntry(this.lastSpecies);
const defaultStarterDexEntry = this.scene.gameData.getDefaultDexEntry(this.lastSpecies);
const lastSpeciesIcon = (this.starterSelectGenIconContainers[this.lastSpecies.generation - 1].getAt(this.genSpecies[this.lastSpecies.generation - 1].indexOf(this.lastSpecies)) as Phaser.GameObjects.Sprite);
lastSpeciesIcon.play(this.lastSpecies.getIconKey(!!defaultStarterDexEntry?.female, defaultStarterDexEntry?.formIndex)).stop();
}
@ -416,16 +432,21 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
this.pokemonSprite.setVisible(false);
if (this.assetLoadCancelled) {
this.assetLoadCancelled.value = true;
this.assetLoadCancelled = null;
}
if (species) {
const defaultDexEntry = this.scene.saveData.getDefaultStarterDexEntry(species, shiny, formIndex, female);
const dexEntry = this.scene.saveData.getDexEntry(species, !!this.shinyCursor, this.formCursor, !!this.genderCursor);
const defaultDexEntry = this.scene.gameData.getDefaultDexEntry(species, shiny, formIndex, female) || this.scene.gameData.getDefaultDexEntry(species);
const dexEntry = this.scene.gameData.getDexEntry(species, !!this.shinyCursor, this.formCursor, !!this.genderCursor);
if (!dexEntry.caught) {
if (shiny === undefined)
if (shiny === undefined || (defaultDexEntry && shiny !== defaultDexEntry.shiny))
shiny = defaultDexEntry.shiny;
if (formIndex === undefined)
formIndex = defaultDexEntry.formIndex;
if (female === undefined)
if (formIndex === undefined || (defaultDexEntry && formIndex !== defaultDexEntry.formIndex))
formIndex = defaultDexEntry.formIndex || 0;
if (female === undefined || (defaultDexEntry && female !== defaultDexEntry.female))
female = defaultDexEntry.female;
} else {
shiny = !!this.shinyCursor;
@ -433,11 +454,6 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
female = !!this.genderCursor;
}
if (this.assetLoadCancelled) {
this.assetLoadCancelled.value = true;
this.assetLoadCancelled = null;
}
if (this.speciesStarterDexTree) {
const assetLoadCancelled = new Utils.BooleanHolder(false);
this.assetLoadCancelled = assetLoadCancelled;
@ -451,7 +467,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
this.pokemonSprite.setVisible(true);
});
species.generateIconAnim(this.scene, this.speciesStarterDexEntry.female, this.speciesStarterDexEntry.formIndex);
species.generateIconAnim(this.scene, female, formIndex);
(this.starterSelectGenIconContainers[this.genCursor].getAt(this.cursor) as Phaser.GameObjects.Sprite).play(species.getIconKey(female, formIndex));
let count: integer;
@ -484,9 +500,16 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
} else
this.canCycleGender = false;
}
} else {
}
if (species.malePercent !== null) {
const gender = !female ? Gender.MALE : Gender.FEMALE;
this.pokemonGenderText.setText(getGenderSymbol(gender));
this.pokemonGenderText.setColor(getGenderColor(gender));
this.pokemonGenderText.setShadowColor(getGenderColor(gender, true));
} else
this.pokemonGenderText.setText('');
} else
this.pokemonGenderText.setText('');
this.updateInstructions();
}