From 40a925698368fc93779bf82dcaeb653788137d95 Mon Sep 17 00:00:00 2001 From: Bertie690 Date: Thu, 7 Aug 2025 23:58:50 -0400 Subject: [PATCH] Fiexd embarassing bug --- src/battle-scene.ts | 4 ---- src/data/helpers/force-switch.ts | 2 +- src/field/pokemon.ts | 4 ++++ src/phases/switch-summon-phase.ts | 23 +++++++++++-------- test/moves/force-switch.test.ts | 7 +++--- .../test-utils/array-utils.ts | 1 - 6 files changed, 22 insertions(+), 19 deletions(-) rename src/utils/array.ts => test/test-utils/array-utils.ts (99%) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 7cec4045893..77eaf68b7f7 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -809,7 +809,6 @@ export class BattleScene extends SceneBase { * Used for switch out logic checks. * @param pokemon - A {@linkcode Pokemon} on the desired side of the field, used to infer the side and trainer slot (as applicable) * @returns An array containing the **INDICES** of all {@linkcode Pokemon} in reserve able to be switched into. - * @overload */ public getBackupPartyMemberIndices(pokemon: Pokemon): number[]; /** @@ -819,7 +818,6 @@ export class BattleScene extends SceneBase { * Used for switch out logic checks. * @param player - Whether to search the player (`true`) or enemy (`false`) party; default `true` * @returns An array containing the **INDICES** of all {@linkcode Pokemon} in reserve able to be switched into. - * @overload */ public getBackupPartyMemberIndices(player: true): number[]; /** @@ -831,10 +829,8 @@ export class BattleScene extends SceneBase { * @param trainerSlot - The {@linkcode TrainerSlot | trainer slot} to check against for enemy trainers; * used to verify ownership in multi battles * @returns An array containing the **INDICES** of all {@linkcode Pokemon} in reserve able to be switched into. - * @overload */ public getBackupPartyMemberIndices(player: false, trainerSlot: TrainerSlot): number[]; - public getBackupPartyMemberIndices(player: boolean | Pokemon, trainerSlot?: number): number[] { // Note: We return the indices instead of the actual Pokemon because `SwitchSummonPhase` and co. take an index instead of a pokemon. // If this is ever changed, this can be replaced with a simpler version involving `filter` and conditional type annotations. diff --git a/src/data/helpers/force-switch.ts b/src/data/helpers/force-switch.ts index bfcc86afd7d..8e90f97d7a3 100644 --- a/src/data/helpers/force-switch.ts +++ b/src/data/helpers/force-switch.ts @@ -183,7 +183,7 @@ export class ForceSwitchOutHelper implements ForceSwitchOutHelperArgs { switchOutTarget.getFieldIndex(), summonIndex, false, - true, + false, ); } diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 66c90919e92..2302641549c 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -510,6 +510,10 @@ export abstract class Pokemon extends Phaser.GameObjects.Container { abstract initBattleInfo(): void; + /** + * Return whether this Pokemon is currently partaking in battle on field. + * @returns Whether this Pokemon is on field. + */ isOnField(): boolean { if (!globalScene) { return false; diff --git a/src/phases/switch-summon-phase.ts b/src/phases/switch-summon-phase.ts index 1a146bb92d8..113ad6faf42 100644 --- a/src/phases/switch-summon-phase.ts +++ b/src/phases/switch-summon-phase.ts @@ -33,11 +33,7 @@ export class SwitchSummonPhase extends SummonPhase { super(fieldIndex, player); this.switchType = switchType; - // -1 = "use trainer switch logic" - this.slotIndex = - slotIndex > -1 - ? slotIndex - : globalScene.currentBattle.trainer!.getNextSummonIndex(this.getTrainerSlotFromFieldIndex()); + this.slotIndex = slotIndex; this.doReturn = doReturn; } @@ -48,12 +44,19 @@ export class SwitchSummonPhase extends SummonPhase { super.start(); } - override preSummon(): void { + preSummon(): void { const switchOutPokemon = this.getPokemon(); - if (!this.player && globalScene.currentBattle.trainer) { - this.showEnemyTrainer(this.getTrainerSlotFromFieldIndex()); - globalScene.pbTrayEnemy.showPbTray(globalScene.getEnemyParty()); + if (!this.player) { + if (this.slotIndex === -1) { + //@ts-expect-error + this.slotIndex = globalScene.currentBattle.trainer?.getNextSummonIndex(this.getTrainerSlotFromFieldIndex()); // TODO: what would be the default trainer-slot fallback? + } + // TODO: This should always be -1 + if (this.slotIndex > -1) { + this.showEnemyTrainer(this.getTrainerSlotFromFieldIndex()); + globalScene.pbTrayEnemy.showPbTray(globalScene.getEnemyParty()); + } } if ( @@ -120,7 +123,7 @@ export class SwitchSummonPhase extends SummonPhase { } switchAndSummon() { - const party = this.player ? this.getParty() : globalScene.getEnemyParty(); + const party = this.getParty(); const switchedInPokemon: Pokemon | undefined = party[this.slotIndex]; this.lastPokemon = this.getPokemon(); diff --git a/test/moves/force-switch.test.ts b/test/moves/force-switch.test.ts index 05445861d0a..93daaf7f283 100644 --- a/test/moves/force-switch.test.ts +++ b/test/moves/force-switch.test.ts @@ -1,6 +1,5 @@ import { SubstituteTag } from "#app/data/battler-tags"; import { getPokemonNameWithAffix } from "#app/messages"; -import { splitArray } from "#app/utils/array"; import { toDmgValue } from "#app/utils/common"; import { AbilityId } from "#enums/ability-id"; import { BattleType } from "#enums/battle-type"; @@ -14,6 +13,7 @@ import { SpeciesId } from "#enums/species-id"; import { Stat } from "#enums/stat"; import { TrainerSlot } from "#enums/trainer-slot"; import { TrainerType } from "#enums/trainer-type"; +import { splitArray } from "#test/test-utils/array-utils"; import { GameManager } from "#test/test-utils/game-manager"; import i18next from "i18next"; import Phaser from "phaser"; @@ -42,7 +42,8 @@ describe("Moves - Switching Moves", () => { .enemySpecies(SpeciesId.WAILORD) .enemyAbility(AbilityId.STURDY) .enemyMoveset(MoveId.SPLASH) - .criticalHits(false); + .criticalHits(false) + .randomTrainer({ trainerType: TrainerType.ACEROLA, alwaysDouble: false }); }); describe("Force Switch Moves", () => { @@ -57,7 +58,7 @@ describe("Moves - Switching Moves", () => { const enemy = game.field.getEnemyPokemon(); game.move.use(move); - await game.toNextTurn(); + await game.toEndOfTurn(); const newEnemy = game.field.getEnemyPokemon(); expect(newEnemy).not.toBe(enemy); diff --git a/src/utils/array.ts b/test/test-utils/array-utils.ts similarity index 99% rename from src/utils/array.ts rename to test/test-utils/array-utils.ts index 3f8595718d7..9a088f6dd7b 100644 --- a/src/utils/array.ts +++ b/test/test-utils/array-utils.ts @@ -24,7 +24,6 @@ export function splitArray( predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: unknown, ): [matches: T[], nonMatches: T[]]; - export function splitArray( arr: T[], predicate: (value: T, index: number, array: T[]) => unknown,