diff --git a/src/battle-scene.ts b/src/battle-scene.ts index f0aeb68e277..30adf058a0e 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -1330,13 +1330,14 @@ export default class BattleScene extends SceneBase { } this.executeWithSeedOffset(() => { - this.currentBattle = new Battle(this.gameMode, newWaveIndex, newBattleType, newTrainer, newDouble); + this.currentBattle = new Battle(this.gameMode, newWaveIndex, newBattleType, newTrainer, newDouble, this.currentBattle?.playerFaints, this.currentBattle?.enemyFaints); }, 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.resetFaintsCount(); } //this.pushPhase(new TrainerMessageTestPhase(this, TrainerType.RIVAL, TrainerType.RIVAL_2, TrainerType.RIVAL_3, TrainerType.RIVAL_4, TrainerType.RIVAL_5, TrainerType.RIVAL_6)); @@ -1354,6 +1355,8 @@ export default class BattleScene extends SceneBase { this.arena.updatePoolsForTimeOfDay(); } if (resetArenaState) { + this.resetFaintsCount(); + this.arena.resetArenaEffects(); playerField.forEach((pokemon) => pokemon.lapseTag(BattlerTagType.COMMANDED)); @@ -1403,6 +1406,14 @@ export default class BattleScene extends SceneBase { return this.arena; } + /** + * resets player/enemyFaints count on {@linkcode currentBattle} + */ + resetFaintsCount(): void { + this.currentBattle.playerFaints = 0; + this.currentBattle.enemyFaints = 0; + } + updateFieldScale(): Promise { return new Promise(resolve => { const fieldScale = Math.floor(Math.pow(1 / this.getField(true) diff --git a/src/battle.ts b/src/battle.ts index 287a981f83d..836076ef26b 100644 --- a/src/battle.ts +++ b/src/battle.ts @@ -102,9 +102,9 @@ export default class Battle { private battleSeedState: string | null = null; public moneyScattered: number = 0; public lastUsedPokeball: PokeballType | null = null; - /** The number of times a Pokemon on the player's side has fainted this battle */ + /** The number of times a Pokemon on the player's side has fainted this arena encounter */ public playerFaints: number = 0; - /** The number of times a Pokemon on the enemy's side has fainted this battle */ + /** The number of times a Pokemon on the enemy's side has fainted this arena encounter */ public enemyFaints: number = 0; public playerFaintsHistory: FaintLogEntry[] = []; public enemyFaintsHistory: FaintLogEntry[] = []; @@ -115,7 +115,7 @@ export default class Battle { private rngCounter: number = 0; - constructor(gameMode: GameMode, waveIndex: number, battleType: BattleType, trainer?: Trainer, double?: boolean) { + constructor(gameMode: GameMode, waveIndex: number, battleType: BattleType, trainer?: Trainer, double?: boolean, playerFaints?: number, enemyFaints?: number) { this.gameMode = gameMode; this.waveIndex = waveIndex; this.battleType = battleType; @@ -125,6 +125,8 @@ export default class Battle { ? new Array(double ? 2 : 1).fill(null).map(() => this.getLevelForWave()) : trainer?.getPartyLevels(this.waveIndex); this.double = double ?? false; + this.playerFaints = playerFaints ?? 0; + this.enemyFaints = enemyFaints ?? 0; } private initBattleSpec(): void { diff --git a/src/data/ability.ts b/src/data/ability.ts index 00d6c4d8b68..4d1f7ab7641 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -6319,7 +6319,7 @@ export function initAbilities() { new Ability(Abilities.SHARPNESS, 9) .attr(MovePowerBoostAbAttr, (user, target, move) => move.hasFlag(MoveFlags.SLICING_MOVE), 1.5), new Ability(Abilities.SUPREME_OVERLORD, 9) - .attr(VariableMovePowerBoostAbAttr, (user, target, move) => 1 + 0.1 * Math.min(user.isPlayer() ? globalScene.getPlayerParty().filter(pokemon => pokemon.isFainted()).length : globalScene.getEnemyParty().filter(pokemon => pokemon.isFainted()).length, 5)), + .attr(VariableMovePowerBoostAbAttr, (user, target, move) => 1 + 0.1 * Math.min(user.isPlayer() ? globalScene.currentBattle.playerFaints : globalScene.currentBattle.enemyFaints, 5)), new Ability(Abilities.COSTAR, 9) .attr(PostSummonCopyAllyStatsAbAttr), new Ability(Abilities.TOXIC_DEBRIS, 9) diff --git a/src/phases/faint-phase.ts b/src/phases/faint-phase.ts index 23827d18159..8bb0f488193 100644 --- a/src/phases/faint-phase.ts +++ b/src/phases/faint-phase.ts @@ -96,8 +96,7 @@ export class FaintPhase extends PokemonPhase { doFaint(): void { const pokemon = this.getPokemon(); - - // Track total times pokemon have been KO'd for last respects + // Track total times pokemon have been KO'd for last respects/supreme overlord if (pokemon.isPlayer()) { globalScene.currentBattle.playerFaints += 1; globalScene.currentBattle.playerFaintsHistory.push({ pokemon: pokemon, turn: globalScene.currentBattle.turn }); diff --git a/src/test/abilities/supreme_overlord.test.ts b/src/test/abilities/supreme_overlord.test.ts index 03c839877ee..21f89ae6984 100644 --- a/src/test/abilities/supreme_overlord.test.ts +++ b/src/test/abilities/supreme_overlord.test.ts @@ -12,6 +12,9 @@ describe("Abilities - Supreme Overlord", () => { let phaserGame: Phaser.Game; let game: GameManager; + const move = allMoves[Moves.TACKLE]; + const basePower = move.power; + beforeAll(() => { phaserGame = new Phaser.Game({ type: Phaser.HEADLESS, @@ -32,17 +35,14 @@ describe("Abilities - Supreme Overlord", () => { .enemyAbility(Abilities.BALL_FETCH) .ability(Abilities.SUPREME_OVERLORD) .enemyMoveset([ Moves.SPLASH ]) - .moveset([ Moves.TACKLE, Moves.EXPLOSION ]); + .moveset([ Moves.TACKLE, Moves.EXPLOSION, Moves.LUNAR_DANCE ]); + + vi.spyOn(move, "calculateBattlePower"); }); it("should increase Power by 20% if 2 Pokemon are fainted in the party", async() => { await game.startBattle([ Species.BULBASAUR, Species.CHARMANDER, Species.SQUIRTLE ]); - const moveToCheck = allMoves[Moves.TACKLE]; - const basePower = moveToCheck.power; - - vi.spyOn(moveToCheck, "calculateBattlePower"); - game.move.select(Moves.EXPLOSION); await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]); game.doSelectPartyPokemon(1); @@ -57,6 +57,87 @@ describe("Abilities - Supreme Overlord", () => { await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]); await game.phaseInterceptor.to(MoveEffectPhase); - expect(moveToCheck.calculateBattlePower).toHaveReturnedWith(basePower * 1.2); + expect(move.calculateBattlePower).toHaveReturnedWith(basePower * 1.2); + }); + + it("should maintain its power during next battle if it is within the same arena encounter", async () => { + game.override + .enemySpecies(Species.MAGIKARP) + .startingWave(1) + .enemyLevel(1) + .startingLevel(100); + + 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.TACKLE); + await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]); + await game.toNextWave(); + + game.move.select(Moves.TACKLE); + await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]); + await game.phaseInterceptor.to("TurnEndPhase"); + + expect(move.calculateBattlePower).toHaveLastReturnedWith(basePower * 1.1); + }); + + it("should reset playerFaints count if we enter new trainer battle", async () => { + game.override + .enemySpecies(Species.MAGIKARP) + .startingWave(4) + .enemyLevel(1) + .startingLevel(100); + + await game.classicMode.startBattle([ Species.BULBASAUR, Species.CHARMANDER, Species.SQUIRTLE ]); + + game.move.select(Moves.LUNAR_DANCE); + await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]); + game.doSelectPartyPokemon(1); + await game.toNextTurn(); + + game.move.select(Moves.TACKLE); + await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]); + await game.toNextWave(); + + game.move.select(Moves.TACKLE); + await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]); + await game.phaseInterceptor.to("BerryPhase", false); + + expect(move.calculateBattlePower).toHaveLastReturnedWith(basePower); + }); + + it("should reset playerFaints count if we enter new biome", async () => { + game.override + .enemySpecies(Species.MAGIKARP) + .startingWave(10) + .enemyLevel(1) + .startingLevel(100); + + await game.classicMode.startBattle([ Species.BULBASAUR, Species.CHARMANDER, Species.SQUIRTLE ]); + + game.move.select(Moves.LUNAR_DANCE); + await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]); + game.doSelectPartyPokemon(1); + await game.toNextTurn(); + + game.move.select(Moves.TACKLE); + await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]); + await game.toNextWave(); + + game.move.select(Moves.TACKLE); + await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]); + await game.phaseInterceptor.to("BerryPhase", false); + + expect(move.calculateBattlePower).toHaveLastReturnedWith(basePower); }); });