11import { getGameMode } from "#app/game-mode" ;
22import { Status } from "#data/status-effect" ;
33import { AbilityId } from "#enums/ability-id" ;
4+ import { BattleType } from "#enums/battle-type" ;
45import { GameModes } from "#enums/game-modes" ;
56import { MoveId } from "#enums/move-id" ;
67import { SpeciesId } from "#enums/species-id" ;
78import { StatusEffect } from "#enums/status-effect" ;
9+ import { TrainerType } from "#enums/trainer-type" ;
10+ import { TrainerVariant } from "#enums/trainer-variant" ;
811import { GameManager } from "#test/framework/game-manager" ;
912import Phaser from "phaser" ;
1013import { beforeAll , beforeEach , describe , expect , it , vi } from "vitest" ;
@@ -23,16 +26,20 @@ describe("Double Battles", () => {
2326
2427 beforeEach ( ( ) => {
2528 game = new GameManager ( phaserGame ) ;
29+ game . override //
30+ . enemyAbility ( AbilityId . BALL_FETCH )
31+ . enemyMoveset ( MoveId . SPLASH )
32+ . ability ( AbilityId . BALL_FETCH ) ;
2633 } ) ;
2734
2835 // double-battle player's pokemon both fainted in same round, then revive one, and next double battle summons two player's pokemon successfully.
2936 // (There were bugs that either only summon one when can summon two, player stuck in switchPhase etc)
3037 it ( "3v2 edge case: player summons 2 pokemon on the next battle after being fainted and revived" , async ( ) => {
31- game . override . battleStyle ( "double" ) . enemyMoveset ( MoveId . SPLASH ) . moveset ( MoveId . SPLASH ) ;
38+ game . override . battleStyle ( "double" ) ;
3239 await game . classicMode . startBattle ( SpeciesId . BULBASAUR , SpeciesId . CHARIZARD , SpeciesId . SQUIRTLE ) ;
3340
34- game . move . select ( MoveId . SPLASH ) ;
35- game . move . select ( MoveId . SPLASH , 1 ) ;
41+ game . move . use ( MoveId . SPLASH ) ;
42+ game . move . use ( MoveId . SPLASH , 1 ) ;
3643
3744 for ( const pokemon of game . scene . getPlayerField ( ) ) {
3845 pokemon . hp = 0 ;
@@ -61,20 +68,14 @@ describe("Double Battles", () => {
6168 return rngSweepProgress * ( max - min ) + min ;
6269 } ) ;
6370
64- game . override
65- . enemyMoveset ( MoveId . SPLASH )
66- . moveset ( MoveId . SPLASH )
67- . enemyAbility ( AbilityId . BALL_FETCH )
68- . ability ( AbilityId . BALL_FETCH ) ;
69-
7071 // Play through endless, waves 1 to 9, counting number of double battles from waves 2 to 9
7172 await game . classicMode . startBattle ( SpeciesId . BULBASAUR ) ;
7273 game . scene . gameMode = getGameMode ( GameModes . ENDLESS ) ;
7374
7475 for ( let i = 0 ; i < DOUBLE_CHANCE ; i ++ ) {
7576 rngSweepProgress = ( i + 0.5 ) / DOUBLE_CHANCE ;
7677
77- game . move . select ( MoveId . SPLASH ) ;
78+ game . move . use ( MoveId . SPLASH ) ;
7879 await game . doKillOpponents ( ) ;
7980 await game . toNextWave ( ) ;
8081
@@ -88,4 +89,21 @@ describe("Double Battles", () => {
8889 expect ( doubleCount ) . toBe ( 1 ) ;
8990 expect ( singleCount ) . toBe ( DOUBLE_CHANCE - 1 ) ;
9091 } ) ;
92+
93+ it ( "won't queue multiple `BattleEndPhase`s/etc if the last 2 enemy Pokemon are defeated simultaneously in a trainer battle" , async ( ) => {
94+ game . override //
95+ . battleType ( BattleType . TRAINER )
96+ . randomTrainer ( { trainerType : TrainerType . YOUNGSTER , trainerVariant : TrainerVariant . DOUBLE } )
97+ . startingLevel ( 200 ) ;
98+
99+ await game . classicMode . startBattle ( SpeciesId . FEEBAS ) ;
100+
101+ expect ( game . field . getEnemyParty ( ) ) . toHaveLength ( 2 ) ;
102+ expect ( game . scene . getEnemyField ( ) ) . toHaveLength ( 2 ) ;
103+
104+ game . move . use ( MoveId . SURF ) ;
105+ await game . toEndOfTurn ( false ) ;
106+
107+ expect ( game . scene . phaseManager [ "phaseQueue" ] . findAll ( "BattleEndPhase" ) ) . toHaveLength ( 1 ) ;
108+ } ) ;
91109} ) ;
0 commit comments