From 612dcc5f27e75cab7eefde72735310ef9bebc920 Mon Sep 17 00:00:00 2001 From: "Amani H." <109637146+xsn34kzx@users.noreply.github.com> Date: Sat, 21 Sep 2024 21:40:47 -0400 Subject: [PATCH] [Balance] Adjust Relevant Abilities to Match Lures (#4231) * [Balance] Adjust Relevant Abilities to Match Lures * Add Relevant Unit Tests --- src/battle-scene.ts | 12 +++-- src/data/ability.ts | 19 ++++++-- src/modifier/modifier.ts | 4 +- src/test/abilities/arena_trap.test.ts | 59 +++++++++++++++++++++++ src/test/abilities/illuminate.test.ts | 59 +++++++++++++++++++++++ src/test/abilities/no_guard.test.ts | 68 +++++++++++++++++++++++++++ 6 files changed, 212 insertions(+), 9 deletions(-) create mode 100644 src/test/abilities/arena_trap.test.ts create mode 100644 src/test/abilities/illuminate.test.ts create mode 100644 src/test/abilities/no_guard.test.ts diff --git a/src/battle-scene.ts b/src/battle-scene.ts index d1fcc00e692..08fdd0531c2 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -1146,6 +1146,13 @@ export default class BattleScene extends SceneBase { } } + getDoubleBattleChance(newWaveIndex: number, playerField: PlayerPokemon[]) { + const doubleChance = new Utils.IntegerHolder(newWaveIndex % 10 === 0 ? 32 : 8); + this.applyModifiers(DoubleBattleChanceBoosterModifier, true, doubleChance); + playerField.forEach(p => applyAbAttrs(DoubleBattleChanceAbAttr, p, null, false, doubleChance)); + return Math.max(doubleChance.value, 1); + } + newBattle(waveIndex?: integer, battleType?: BattleType, trainerData?: TrainerData, double?: boolean, mysteryEncounterType?: MysteryEncounterType): Battle | null { const _startingWave = Overrides.STARTING_WAVE_OVERRIDE || startingWave; const newWaveIndex = waveIndex || ((this.currentBattle?.waveIndex || (_startingWave - 1)) + 1); @@ -1229,10 +1236,7 @@ export default class BattleScene extends SceneBase { if (double === undefined && newWaveIndex > 1) { if (newBattleType === BattleType.WILD && !this.gameMode.isWaveFinal(newWaveIndex)) { - const doubleChance = new Utils.IntegerHolder(newWaveIndex % 10 === 0 ? 32 : 8); - this.applyModifiers(DoubleBattleChanceBoosterModifier, true, doubleChance); - playerField.forEach(p => applyAbAttrs(DoubleBattleChanceAbAttr, p, null, false, doubleChance)); - newDouble = !Utils.randSeedInt(doubleChance.value); + newDouble = !Utils.randSeedInt(this.getDoubleBattleChance(newWaveIndex, playerField)); } else if (newBattleType === BattleType.TRAINER) { newDouble = newTrainer?.variant === TrainerVariant.DOUBLE; } diff --git a/src/data/ability.ts b/src/data/ability.ts index 06eb8725f76..28784c07134 100755 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -165,14 +165,27 @@ export class BlockRecoilDamageAttr extends AbAttr { } } +/** + * Attribute for abilities that increase the chance of a double battle + * occurring. + * @see apply + */ export class DoubleBattleChanceAbAttr extends AbAttr { constructor() { super(false); } - apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): boolean { - const doubleChance = (args[0] as Utils.IntegerHolder); - doubleChance.value = Math.max(doubleChance.value / 2, 1); + /** + * Increases the chance of a double battle occurring + * @param args [0] {@linkcode Utils.NumberHolder} for double battle chance + * @returns true if the ability was applied + */ + apply(_pokemon: Pokemon, _passive: boolean, _simulated: boolean, _cancelled: Utils.BooleanHolder, args: any[]): boolean { + const doubleBattleChance = args[0] as Utils.NumberHolder; + // This is divided because the chance is generated as a number from 0 to doubleBattleChance.value using Utils.randSeedInt + // A double battle will initiate if the generated number is 0 + doubleBattleChance.value = doubleBattleChance.value / 4; + return true; } } diff --git a/src/modifier/modifier.ts b/src/modifier/modifier.ts index 81a3f4f81cc..3a021439f39 100644 --- a/src/modifier/modifier.ts +++ b/src/modifier/modifier.ts @@ -413,7 +413,7 @@ export class DoubleBattleChanceBoosterModifier extends LapsingPersistentModifier } /** - * Modifies the chance of a double battle occurring + * Increases the chance of a double battle occurring * @param args [0] {@linkcode Utils.NumberHolder} for double battle chance * @returns true if the modifier was applied */ @@ -421,7 +421,7 @@ export class DoubleBattleChanceBoosterModifier extends LapsingPersistentModifier const doubleBattleChance = args[0] as Utils.NumberHolder; // This is divided because the chance is generated as a number from 0 to doubleBattleChance.value using Utils.randSeedInt // A double battle will initiate if the generated number is 0 - doubleBattleChance.value = Math.ceil(doubleBattleChance.value / 4); + doubleBattleChance.value = doubleBattleChance.value / 4; return true; } diff --git a/src/test/abilities/arena_trap.test.ts b/src/test/abilities/arena_trap.test.ts new file mode 100644 index 00000000000..6b313fcc8db --- /dev/null +++ b/src/test/abilities/arena_trap.test.ts @@ -0,0 +1,59 @@ +import { Abilities } from "#enums/abilities"; +import { Moves } from "#enums/moves"; +import { Species } from "#enums/species"; +import GameManager from "#test/utils/gameManager"; +import Phaser from "phaser"; +import { afterEach, beforeAll, beforeEach, describe, it, expect } from "vitest"; + +describe("Abilities - Arena Trap", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + const TIMEOUT = 20 * 1000; + + beforeAll(() => { + phaserGame = new Phaser.Game({ + type: Phaser.HEADLESS, + }); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + + beforeEach(() => { + game = new GameManager(phaserGame); + game.override + .moveset(Moves.SPLASH) + .ability(Abilities.ARENA_TRAP) + .enemySpecies(Species.RALTS) + .enemyAbility(Abilities.BALL_FETCH) + .enemyMoveset(Moves.TELEPORT); + }); + + // TODO: Enable test when Issue #935 is addressed + it.todo("should not allow grounded Pokémon to flee", async () => { + game.override.battleType("single"); + + await game.classicMode.startBattle(); + + const enemy = game.scene.getEnemyPokemon(); + + game.move.select(Moves.SPLASH); + + await game.toNextTurn(); + + expect(enemy).toBe(game.scene.getEnemyPokemon()); + }, TIMEOUT); + + it("should guarantee double battle with any one LURE", async () => { + game.override + .startingModifier([ + { name: "LURE" }, + ]) + .startingWave(2); + + await game.classicMode.startBattle(); + + expect(game.scene.getEnemyField().length).toBe(2); + }, TIMEOUT); +}); diff --git a/src/test/abilities/illuminate.test.ts b/src/test/abilities/illuminate.test.ts new file mode 100644 index 00000000000..73e4a49be95 --- /dev/null +++ b/src/test/abilities/illuminate.test.ts @@ -0,0 +1,59 @@ +import { Stat } from "#app/enums/stat"; +import { Abilities } from "#enums/abilities"; +import { Moves } from "#enums/moves"; +import GameManager from "#test/utils/gameManager"; +import Phaser from "phaser"; +import { afterEach, beforeAll, beforeEach, describe, it, expect } from "vitest"; + +describe("Abilities - Illuminate", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + const TIMEOUT = 20 * 1000; + + beforeAll(() => { + phaserGame = new Phaser.Game({ + type: Phaser.HEADLESS, + }); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + + beforeEach(() => { + game = new GameManager(phaserGame); + game.override + .moveset(Moves.SPLASH) + .ability(Abilities.ILLUMINATE) + .enemyAbility(Abilities.BALL_FETCH) + .enemyMoveset(Moves.SAND_ATTACK); + }); + + it("should prevent ACC stat stage from being lowered", async () => { + game.override.battleType("single"); + + await game.classicMode.startBattle(); + + const player = game.scene.getPlayerPokemon()!; + + expect(player.getStatStage(Stat.ACC)).toBe(0); + + game.move.select(Moves.SPLASH); + + await game.toNextTurn(); + + expect(player.getStatStage(Stat.ACC)).toBe(0); + }, TIMEOUT); + + it("should guarantee double battle with any one LURE", async () => { + game.override + .startingModifier([ + { name: "LURE" }, + ]) + .startingWave(2); + + await game.classicMode.startBattle(); + + expect(game.scene.getEnemyField().length).toBe(2); + }, TIMEOUT); +}); diff --git a/src/test/abilities/no_guard.test.ts b/src/test/abilities/no_guard.test.ts new file mode 100644 index 00000000000..b793ede7099 --- /dev/null +++ b/src/test/abilities/no_guard.test.ts @@ -0,0 +1,68 @@ +import { BattlerIndex } from "#app/battle"; +import { MoveEffectPhase } from "#app/phases/move-effect-phase"; +import { MoveEndPhase } from "#app/phases/move-end-phase"; +import { Abilities } from "#enums/abilities"; +import { Moves } from "#enums/moves"; +import { Species } from "#enums/species"; +import GameManager from "#test/utils/gameManager"; +import Phaser from "phaser"; +import { afterEach, beforeAll, beforeEach, describe, it, expect, vi } from "vitest"; + +describe("Abilities - No Guard", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + const TIMEOUT = 20 * 1000; + + beforeAll(() => { + phaserGame = new Phaser.Game({ + type: Phaser.HEADLESS, + }); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + + beforeEach(() => { + game = new GameManager(phaserGame); + game.override + .moveset(Moves.ZAP_CANNON) + .ability(Abilities.NO_GUARD) + .enemyLevel(200) + .enemyAbility(Abilities.BALL_FETCH) + .enemyMoveset(Moves.SPLASH); + }); + + it("should make moves always hit regardless of move accuracy", async () => { + game.override.battleType("single"); + + await game.classicMode.startBattle([ + Species.REGIELEKI + ]); + + game.move.select(Moves.ZAP_CANNON); + + await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]); + + await game.phaseInterceptor.to(MoveEffectPhase, false); + + const moveEffectPhase = game.scene.getCurrentPhase() as MoveEffectPhase; + vi.spyOn(moveEffectPhase, "hitCheck"); + + await game.phaseInterceptor.to(MoveEndPhase); + + expect(moveEffectPhase.hitCheck).toHaveReturnedWith(true); + }, TIMEOUT); + + it("should guarantee double battle with any one LURE", async () => { + game.override + .startingModifier([ + { name: "LURE" }, + ]) + .startingWave(2); + + await game.classicMode.startBattle(); + + expect(game.scene.getEnemyField().length).toBe(2); + }, TIMEOUT); +});