[Bug] Fix Guard Swap and Power Swap swapping all stats (#4213)

* [Bug] Fix `SwapStatStagesAttr` Oversight

* Remove SPLASH_ONLY Leftover
This commit is contained in:
Amani H. 2024-09-13 12:31:25 -04:00 committed by GitHub
parent dd61950cb1
commit 1cf075adc9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 112 additions and 35 deletions

View File

@ -2836,7 +2836,7 @@ export class SwapStatStagesAttr extends MoveEffectAttr {
*/
apply(user: Pokemon, target: Pokemon, move: Move, args: any []): boolean {
if (super.apply(user, target, move, args)) {
for (const s of BATTLE_STATS) {
for (const s of this.stats) {
const temp = user.getStatStage(s);
user.setStatStage(s, target.getStatStage(s));
target.setStatStage(s, temp);

View File

@ -1,16 +1,17 @@
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import Phaser from "phaser";
import GameManager from "#app/test/utils/gameManager";
import { Species } from "#enums/species";
import { TurnEndPhase } from "#app/phases/turn-end-phase";
import { Moves } from "#enums/moves";
import { Stat } from "#enums/stat";
import { Stat, BATTLE_STATS } from "#enums/stat";
import { Abilities } from "#enums/abilities";
import { MoveEndPhase } from "#app/phases/move-end-phase";
describe("Moves - Guard Swap", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
const TIMEOUT = 20 * 1000;
beforeAll(() => {
phaserGame = new Phaser.Game({
@ -27,37 +28,42 @@ describe("Moves - Guard Swap", () => {
game.override
.battleType("single")
.enemyAbility(Abilities.BALL_FETCH)
.enemyMoveset([Moves.SHELL_SMASH])
.enemySpecies(Species.MEW)
.enemyMoveset(Moves.SPLASH)
.enemySpecies(Species.INDEEDEE)
.enemyLevel(200)
.moveset([ Moves.GUARD_SWAP ])
.ability(Abilities.NONE);
});
it("should swap the user's DEF AND SPDEF stat stages with the target's", async () => {
await game.startBattle([
it("should swap the user's DEF and SPDEF stat stages with the target's", async () => {
await game.classicMode.startBattle([
Species.INDEEDEE
]);
// Should start with no stat stages
const player = game.scene.getPlayerPokemon()!;
// After Shell Smash, should have +2 in ATK and SPATK, -1 in DEF and SPDEF
const enemy = game.scene.getEnemyPokemon()!;
vi.spyOn(enemy.summonData, "statStages", "get").mockReturnValue(new Array(BATTLE_STATS.length).fill(1));
game.move.select(Moves.GUARD_SWAP);
await game.phaseInterceptor.to(MoveEndPhase);
expect(player.getStatStage(Stat.DEF)).toBe(0);
expect(player.getStatStage(Stat.SPDEF)).toBe(0);
expect(enemy.getStatStage(Stat.DEF)).toBe(-1);
expect(enemy.getStatStage(Stat.SPDEF)).toBe(-1);
for (const s of BATTLE_STATS) {
expect(player.getStatStage(s)).toBe(0);
expect(enemy.getStatStage(s)).toBe(1);
}
await game.phaseInterceptor.to(TurnEndPhase);
expect(player.getStatStage(Stat.DEF)).toBe(-1);
expect(player.getStatStage(Stat.SPDEF)).toBe(-1);
expect(enemy.getStatStage(Stat.DEF)).toBe(0);
expect(enemy.getStatStage(Stat.SPDEF)).toBe(0);
}, 20000);
for (const s of BATTLE_STATS) {
if (s === Stat.DEF || s === Stat.SPDEF) {
expect(player.getStatStage(s)).toBe(1);
expect(enemy.getStatStage(s)).toBe(0);
} else {
expect(player.getStatStage(s)).toBe(0);
expect(enemy.getStatStage(s)).toBe(1);
}
}
}, TIMEOUT);
});

View File

@ -0,0 +1,64 @@
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import Phaser from "phaser";
import GameManager from "#app/test/utils/gameManager";
import { Species } from "#enums/species";
import { TurnEndPhase } from "#app/phases/turn-end-phase";
import { Moves } from "#enums/moves";
import { BATTLE_STATS } from "#enums/stat";
import { Abilities } from "#enums/abilities";
import { MoveEndPhase } from "#app/phases/move-end-phase";
describe("Moves - Heart Swap", () => {
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
.battleType("single")
.enemyAbility(Abilities.BALL_FETCH)
.enemyMoveset(Moves.SPLASH)
.enemySpecies(Species.INDEEDEE)
.enemyLevel(200)
.moveset([ Moves.HEART_SWAP ])
.ability(Abilities.NONE);
});
it("should swap all of the user's stat stages with the target's", async () => {
await game.classicMode.startBattle([
Species.MANAPHY
]);
const player = game.scene.getPlayerPokemon()!;
const enemy = game.scene.getEnemyPokemon()!;
vi.spyOn(enemy.summonData, "statStages", "get").mockReturnValue(new Array(BATTLE_STATS.length).fill(1));
game.move.select(Moves.HEART_SWAP);
await game.phaseInterceptor.to(MoveEndPhase);
for (const s of BATTLE_STATS) {
expect(player.getStatStage(s)).toBe(0);
expect(enemy.getStatStage(s)).toBe(1);
}
await game.phaseInterceptor.to(TurnEndPhase);
for (const s of BATTLE_STATS) {
expect(enemy.getStatStage(s)).toBe(0);
expect(player.getStatStage(s)).toBe(1);
}
}, TIMEOUT);
});

View File

@ -1,16 +1,17 @@
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import Phaser from "phaser";
import GameManager from "#app/test/utils/gameManager";
import { Species } from "#enums/species";
import { TurnEndPhase } from "#app/phases/turn-end-phase";
import { Moves } from "#enums/moves";
import { Stat } from "#enums/stat";
import { Stat, BATTLE_STATS } from "#enums/stat";
import { Abilities } from "#enums/abilities";
import { MoveEndPhase } from "#app/phases/move-end-phase";
describe("Moves - Power Swap", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
const TIMEOUT = 20 * 1000;
beforeAll(() => {
phaserGame = new Phaser.Game({
@ -27,36 +28,42 @@ describe("Moves - Power Swap", () => {
game.override
.battleType("single")
.enemyAbility(Abilities.BALL_FETCH)
.enemyMoveset([Moves.SHELL_SMASH])
.enemySpecies(Species.MEW)
.enemyMoveset(Moves.SPLASH)
.enemySpecies(Species.INDEEDEE)
.enemyLevel(200)
.moveset([ Moves.POWER_SWAP ])
.ability(Abilities.NONE);
});
it("should swap the user's ATK AND SPATK stat stages with the target's", async () => {
await game.startBattle([
it("should swap the user's ATK and SPATK stat stages with the target's", async () => {
await game.classicMode.startBattle([
Species.INDEEDEE
]);
// Should start with no stat stages
const player = game.scene.getPlayerPokemon()!;
// After Shell Smash, should have +2 in ATK and SPATK, -1 in DEF and SPDEF
const enemy = game.scene.getEnemyPokemon()!;
vi.spyOn(enemy.summonData, "statStages", "get").mockReturnValue(new Array(BATTLE_STATS.length).fill(1));
game.move.select(Moves.POWER_SWAP);
await game.phaseInterceptor.to(MoveEndPhase);
expect(player.getStatStage(Stat.ATK)).toBe(0);
expect(player.getStatStage(Stat.SPATK)).toBe(0);
expect(enemy.getStatStage(Stat.ATK)).toBe(2);
expect(enemy.getStatStage(Stat.SPATK)).toBe(2);
for (const s of BATTLE_STATS) {
expect(player.getStatStage(s)).toBe(0);
expect(enemy.getStatStage(s)).toBe(1);
}
await game.phaseInterceptor.to(TurnEndPhase);
expect(player.getStatStage(Stat.ATK)).toBe(2);
expect(player.getStatStage(Stat.SPATK)).toBe(2);
expect(enemy.getStatStage(Stat.ATK)).toBe(0);
expect(enemy.getStatStage(Stat.SPATK)).toBe(0);
}, 20000);
for (const s of BATTLE_STATS) {
if (s === Stat.ATK || s === Stat.SPATK) {
expect(player.getStatStage(s)).toBe(1);
expect(enemy.getStatStage(s)).toBe(0);
} else {
expect(player.getStatStage(s)).toBe(0);
expect(enemy.getStatStage(s)).toBe(1);
}
}
}, TIMEOUT);
});