[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
This commit is contained in:
schmidtc1 2024-08-22 16:57:38 -04:00 committed by GitHub
parent 4455a0e4eb
commit 3baa1400cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 109 additions and 2 deletions

View File

@ -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;

View File

@ -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);
});
});