pokerogue/test/moves/assist.test.ts

106 lines
4.5 KiB
TypeScript
Raw Normal View History

[Bug][Move] Refactor moves that call a random move (#3380) * Combine moveset from allies and uses it to get a move * Clearer implementation of combining user and teammates' moves * Refactor assist and sleep talk to use metronome's attribute for calling a move * Refactor move filtering in RandomMovesetMoveAttr, creates arrays with invalid moves for assist/sleep talk * Refactor RandomMoveAttr to set moveId in condition, places reused code in callMove in RandomMoveAttr * Correct invalid move lists, adds Max/Z moves to metronome's list * Remove ignoresVirtual from beta merge * Remove Max/Z moves per frutescens' comment * Fix bug with metronome/copycat/assist/sleep talk targeting ally * Experimental async/await to be tested * Refactor other attributes to extend CallMoveAttr * Replace QueuedMove with TurnMove, refactor to attempt two-turn move fix for metronome * Fix Swallow test due to TurnMove refactor * Further fixes for TurnMove refactor * Fix metronome two turn moves for enemy pokemon * Replace nested ternary with if-else block per DayKev's comment * Minor fixes * Adjust command phase args handling * Create metronome test, refactor RandomMoveAttr for easier testing * Add unit test for recharge moves * Refactor Copycat and Mirror Move, adjust move targeting * Add unit test for ally targeting with Aromatic Mist * Add tests for secondary effects and recharge moves for metronome * Add test for Roar, remove test for Acupressure * Create test for Assist * Add test for assist failing * Add sleep talk unit test coverage * Adjust move-phase to better track last move for copycat, write and update unit tests for assist/copycat * Create moveHistory in Battle to track all moves used, adjust mirror move to use this, writes unit tests * Correct mirror move implementation, rewrite unit test to adjust * Add docs to attrs, update assist to only grab allies sets * Update assist unit test to match expected functionality * Update metronome unit test to use getMoveOverride * Update copycat unit test to use metronome getMoveOverride mock * Fix phase interception * Add docs from missed conversations * Update assist tests to use manual moveset overrides Minor fixes to other tests * Remove `export` from `CallMoveAttr` * Add missing `.unimplemented()` to some Max- and Z-Moves --------- Co-authored-by: Tempoanon <163687446+Tempo-anon@users.noreply.github.com> Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
2025-01-14 18:26:35 -05:00
import { BattlerIndex } from "#app/battle";
import { Stat } from "#app/enums/stat";
import { MoveResult } from "#app/field/pokemon";
import { CommandPhase } from "#app/phases/command-phase";
import { Abilities } from "#enums/abilities";
import { Moves } from "#enums/moves";
import { Species } from "#enums/species";
import GameManager from "#test/testUtils/gameManager";
[Bug][Move] Refactor moves that call a random move (#3380) * Combine moveset from allies and uses it to get a move * Clearer implementation of combining user and teammates' moves * Refactor assist and sleep talk to use metronome's attribute for calling a move * Refactor move filtering in RandomMovesetMoveAttr, creates arrays with invalid moves for assist/sleep talk * Refactor RandomMoveAttr to set moveId in condition, places reused code in callMove in RandomMoveAttr * Correct invalid move lists, adds Max/Z moves to metronome's list * Remove ignoresVirtual from beta merge * Remove Max/Z moves per frutescens' comment * Fix bug with metronome/copycat/assist/sleep talk targeting ally * Experimental async/await to be tested * Refactor other attributes to extend CallMoveAttr * Replace QueuedMove with TurnMove, refactor to attempt two-turn move fix for metronome * Fix Swallow test due to TurnMove refactor * Further fixes for TurnMove refactor * Fix metronome two turn moves for enemy pokemon * Replace nested ternary with if-else block per DayKev's comment * Minor fixes * Adjust command phase args handling * Create metronome test, refactor RandomMoveAttr for easier testing * Add unit test for recharge moves * Refactor Copycat and Mirror Move, adjust move targeting * Add unit test for ally targeting with Aromatic Mist * Add tests for secondary effects and recharge moves for metronome * Add test for Roar, remove test for Acupressure * Create test for Assist * Add test for assist failing * Add sleep talk unit test coverage * Adjust move-phase to better track last move for copycat, write and update unit tests for assist/copycat * Create moveHistory in Battle to track all moves used, adjust mirror move to use this, writes unit tests * Correct mirror move implementation, rewrite unit test to adjust * Add docs to attrs, update assist to only grab allies sets * Update assist unit test to match expected functionality * Update metronome unit test to use getMoveOverride * Update copycat unit test to use metronome getMoveOverride mock * Fix phase interception * Add docs from missed conversations * Update assist tests to use manual moveset overrides Minor fixes to other tests * Remove `export` from `CallMoveAttr` * Add missing `.unimplemented()` to some Max- and Z-Moves --------- Co-authored-by: Tempoanon <163687446+Tempo-anon@users.noreply.github.com> Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
2025-01-14 18:26:35 -05:00
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
describe("Moves - Assist", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(() => {
game = new GameManager(phaserGame);
// Manual moveset overrides are required for the player pokemon in these tests
// because the normal moveset override doesn't allow for accurate testing of moveset changes
game.override
.ability(Abilities.BALL_FETCH)
.battleType("double")
.disableCrits()
.enemySpecies(Species.MAGIKARP)
.enemyLevel(100)
.enemyAbility(Abilities.BALL_FETCH)
.enemyMoveset(Moves.SPLASH);
});
it("should only use an ally's moves", async () => {
game.override.enemyMoveset(Moves.SWORDS_DANCE);
await game.classicMode.startBattle([ Species.FEEBAS, Species.SHUCKLE ]);
const [ feebas, shuckle ] = game.scene.getPlayerField();
// These are all moves Assist cannot call; Sketch will be used to test that it can call other moves properly
game.move.changeMoveset(feebas, [ Moves.ASSIST, Moves.SKETCH, Moves.PROTECT, Moves.DRAGON_TAIL ]);
game.move.changeMoveset(shuckle, [ Moves.ASSIST, Moves.SKETCH, Moves.PROTECT, Moves.DRAGON_TAIL ]);
game.move.select(Moves.ASSIST, 0);
game.move.select(Moves.SKETCH, 1);
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.PLAYER ]);
// Player_2 uses Sketch, copies Swords Dance, Player_1 uses Assist, uses Player_2's Sketched Swords Dance
await game.toNextTurn();
expect(game.scene.getPlayerPokemon()!.getStatStage(Stat.ATK)).toBe(2); // Stat raised from Assist -> Swords Dance
});
it("should fail if there are no allies", async () => {
await game.classicMode.startBattle([ Species.FEEBAS ]);
const feebas = game.scene.getPlayerPokemon()!;
game.move.changeMoveset(feebas, [ Moves.ASSIST, Moves.SKETCH, Moves.PROTECT, Moves.DRAGON_TAIL ]);
game.move.select(Moves.ASSIST, 0);
await game.toNextTurn();
expect(game.scene.getPlayerPokemon()!.getLastXMoves()[0].result).toBe(MoveResult.FAIL);
});
it("should fail if ally has no usable moves and user has usable moves", async () => {
game.override.enemyMoveset(Moves.SWORDS_DANCE);
await game.classicMode.startBattle([ Species.FEEBAS, Species.SHUCKLE ]);
const [ feebas, shuckle ] = game.scene.getPlayerField();
game.move.changeMoveset(feebas, [ Moves.ASSIST, Moves.SKETCH, Moves.PROTECT, Moves.DRAGON_TAIL ]);
game.move.changeMoveset(shuckle, [ Moves.ASSIST, Moves.SKETCH, Moves.PROTECT, Moves.DRAGON_TAIL ]);
game.move.select(Moves.SKETCH, 0);
game.move.select(Moves.PROTECT, 1);
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER, BattlerIndex.PLAYER_2 ]);
// Player uses Sketch to copy Swords Dance, Player_2 stalls a turn. Player will attempt Assist and should have no usable moves
await game.toNextTurn();
game.move.select(Moves.ASSIST, 0);
await game.phaseInterceptor.to(CommandPhase);
game.move.select(Moves.PROTECT, 1);
await game.toNextTurn();
expect(game.scene.getPlayerPokemon()!.getLastXMoves()[0].result).toBe(MoveResult.FAIL);
});
it("should apply secondary effects of a move", async () => {
game.override.moveset([ Moves.ASSIST, Moves.WOOD_HAMMER, Moves.WOOD_HAMMER, Moves.WOOD_HAMMER ]);
await game.classicMode.startBattle([ Species.FEEBAS, Species.SHUCKLE ]);
const [ feebas, shuckle ] = game.scene.getPlayerField();
game.move.changeMoveset(feebas, [ Moves.ASSIST, Moves.SKETCH, Moves.PROTECT, Moves.DRAGON_TAIL ]);
game.move.changeMoveset(shuckle, [ Moves.ASSIST, Moves.SKETCH, Moves.PROTECT, Moves.DRAGON_TAIL ]);
game.move.select(Moves.ASSIST, 0);
await game.phaseInterceptor.to(CommandPhase);
game.move.select(Moves.ASSIST, 1);
await game.toNextTurn();
expect(game.scene.getPlayerPokemon()!.isFullHp()).toBeFalsy(); // should receive recoil damage from Wood Hammer
});
});