From 1b036d61b3f0698ab13579458b4d1de5b3554113 Mon Sep 17 00:00:00 2001 From: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com> Date: Sun, 9 Feb 2025 20:02:56 -0600 Subject: [PATCH] Reset enemy faint counter per battle --- src/battle-scene.ts | 3 +- src/battle.ts | 3 +- src/test/moves/last_respects.test.ts | 48 ++++++++++++++++++++++++---- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index c7acd49a4f2..b6e9160d2da 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -1337,14 +1337,13 @@ export default class BattleScene extends SceneBase { } this.executeWithSeedOffset(() => { - this.currentBattle = new Battle(this.gameMode, newWaveIndex, newBattleType, newTrainer, newDouble, this.currentBattle?.enemyFaints); + this.currentBattle = new Battle(this.gameMode, newWaveIndex, newBattleType, newTrainer, newDouble); }, newWaveIndex << 3, this.waveSeed); this.currentBattle.incrementTurn(); if (newBattleType === BattleType.MYSTERY_ENCOUNTER) { // Will generate the actual Mystery Encounter during NextEncounterPhase, to ensure it uses proper biome this.currentBattle.mysteryEncounterType = mysteryEncounterType; - this.resetEnemyFaintCount(); this.arena.resetPlayerFaintCount(); } diff --git a/src/battle.ts b/src/battle.ts index dccfd7e71b3..9c70f68f597 100644 --- a/src/battle.ts +++ b/src/battle.ts @@ -117,7 +117,7 @@ export default class Battle { private rngCounter: number = 0; - constructor(gameMode: GameMode, waveIndex: number, battleType: BattleType, trainer?: Trainer, double: boolean = false, enemyFaints: number = 0) { + constructor(gameMode: GameMode, waveIndex: number, battleType: BattleType, trainer?: Trainer, double: boolean = false) { this.gameMode = gameMode; this.waveIndex = waveIndex; this.battleType = battleType; @@ -127,7 +127,6 @@ export default class Battle { ? new Array(double ? 2 : 1).fill(null).map(() => this.getLevelForWave()) : trainer?.getPartyLevels(this.waveIndex); this.double = double; - this.enemyFaints = enemyFaints; } private initBattleSpec(): void { diff --git a/src/test/moves/last_respects.test.ts b/src/test/moves/last_respects.test.ts index 6b83861b66f..71a76e3fa1a 100644 --- a/src/test/moves/last_respects.test.ts +++ b/src/test/moves/last_respects.test.ts @@ -42,7 +42,7 @@ describe("Moves - Last Respects", () => { }); it("should have 150 power if 2 allies faint before using move", async () => { - await game.startBattle([ Species.BULBASAUR, Species.CHARMANDER, Species.SQUIRTLE ]); + await game.classicMode.startBattle([ Species.BULBASAUR, Species.CHARMANDER, Species.SQUIRTLE ]); /** * Bulbasur faints once @@ -67,8 +67,8 @@ describe("Moves - Last Respects", () => { expect(move.calculateBattlePower).toHaveReturnedWith(basePower + (2 * 50)); }); - it("should have 200 power if an ally fainted twice and antoher one once", async () => { - await game.startBattle([ Species.BULBASAUR, Species.CHARMANDER, Species.SQUIRTLE ]); + it("should have 200 power if an ally fainted twice and another one once", async () => { + await game.classicMode.startBattle([ Species.BULBASAUR, Species.CHARMANDER, Species.SQUIRTLE ]); /** * Bulbasur faints once @@ -102,12 +102,13 @@ describe("Moves - Last Respects", () => { expect(move.calculateBattlePower).toHaveReturnedWith(basePower + (3 * 50)); }); - it("should maintain its power during next battle if it is within the same arena encounter", async () => { + it("should maintain its power for the player during the next battle if it is within the same arena encounter", async () => { game.override .enemySpecies(Species.MAGIKARP) .startingWave(1) .enemyLevel(1) - .startingLevel(100); + .startingLevel(100) + .enemyMoveset(Moves.SPLASH); await game.classicMode.startBattle([ Species.BULBASAUR, Species.CHARMANDER, Species.SQUIRTLE ]); @@ -125,14 +126,47 @@ describe("Moves - Last Respects", () => { game.move.select(Moves.LAST_RESPECTS); await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]); await game.toNextWave(); + expect(game.scene.arena.playerFaints).toBe(1); game.move.select(Moves.LAST_RESPECTS); await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]); - await game.phaseInterceptor.to("TurnEndPhase"); - + await game.phaseInterceptor.to("MoveEndPhase"); expect(move.calculateBattlePower).toHaveLastReturnedWith(basePower + (1 * 50)); }); + it("should reset enemyFaints count on progressing to the next wave.", async () => { + game.override + .enemySpecies(Species.MAGIKARP) + .startingWave(1) + .enemyLevel(1) + .startingLevel(100) + .enemyMoveset(Moves.LAST_RESPECTS) + .moveset([ Moves.LUNAR_DANCE, Moves.LAST_RESPECTS, Moves.SPLASH ]); + + await game.classicMode.startBattle([ Species.BULBASAUR, Species.CHARMANDER, Species.SQUIRTLE ]); + + /** + * The first Pokemon faints and another Pokemon in the party is selected. + */ + game.move.select(Moves.LUNAR_DANCE); + await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]); + game.doSelectPartyPokemon(1); + await game.toNextTurn(); + + /** + * Enemy Pokemon faints and new wave is entered. + */ + game.move.select(Moves.LAST_RESPECTS); + await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]); + await game.toNextWave(); + expect(game.scene.currentBattle.enemyFaints).toBe(0); + + game.move.select(Moves.LAST_RESPECTS); + await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]); + await game.phaseInterceptor.to("MoveEndPhase"); + expect(move.calculateBattlePower).toHaveLastReturnedWith(basePower); + }); + it("should reset playerFaints count if we enter new trainer battle", async () => { game.override .enemySpecies(Species.MAGIKARP)