diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index b659923c47d..7d8f8d8dc91 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -211,8 +211,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.generateFusionSpecies(); } } - this.luck = (this.shiny ? this.variant + 1 : 0) + (this.fusionShiny ? this.fusionVariant + 1 : 0); + this.fusionLuck = this.luck; } this.generateName(); diff --git a/src/loading-scene.ts b/src/loading-scene.ts index d45aa83c740..395e4f534c5 100644 --- a/src/loading-scene.ts +++ b/src/loading-scene.ts @@ -29,6 +29,7 @@ export class LoadingScene extends SceneBase { } preload() { + Utils.localPing(); this.load["manifest"] = this.game["manifest"]; if (!isMobile()) { diff --git a/src/utils.ts b/src/utils.ts index 6d965369ca3..68f6e323af1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -263,6 +263,8 @@ export const isLocal = ( // Set the server URL based on whether it's local or not export const serverUrl = isLocal ? `${window.location.hostname}:${window.location.port}` : ""; export const apiUrl = isLocal ? serverUrl : "https://api.pokerogue.net"; +// used to disable api calls when isLocal is true and a server is not found +export let isLocalServerConnected = false; export function setCookie(cName: string, cValue: string): void { const expiration = new Date(); @@ -285,8 +287,22 @@ export function getCookie(cName: string): string { return ""; } +/** + * When locally running the game, "pings" the local server + * with a GET request to verify if a server is running, + * sets isLocalServerConnected based on results + */ +export function localPing() { + if (isLocal) { + apiFetch("game/titlestats") + .then(resolved => isLocalServerConnected = true, + rejected => isLocalServerConnected = false + ); + } +} + export function apiFetch(path: string, authed: boolean = false): Promise<Response> { - return new Promise((resolve, reject) => { + return (isLocal && isLocalServerConnected) || !isLocal ? new Promise((resolve, reject) => { const request = {}; if (authed) { const sId = getCookie(sessionIdKey); @@ -297,11 +313,11 @@ export function apiFetch(path: string, authed: boolean = false): Promise<Respons fetch(`${apiUrl}/${path}`, request) .then(response => resolve(response)) .catch(err => reject(err)); - }); + }) : new Promise(() => {}); } export function apiPost(path: string, data?: any, contentType: string = "application/json", authed: boolean = false): Promise<Response> { - return new Promise((resolve, reject) => { + return (isLocal && isLocalServerConnected) || !isLocal ? new Promise((resolve, reject) => { const headers = { "Accept": contentType, "Content-Type": contentType, @@ -315,7 +331,7 @@ export function apiPost(path: string, data?: any, contentType: string = "applica fetch(`${apiUrl}/${path}`, { method: "POST", headers: headers, body: data }) .then(response => resolve(response)) .catch(err => reject(err)); - }); + }) : new Promise(() => {}); } export class BooleanHolder {