Final changes
This commit is contained in:
parent
4fd321790a
commit
1dc495cb38
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
1118
src/phases.ts
1118
src/phases.ts
File diff suppressed because it is too large
Load Diff
|
@ -1,19 +1,19 @@
|
|||
import i18next from "i18next";
|
||||
import BattleScene, { PokeballCounts, bypassLogin } from "../battle-scene";
|
||||
import Pokemon, { EnemyPokemon, PlayerPokemon } from "../field/pokemon";
|
||||
import { pokemonEvolutions, pokemonPrevolutions } from "../data/pokemon-evolutions";
|
||||
import PokemonSpecies, { allSpecies, getPokemonSpecies, noStarterFormKeys, speciesStarters } from "../data/pokemon-species";
|
||||
import { Species, defaultStarterSpecies } from "../data/enums/species";
|
||||
import * as Utils from "../utils";
|
||||
import Overrides from "#app/overrides";
|
||||
import * as Overrides from "../overrides";
|
||||
import PokemonData from "./pokemon-data";
|
||||
import PersistentModifierData from "./modifier-data";
|
||||
import ArenaData from "./arena-data";
|
||||
import { Unlockables } from "./unlockables";
|
||||
import { GameModes, getGameMode } from "../game-mode";
|
||||
import { GameModes, gameModes } from "../game-mode";
|
||||
import { BattleType } from "../battle";
|
||||
import TrainerData from "./trainer-data";
|
||||
import { trainerConfigs } from "../data/trainer-config";
|
||||
import { SettingKeys, resetSettings, setSetting } from "./settings/settings";
|
||||
import { Setting, setSetting, settingDefaults } from "./settings";
|
||||
import { achvs } from "./achv";
|
||||
import EggData from "./egg-data";
|
||||
import { Egg } from "../data/egg";
|
||||
|
@ -24,39 +24,34 @@ import { clientSessionId, loggedInUser, updateUserInfo } from "../account";
|
|||
import { Nature } from "../data/nature";
|
||||
import { GameStats } from "./game-stats";
|
||||
import { Tutorial } from "../tutorial";
|
||||
import { Moves } from "../data/enums/moves";
|
||||
import { speciesEggMoves } from "../data/egg-moves";
|
||||
import { allMoves } from "../data/move";
|
||||
import { TrainerVariant } from "../field/trainer";
|
||||
import { OutdatedPhase, ReloadSessionPhase } from "#app/phases";
|
||||
import { Variant, variantData } from "#app/data/variant";
|
||||
import {setSettingGamepad, SettingGamepad, settingGamepadDefaults} from "./settings/settings-gamepad";
|
||||
import {setSettingKeyboard, SettingKeyboard} from "#app/system/settings/settings-keyboard";
|
||||
import { TerrainChangedEvent, WeatherChangedEvent } from "#app/events/arena.js";
|
||||
import { EnemyAttackStatusEffectChanceModifier } from "../modifier/modifier";
|
||||
import { StatusEffect } from "#app/data/status-effect.js";
|
||||
import ChallengeData from "./challenge-data";
|
||||
import { Device } from "#enums/devices";
|
||||
import { GameDataType } from "#enums/game-data-type";
|
||||
import { Moves } from "#enums/moves";
|
||||
import { PlayerGender } from "#enums/player-gender";
|
||||
import { Species } from "#enums/species";
|
||||
import { applyChallenges, ChallengeType } from "#app/data/challenge.js";
|
||||
import { Abilities } from "#app/enums/abilities.js";
|
||||
|
||||
export const defaultStarterSpecies: Species[] = [
|
||||
Species.BULBASAUR, Species.CHARMANDER, Species.SQUIRTLE,
|
||||
Species.CHIKORITA, Species.CYNDAQUIL, Species.TOTODILE,
|
||||
Species.TREECKO, Species.TORCHIC, Species.MUDKIP,
|
||||
Species.TURTWIG, Species.CHIMCHAR, Species.PIPLUP,
|
||||
Species.SNIVY, Species.TEPIG, Species.OSHAWOTT,
|
||||
Species.CHESPIN, Species.FENNEKIN, Species.FROAKIE,
|
||||
Species.ROWLET, Species.LITTEN, Species.POPPLIO,
|
||||
Species.GROOKEY, Species.SCORBUNNY, Species.SOBBLE,
|
||||
Species.SPRIGATITO, Species.FUECOCO, Species.QUAXLY
|
||||
];
|
||||
|
||||
const saveKey = "x0i2O7WRiANTqPmZ"; // Temporary; secure encryption is not yet necessary
|
||||
|
||||
export enum GameDataType {
|
||||
SYSTEM,
|
||||
SESSION,
|
||||
SETTINGS,
|
||||
TUTORIALS,
|
||||
RUN_HISTORY
|
||||
}
|
||||
|
||||
export enum PlayerGender {
|
||||
UNSET,
|
||||
MALE,
|
||||
FEMALE
|
||||
}
|
||||
|
||||
export enum Passive {
|
||||
UNLOCKED = 1,
|
||||
ENABLED = 2
|
||||
}
|
||||
|
||||
export function getDataTypeKey(dataType: GameDataType, slotId: integer = 0): string {
|
||||
switch (dataType) {
|
||||
case GameDataType.SYSTEM:
|
||||
|
@ -71,18 +66,18 @@ export function getDataTypeKey(dataType: GameDataType, slotId: integer = 0): str
|
|||
return "settings";
|
||||
case GameDataType.TUTORIALS:
|
||||
return "tutorials";
|
||||
case GameDataType.SEEN_DIALOGUES:
|
||||
return "seenDialogues";
|
||||
case GameDataType.RUN_HISTORY:
|
||||
return "runHistory";
|
||||
}
|
||||
}
|
||||
|
||||
export function encrypt(data: string, bypassLogin: boolean): string {
|
||||
function encrypt(data: string, bypassLogin: boolean): string {
|
||||
return (bypassLogin
|
||||
? (data: string) => btoa(data)
|
||||
: (data: string) => AES.encrypt(data, saveKey))(data);
|
||||
}
|
||||
|
||||
export function decrypt(data: string, bypassLogin: boolean): string {
|
||||
function decrypt(data: string, bypassLogin: boolean): string {
|
||||
return (bypassLogin
|
||||
? (data: string) => atob(data)
|
||||
: (data: string) => AES.decrypt(data, saveKey).toString(enc.Utf8))(data);
|
||||
|
@ -95,6 +90,7 @@ interface SystemSaveData {
|
|||
dexData: DexData;
|
||||
starterData: StarterData;
|
||||
gameStats: GameStats;
|
||||
runHistory: RunHistoryData;
|
||||
unlocks: Unlocks;
|
||||
achvUnlocks: AchvUnlocks;
|
||||
voucherUnlocks: VoucherUnlocks;
|
||||
|
@ -102,8 +98,6 @@ interface SystemSaveData {
|
|||
eggs: EggData[];
|
||||
gameVersion: string;
|
||||
timestamp: integer;
|
||||
eggPity: integer[];
|
||||
unlockPity: integer[];
|
||||
}
|
||||
|
||||
export interface SessionSaveData {
|
||||
|
@ -123,7 +117,15 @@ export interface SessionSaveData {
|
|||
trainer: TrainerData;
|
||||
gameVersion: string;
|
||||
timestamp: integer;
|
||||
challenges: ChallengeData[];
|
||||
}
|
||||
|
||||
export interface RunHistoryData {
|
||||
[key: integer]: RunEntries;
|
||||
}
|
||||
|
||||
export interface RunEntries {
|
||||
entry: SessionSaveData;
|
||||
victory: boolean;
|
||||
}
|
||||
|
||||
interface Unlocks {
|
||||
|
@ -139,7 +141,7 @@ interface VoucherUnlocks {
|
|||
}
|
||||
|
||||
export interface VoucherCounts {
|
||||
[type: string]: integer;
|
||||
[type: string]: integer;
|
||||
}
|
||||
|
||||
export interface DexData {
|
||||
|
@ -190,46 +192,6 @@ export interface StarterMoveData {
|
|||
[key: integer]: StarterMoveset | StarterFormMoveData
|
||||
}
|
||||
|
||||
export interface StarterAttributes {
|
||||
nature?: integer;
|
||||
ability?: integer;
|
||||
variant?: integer;
|
||||
form?: integer;
|
||||
female?: boolean;
|
||||
}
|
||||
|
||||
export interface StarterPreferences {
|
||||
[key: integer]: StarterAttributes;
|
||||
}
|
||||
|
||||
// the latest data saved/loaded for the Starter Preferences. Required to reduce read/writes. Initialize as "{}", since this is the default value and no data needs to be stored if present.
|
||||
// if they ever add private static variables, move this into StarterPrefs
|
||||
const StarterPrefers_DEFAULT : string = "{}";
|
||||
let StarterPrefers_private_latest : string = StarterPrefers_DEFAULT;
|
||||
|
||||
// This is its own class as StarterPreferences...
|
||||
// - don't need to be loaded on startup
|
||||
// - isn't stored with other data
|
||||
// - don't require to be encrypted
|
||||
// - shouldn't require calls outside of the starter selection
|
||||
export class StarterPrefs {
|
||||
// called on starter selection show once
|
||||
static load(): StarterPreferences {
|
||||
return JSON.parse(
|
||||
StarterPrefers_private_latest = (localStorage.getItem(`starterPrefs_${loggedInUser?.username}`) || StarterPrefers_DEFAULT)
|
||||
);
|
||||
}
|
||||
|
||||
// called on starter selection clear, always
|
||||
static save(prefs: StarterPreferences): void {
|
||||
const pStr : string = JSON.stringify(prefs);
|
||||
if (pStr !== StarterPrefers_private_latest) {
|
||||
// something changed, store the update
|
||||
localStorage.setItem(`starterPrefs_${loggedInUser?.username}`, pStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface StarterDataEntry {
|
||||
moveset: StarterMoveset | StarterFormMoveData;
|
||||
eggMoves: integer;
|
||||
|
@ -249,10 +211,6 @@ export interface TutorialFlags {
|
|||
[key: string]: boolean
|
||||
}
|
||||
|
||||
export interface SeenDialogues {
|
||||
[key: string]: boolean;
|
||||
}
|
||||
|
||||
const systemShortKeys = {
|
||||
seenAttr: "$sa",
|
||||
caughtAttr: "$ca",
|
||||
|
@ -285,7 +243,7 @@ export class GameData {
|
|||
public starterData: StarterData;
|
||||
|
||||
public gameStats: GameStats;
|
||||
|
||||
public runHistory: RunHistoryData;
|
||||
public unlocks: Unlocks;
|
||||
|
||||
public achvUnlocks: AchvUnlocks;
|
||||
|
@ -293,17 +251,14 @@ export class GameData {
|
|||
public voucherUnlocks: VoucherUnlocks;
|
||||
public voucherCounts: VoucherCounts;
|
||||
public eggs: Egg[];
|
||||
public eggPity: integer[];
|
||||
public unlockPity: integer[];
|
||||
|
||||
constructor(scene: BattleScene) {
|
||||
this.scene = scene;
|
||||
this.loadSettings();
|
||||
this.loadGamepadSettings();
|
||||
this.loadMappingConfigs();
|
||||
this.trainerId = Utils.randInt(65536);
|
||||
this.secretId = Utils.randInt(65536);
|
||||
this.starterData = {};
|
||||
this.runHistory = {};
|
||||
this.gameStats = new GameStats();
|
||||
this.unlocks = {
|
||||
[Unlockables.ENDLESS_MODE]: false,
|
||||
|
@ -319,8 +274,6 @@ export class GameData {
|
|||
[VoucherType.GOLDEN]: 0
|
||||
};
|
||||
this.eggs = [];
|
||||
this.eggPity = [0, 0, 0, 0];
|
||||
this.unlockPity = [0, 0, 0, 0];
|
||||
this.initDexData();
|
||||
this.initStarterData();
|
||||
}
|
||||
|
@ -330,6 +283,7 @@ export class GameData {
|
|||
trainerId: this.trainerId,
|
||||
secretId: this.secretId,
|
||||
gender: this.gender,
|
||||
runHistory: this.runHistory,
|
||||
dexData: this.dexData,
|
||||
starterData: this.starterData,
|
||||
gameStats: this.gameStats,
|
||||
|
@ -339,9 +293,7 @@ export class GameData {
|
|||
voucherCounts: this.voucherCounts,
|
||||
eggs: this.eggs.map(e => new EggData(e)),
|
||||
gameVersion: this.scene.game.config.gameVersion,
|
||||
timestamp: new Date().getTime(),
|
||||
eggPity: this.eggPity.slice(0),
|
||||
unlockPity: this.unlockPity.slice(0)
|
||||
timestamp: new Date().getTime()
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -356,7 +308,7 @@ export class GameData {
|
|||
localStorage.setItem(`data_${loggedInUser.username}`, encrypt(systemData, bypassLogin));
|
||||
|
||||
if (!bypassLogin) {
|
||||
Utils.apiPost(`savedata/system/update?clientSessionId=${clientSessionId}`, systemData, undefined, true)
|
||||
Utils.apiPost(`savedata/update?datatype=${GameDataType.SYSTEM}&clientSessionId=${clientSessionId}`, systemData, undefined, true)
|
||||
.then(response => response.text())
|
||||
.then(error => {
|
||||
this.scene.ui.savingIcon.hide();
|
||||
|
@ -390,7 +342,7 @@ export class GameData {
|
|||
}
|
||||
|
||||
if (!bypassLogin) {
|
||||
Utils.apiFetch(`savedata/system/get?clientSessionId=${clientSessionId}`, true)
|
||||
Utils.apiFetch(`savedata/system?clientSessionId=${clientSessionId}`, true)
|
||||
.then(response => response.text())
|
||||
.then(response => {
|
||||
if (!response.length || response[0] !== "{") {
|
||||
|
@ -434,6 +386,11 @@ export class GameData {
|
|||
|
||||
localStorage.setItem(`data_${loggedInUser.username}`, encrypt(systemDataStr, bypassLogin));
|
||||
|
||||
if (!localStorage.hasOwnProperty(`runHistoryData_${loggedInUser.username}`)) {
|
||||
localStorage.setItem(`runHistoryData_${loggedInUser.username}`, encrypt("", true));
|
||||
}
|
||||
|
||||
|
||||
/*const versions = [ this.scene.game.config.gameVersion, data.gameVersion || '0.0.0' ];
|
||||
|
||||
if (versions[0] !== versions[1]) {
|
||||
|
@ -445,7 +402,7 @@ export class GameData {
|
|||
|
||||
this.gender = systemData.gender;
|
||||
|
||||
this.saveSetting(SettingKeys.Player_Gender, systemData.gender === PlayerGender.FEMALE ? 1 : 0);
|
||||
this.saveSetting(Setting.Player_Gender, systemData.gender === PlayerGender.FEMALE ? 1 : 0);
|
||||
|
||||
const initStarterData = !systemData.starterData;
|
||||
|
||||
|
@ -524,9 +481,6 @@ export class GameData {
|
|||
? systemData.eggs.map(e => e.toEgg())
|
||||
: [];
|
||||
|
||||
this.eggPity = systemData.eggPity ? systemData.eggPity.slice(0) : [0, 0, 0, 0];
|
||||
this.unlockPity = systemData.unlockPity ? systemData.unlockPity.slice(0) : [0, 0, 0, 0];
|
||||
|
||||
this.dexData = Object.assign(this.dexData, systemData.dexData);
|
||||
this.consolidateDexData(this.dexData);
|
||||
this.defaultDexData = null;
|
||||
|
@ -550,7 +504,7 @@ export class GameData {
|
|||
});
|
||||
}
|
||||
|
||||
parseSystemData(dataStr: string): SystemSaveData {
|
||||
private parseSystemData(dataStr: string): SystemSaveData {
|
||||
return JSON.parse(dataStr, (k: string, v: any) => {
|
||||
if (k === "gameStats") {
|
||||
return new GameStats(v);
|
||||
|
@ -569,13 +523,11 @@ export class GameData {
|
|||
}) as SystemSaveData;
|
||||
}
|
||||
|
||||
convertSystemDataStr(dataStr: string, shorten: boolean = false): string {
|
||||
private convertSystemDataStr(dataStr: string, shorten: boolean = false): string {
|
||||
if (!shorten) {
|
||||
// Account for past key oversight
|
||||
dataStr = dataStr.replace(/\$pAttr/g, "$pa");
|
||||
}
|
||||
dataStr = dataStr.replace(/"trainerId":\d+/g, `"trainerId":${this.trainerId}`);
|
||||
dataStr = dataStr.replace(/"secretId":\d+/g, `"secretId":${this.secretId}`);
|
||||
const fromKeys = shorten ? Object.keys(systemShortKeys) : Object.values(systemShortKeys);
|
||||
const toKeys = shorten ? Object.values(systemShortKeys) : Object.keys(systemShortKeys);
|
||||
for (const k in fromKeys) {
|
||||
|
@ -590,7 +542,7 @@ export class GameData {
|
|||
return true;
|
||||
}
|
||||
|
||||
const response = await Utils.apiFetch(`savedata/system/verify?clientSessionId=${clientSessionId}`, true)
|
||||
const response = await Utils.apiPost("savedata/system/verify", JSON.stringify({ clientSessionId: clientSessionId }), undefined, true)
|
||||
.then(response => response.json());
|
||||
|
||||
if (!response.valid) {
|
||||
|
@ -613,123 +565,27 @@ export class GameData {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a setting to localStorage
|
||||
* @param setting string ideally of SettingKeys
|
||||
* @param valueIndex index of the setting's option
|
||||
* @returns true
|
||||
*/
|
||||
public saveSetting(setting: string, valueIndex: integer): boolean {
|
||||
public saveSetting(setting: Setting, valueIndex: integer): boolean {
|
||||
let settings: object = {};
|
||||
if (localStorage.hasOwnProperty("settings")) {
|
||||
settings = JSON.parse(localStorage.getItem("settings"));
|
||||
}
|
||||
|
||||
setSetting(this.scene, setting, valueIndex);
|
||||
setSetting(this.scene, setting as Setting, valueIndex);
|
||||
|
||||
settings[setting] = valueIndex;
|
||||
Object.keys(settingDefaults).forEach(s => {
|
||||
if (s === setting) {
|
||||
settings[s] = valueIndex;
|
||||
}
|
||||
});
|
||||
|
||||
localStorage.setItem("settings", JSON.stringify(settings));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the mapping configurations for a specified device.
|
||||
*
|
||||
* @param deviceName - The name of the device for which the configurations are being saved.
|
||||
* @param config - The configuration object containing custom mapping details.
|
||||
* @returns `true` if the configurations are successfully saved.
|
||||
*/
|
||||
public saveMappingConfigs(deviceName: string, config): boolean {
|
||||
const key = deviceName.toLowerCase(); // Convert the gamepad name to lowercase to use as a key
|
||||
let mappingConfigs: object = {}; // Initialize an empty object to hold the mapping configurations
|
||||
if (localStorage.hasOwnProperty("mappingConfigs")) {// Check if 'mappingConfigs' exists in localStorage
|
||||
mappingConfigs = JSON.parse(localStorage.getItem("mappingConfigs"));
|
||||
} // Parse the existing 'mappingConfigs' from localStorage
|
||||
if (!mappingConfigs[key]) {
|
||||
mappingConfigs[key] = {};
|
||||
} // If there is no configuration for the given key, create an empty object for it
|
||||
mappingConfigs[key].custom = config.custom; // Assign the custom configuration to the mapping configuration for the given key
|
||||
localStorage.setItem("mappingConfigs", JSON.stringify(mappingConfigs)); // Save the updated mapping configurations back to localStorage
|
||||
return true; // Return true to indicate the operation was successful
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the mapping configurations from localStorage and injects them into the input controller.
|
||||
*
|
||||
* @returns `true` if the configurations are successfully loaded and injected; `false` if no configurations are found in localStorage.
|
||||
*
|
||||
* @remarks
|
||||
* This method checks if the 'mappingConfigs' entry exists in localStorage. If it does not exist, the method returns `false`.
|
||||
* If 'mappingConfigs' exists, it parses the configurations and injects each configuration into the input controller
|
||||
* for the corresponding gamepad or device key. The method then returns `true` to indicate success.
|
||||
*/
|
||||
public loadMappingConfigs(): boolean {
|
||||
if (!localStorage.hasOwnProperty("mappingConfigs")) {// Check if 'mappingConfigs' exists in localStorage
|
||||
return false;
|
||||
} // If 'mappingConfigs' does not exist, return false
|
||||
|
||||
const mappingConfigs = JSON.parse(localStorage.getItem("mappingConfigs")); // Parse the existing 'mappingConfigs' from localStorage
|
||||
|
||||
for (const key of Object.keys(mappingConfigs)) {// Iterate over the keys of the mapping configurations
|
||||
this.scene.inputController.injectConfig(key, mappingConfigs[key]);
|
||||
} // Inject each configuration into the input controller for the corresponding key
|
||||
|
||||
return true; // Return true to indicate the operation was successful
|
||||
}
|
||||
|
||||
public resetMappingToFactory(): boolean {
|
||||
if (!localStorage.hasOwnProperty("mappingConfigs")) {// Check if 'mappingConfigs' exists in localStorage
|
||||
return false;
|
||||
} // If 'mappingConfigs' does not exist, return false
|
||||
localStorage.removeItem("mappingConfigs");
|
||||
this.scene.inputController.resetConfigs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a gamepad setting to localStorage.
|
||||
*
|
||||
* @param setting - The gamepad setting to save.
|
||||
* @param valueIndex - The index of the value to set for the gamepad setting.
|
||||
* @returns `true` if the setting is successfully saved.
|
||||
*
|
||||
* @remarks
|
||||
* This method initializes an empty object for gamepad settings if none exist in localStorage.
|
||||
* It then updates the setting in the current scene and iterates over the default gamepad settings
|
||||
* to update the specified setting with the new value. Finally, it saves the updated settings back
|
||||
* to localStorage and returns `true` to indicate success.
|
||||
*/
|
||||
public saveControlSetting(device: Device, localStoragePropertyName: string, setting: SettingGamepad|SettingKeyboard, settingDefaults, valueIndex: integer): boolean {
|
||||
let settingsControls: object = {}; // Initialize an empty object to hold the gamepad settings
|
||||
|
||||
if (localStorage.hasOwnProperty(localStoragePropertyName)) { // Check if 'settingsControls' exists in localStorage
|
||||
settingsControls = JSON.parse(localStorage.getItem(localStoragePropertyName)); // Parse the existing 'settingsControls' from localStorage
|
||||
}
|
||||
|
||||
if (device === Device.GAMEPAD) {
|
||||
setSettingGamepad(this.scene, setting as SettingGamepad, valueIndex); // Set the gamepad setting in the current scene
|
||||
} else if (device === Device.KEYBOARD) {
|
||||
setSettingKeyboard(this.scene, setting as SettingKeyboard, valueIndex); // Set the keyboard setting in the current scene
|
||||
}
|
||||
|
||||
Object.keys(settingDefaults).forEach(s => { // Iterate over the default gamepad settings
|
||||
if (s === setting) {// If the current setting matches, update its value
|
||||
settingsControls[s] = valueIndex;
|
||||
}
|
||||
});
|
||||
|
||||
localStorage.setItem(localStoragePropertyName, JSON.stringify(settingsControls)); // Save the updated gamepad settings back to localStorage
|
||||
|
||||
return true; // Return true to indicate the operation was successful
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads Settings from local storage if available
|
||||
* @returns true if succesful, false if not
|
||||
*/
|
||||
private loadSettings(): boolean {
|
||||
resetSettings(this.scene);
|
||||
Object.values(Setting).map(setting => setting as Setting).forEach(setting => setSetting(this.scene, setting, settingDefaults[setting]));
|
||||
|
||||
if (!localStorage.hasOwnProperty("settings")) {
|
||||
return false;
|
||||
|
@ -738,28 +594,14 @@ export class GameData {
|
|||
const settings = JSON.parse(localStorage.getItem("settings"));
|
||||
|
||||
for (const setting of Object.keys(settings)) {
|
||||
setSetting(this.scene, setting, settings[setting]);
|
||||
}
|
||||
}
|
||||
|
||||
private loadGamepadSettings(): boolean {
|
||||
Object.values(SettingGamepad).map(setting => setting as SettingGamepad).forEach(setting => setSettingGamepad(this.scene, setting, settingGamepadDefaults[setting]));
|
||||
|
||||
if (!localStorage.hasOwnProperty("settingsGamepad")) {
|
||||
return false;
|
||||
}
|
||||
const settingsGamepad = JSON.parse(localStorage.getItem("settingsGamepad"));
|
||||
|
||||
for (const setting of Object.keys(settingsGamepad)) {
|
||||
setSettingGamepad(this.scene, setting as SettingGamepad, settingsGamepad[setting]);
|
||||
setSetting(this.scene, setting as Setting, settings[setting]);
|
||||
}
|
||||
}
|
||||
|
||||
public saveTutorialFlag(tutorial: Tutorial, flag: boolean): boolean {
|
||||
const key = getDataTypeKey(GameDataType.TUTORIALS);
|
||||
let tutorials: object = {};
|
||||
if (localStorage.hasOwnProperty(key)) {
|
||||
tutorials = JSON.parse(localStorage.getItem(key));
|
||||
if (localStorage.hasOwnProperty("tutorials")) {
|
||||
tutorials = JSON.parse(localStorage.getItem("tutorials"));
|
||||
}
|
||||
|
||||
Object.keys(Tutorial).map(t => t as Tutorial).forEach(t => {
|
||||
|
@ -771,21 +613,20 @@ export class GameData {
|
|||
}
|
||||
});
|
||||
|
||||
localStorage.setItem(key, JSON.stringify(tutorials));
|
||||
localStorage.setItem("tutorials", JSON.stringify(tutorials));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public getTutorialFlags(): TutorialFlags {
|
||||
const key = getDataTypeKey(GameDataType.TUTORIALS);
|
||||
const ret: TutorialFlags = {};
|
||||
Object.values(Tutorial).map(tutorial => tutorial as Tutorial).forEach(tutorial => ret[Tutorial[tutorial]] = false);
|
||||
|
||||
if (!localStorage.hasOwnProperty(key)) {
|
||||
if (!localStorage.hasOwnProperty("tutorials")) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
const tutorials = JSON.parse(localStorage.getItem(key));
|
||||
const tutorials = JSON.parse(localStorage.getItem("tutorials"));
|
||||
|
||||
for (const tutorial of Object.keys(tutorials)) {
|
||||
ret[tutorial] = tutorials[tutorial];
|
||||
|
@ -794,34 +635,6 @@ export class GameData {
|
|||
return ret;
|
||||
}
|
||||
|
||||
public saveSeenDialogue(dialogue: string): boolean {
|
||||
const key = getDataTypeKey(GameDataType.SEEN_DIALOGUES);
|
||||
const dialogues: object = this.getSeenDialogues();
|
||||
|
||||
dialogues[dialogue] = true;
|
||||
localStorage.setItem(key, JSON.stringify(dialogues));
|
||||
console.log("Dialogue saved as seen:", dialogue);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public getSeenDialogues(): SeenDialogues {
|
||||
const key = getDataTypeKey(GameDataType.SEEN_DIALOGUES);
|
||||
const ret: SeenDialogues = {};
|
||||
|
||||
if (!localStorage.hasOwnProperty(key)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
const dialogues = JSON.parse(localStorage.getItem(key));
|
||||
|
||||
for (const dialogue of Object.keys(dialogues)) {
|
||||
ret[dialogue] = dialogues[dialogue];
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private getSessionSaveData(scene: BattleScene): SessionSaveData {
|
||||
return {
|
||||
seed: scene.seed,
|
||||
|
@ -839,8 +652,7 @@ export class GameData {
|
|||
battleType: scene.currentBattle.battleType,
|
||||
trainer: scene.currentBattle.battleType === BattleType.TRAINER ? new TrainerData(scene.currentBattle.trainer) : null,
|
||||
gameVersion: scene.game.config.gameVersion,
|
||||
timestamp: new Date().getTime(),
|
||||
challenges: scene.gameMode.challenges.map(c => new ChallengeData(c))
|
||||
timestamp: new Date().getTime()
|
||||
} as SessionSaveData;
|
||||
}
|
||||
|
||||
|
@ -852,14 +664,6 @@ export class GameData {
|
|||
const handleSessionData = async (sessionDataStr: string) => {
|
||||
try {
|
||||
const sessionData = this.parseSessionData(sessionDataStr);
|
||||
for (let i = 0; i <= 5; i++) {
|
||||
const speciesToCheck = getPokemonSpecies(sessionData.party[i]?.species);
|
||||
if (sessionData.party[i]?.abilityIndex === 1) {
|
||||
if (speciesToCheck.ability1 === speciesToCheck.ability2 && speciesToCheck.abilityHidden !== Abilities.NONE && speciesToCheck.abilityHidden !== speciesToCheck.ability1) {
|
||||
sessionData.party[i].abilityIndex = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
resolve(sessionData);
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
|
@ -868,7 +672,7 @@ export class GameData {
|
|||
};
|
||||
|
||||
if (!bypassLogin && !localStorage.getItem(`sessionData${slotId ? slotId : ""}_${loggedInUser.username}`)) {
|
||||
Utils.apiFetch(`savedata/session/get?slot=${slotId}&clientSessionId=${clientSessionId}`, true)
|
||||
Utils.apiFetch(`savedata/session?slot=${slotId}&clientSessionId=${clientSessionId}`, true)
|
||||
.then(response => response.text())
|
||||
.then(async response => {
|
||||
if (!response.length || response[0] !== "{") {
|
||||
|
@ -894,13 +698,10 @@ export class GameData {
|
|||
loadSession(scene: BattleScene, slotId: integer, sessionData?: SessionSaveData): Promise<boolean> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const initSessionFromData = async (sessionData: SessionSaveData) => {
|
||||
const initSessionFromData = async sessionData => {
|
||||
console.debug(sessionData);
|
||||
|
||||
scene.gameMode = getGameMode(sessionData.gameMode || GameModes.CLASSIC);
|
||||
if (sessionData.challenges) {
|
||||
scene.gameMode.challenges = sessionData.challenges.map(c => c.toChallenge());
|
||||
}
|
||||
scene.gameMode = gameModes[sessionData.gameMode || GameModes.CLASSIC];
|
||||
|
||||
scene.setSeed(sessionData.seed || scene.game.config.seed[0]);
|
||||
scene.resetSeed();
|
||||
|
@ -959,10 +760,6 @@ export class GameData {
|
|||
});
|
||||
|
||||
scene.arena.weather = sessionData.arena.weather;
|
||||
scene.arena.eventTarget.dispatchEvent(new WeatherChangedEvent(null, scene.arena.weather?.weatherType, scene.arena.weather?.turnsLeft));
|
||||
|
||||
scene.arena.terrain = sessionData.arena.terrain;
|
||||
scene.arena.eventTarget.dispatchEvent(new TerrainChangedEvent(null, scene.arena.terrain?.terrainType, scene.arena.terrain?.turnsLeft));
|
||||
// TODO
|
||||
//scene.arena.tags = sessionData.arena.tags;
|
||||
|
||||
|
@ -1016,7 +813,7 @@ export class GameData {
|
|||
if (success !== null && !success) {
|
||||
return resolve(false);
|
||||
}
|
||||
Utils.apiFetch(`savedata/session/delete?slot=${slotId}&clientSessionId=${clientSessionId}`, true).then(response => {
|
||||
Utils.apiFetch(`savedata/delete?datatype=${GameDataType.SESSION}&slot=${slotId}&clientSessionId=${clientSessionId}`, true).then(response => {
|
||||
if (response.ok) {
|
||||
loggedInUser.lastSessionSlot = -1;
|
||||
localStorage.removeItem(`sessionData${this.scene.sessionSlotId ? this.scene.sessionSlotId : ""}_${loggedInUser.username}`);
|
||||
|
@ -1080,7 +877,7 @@ export class GameData {
|
|||
return resolve([false, false]);
|
||||
}
|
||||
const sessionData = this.getSessionSaveData(scene);
|
||||
Utils.apiPost(`savedata/session/clear?slot=${slotId}&trainerId=${this.trainerId}&secretId=${this.secretId}&clientSessionId=${clientSessionId}`, JSON.stringify(sessionData), undefined, true).then(response => {
|
||||
Utils.apiPost(`savedata/clear?slot=${slotId}&trainerId=${this.trainerId}&secretId=${this.secretId}&clientSessionId=${clientSessionId}`, JSON.stringify(sessionData), undefined, true).then(response => {
|
||||
if (response.ok) {
|
||||
loggedInUser.lastSessionSlot = -1;
|
||||
localStorage.removeItem(`sessionData${this.scene.sessionSlotId ? this.scene.sessionSlotId : ""}_${loggedInUser.username}`);
|
||||
|
@ -1101,7 +898,7 @@ export class GameData {
|
|||
});
|
||||
}
|
||||
|
||||
public parseSessionData(dataStr: string): SessionSaveData {
|
||||
parseSessionData(dataStr: string): SessionSaveData {
|
||||
return JSON.parse(dataStr, (k: string, v: any) => {
|
||||
/*const versions = [ scene.game.config.gameVersion, sessionData.gameVersion || '0.0.0' ];
|
||||
|
||||
|
@ -1134,9 +931,6 @@ export class GameData {
|
|||
if (md?.className === "ExpBalanceModifier") { // Temporarily limit EXP Balance until it gets reworked
|
||||
md.stackCount = Math.min(md.stackCount, 4);
|
||||
}
|
||||
if (md instanceof EnemyAttackStatusEffectChanceModifier && md.effect === StatusEffect.FREEZE || md.effect === StatusEffect.SLEEP) {
|
||||
continue;
|
||||
}
|
||||
ret.push(new PersistentModifierData(md, player));
|
||||
}
|
||||
return ret;
|
||||
|
@ -1146,21 +940,65 @@ export class GameData {
|
|||
return new ArenaData(v);
|
||||
}
|
||||
|
||||
if (k === "challenges") {
|
||||
const ret: ChallengeData[] = [];
|
||||
if (v === null) {
|
||||
v = [];
|
||||
}
|
||||
for (const c of v) {
|
||||
ret.push(new ChallengeData(c));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
return v;
|
||||
}) as SessionSaveData;
|
||||
}
|
||||
|
||||
async public getRunHistoryData(scene: BattleScene): Promise<Object> {
|
||||
try {
|
||||
const response = await Utils.apiFetch("savedata/runHistory", true);
|
||||
const data = await response.json();
|
||||
console.log(data);
|
||||
if (!data) {
|
||||
throw new Error("No data");
|
||||
} else {
|
||||
var cachedResponse = localStorage.getItem(`runHistoryData_${loggedInUser.username}`, true);
|
||||
if (cachedResponse) {
|
||||
cachedResponse = JSON.parse(decrypt(cachedResponse, true));
|
||||
}
|
||||
const cachedRHData = cachedResponse ?? {};
|
||||
//check to see whether cachedData or serverData is more up-to-date
|
||||
if ( Object.keys(cachedRHData).length >= Object.keys(data).length ) {
|
||||
return cachedRHData;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
} catch (err) {
|
||||
console.log("Something went wrong: ", err);
|
||||
var cachedResponse = localStorage.getItem(`runHistoryData_${loggedInUser.username}`, true);
|
||||
if (cachedResponse) {
|
||||
cachedResponse = JSON.parse(decrypt(cachedResponse, true));
|
||||
}
|
||||
return cachedResponse ?? {};
|
||||
}
|
||||
}
|
||||
|
||||
async saveRunHistory(scene: BattleScene, runEntry : SessionSaveData, victory: boolean): Promise<boolean> {
|
||||
|
||||
const runHistoryData = await this.getRunHistoryData(scene);
|
||||
const timestamps = Object.keys(runHistoryData);
|
||||
|
||||
//Arbitrary limit of 25 entries per User --> Can increase or decrease
|
||||
if (timestamps.length >= 25) {
|
||||
delete this.scene.gameData.runHistory[Math.min(timestamps)];
|
||||
}
|
||||
|
||||
const timestamp = (runEntry.timestamp).toString();
|
||||
runHistoryData[timestamp] = {};
|
||||
runHistoryData[timestamp]["entry"] = runEntry;
|
||||
runHistoryData[timestamp]["victory"] = victory;
|
||||
|
||||
localStorage.setItem(`runHistoryData_${loggedInUser.username}`, encrypt(JSON.stringify(runHistoryData), true));
|
||||
|
||||
try {
|
||||
const response = Utils.apiPost("savedata/runHistory", JSON.stringify(runHistoryData), undefined, true);
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.log("savedata/runHistory POST failed : ", err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
saveAll(scene: BattleScene, skipVerification: boolean = false, sync: boolean = false, useCachedSession: boolean = false, useCachedSystem: boolean = false): Promise<boolean> {
|
||||
return new Promise<boolean>(resolve => {
|
||||
Utils.executeIf(!skipVerification, updateUserInfo).then(success => {
|
||||
|
@ -1237,7 +1075,7 @@ export class GameData {
|
|||
link.remove();
|
||||
};
|
||||
if (!bypassLogin && dataType < GameDataType.SETTINGS) {
|
||||
Utils.apiFetch(`savedata/${dataType === GameDataType.SYSTEM ? "system" : "session"}/get?clientSessionId=${clientSessionId}${dataType === GameDataType.SESSION ? `&slot=${slotId}` : ""}`, true)
|
||||
Utils.apiFetch(`savedata/${dataType === GameDataType.SYSTEM ? "system" : "session"}?clientSessionId=${clientSessionId}${dataType === GameDataType.SESSION ? `&slot=${slotId}` : ""}`, true)
|
||||
.then(response => response.text())
|
||||
.then(response => {
|
||||
if (!response.length || response[0] !== "{") {
|
||||
|
@ -1278,11 +1116,9 @@ export class GameData {
|
|||
|
||||
reader.onload = (_ => {
|
||||
return e => {
|
||||
let dataName: string;
|
||||
let dataStr = AES.decrypt(e.target.result.toString(), saveKey).toString(enc.Utf8);
|
||||
let valid = false;
|
||||
try {
|
||||
dataName = GameDataType[dataType].toLowerCase();
|
||||
switch (dataType) {
|
||||
case GameDataType.SYSTEM:
|
||||
dataStr = this.convertSystemDataStr(dataStr);
|
||||
|
@ -1302,28 +1138,38 @@ export class GameData {
|
|||
console.error(ex);
|
||||
}
|
||||
|
||||
let dataName: string;
|
||||
switch (dataType) {
|
||||
case GameDataType.SYSTEM:
|
||||
dataName = "save";
|
||||
break;
|
||||
case GameDataType.SESSION:
|
||||
dataName = "session";
|
||||
break;
|
||||
case GameDataType.SETTINGS:
|
||||
dataName = "settings";
|
||||
break;
|
||||
case GameDataType.TUTORIALS:
|
||||
dataName = "tutorials";
|
||||
break;
|
||||
}
|
||||
|
||||
const displayError = (error: string) => this.scene.ui.showText(error, null, () => this.scene.ui.showText(null, 0), Utils.fixedInt(1500));
|
||||
|
||||
if (!valid) {
|
||||
return this.scene.ui.showText(`Your ${dataName} data could not be loaded. It may be corrupted.`, null, () => this.scene.ui.showText(null, 0), Utils.fixedInt(1500));
|
||||
}
|
||||
|
||||
this.scene.ui.revertMode();
|
||||
this.scene.ui.showText(`Your ${dataName} data will be overridden and the page will reload. Proceed?`, null, () => {
|
||||
this.scene.ui.setOverlayMode(Mode.CONFIRM, () => {
|
||||
localStorage.setItem(dataKey, encrypt(dataStr, bypassLogin));
|
||||
|
||||
if (!bypassLogin && dataType < GameDataType.SETTINGS) {
|
||||
updateUserInfo().then(success => {
|
||||
if (!success[0]) {
|
||||
if (!success) {
|
||||
return displayError(`Could not contact the server. Your ${dataName} data could not be imported.`);
|
||||
}
|
||||
let url: string;
|
||||
if (dataType === GameDataType.SESSION) {
|
||||
url = `savedata/session/update?slot=${slotId}&trainerId=${this.trainerId}&secretId=${this.secretId}&clientSessionId=${clientSessionId}`;
|
||||
} else {
|
||||
url = `savedata/system/update?trainerId=${this.trainerId}&secretId=${this.secretId}&clientSessionId=${clientSessionId}`;
|
||||
}
|
||||
Utils.apiPost(url, dataStr, undefined, true)
|
||||
Utils.apiPost(`savedata/update?datatype=${dataType}${dataType === GameDataType.SESSION ? `&slot=${slotId}` : ""}&trainerId=${this.trainerId}&secretId=${this.secretId}&clientSessionId=${clientSessionId}`, dataStr, undefined, true)
|
||||
.then(response => response.text())
|
||||
.then(error => {
|
||||
if (error) {
|
||||
|
@ -1498,7 +1344,7 @@ export class GameData {
|
|||
|
||||
if (newCatch && speciesStarters.hasOwnProperty(species.speciesId)) {
|
||||
this.scene.playSound("level_up_fanfare");
|
||||
this.scene.ui.showText(i18next.t("battle:addedAsAStarter", { pokemonName: species.name }), null, () => checkPrevolution(), null, true);
|
||||
this.scene.ui.showText(`${species.name} has been\nadded as a starter!`, null, () => checkPrevolution(), null, true);
|
||||
} else {
|
||||
checkPrevolution();
|
||||
}
|
||||
|
@ -1564,9 +1410,7 @@ export class GameData {
|
|||
this.starterData[speciesId].eggMoves |= value;
|
||||
|
||||
this.scene.playSound("level_up_fanfare");
|
||||
|
||||
const moveName = allMoves[speciesEggMoves[speciesId][eggMoveIndex]].name;
|
||||
this.scene.ui.showText(eggMoveIndex === 3 ? i18next.t("egg:rareEggMoveUnlock", { moveName: moveName }) : i18next.t("egg:eggMoveUnlock", { moveName: moveName }), null, () => resolve(true), null, true);
|
||||
this.scene.ui.showText(`${eggMoveIndex === 3 ? "Rare " : ""}Egg Move unlocked: ${allMoves[speciesEggMoves[speciesId][eggMoveIndex]].name}`, null, () => resolve(true), null, true);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1688,10 +1532,7 @@ export class GameData {
|
|||
value = decrementValue(value);
|
||||
}
|
||||
|
||||
const cost = new Utils.NumberHolder(value);
|
||||
applyChallenges(this.scene.gameMode, ChallengeType.STARTER_COST, speciesId, cost);
|
||||
|
||||
return cost.value;
|
||||
return value;
|
||||
}
|
||||
|
||||
getFormIndex(attr: bigint): integer {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import BattleScene from "../battle-scene";
|
||||
import { gameModes } from "../game-mode";
|
||||
import { SessionSaveData, parseSessionData, RunHistoryData, RunEntries } from "../system/game-data";
|
||||
import { gameModes, GameModes } from "../game-mode";
|
||||
import { SessionSaveData, parseSessionData, getRunHistoryData, RunHistoryData, RunEntries, decrypt } from "../system/game-data";
|
||||
import { TextStyle, addTextObject } from "./text";
|
||||
import { Mode } from "./ui";
|
||||
import { addWindow } from "./ui-theme";
|
||||
import * as Utils from "../utils";
|
||||
import { PokemonData } from "../system/pokemon-data";
|
||||
import { TrainerData } from "../system/trainer-data"
|
||||
import { TrainerData } from "../system/trainer-data";
|
||||
import Pokemon, { EnemyPokemon, PlayerPokemon } from "../field/pokemon";
|
||||
import { PokemonHeldItemModifier } from "../modifier/modifier";
|
||||
import MessageUiHandler from "./message-ui-handler";
|
||||
|
@ -14,6 +14,8 @@ import i18next from "i18next";
|
|||
import {Button} from "../enums/buttons";
|
||||
import { BattleType } from "../battle";
|
||||
import {TrainerType} from "../data/enums/trainer-type";
|
||||
import { TrainerVariant } from "../field/trainer";
|
||||
import { getPartyLuckValue, getLuckString, getLuckTextTint } from "../modifier/modifier-type";
|
||||
|
||||
export const runCount = 25;
|
||||
|
||||
|
@ -76,7 +78,7 @@ export default class RunHistoryUiHandler extends MessageUiHandler {
|
|||
|
||||
this.getUi().bringToTop(this.runSelectContainer);
|
||||
this.runSelectContainer.setVisible(true);
|
||||
this.populateruns();
|
||||
this.populateruns(this.scene);
|
||||
|
||||
this.setScrollCursor(0);
|
||||
this.setCursor(0);
|
||||
|
@ -130,15 +132,16 @@ export default class RunHistoryUiHandler extends MessageUiHandler {
|
|||
}
|
||||
|
||||
|
||||
populateruns() {
|
||||
const timestamps = Object.keys(this.scene.gameData.runHistory);
|
||||
async populateruns(scene: BattleScene) {
|
||||
const response = await this.scene.gameData.getRunHistoryData(this.scene);
|
||||
console.log(response);
|
||||
const timestamps = Object.keys(response);
|
||||
if (timestamps.length > 1) {
|
||||
timestamps.sort((a, b) => a - b);
|
||||
}
|
||||
const entryCount = timestamps.length;
|
||||
console.log(entryCount);
|
||||
for (let s = 0; s < entryCount; s++) {
|
||||
const entry = new RunEntry(this.scene, timestamps[s], s);
|
||||
const entry = new RunEntry(this.scene, response, timestamps[s], s);
|
||||
this.scene.add.existing(entry);
|
||||
this.runsContainer.add(entry);
|
||||
this.runs.push(entry);
|
||||
|
@ -215,12 +218,12 @@ class RunEntry extends Phaser.GameObjects.Container {
|
|||
public hasData: boolean;
|
||||
private loadingLabel: Phaser.GameObjects.Text;
|
||||
|
||||
constructor(scene: BattleScene, timestamp: string, slotId: integer) {
|
||||
constructor(scene: BattleScene, runHistory: RunHistoryData, timestamp: string, slotId: integer) {
|
||||
super(scene, 0, slotId*56);
|
||||
|
||||
this.slotId = slotId;
|
||||
|
||||
this.setup(this.scene.gameData.runHistory[timestamp]);
|
||||
this.setup(runHistory[timestamp]);
|
||||
|
||||
}
|
||||
|
||||
|
@ -228,7 +231,6 @@ class RunEntry extends Phaser.GameObjects.Container {
|
|||
|
||||
const victory = run.victory;
|
||||
const data = this.scene.gameData.parseSessionData(JSON.stringify(run.entry));
|
||||
console.log(data);
|
||||
|
||||
const slotWindow = addWindow(this.scene, 0, 0, 304, 52);
|
||||
this.add(slotWindow);
|
||||
|
@ -238,13 +240,15 @@ class RunEntry extends Phaser.GameObjects.Container {
|
|||
const gameOutcomeLabel = addTextObject(this.scene, 8, 5, "Victory", TextStyle.WINDOW);
|
||||
this.add(gameOutcomeLabel);
|
||||
} else {
|
||||
if (data.battleType === BattleType.WILD) {
|
||||
const enemyContainer = this.scene.add.container(8,5);
|
||||
if (data.battleType === BattleType.WILD) {
|
||||
const enemyContainer = this.scene.add.container(8, 5);
|
||||
const gameOutcomeLabel = addTextObject(this.scene, 0, 0, "Defeated by ", TextStyle.WINDOW);
|
||||
enemyContainer.add(gameOutcomeLabel);
|
||||
const enemyIconContainer = this.scene.add.container(58,-8);
|
||||
enemyIconContainer.setScale(0.75);
|
||||
data.enemyParty.forEach((enemyData, e) => {
|
||||
//This allows the enemyParty to be shown - doubles or sings -> 58+(e*8)
|
||||
const enemyIconContainer = this.scene.add.container(65+(e*25),-8);
|
||||
enemyIconContainer.setScale(0.75);
|
||||
enemyData.boss = false;
|
||||
const enemy = enemyData.toPokemon(this.scene);
|
||||
const enemyIcon = this.scene.addPokemonIcon(enemy, 0, 0, 0, 0);
|
||||
const enemyLevel = addTextObject(this.scene, 32, 20, `Lv${Utils.formatLargeNumber(enemy.level, 1000)}`, TextStyle.PARTY, { fontSize: "54px", color: "#f8f8f8" });
|
||||
|
@ -257,22 +261,33 @@ class RunEntry extends Phaser.GameObjects.Container {
|
|||
enemy.destroy();
|
||||
});
|
||||
this.add(enemyContainer);
|
||||
}
|
||||
else if (data.battleType === BattleType.TRAINER) {
|
||||
} else if (data.battleType === BattleType.TRAINER) {
|
||||
const tObj = data.trainer.toTrainer(this.scene);
|
||||
const tType = TrainerType[data.trainer.trainerType];
|
||||
const gameOutcomeLabel = addTextObject(this.scene, 8, 5, `Defeated by ${tType.charAt(0)+tType.substring(1).toLowerCase()}`, TextStyle.WINDOW);
|
||||
this.add(gameOutcomeLabel);
|
||||
}
|
||||
if (data.trainer.trainerType >= 375) {
|
||||
const gameOutcomeLabel = addTextObject(this.scene, 8, 5, "Defeated by Rival", TextStyle.WINDOW);
|
||||
//otherwise it becomes Rival_5 in Ivy's case
|
||||
this.add(gameOutcomeLabel);
|
||||
} else {
|
||||
if (tObj.variant === TrainerVariant.DOUBLE) {
|
||||
const gameOutcomeLabel = addTextObject(this.scene, 8, 5, "Defeated by Duo", TextStyle.WINDOW);
|
||||
}
|
||||
const gameOutcomeLabel = addTextObject(this.scene, 8, 5, `Defeated by ${tObj.getName(0, true)}`, TextStyle.WINDOW);
|
||||
this.add(gameOutcomeLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const gameModeLabel = addTextObject(this.scene, 8, 19, `${gameModes[data.gameMode]?.getName() || "Unknown"} - Wave ${data.waveIndex}`, TextStyle.WINDOW);
|
||||
this.add(gameModeLabel);
|
||||
|
||||
const date = new Date(data.timestamp);
|
||||
|
||||
const timestampLabel = addTextObject(this.scene, 8, 33, new Date(data.timestamp).toLocaleString(), TextStyle.WINDOW);
|
||||
this.add(timestampLabel);
|
||||
|
||||
const pokemonIconsContainer = this.scene.add.container(144, 4);
|
||||
const pokemonIconsContainer = this.scene.add.container(125, 17);
|
||||
let luckValue = 0;
|
||||
|
||||
data.party.forEach((p: PokemonData, i: integer) => {
|
||||
const iconContainer = this.scene.add.container(26 * i, 0);
|
||||
|
@ -290,11 +305,31 @@ class RunEntry extends Phaser.GameObjects.Container {
|
|||
|
||||
pokemonIconsContainer.add(iconContainer);
|
||||
|
||||
luckValue += pokemon.getLuck();
|
||||
|
||||
pokemon.destroy();
|
||||
});
|
||||
|
||||
this.add(pokemonIconsContainer);
|
||||
|
||||
//Display Score - only visible for Daily Mode
|
||||
//Display Luck - only visible for Endless Modes
|
||||
switch (data.gameMode) {
|
||||
case GameModes.DAILY:
|
||||
const runScore = data.score;
|
||||
const scoreText = addTextObject(this.scene, 240, 5, `Score: ${data.score}`, TextStyle.WINDOW, {color: "#f89890"});
|
||||
this.add(scoreText);
|
||||
break;
|
||||
case GameModes.ENDLESS:
|
||||
case GameModes.SPLICED_ENDLESS:
|
||||
if (luckValue > 14) {
|
||||
luckValue = 14;
|
||||
}
|
||||
const luckTextTint = "#"+(getLuckTextTint(luckValue)).toString(16);
|
||||
const luckText = addTextObject(this.scene, 240, 5, `Luck: ${getLuckString(luckValue)}`, TextStyle.WINDOW, {color: `${luckTextTint}`});
|
||||
this.add(luckText);
|
||||
break;
|
||||
}
|
||||
/*
|
||||
const modifiersModule = import("../modifier/modifier");
|
||||
|
||||
|
|
|
@ -0,0 +1,659 @@
|
|||
import BattleScene from "../battle-scene";
|
||||
import { GameModes } from "../game-mode";
|
||||
import UiHandler from "./ui-handler";
|
||||
import { SessionSaveData } from "../system/game-data";
|
||||
import { TextStyle, addTextObject, addBBCodeTextObject } from "./text";
|
||||
import { Mode } from "./ui";
|
||||
import { addWindow } from "./ui-theme";
|
||||
import * as Utils from "../utils";
|
||||
import PokemonData from "../system/pokemon-data";
|
||||
import i18next from "i18next";
|
||||
import {Button} from "../enums/buttons";
|
||||
import { BattleType } from "../battle";
|
||||
import { TrainerVariant } from "../field/trainer";
|
||||
import { Challenges } from "#enums/challenges";
|
||||
import { getLuckString, getLuckTextTint } from "../modifier/modifier-type";
|
||||
import RoundRectangle from "phaser3-rex-plugins/plugins/roundrectangle.js";
|
||||
import { Type, getTypeRgb } from "../data/type";
|
||||
import { starterPassiveAbilities } from "../data/pokemon-species";
|
||||
import { getNatureStatMultiplier, getNatureName } from "../data/nature";
|
||||
import { allAbilities } from "../data/ability";
|
||||
import { getVariantTint } from "#app/data/variant";
|
||||
import { PokemonHeldItemModifier } from "../modifier/modifier";
|
||||
import {modifierSortFunc} from "../modifier/modifier";
|
||||
import { Species } from "#enums/species";
|
||||
|
||||
/*
|
||||
enum Page {
|
||||
GENERAL,
|
||||
STATS,
|
||||
HALL_OF_FAME
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
export enum RunVictory {
|
||||
DEFEATED,
|
||||
VICTORY
|
||||
}
|
||||
|
||||
export default class GameInfoUiHandler extends UiHandler {
|
||||
private runInfo: SessionSaveData;
|
||||
private victory: boolean;
|
||||
|
||||
private gameStatsContainer: Phaser.GameObjects.Container;
|
||||
private statsContainer: Phaser.GameObjects.Container;
|
||||
|
||||
private runResultContainer: Phaser.GameObjects.Container;
|
||||
private runInfoContainer: Phaser.GameObjects.Container;
|
||||
private partyContainer: Phaser.GameObjects.Container;
|
||||
private partyHeldItemsContainer: Phaser.GameObjects.Container;
|
||||
private statsBgWidth: integer;
|
||||
private partyContainerHeight: integer;
|
||||
private partyContainerWidth: integer;
|
||||
|
||||
private hallofFameContainer: Phaser.GameObjects.Container;
|
||||
|
||||
private partyInfo: Phaser.GameObjects.Container[];
|
||||
private partyVisibility: Boolean;
|
||||
private modifiersModule: any;
|
||||
|
||||
private statValues: Phaser.GameObjects.Text[];
|
||||
|
||||
constructor(scene: BattleScene) {
|
||||
super(scene, Mode.RUN_INFO);
|
||||
}
|
||||
|
||||
async setup() {
|
||||
//const page = 0;
|
||||
this.gameStatsContainer = this.scene.add.container(1, -(this.scene.game.canvas.height / 6) + 1);
|
||||
this.modifiersModule = await import("../modifier/modifier");
|
||||
this.gameStatsContainer.setVisible(false);
|
||||
}
|
||||
|
||||
show(args: any[]): boolean {
|
||||
super.show(args);
|
||||
|
||||
const gameStatsBg = this.scene.add.rectangle(0, 0, this.scene.game.canvas.width, this.scene.game.canvas.height, 0x006860);
|
||||
gameStatsBg.setOrigin(0, 0);
|
||||
this.gameStatsContainer.add(gameStatsBg);
|
||||
|
||||
const headerBg = addWindow(this.scene, 0, 0, (this.scene.game.canvas.width / 6) - 2, 24);
|
||||
headerBg.setOrigin(0, 0);
|
||||
|
||||
const downButtonContainer = this.scene.add.container(0, 0);
|
||||
const downButtonText = addTextObject(this.scene, 8, 0, i18next.t("runHistory:viewHeldItems"), TextStyle.WINDOW, {fontSize:"34px"});
|
||||
const downButtonElement = new Phaser.GameObjects.Sprite(this.scene, 0, 2, "keyboard", "KEY_ARROW_DOWN.png");
|
||||
downButtonContainer.add([downButtonText, downButtonElement]);
|
||||
downButtonContainer.setPositionRelative(headerBg, 275, 10);
|
||||
const headerText = addTextObject(this.scene, 0, 0, i18next.t("runHistory:runInfo"), TextStyle.SETTINGS_LABEL);
|
||||
headerText.setOrigin(0, 0);
|
||||
headerText.setPositionRelative(headerBg, 8, 4);
|
||||
this.gameStatsContainer.add(headerBg);
|
||||
this.gameStatsContainer.add(downButtonContainer);
|
||||
this.gameStatsContainer.add(headerText);
|
||||
|
||||
const run = args[0];
|
||||
this.runInfo = this.scene.gameData.parseSessionData(JSON.stringify(run.entry));
|
||||
this.victory = run.victory;
|
||||
|
||||
this.statsBgWidth = ((this.scene.game.canvas.width / 6) - 2) / 3;
|
||||
|
||||
this.runResultContainer = this.scene.add.container(0, 24);
|
||||
const runResultWindow = addWindow(this.scene, 0, 0, this.statsBgWidth-11, 65);
|
||||
runResultWindow.setOrigin(0, 0);
|
||||
this.runResultContainer.add(runResultWindow);
|
||||
this.parseRunResult(this.runInfo, this.victory);
|
||||
|
||||
this.partyContainer = this.scene.add.container(this.statsBgWidth-10, 23);
|
||||
|
||||
this.setCursor(0);
|
||||
|
||||
this.runInfoContainer = this.scene.add.container(0, 89);
|
||||
const runInfoWindow = addWindow(this.scene, 0, 0, this.statsBgWidth-11, 90);
|
||||
this.runInfoContainer.add(runInfoWindow);
|
||||
this.parseRunInfo(this.runInfo);
|
||||
|
||||
const partyData = this.runInfo.party;
|
||||
this.parsePartyInfo(partyData);
|
||||
this.showParty(true);
|
||||
|
||||
this.gameStatsContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6), Phaser.Geom.Rectangle.Contains);
|
||||
this.getUi().bringToTop(this.gameStatsContainer);
|
||||
this.gameStatsContainer.setVisible(true);
|
||||
|
||||
if (this.victory) {
|
||||
this.createHallofFame();
|
||||
this.getUi().bringToTop(this.hallofFameContainer);
|
||||
}
|
||||
|
||||
this.setCursor(0);
|
||||
|
||||
this.getUi().add(this.gameStatsContainer);
|
||||
//this.updateStats();
|
||||
|
||||
this.getUi().hideTooltip();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
async parseRunResult(runData: any, runResult: boolean) {
|
||||
const runResultText = addBBCodeTextObject(this.scene, 6, 4, `${(runResult ? i18next.t("runHistory:victory") : i18next.t("runHistory:defeated")+" - Wave "+runData.waveIndex)}`, TextStyle.WINDOW, {fontSize : "65px", lineSpacing: 0.1});
|
||||
this.runResultContainer.add(runResultText);
|
||||
|
||||
if (runResult) {
|
||||
const hallofFameInstructionContainer = this.scene.add.container(0, 0);
|
||||
const upButtonText = addTextObject(this.scene, 8, 0, i18next.t("runHistory:viewHallOfFame"), TextStyle.WINDOW, {fontSize:"65px"});
|
||||
const upButtonElement = new Phaser.GameObjects.Sprite(this.scene, 0, 4, "keyboard", "KEY_ARROW_UP.png");
|
||||
hallofFameInstructionContainer.add([upButtonText, upButtonElement]);
|
||||
hallofFameInstructionContainer.setPosition(12, 25);
|
||||
this.runResultContainer.add(hallofFameInstructionContainer);
|
||||
}
|
||||
|
||||
if (!runResult) {
|
||||
const enemyContainer = this.scene.add.container(0, 0);
|
||||
|
||||
//Wild - Single and Doubles
|
||||
if (runData.battleType === BattleType.WILD) {
|
||||
switch (runData.enemyParty.length) {
|
||||
case 1:
|
||||
//Wild - Singles
|
||||
const enemyIconContainer = this.scene.add.container(0, 0);
|
||||
const enemyData = runData.enemyParty[0];
|
||||
const bossStatus = enemyData.boss;
|
||||
enemyData.boss = false;
|
||||
//addPokemonIcon() throws an error if the Pokemon used is a boss
|
||||
const enemy = enemyData.toPokemon(this.scene);
|
||||
const enemyIcon = this.scene.addPokemonIcon(enemy, 0, 0, 0, 0);
|
||||
const enemyLevel = addTextObject(this.scene, 36, 26, `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(enemy.level, 1000)}`, bossStatus ? TextStyle.PARTY_RED : TextStyle.PARTY, { fontSize: "44px", color: "#f8f8f8" });
|
||||
enemyLevel.setShadow(0, 0, null);
|
||||
enemyLevel.setStroke("#424242", 14);
|
||||
enemyLevel.setOrigin(1, 0);
|
||||
enemyIconContainer.add(enemyIcon);
|
||||
enemyIconContainer.add(enemyLevel);
|
||||
enemyContainer.add(enemyIconContainer);
|
||||
enemyContainer.setPosition(27, 10);
|
||||
enemy.destroy();
|
||||
break;
|
||||
case 2:
|
||||
runData.enemyParty.forEach((enemyData, e) => {
|
||||
const enemyIconContainer = this.scene.add.container(0, 0);
|
||||
const bossStatus = enemyData.boss;
|
||||
enemyData.boss = false;
|
||||
const enemy = enemyData.toPokemon(this.scene);
|
||||
const enemyIcon = this.scene.addPokemonIcon(enemy, 0, 0, 0, 0);
|
||||
const enemyLevel = addTextObject(this.scene, 36, 26, `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(enemy.level, 1000)}`, bossStatus ? TextStyle.PARTY_RED : TextStyle.PARTY, { fontSize: "44px", color: "#f8f8f8" });
|
||||
enemyLevel.setShadow(0, 0, null);
|
||||
enemyLevel.setStroke("#424242", 14);
|
||||
enemyLevel.setOrigin(1, 0);
|
||||
enemyIconContainer.add(enemyIcon);
|
||||
enemyIconContainer.add(enemyLevel);
|
||||
enemyIconContainer.setPosition(e*35, 0);
|
||||
enemyContainer.add(enemyIconContainer);
|
||||
enemy.destroy();
|
||||
});
|
||||
enemyContainer.setPosition(8, 14);
|
||||
break;
|
||||
}
|
||||
//Trainer - Single and Double
|
||||
} else if (runData.battleType === BattleType.TRAINER) {
|
||||
const tObj = runData.trainer.toTrainer(this.scene);
|
||||
const tObjSpriteKey = tObj.config.getSpriteKey(runData.trainer.variant === TrainerVariant.FEMALE, false);
|
||||
const tObjSprite = this.scene.add.sprite(0, 0, tObjSpriteKey);
|
||||
if (runData.trainer.variant === TrainerVariant.DOUBLE) {
|
||||
const doubleContainer = this.scene.add.container(5, 8);
|
||||
tObjSprite.setPosition(-3, -3);
|
||||
const tObjPartnerSpriteKey = tObj.config.getSpriteKey(true, true);
|
||||
const tObjPartnerSprite = this.scene.add.sprite(5, -3, tObjPartnerSpriteKey);
|
||||
tObjPartnerSprite.setScale(0.20);
|
||||
tObjSprite.setScale(0.20);
|
||||
doubleContainer.add(tObjSprite);
|
||||
doubleContainer.add(tObjPartnerSprite);
|
||||
enemyContainer.add(doubleContainer);
|
||||
} else {
|
||||
tObjSprite.setScale(0.25, 0.25);
|
||||
tObjSprite.setPosition(9, 23);
|
||||
enemyContainer.add(tObjSprite);
|
||||
}
|
||||
|
||||
const teraPokemon = {};
|
||||
runData.enemyModifiers.forEach((m) => {
|
||||
if (m.className === "TerastallizeModifier") {
|
||||
teraPokemon[m.args[0]] = m.args[1];
|
||||
}
|
||||
});
|
||||
|
||||
const enemyPartyContainer = this.scene.add.container(0, 0);
|
||||
runData.enemyParty.forEach((enemyData, e) => {
|
||||
const pokemonRowHeight = Math.floor(e/3);
|
||||
const enemyIconContainer = this.scene.add.container(0, 0);
|
||||
enemyIconContainer.setScale(0.6);
|
||||
const isBoss = enemyData.boss;
|
||||
enemyData.boss = false;
|
||||
const enemy = enemyData.toPokemon(this.scene);
|
||||
const enemyIcon = this.scene.addPokemonIcon(enemy, 0, 0, 0, 0);
|
||||
const enemySprite1 = enemyIcon.list[0] as Phaser.GameObjects.Sprite;
|
||||
const enemySprite2 = (enemyIcon.list.length > 1) ? enemyIcon.list[1] as Phaser.GameObjects.Sprite : null;
|
||||
if (teraPokemon[enemyData.id]) {
|
||||
const teraTint = getTypeRgb(teraPokemon[enemyData.id]);
|
||||
const teraColor = new Phaser.Display.Color(teraTint[0], teraTint[1], teraTint[2]);
|
||||
enemySprite1.setTint(teraColor.color);
|
||||
if (enemySprite2) {
|
||||
enemySprite2.setTint(teraColor.color);
|
||||
}
|
||||
}
|
||||
enemyIcon.setPosition(39*(e%3), (35*pokemonRowHeight));
|
||||
const enemyLevel = addTextObject(this.scene, 43*(e%3), (27*(pokemonRowHeight+1)), `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(enemy.level, 1000)}`, isBoss ? TextStyle.PARTY_RED : TextStyle.PARTY, { fontSize: "54px" });
|
||||
enemyLevel.setShadow(0, 0, null);
|
||||
enemyLevel.setStroke("#424242", 14);
|
||||
enemyLevel.setOrigin(0, 0);
|
||||
|
||||
enemyIconContainer.add(enemyIcon);
|
||||
enemyIconContainer.add(enemyLevel);
|
||||
enemyPartyContainer.add(enemyIconContainer);
|
||||
enemy.destroy();
|
||||
});
|
||||
enemyPartyContainer.setPosition(25, 18);
|
||||
enemyContainer.add(enemyPartyContainer);
|
||||
}
|
||||
this.runResultContainer.add(enemyContainer);
|
||||
}
|
||||
this.gameStatsContainer.add(this.runResultContainer);
|
||||
}
|
||||
|
||||
async parseRunInfo(runData:any) {
|
||||
const modeText = addBBCodeTextObject(this.scene, 7, 0, "", TextStyle.WINDOW, {fontSize : "50px", lineSpacing:3});
|
||||
modeText.setPosition(7, 5);
|
||||
modeText.appendText(i18next.t("runHistory:mode")+": ", false);
|
||||
switch (runData.gameMode) {
|
||||
case GameModes.DAILY:
|
||||
modeText.appendText(`${i18next.t("gameMode:dailyRun")}`, false);
|
||||
break;
|
||||
case GameModes.SPLICED_ENDLESS:
|
||||
modeText.appendText(`${i18next.t("gameMode:endlessSpliced")}`, false);
|
||||
if (runData.waveIndex === this.scene.gameData.gameStats.highestEndlessWave) {
|
||||
modeText.appendText(` [${i18next.t("runHistory:personalBest")}]`, false);
|
||||
modeText.setTint(0xffef5c, 0x47ff69, 0x6b6bff, 0xff6969);
|
||||
}
|
||||
break;
|
||||
case GameModes.CHALLENGE:
|
||||
modeText.appendText(`${i18next.t("gameMode:challenge")}`, false);
|
||||
modeText.appendText(`\t\t${i18next.t("runHistory:challengeRules")}: `);
|
||||
const runChallenges = runData.challenges;
|
||||
const rules = [];
|
||||
for (let i = 0; i < runChallenges.length; i++) {
|
||||
if (runChallenges[i].id === Challenges.SINGLE_GENERATION && runChallenges[i].value !== 0) {
|
||||
rules.push(i18next.t(`runHistory:challengeMonoGen${runChallenges[i].value}` as const));
|
||||
} else if (runChallenges[i].id === Challenges.SINGLE_TYPE && runChallenges[i].value !== 0) {
|
||||
rules.push(i18next.t(`pokemonInfo:Type.${Type[runChallenges[i].value-1]}` as const));
|
||||
}
|
||||
}
|
||||
if (rules) {
|
||||
for (let i = 0; i < rules.length; i++) {
|
||||
if (i > 0) {
|
||||
modeText.appendText(" + ", false);
|
||||
}
|
||||
modeText.appendText(rules[i], false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GameModes.ENDLESS:
|
||||
modeText.appendText(`${i18next.t("gameMode:endless")}`, false);
|
||||
if (runData.waveIndex === this.scene.gameData.gameStats.highestEndlessWave) {
|
||||
modeText.appendText(` [${i18next.t("runHistory:personalBest")}]`, false);
|
||||
modeText.setTint(0xffef5c, 0x47ff69, 0x6b6bff, 0xff6969);
|
||||
}
|
||||
break;
|
||||
case GameModes.CLASSIC:
|
||||
modeText.appendText(`${i18next.t("gameMode:classic")}`, false);
|
||||
break;
|
||||
}
|
||||
|
||||
const runInfoTextContainer = this.scene.add.container(0, 0);
|
||||
const runInfoText = addBBCodeTextObject(this.scene, 7, 0, "", TextStyle.WINDOW, {fontSize : "50px", lineSpacing:3});
|
||||
const runTime = Utils.getPlayTimeString(runData.playTime);
|
||||
runInfoText.appendText(`${i18next.t("runHistory:runLength")}: ${runTime}`, false);
|
||||
runInfoText.appendText(`[color=#e8e8a8]\u20BD${Utils.formatLargeNumber(runData.money, 1000)}[/color]`);
|
||||
const luckText = addBBCodeTextObject(this.scene, 0, 0, "", TextStyle.WINDOW, {fontSize: "55px"});
|
||||
const luckValue = Phaser.Math.Clamp(runData.party.map(p => p.toPokemon(this.scene).getLuck()).reduce((total: integer, value: integer) => total += value, 0), 0, 14);
|
||||
let luckInfo = i18next.t("runHistory:luck")+": "+getLuckString(luckValue);
|
||||
if (luckValue < 14) {
|
||||
luckInfo = "[color=#"+(getLuckTextTint(luckValue)).toString(16)+"]"+luckInfo+"[/color]";
|
||||
} else {
|
||||
luckText.setTint(0xffef5c, 0x47ff69, 0x6b6bff, 0xff6969);
|
||||
}
|
||||
luckText.appendText("[align=right]"+luckInfo+"[/align]", false);
|
||||
runInfoText.setPosition(7, 70);
|
||||
luckText.setPosition(62,77);
|
||||
runInfoTextContainer.add(runInfoText);
|
||||
runInfoTextContainer.add(luckText);
|
||||
|
||||
|
||||
if (runData.modifiers.length) {
|
||||
let visibleModifierIndex = 0;
|
||||
|
||||
const modifierIconsContainer = this.scene.add.container(8, (runData.gameMode === GameModes.CHALLENGE) ? 20 : 15);
|
||||
modifierIconsContainer.setScale(0.45);
|
||||
for (const m of runData.modifiers) {
|
||||
const modifier = m.toModifier(this.scene, this.modifiersModule[m.className]);
|
||||
if (modifier instanceof PokemonHeldItemModifier) {
|
||||
continue;
|
||||
}
|
||||
const item = this.scene.add.sprite(0, 12, "items");
|
||||
item.setFrame(modifier.type.iconImage);
|
||||
|
||||
item.setOrigin(0, 0.5);
|
||||
const rowHeightModifier = Math.floor(visibleModifierIndex/7);
|
||||
item.setPosition(24 * (visibleModifierIndex%7), 20+(35*rowHeightModifier));
|
||||
|
||||
modifierIconsContainer.add(item);
|
||||
const maxStackCount = modifier.getMaxStackCount(this.scene);
|
||||
if (maxStackCount > 1) {
|
||||
const itemStackCount = addTextObject(this.scene, (24*(visibleModifierIndex%7))+22, 22+(35*rowHeightModifier), modifier.stackCount, TextStyle.PARTY, {fontSize:"64px"});
|
||||
if (modifier.stackCount === maxStackCount) {
|
||||
itemStackCount.setColor("#f89890");
|
||||
}
|
||||
modifierIconsContainer.add(itemStackCount);
|
||||
}
|
||||
|
||||
if (++visibleModifierIndex === 20) {
|
||||
const maxItems = addTextObject(this.scene, 45, 90, "+", TextStyle.WINDOW);
|
||||
maxItems.setPositionRelative(modifierIconsContainer, 70, 45);
|
||||
this.runInfoContainer.add(maxItems);
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.runInfoContainer.add(modifierIconsContainer);
|
||||
}
|
||||
|
||||
this.runInfoContainer.add(modeText);
|
||||
this.runInfoContainer.add(runInfoTextContainer);
|
||||
this.gameStatsContainer.add(this.runInfoContainer);
|
||||
}
|
||||
|
||||
parsePartyInfo(party: any): void {
|
||||
|
||||
const currentLanguage = i18next.resolvedLanguage;
|
||||
const windowHeight = ((this.scene.game.canvas.height / 6) - 23)/6;
|
||||
|
||||
party.forEach((p: PokemonData, i: integer) => {
|
||||
const pokemonInfoWindow = new RoundRectangle(this.scene, 0, 14, (this.statsBgWidth*2)+10, windowHeight-2, 3);
|
||||
|
||||
const pokemon = p.toPokemon(this.scene);
|
||||
const pokemonInfoContainer = this.scene.add.container(this.statsBgWidth+5, (windowHeight-0.5)*i);
|
||||
|
||||
const types = pokemon.getTypes();
|
||||
let typeColor = getTypeRgb(types[0]);
|
||||
const type1Color = new Phaser.Display.Color(typeColor[0], typeColor[1], typeColor[2]);
|
||||
|
||||
const bgColor = type1Color.clone().darken(45);
|
||||
pokemonInfoWindow.setFillStyle(bgColor.color);
|
||||
|
||||
const iconContainer = this.scene.add.container(0, 0);
|
||||
const icon = this.scene.addPokemonIcon(pokemon, 0, 0, 0, 0);
|
||||
icon.setScale(0.75);
|
||||
icon.setPosition(-99, 1);
|
||||
typeColor = types[1] ? getTypeRgb(types[1]) : null;
|
||||
const type2Color = typeColor ? new Phaser.Display.Color(typeColor[0], typeColor[1], typeColor[2]) : null;
|
||||
type2Color ? pokemonInfoWindow.setStrokeStyle(1, type2Color.color, 0.95) : pokemonInfoWindow.setStrokeStyle(1, type1Color.color, 0.95);
|
||||
|
||||
this.getUi().bringToTop(icon);
|
||||
|
||||
const pokeInfoTextContainer = this.scene.add.container(-85, 3.5);
|
||||
const textContainerFontSize = "34px";
|
||||
const pSpecies = pokemon.species;
|
||||
const pNature = getNatureName(pokemon.nature);
|
||||
const pName = pokemon.fusionSpecies ? pokemon.name : pSpecies.name;
|
||||
const passiveLabel = (currentLanguage==="ko"||currentLanguage==="zh_CN"||currentLanguage==="zh_TW") ? i18next.t("starterSelectUiHandler:passive") : i18next.t("starterSelectUiHandler:passive").charAt(0);
|
||||
const abilityLabel = (currentLanguage==="ko"||currentLanguage==="zh_CN"||currentLanguage==="zh_TW") ? i18next.t("starterSelectUiHandler:ability") : i18next.t("starterSelectUiHandler:ability").charAt(0);
|
||||
const pPassiveInfo = pokemon.passive ? `${passiveLabel+": "+allAbilities[starterPassiveAbilities[pSpecies.speciesId]].name}` : "";
|
||||
const pAbilityInfo = abilityLabel + ": " + pokemon.getAbility().name;
|
||||
const pokeInfoText = addBBCodeTextObject(this.scene, 0, 0, pName, TextStyle.SUMMARY, {fontSize: textContainerFontSize, lineSpacing:3});
|
||||
pokeInfoText.appendText(`${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatFancyLargeNumber(pokemon.level, 1)} - ${pNature}`);
|
||||
pokeInfoText.appendText(pAbilityInfo);
|
||||
pokeInfoText.appendText(pPassiveInfo);
|
||||
pokeInfoTextContainer.add(pokeInfoText);
|
||||
|
||||
const pokeStatTextContainer = this.scene.add.container(-35, 6);
|
||||
const pStats = [];
|
||||
pokemon.stats.forEach((element) => pStats.push(Utils.formatFancyLargeNumber(element,1)));
|
||||
|
||||
for (let i = 0; i < pStats.length; i++) {
|
||||
const isMult = getNatureStatMultiplier(pokemon.nature, i);
|
||||
pStats[i] = (isMult < 1) ? pStats[i] + "[color=#40c8f8]↓[/color]" : pStats[i];
|
||||
pStats[i] = (isMult > 1) ? pStats[i] + "[color=#f89890]↑[/color]" : pStats[i];
|
||||
}
|
||||
|
||||
const hp = i18next.t("pokemonInfo:Stat.HPshortened")+": "+pStats[0];
|
||||
const atk = i18next.t("pokemonInfo:Stat.ATKshortened")+": "+pStats[1];
|
||||
const def = i18next.t("pokemonInfo:Stat.DEFshortened")+": "+pStats[2];
|
||||
const spatk = i18next.t("pokemonInfo:Stat.SPATKshortened")+": "+pStats[3];
|
||||
const spdef = i18next.t("pokemonInfo:Stat.SPDEFshortened")+": "+pStats[4];
|
||||
const speedLabel = (currentLanguage==="es"||currentLanguage==="pt_BR") ? i18next.t("runHistory:SPDshortened") : i18next.t("pokemonInfo:Stat.SPDshortened");
|
||||
const speed = speedLabel+": "+pStats[5];
|
||||
|
||||
//Column 1: HP Atk Def
|
||||
const pokeStatText1 = addBBCodeTextObject(this.scene, -5, 0, hp, TextStyle.SUMMARY, {fontSize: textContainerFontSize, lineSpacing:3});
|
||||
pokeStatText1.appendText(atk);
|
||||
pokeStatText1.appendText(def);
|
||||
pokeStatTextContainer.add(pokeStatText1);
|
||||
//Column 2: SpAtk SpDef Speed
|
||||
const pokeStatText2 = addBBCodeTextObject(this.scene, 25, 0, spatk, TextStyle.SUMMARY, {fontSize: textContainerFontSize, lineSpacing:3});
|
||||
pokeStatText2.appendText(spdef);
|
||||
pokeStatText2.appendText(speed);
|
||||
pokeStatTextContainer.add(pokeStatText2);
|
||||
|
||||
const marksContainer = this.scene.add.container(0, 0);
|
||||
|
||||
if (pokemon.fusionSpecies) {
|
||||
const splicedIcon = this.scene.add.image(0, 0, "icon_spliced");
|
||||
splicedIcon.setScale(0.35);
|
||||
splicedIcon.setOrigin(0, 0);
|
||||
pokemon.shiny ? splicedIcon.setPositionRelative(pokeInfoTextContainer, 35, 0) : splicedIcon.setPositionRelative(pokeInfoTextContainer, 28, 0);
|
||||
marksContainer.add(splicedIcon);
|
||||
this.getUi().bringToTop(splicedIcon);
|
||||
}
|
||||
|
||||
if (pokemon.isShiny()) {
|
||||
const doubleShiny = pokemon.isFusion() && pokemon.shiny && pokemon.fusionShiny;
|
||||
|
||||
const shinyStar = this.scene.add.image(0, 0, `shiny_star_small${doubleShiny ? "_1" : ""}`);
|
||||
shinyStar.setOrigin(0, 0);
|
||||
shinyStar.setScale(0.65);
|
||||
shinyStar.setPositionRelative(pokeInfoTextContainer, 28, 0);
|
||||
shinyStar.setTint(getVariantTint(!doubleShiny ? pokemon.getVariant() : pokemon.variant));
|
||||
marksContainer.add(shinyStar);
|
||||
this.getUi().bringToTop(shinyStar);
|
||||
|
||||
if (doubleShiny) {
|
||||
const fusionShinyStar = this.scene.add.image(0, 0, "shiny_star_small_2");
|
||||
fusionShinyStar.setOrigin(0, 0);
|
||||
fusionShinyStar.setScale(0.5);
|
||||
fusionShinyStar.setPosition(shinyStar.x, shinyStar.y);
|
||||
fusionShinyStar.setTint(getVariantTint(pokemon.fusionVariant));
|
||||
marksContainer.add(fusionShinyStar);
|
||||
this.getUi().bringToTop(fusionShinyStar);
|
||||
}
|
||||
}
|
||||
|
||||
const pokemonMoveset = pokemon.getMoveset();
|
||||
const movesetContainer = this.scene.add.container(70, -29);
|
||||
const pokemonMoveBgs = [];
|
||||
const pokemonMoveLabels = [];
|
||||
const movePos = [[-6.5,35.5],[37,35.5],[-6.5,43.5],[37,43.5]];
|
||||
for (let m = 0; m < pokemonMoveset.length; m++) {
|
||||
const moveContainer = this.scene.add.container(movePos[m][0], movePos[m][1]);
|
||||
moveContainer.setScale(0.5);
|
||||
|
||||
const moveBg = this.scene.add.nineslice(0, 0, "type_bgs", "unknown", 85, 15, 2, 2, 2, 2);
|
||||
moveBg.setOrigin(1, 0);
|
||||
|
||||
const moveLabel = addTextObject(this.scene, -moveBg.width / 2, 2, "-", TextStyle.PARTY);
|
||||
moveLabel.setOrigin(0.5, 0);
|
||||
moveLabel.setName("text-move-label");
|
||||
|
||||
pokemonMoveBgs.push(moveBg);
|
||||
pokemonMoveLabels.push(moveLabel);
|
||||
|
||||
moveContainer.add(moveBg);
|
||||
moveContainer.add(moveLabel);
|
||||
|
||||
movesetContainer.add(moveContainer);
|
||||
|
||||
const move = m < pokemonMoveset.length ? pokemonMoveset[m].getMove() : null;
|
||||
pokemonMoveBgs[m].setFrame(Type[move ? move.type : Type.UNKNOWN].toString().toLowerCase());
|
||||
pokemonMoveLabels[m].setText(move ? move.name : "-");
|
||||
}
|
||||
|
||||
const heldItemsScale = (this.runInfo.gameMode === GameModes.SPLICED_ENDLESS || this.runInfo.gameMode === GameModes.ENDLESS) ? 0.25 : 0.5;
|
||||
const heldItemsContainer = this.scene.add.container(-82, 6);
|
||||
const heldItemsList = [];
|
||||
if (this.runInfo.modifiers.length) {
|
||||
for (const m of this.runInfo.modifiers) {
|
||||
const modifier = m.toModifier(this.scene, this.modifiersModule[m.className]);
|
||||
if (modifier instanceof PokemonHeldItemModifier && modifier.pokemonId === pokemon.id) {
|
||||
modifier.stackCount = m["stackCount"];
|
||||
heldItemsList.push(modifier);
|
||||
}
|
||||
}
|
||||
if (heldItemsList.length > 0) {
|
||||
(heldItemsList as PokemonHeldItemModifier[]).sort(modifierSortFunc);
|
||||
let row = 0;
|
||||
for (const [index, item] of heldItemsList.entries()) {
|
||||
if ( index > 36 ) {
|
||||
const overflowIcon = addTextObject(this.scene, 182, 4, "+", TextStyle.WINDOW);
|
||||
heldItemsContainer.add(overflowIcon);
|
||||
break;
|
||||
}
|
||||
const itemIcon = item.getIcon(this.scene, true);
|
||||
//itemIcon.setFrame(item.type.iconImage);
|
||||
itemIcon.setScale(heldItemsScale);
|
||||
itemIcon.setPosition((index%19)*10, row*10);
|
||||
heldItemsContainer.add(itemIcon);
|
||||
if (index !== 0 && index%18 === 0) {
|
||||
row++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
heldItemsContainer.setName("heldItems");
|
||||
heldItemsContainer.setVisible(false);
|
||||
|
||||
pokemonInfoContainer.add(pokemonInfoWindow);
|
||||
iconContainer.add(icon);
|
||||
pokemonInfoContainer.add(iconContainer);
|
||||
marksContainer.setName("PkmnMarks");
|
||||
pokemonInfoContainer.add(marksContainer);
|
||||
movesetContainer.setName("PkmnMoves");
|
||||
pokemonInfoContainer.add(movesetContainer);
|
||||
pokeInfoTextContainer.setName("PkmnInfoText");
|
||||
pokemonInfoContainer.add(pokeInfoTextContainer);
|
||||
pokeStatTextContainer.setName("PkmnStatsText");
|
||||
pokemonInfoContainer.add(pokeStatTextContainer);
|
||||
pokemonInfoContainer.add(heldItemsContainer);
|
||||
pokemonInfoContainer.setName("PkmnInfo");
|
||||
this.partyContainer.add(pokemonInfoContainer);
|
||||
pokemon.destroy();
|
||||
});
|
||||
this.gameStatsContainer.add(this.partyContainer);
|
||||
}
|
||||
|
||||
showParty(partyVisible: boolean): void {
|
||||
const allContainers = this.partyContainer.getAll("name", "PkmnInfo");
|
||||
allContainers.forEach((c: Phaser.GameObjects.Container) => {
|
||||
console.log(c.getByName("PkmnMoves"));
|
||||
c.getByName("PkmnMoves").setVisible(partyVisible);
|
||||
c.getByName("PkmnInfoText").setVisible(partyVisible);
|
||||
c.getByName("PkmnStatsText").setVisible(partyVisible);
|
||||
c.getByName("PkmnMarks").setVisible(partyVisible);
|
||||
c.getByName("heldItems").setVisible(!partyVisible);
|
||||
this.partyVisibility = partyVisible;
|
||||
});
|
||||
}
|
||||
|
||||
createHallofFame(): void {
|
||||
this.hallofFameContainer = this.scene.add.container(0, 0);
|
||||
//Thank you Hayuna for the code
|
||||
const hallofFameBg = this.scene.add.image(0, 0, "hall_of_fame");
|
||||
hallofFameBg.setPosition(159, 89);
|
||||
hallofFameBg.setSize(this.scene.game.canvas.width, this.scene.game.canvas.height+10);
|
||||
this.hallofFameContainer.add(hallofFameBg);
|
||||
const hallofFameText = addTextObject(this.scene, 0, 0, i18next.t("runHistory:hallofFameText"), TextStyle.WINDOW);
|
||||
hallofFameText.setPosition(85, 145);
|
||||
this.hallofFameContainer.add(hallofFameText);
|
||||
this.runInfo.party.forEach((p, i) => {
|
||||
const species = p.toPokemon(this.scene);
|
||||
const row = i % 2;
|
||||
const id = species.id;
|
||||
const shiny = species.shiny;
|
||||
const formIndex = species.formIndex;
|
||||
const variant = species.variant;
|
||||
const pokemonSprite: Phaser.GameObjects.Sprite = this.scene.add.sprite(60 + 40 * i, 40 + row * 60, "pkmn__sub");
|
||||
pokemonSprite.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true });
|
||||
this.hallofFameContainer.add(pokemonSprite);
|
||||
const speciesLoaded: Map<Species, boolean> = new Map<Species, boolean>();
|
||||
speciesLoaded.set(id, false);
|
||||
|
||||
const female = species.gender === 1;
|
||||
species.species.loadAssets(this.scene, female, formIndex, shiny, variant, true).then(() => {
|
||||
speciesLoaded.set(id, true);
|
||||
pokemonSprite.play(species.species.getSpriteKey(female, formIndex, shiny, variant));
|
||||
pokemonSprite.setPipelineData("shiny", shiny);
|
||||
pokemonSprite.setPipelineData("variant", variant);
|
||||
pokemonSprite.setPipelineData("spriteKey", species.species.getSpriteKey(female, formIndex, shiny, variant));
|
||||
pokemonSprite.setVisible(true);
|
||||
});
|
||||
species.destroy();
|
||||
});
|
||||
this.hallofFameContainer.setVisible(false);
|
||||
this.gameStatsContainer.add(this.hallofFameContainer);
|
||||
}
|
||||
|
||||
processInput(button: Button): boolean {
|
||||
const ui = this.getUi();
|
||||
|
||||
let success = false;
|
||||
const error = false;
|
||||
|
||||
if (button === Button.CANCEL) {
|
||||
success = true;
|
||||
this.runInfoContainer.removeAll(true);
|
||||
this.runResultContainer.removeAll(true);
|
||||
this.partyContainer.removeAll(true);
|
||||
this.gameStatsContainer.removeAll(true);
|
||||
this.hallofFameContainer.removeAll(true);
|
||||
super.clear();
|
||||
this.gameStatsContainer.setVisible(false);
|
||||
ui.revertMode();
|
||||
} else {
|
||||
switch (button) {
|
||||
case Button.DOWN:
|
||||
if (this.partyVisibility) {
|
||||
this.showParty(false);
|
||||
} else {
|
||||
this.showParty(true);
|
||||
}
|
||||
break;
|
||||
case Button.UP:
|
||||
if (this.victory) {
|
||||
if (!this.hallofFameContainer.visible) {
|
||||
this.hallofFameContainer.setVisible(true);
|
||||
break;
|
||||
} else {
|
||||
this.hallofFameContainer.setVisible(false);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (success) {
|
||||
ui.playSelect();
|
||||
} else if (error) {
|
||||
ui.playError();
|
||||
}
|
||||
return success || error;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue