diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 723bf0ef4ab..609a3f9153d 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -1098,7 +1098,7 @@ export default class BattleScene extends SceneBase { // Check for mystery encounter // Can only occur in place of a standard wild battle, waves 10-180 - if (this.gameMode.hasMysteryEncounters && newBattleType === BattleType.WILD && !this.gameMode.isBoss(newWaveIndex) && !(this.gameMode.isClassic && (newWaveIndex > 180 || newWaveIndex < 10))) { + if (this.gameMode.hasMysteryEncounters && newBattleType === BattleType.WILD && !this.gameMode.isBoss(newWaveIndex) && newWaveIndex < 180 && newWaveIndex > 10) { const roll = Utils.randSeedInt(256); // Base spawn weight is 3/256, and increases by 1/256 for each missed attempt at spawning an encounter on a valid floor @@ -1111,7 +1111,7 @@ export default class BattleScene extends SceneBase { const currentRunDiffFromAvg = expectedEncountersByFloor - (this.mysteryEncounterFlags?.encounteredEvents?.length || 0); const favoredEncounterRate = sessionEncounterRate + currentRunDiffFromAvg * 5; - const successRate = Utils.isNullOrUndefined(Overrides.MYSTERY_ENCOUNTER_RATE_OVERRIDE) ? favoredEncounterRate : Overrides.MYSTERY_ENCOUNTER_RATE_OVERRIDE; + const successRate = isNullOrUndefined(Overrides.MYSTERY_ENCOUNTER_RATE_OVERRIDE) ? favoredEncounterRate : Overrides.MYSTERY_ENCOUNTER_RATE_OVERRIDE; if (roll < successRate) { newBattleType = BattleType.MYSTERY_ENCOUNTER; @@ -2639,7 +2639,7 @@ export default class BattleScene extends SceneBase { getMysteryEncounter(override: MysteryEncounter): MysteryEncounter { // Loading override or session encounter let encounter: MysteryEncounter; - if (!Utils.isNullOrUndefined(Overrides.MYSTERY_ENCOUNTER_OVERRIDE) && allMysteryEncounters.hasOwnProperty(Overrides.MYSTERY_ENCOUNTER_OVERRIDE)) { + if (!isNullOrUndefined(Overrides.MYSTERY_ENCOUNTER_OVERRIDE) && allMysteryEncounters.hasOwnProperty(Overrides.MYSTERY_ENCOUNTER_OVERRIDE)) { encounter = allMysteryEncounters[Overrides.MYSTERY_ENCOUNTER_OVERRIDE]; } else { encounter = override?.encounterType >= 0 ? allMysteryEncounters[override?.encounterType] : null; @@ -2685,7 +2685,7 @@ export default class BattleScene extends SceneBase { const rareThreshold = totalWeight - tierWeights[0] - tierWeights[1] - tierWeights[2]; let tier = tierValue > commonThreshold ? MysteryEncounterTier.COMMON : tierValue > uncommonThreshold ? MysteryEncounterTier.UNCOMMON : tierValue > rareThreshold ? MysteryEncounterTier.RARE : MysteryEncounterTier.SUPER_RARE; - if (!Utils.isNullOrUndefined(Overrides.MYSTERY_ENCOUNTER_TIER_OVERRIDE)) { + if (!isNullOrUndefined(Overrides.MYSTERY_ENCOUNTER_TIER_OVERRIDE)) { tier = Overrides.MYSTERY_ENCOUNTER_TIER_OVERRIDE; } diff --git a/src/data/mystery-encounter-flags.ts b/src/data/mystery-encounter-flags.ts index 339a171ccb9..8e7bce7a291 100644 --- a/src/data/mystery-encounter-flags.ts +++ b/src/data/mystery-encounter-flags.ts @@ -1,7 +1,7 @@ -import * as Utils from "../utils"; import {MysteryEncounterTier} from "#app/data/mystery-encounter"; import {MysteryEncounterType} from "#enums/mystery-encounter-type"; import {BASE_MYSTYERY_ENCOUNTER_WEIGHT} from "#app/data/mystery-encounters/mystery-encounters"; +import {isNullOrUndefined} from "../utils"; export class MysteryEncounterFlags { encounteredEvents: [MysteryEncounterType, MysteryEncounterTier][] = []; @@ -9,7 +9,7 @@ export class MysteryEncounterFlags { nextEncounterQueue: [MysteryEncounterType, integer][] = []; constructor(flags: MysteryEncounterFlags) { - if (!Utils.isNullOrUndefined(flags)) { + if (!isNullOrUndefined(flags)) { Object.assign(this, flags); } } diff --git a/src/data/mystery-encounter.ts b/src/data/mystery-encounter.ts index 74364013046..c85c44a3973 100644 --- a/src/data/mystery-encounter.ts +++ b/src/data/mystery-encounter.ts @@ -122,7 +122,7 @@ export default interface MysteryEncounter { */ export default class MysteryEncounter implements MysteryEncounter { constructor(encounter: MysteryEncounter) { - if (!Utils.isNullOrUndefined(encounter)) { + if (!isNullOrUndefined(encounter)) { Object.assign(this, encounter); } this.encounterTier = this.encounterTier ? this.encounterTier : MysteryEncounterTier.COMMON; diff --git a/src/data/mystery-encounters/mystery-encounter-utils.ts b/src/data/mystery-encounters/mystery-encounter-utils.ts index 74d8f0423d5..9cdb6607752 100644 --- a/src/data/mystery-encounters/mystery-encounter-utils.ts +++ b/src/data/mystery-encounters/mystery-encounter-utils.ts @@ -186,21 +186,19 @@ export function getRandomSpeciesByStarterTier(starterTiers: number | [number, nu let min = starterTiers instanceof Array ? starterTiers[0] : starterTiers; let max = starterTiers instanceof Array ? starterTiers[1] : starterTiers; - let filteredSpecies = Object.entries(speciesStarters) - .map(s => parseInt(s[0])) - .filter(s => getPokemonSpecies(s) && !excludedSpecies.includes(s)); + let filteredSpecies: [PokemonSpecies, number][] = Object.keys(speciesStarters) + .map(s => [parseInt(s) as Species, speciesStarters[s] as number]) + .filter(s => getPokemonSpecies(s[0]) && !excludedSpecies.includes(s[0])) + .map(s => [getPokemonSpecies(s[0]), s[1]]); if (!isNullOrUndefined(types) && types.length > 0) { - filteredSpecies = filteredSpecies.filter(s => { - const species = getPokemonSpecies(s); - return types.includes(species.type1) || types.includes(species.type2); - }); + filteredSpecies = filteredSpecies.filter(s => types.includes(s[0].type1) || types.includes(s[0].type2)); } // If no filtered mons exist at specified starter tiers, will expand starter search range until there are // Starts by decrementing starter tier min until it is 0, then increments tier max up to 10 - let tryFilterStarterTiers = filteredSpecies.filter(s => s[1] >= min && s[1] <= max); - while (tryFilterStarterTiers.length === 0 || !(min === 0 && max === 10)) { + let tryFilterStarterTiers: [PokemonSpecies, number][] = filteredSpecies.filter(s => (s[1] >= min && s[1] <= max)); + while (tryFilterStarterTiers.length === 0 && (min !== 0 && max !== 10)) { if (min > 0) { min--; } else { @@ -212,7 +210,7 @@ export function getRandomSpeciesByStarterTier(starterTiers: number | [number, nu if (tryFilterStarterTiers.length > 0) { const index = Utils.randSeedInt(tryFilterStarterTiers.length); - return Phaser.Math.RND.shuffle(tryFilterStarterTiers)[index]; + return Phaser.Math.RND.shuffle(tryFilterStarterTiers)[index][0].speciesId; } return Species.BULBASAUR; @@ -427,7 +425,7 @@ export function setCustomEncounterRewards(scene: BattleScene, customShopRewards? scene.unshiftPhase(new ModifierRewardPhase(scene, reward)); }); } else { - while (!Utils.isNullOrUndefined(scene.findPhase(p => p instanceof ModifierRewardPhase))) { + while (!isNullOrUndefined(scene.findPhase(p => p instanceof ModifierRewardPhase))) { scene.tryRemovePhase(p => p instanceof ModifierRewardPhase); } } @@ -474,7 +472,6 @@ export function selectPokemonForOption(scene: BattleScene, onPokemonSelected: (p }).concat({ label: i18next.t("menu:cancel"), handler: () => { - scene.ui.clearText(); scene.ui.setMode(Mode.MYSTERY_ENCOUNTER); resolve(false); return true; diff --git a/src/overrides.ts b/src/overrides.ts index 22a341f6d15..6634ca32788 100644 --- a/src/overrides.ts +++ b/src/overrides.ts @@ -118,9 +118,9 @@ export const EGG_GACHA_PULL_COUNT_OVERRIDE: number = 0; */ // 1 to 256, set to null to ignore -export const MYSTERY_ENCOUNTER_RATE_OVERRIDE: number = 256; +export const MYSTERY_ENCOUNTER_RATE_OVERRIDE: number = null; export const MYSTERY_ENCOUNTER_TIER_OVERRIDE: MysteryEncounterTier = null; -export const MYSTERY_ENCOUNTER_OVERRIDE: MysteryEncounterType = MysteryEncounterType.FIGHT_OR_FLIGHT; +export const MYSTERY_ENCOUNTER_OVERRIDE: MysteryEncounterType = null; /** * MODIFIER / ITEM OVERRIDES diff --git a/src/phases/mystery-encounter-phase.ts b/src/phases/mystery-encounter-phase.ts index 4e8fbd4c127..2700ec32ae1 100644 --- a/src/phases/mystery-encounter-phase.ts +++ b/src/phases/mystery-encounter-phase.ts @@ -35,7 +35,6 @@ export class MysteryEncounterPhase extends Phase { super.start(); // Clears out queued phases that are part of standard battle - this.scene.ui.clearText(); this.scene.clearPhaseQueue(); this.scene.clearPhaseQueueSplice(); diff --git a/src/test/ui/transfer-item.test.ts b/src/test/ui/transfer-item.test.ts index 336e5bccd26..90a1eb242a1 100644 --- a/src/test/ui/transfer-item.test.ts +++ b/src/test/ui/transfer-item.test.ts @@ -5,7 +5,6 @@ import { Button } from "#app/enums/buttons"; import * as overrides from "#app/overrides"; import { BattleEndPhase, - SelectModifierPhase } from "#app/phases"; import GameManager from "#app/test/utils/gameManager"; import ModifierSelectUiHandler from "#app/ui/modifier-select-ui-handler"; @@ -15,6 +14,7 @@ import Phaser from "phaser"; import BBCodeText from "phaser3-rex-plugins/plugins/bbcodetext"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import { getMovePosition } from "../utils/gameManagerUtils"; +import {SelectModifierPhase} from "#app/phases/select-modifier-phase"; describe("UI - Transfer Items", () => { diff --git a/src/ui/mystery-encounter-ui-handler.ts b/src/ui/mystery-encounter-ui-handler.ts index 426bc7d82c0..232d916be57 100644 --- a/src/ui/mystery-encounter-ui-handler.ts +++ b/src/ui/mystery-encounter-ui-handler.ts @@ -10,6 +10,7 @@ import { PartyUiMode } from "./party-ui-handler"; import MysteryEncounterOption from "../data/mystery-encounter-option"; import * as Utils from "../utils"; import { getPokeballAtlasKey } from "../data/pokeball"; +import {isNullOrUndefined} from "../utils"; export default class MysteryEncounterUiHandler extends UiHandler { private cursorContainer: Phaser.GameObjects.Container; @@ -294,6 +295,7 @@ export default class MysteryEncounterUiHandler extends UiHandler { } displayEncounterOptions(slideInDescription: boolean = true): void { + this.getUi().clearText(); const mysteryEncounter = this.scene.currentBattle.mysteryEncounter; this.filteredEncounterOptions = mysteryEncounter.options; this.optionsMeetsReqs = []; @@ -405,7 +407,7 @@ export default class MysteryEncounterUiHandler extends UiHandler { } this.tooltipContainer.setVisible(true); - if (Utils.isNullOrUndefined(cursor) || cursor > this.optionsContainer.length - 2) { + if (isNullOrUndefined(cursor) || cursor > this.optionsContainer.length - 2) { // Ignore hovers on view party button return; } diff --git a/src/ui/party-ui-handler.ts b/src/ui/party-ui-handler.ts index 194a4461cd2..467d35bdb2c 100644 --- a/src/ui/party-ui-handler.ts +++ b/src/ui/party-ui-handler.ts @@ -1,4 +1,4 @@ -import { CommandPhase, SelectModifierPhase } from "../phases"; +import { CommandPhase } from "../phases"; import BattleScene from "../battle-scene"; import { PlayerPokemon, PokemonMove } from "../field/pokemon"; import { addBBCodeTextObject, addTextObject, getTextColor, TextStyle } from "./text";