[P1] Prevents crash from using Sketch against a lost turn (#4806)
* Added check to make sure that Sketch does not copy a failed move. * Added check for Struggle. * Added a revised check. * Added test + change to valid move finding conditional. * Made revision to .find target * Reverting previous commit, whoops. * Add moveset checks to Sketch tests --------- Co-authored-by: frutescens <info@laptop> Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
This commit is contained in:
parent
aa2c794910
commit
4821df68f2
|
@ -6748,7 +6748,8 @@ export class SketchAttr extends MoveEffectAttr {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetMove = target.getMoveHistory().filter(m => !m.virtual).at(-1);
|
const targetMove = target.getLastXMoves(target.battleSummonData.turnCount)
|
||||||
|
.find(m => m.move !== Moves.NONE && m.move !== Moves.STRUGGLE && !m.virtual);
|
||||||
if (!targetMove) {
|
if (!targetMove) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import { Abilities } from "#enums/abilities";
|
import { Abilities } from "#enums/abilities";
|
||||||
import { Moves } from "#enums/moves";
|
import { Moves } from "#enums/moves";
|
||||||
import { Species } from "#enums/species";
|
import { Species } from "#enums/species";
|
||||||
import { MoveResult } from "#app/field/pokemon";
|
import { MoveResult, PokemonMove } from "#app/field/pokemon";
|
||||||
import GameManager from "#test/utils/gameManager";
|
import GameManager from "#test/utils/gameManager";
|
||||||
import Phaser from "phaser";
|
import Phaser from "phaser";
|
||||||
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||||
|
import { StatusEffect } from "#app/enums/status-effect";
|
||||||
|
import { BattlerIndex } from "#app/battle";
|
||||||
|
|
||||||
describe("Moves - Sketch", () => {
|
describe("Moves - Sketch", () => {
|
||||||
let phaserGame: Phaser.Game;
|
let phaserGame: Phaser.Game;
|
||||||
|
@ -32,22 +34,46 @@ describe("Moves - Sketch", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Sketch should not fail even if a previous Sketch failed to retrieve a valid move and ran out of PP", async () => {
|
it("Sketch should not fail even if a previous Sketch failed to retrieve a valid move and ran out of PP", async () => {
|
||||||
game.override.moveset([ Moves.SKETCH, Moves.SKETCH ]);
|
|
||||||
|
|
||||||
await game.classicMode.startBattle([ Species.REGIELEKI ]);
|
await game.classicMode.startBattle([ Species.REGIELEKI ]);
|
||||||
const playerPokemon = game.scene.getPlayerPokemon();
|
const playerPokemon = game.scene.getPlayerPokemon()!;
|
||||||
|
// can't use normal moveset override because we need to check moveset changes
|
||||||
|
playerPokemon.moveset = [ new PokemonMove(Moves.SKETCH), new PokemonMove(Moves.SKETCH) ];
|
||||||
|
|
||||||
game.move.select(Moves.SKETCH);
|
game.move.select(Moves.SKETCH);
|
||||||
await game.phaseInterceptor.to("TurnEndPhase");
|
await game.phaseInterceptor.to("TurnEndPhase");
|
||||||
expect(playerPokemon?.getLastXMoves()[0].result).toBe(MoveResult.FAIL);
|
expect(playerPokemon.getLastXMoves()[0].result).toBe(MoveResult.FAIL);
|
||||||
const moveSlot0 = playerPokemon?.getMoveset()[0];
|
const moveSlot0 = playerPokemon.getMoveset()[0]!;
|
||||||
expect(moveSlot0?.moveId).toBe(Moves.SKETCH);
|
expect(moveSlot0.moveId).toBe(Moves.SKETCH);
|
||||||
expect(moveSlot0?.getPpRatio()).toBe(0);
|
expect(moveSlot0.getPpRatio()).toBe(0);
|
||||||
|
|
||||||
await game.toNextTurn();
|
await game.toNextTurn();
|
||||||
game.move.select(Moves.SKETCH);
|
game.move.select(Moves.SKETCH);
|
||||||
await game.phaseInterceptor.to("TurnEndPhase");
|
await game.phaseInterceptor.to("TurnEndPhase");
|
||||||
expect(playerPokemon?.getLastXMoves()[0].result).toBe(MoveResult.SUCCESS);
|
expect(playerPokemon.getLastXMoves()[0].result).toBe(MoveResult.SUCCESS);
|
||||||
// Can't verify if the player Pokemon's moveset was successfully changed because of overrides.
|
expect(playerPokemon.moveset[0]?.moveId).toBe(Moves.SPLASH);
|
||||||
|
expect(playerPokemon.moveset[1]?.moveId).toBe(Moves.SKETCH);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Sketch should retrieve the most recent valid move from its target history", async () => {
|
||||||
|
game.override.enemyStatusEffect(StatusEffect.PARALYSIS);
|
||||||
|
await game.classicMode.startBattle([ Species.REGIELEKI ]);
|
||||||
|
const playerPokemon = game.scene.getPlayerPokemon()!;
|
||||||
|
const enemyPokemon = game.scene.getEnemyPokemon()!;
|
||||||
|
playerPokemon.moveset = [ new PokemonMove(Moves.SKETCH), new PokemonMove(Moves.GROWL) ];
|
||||||
|
|
||||||
|
game.move.select(Moves.GROWL);
|
||||||
|
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]);
|
||||||
|
await game.move.forceStatusActivation(false);
|
||||||
|
await game.phaseInterceptor.to("TurnEndPhase");
|
||||||
|
expect(enemyPokemon.getLastXMoves()[0].result).toBe(MoveResult.SUCCESS);
|
||||||
|
|
||||||
|
await game.toNextTurn();
|
||||||
|
game.move.select(Moves.SKETCH);
|
||||||
|
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]);
|
||||||
|
await game.move.forceStatusActivation(true);
|
||||||
|
await game.phaseInterceptor.to("TurnEndPhase");
|
||||||
|
expect(playerPokemon.getLastXMoves()[0].result).toBe(MoveResult.SUCCESS);
|
||||||
|
expect(playerPokemon.moveset[0]?.moveId).toBe(Moves.SPLASH);
|
||||||
|
expect(playerPokemon.moveset[1]?.moveId).toBe(Moves.GROWL);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue