[Bug] Fix Truant behavior (#6171)

This commit is contained in:
Acelynn Zhang 2025-07-31 16:18:11 -04:00 committed by GitHub
parent 75ececd942
commit 901f6a6812
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 73 additions and 1 deletions

View File

@ -2038,7 +2038,7 @@ export class TruantTag extends AbilityBattlerTag {
const lastMove = pokemon.getLastXMoves()[0];
if (!lastMove) {
if (!lastMove || lastMove.move === MoveId.NONE) {
// Don't interrupt move if last move was `Moves.NONE` OR no prior move was found
return true;
}

View File

@ -0,0 +1,72 @@
import { getPokemonNameWithAffix } from "#app/messages";
import { AbilityId } from "#enums/ability-id";
import { MoveId } from "#enums/move-id";
import { MoveResult } from "#enums/move-result";
import { SpeciesId } from "#enums/species-id";
import { GameManager } from "#test/test-utils/game-manager";
import i18next from "i18next";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
describe("Ability - Truant", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(() => {
game = new GameManager(phaserGame);
game.override
.battleStyle("single")
.criticalHits(false)
.moveset([MoveId.SPLASH, MoveId.TACKLE])
.ability(AbilityId.TRUANT)
.enemySpecies(SpeciesId.MAGIKARP)
.enemyAbility(AbilityId.BALL_FETCH)
.enemyMoveset(MoveId.SPLASH);
});
it("should loaf around and prevent using moves every other turn", async () => {
await game.classicMode.startBattle([SpeciesId.FEEBAS]);
const player = game.field.getPlayerPokemon();
const enemy = game.field.getEnemyPokemon();
// Turn 1: Splash succeeds
game.move.select(MoveId.SPLASH);
await game.toNextTurn();
expect(player.getLastXMoves(1)[0]).toEqual(
expect.objectContaining({ move: MoveId.SPLASH, result: MoveResult.SUCCESS }),
);
// Turn 2: Truant activates, cancelling tackle and displaying message
game.move.select(MoveId.TACKLE);
await game.toNextTurn();
expect(player.getLastXMoves(1)[0]).toEqual(expect.objectContaining({ move: MoveId.NONE, result: MoveResult.FAIL }));
expect(enemy.hp).toBe(enemy.getMaxHp());
expect(game.textInterceptor.logs).toContain(
i18next.t("battlerTags:truantLapse", {
pokemonNameWithAffix: getPokemonNameWithAffix(player),
}),
);
// Turn 3: Truant didn't activate, tackle worked
game.move.select(MoveId.TACKLE);
await game.toNextTurn();
expect(player.getLastXMoves(1)[0]).toEqual(
expect.objectContaining({ move: MoveId.TACKLE, result: MoveResult.SUCCESS }),
);
expect(enemy.hp).toBeLessThan(enemy.getMaxHp());
});
});