From 3baa1400cc4161b815ebebeaa1740778a070c8cc Mon Sep 17 00:00:00 2001 From: schmidtc1 <62030095+schmidtc1@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:57:38 -0400 Subject: [PATCH] [Bug] Fixes Moody increasing and decreasing the same stat (#3694) * Replaces selectableStats array with the proper decreaseStatArray * Adds docs to MoodyAbAttr * Updates docs, creates unit tests for moody --- src/data/ability.ts | 18 ++++++- src/test/abilities/moody.test.ts | 93 ++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 src/test/abilities/moody.test.ts diff --git a/src/data/ability.ts b/src/data/ability.ts index 8b220b14cf1..35ab55c0159 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -3299,11 +3299,25 @@ export class PostTurnLootAbAttr extends PostTurnAbAttr { } } +/** + * Attribute used for {@linkcode Abilities.MOODY} + */ export class MoodyAbAttr extends PostTurnAbAttr { constructor() { super(true); } - + /** + * Randomly increases one BattleStat by 2 stages and decreases a different BattleStat by 1 stage + * @param {Pokemon} pokemon Pokemon that has this ability + * @param passive N/A + * @param simulated true if applying in a simulated call. + * @param args N/A + * @returns true + * + * Any BattleStats at +6 or -6 are excluded from being increased or decreased, respectively + * If the pokemon already has all BattleStats raised to stage 6, it will only decrease one BattleStat by 1 stage + * If the pokemon already has all BattleStats lowered to stage -6, it will only increase one BattleStat by 2 stages + */ applyPostTurn(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { const selectableStats = [BattleStat.ATK, BattleStat.DEF, BattleStat.SPATK, BattleStat.SPDEF, BattleStat.SPD]; const increaseStatArray = selectableStats.filter(s => pokemon.summonData.battleStats[s] < 6); @@ -3315,7 +3329,7 @@ export class MoodyAbAttr extends PostTurnAbAttr { pokemon.scene.unshiftPhase(new StatChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [increaseStat], 2)); } if (!simulated && decreaseStatArray.length > 0) { - const decreaseStat = selectableStats[Utils.randInt(selectableStats.length)]; + const decreaseStat = decreaseStatArray[Utils.randInt(decreaseStatArray.length)]; pokemon.scene.unshiftPhase(new StatChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [decreaseStat], -1)); } return true; diff --git a/src/test/abilities/moody.test.ts b/src/test/abilities/moody.test.ts new file mode 100644 index 00000000000..9e936e8100a --- /dev/null +++ b/src/test/abilities/moody.test.ts @@ -0,0 +1,93 @@ +import { BattleStat } from "#app/data/battle-stat"; +import { Abilities } from "#enums/abilities"; +import { Moves } from "#enums/moves"; +import { Species } from "#enums/species"; +import GameManager from "#test/utils/gameManager"; +import { SPLASH_ONLY } from "#test/utils/testUtils"; +import Phaser from "phaser"; +import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; + +describe("Abilities - Moody", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + + const battleStatsArray = [BattleStat.ATK, BattleStat.DEF, BattleStat.SPATK, BattleStat.SPDEF, BattleStat.SPD]; + + beforeAll(() => { + phaserGame = new Phaser.Game({ + type: Phaser.HEADLESS, + }); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + + beforeEach(() => { + game = new GameManager(phaserGame); + + game.override + .battleType("single") + .enemySpecies(Species.RATTATA) + .enemyAbility(Abilities.BALL_FETCH) + .enemyPassiveAbility(Abilities.HYDRATION) + .ability(Abilities.MOODY) + .enemyMoveset(SPLASH_ONLY) + .moveset(SPLASH_ONLY); + }); + + it( + "should increase one BattleStat by 2 stages and decrease a different BattleStat by 1 stage", + async () => { + await game.startBattle(); + + const playerPokemon = game.scene.getPlayerPokemon()!; + game.move.select(Moves.SPLASH); + await game.toNextTurn(); + + // Find the increased and decreased stats, make sure they are different. + const statChanges = playerPokemon.summonData.battleStats; + const changedStats = battleStatsArray.filter(bs => statChanges[bs] === 2 || statChanges[bs] === -1); + + expect(changedStats).toBeTruthy(); + expect(changedStats.length).toBe(2); + expect(changedStats[0] !== changedStats[1]).toBeTruthy(); + }); + + it( + "should only increase one BattleStat by 2 stages if all BattleStats are at -6", + async () => { + await game.startBattle(); + + const playerPokemon = game.scene.getPlayerPokemon()!; + // Set all BattleStats to -6 + battleStatsArray.forEach(bs => playerPokemon.summonData.battleStats[bs] = -6); + + game.move.select(Moves.SPLASH); + await game.toNextTurn(); + + // Should increase one BattleStat by 2 (from -6, meaning it will be -4) + const increasedStat = battleStatsArray.filter(bs => playerPokemon.summonData.battleStats[bs] === -4); + + expect(increasedStat).toBeTruthy(); + expect(increasedStat.length).toBe(1); + }); + + it( + "should only decrease one BattleStat by 1 stage if all BattleStats are at 6", + async () => { + await game.startBattle(); + + const playerPokemon = game.scene.getPlayerPokemon()!; + // Set all BattleStats to 6 + battleStatsArray.forEach(bs => playerPokemon.summonData.battleStats[bs] = 6); + + game.move.select(Moves.SPLASH); + await game.toNextTurn(); + + // Should decrease one BattleStat by 1 (from 6, meaning it will be 5) + const decreasedStat = battleStatsArray.filter(bs => playerPokemon.summonData.battleStats[bs] === 5); + expect(decreasedStat).toBeTruthy(); + expect(decreasedStat.length).toBe(1); + }); +});