bug fixes, cleanup, and tests

This commit is contained in:
ImperialSympathizer 2024-07-05 18:09:32 -04:00
parent 69f574b908
commit 666ec135ba
9 changed files with 23 additions and 25 deletions

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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();

View File

@ -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", () => {

View File

@ -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;
}

View File

@ -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";