mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-20 06:19:29 +02:00
[P2][Beta] Fix Sketch failing to sketch Metronome et al
This commit is contained in:
parent
4821df68f2
commit
32f9f3ed74
@ -6362,10 +6362,17 @@ export class RandomMovesetMoveAttr extends OverrideMoveEffectAttr {
|
||||
}
|
||||
|
||||
export class RandomMoveAttr extends OverrideMoveEffectAttr {
|
||||
/**
|
||||
* This function exists solely to allow tests to override the randomly selected move by mocking this function.
|
||||
*/
|
||||
public getMoveOverride(): Moves | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise<boolean> {
|
||||
return new Promise(resolve => {
|
||||
const moveIds = Utils.getEnumValues(Moves).filter(m => !allMoves[m].hasFlag(MoveFlags.IGNORE_VIRTUAL) && !allMoves[m].name.endsWith(" (N)"));
|
||||
const moveId = moveIds[user.randSeedInt(moveIds.length)];
|
||||
const moveId = this.getMoveOverride() ?? moveIds[user.randSeedInt(moveIds.length)];
|
||||
|
||||
const moveTargets = getMoveTargets(user, moveId);
|
||||
if (!moveTargets.targets.length) {
|
||||
@ -6748,7 +6755,7 @@ export class SketchAttr extends MoveEffectAttr {
|
||||
return false;
|
||||
}
|
||||
|
||||
const targetMove = target.getLastXMoves(target.battleSummonData.turnCount)
|
||||
const targetMove = target.getLastXMoves(-1)
|
||||
.find(m => m.move !== Moves.NONE && m.move !== Moves.STRUGGLE && !m.virtual);
|
||||
if (!targetMove) {
|
||||
return false;
|
||||
|
@ -3220,9 +3220,19 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
||||
this.getMoveHistory().push(turnMove);
|
||||
}
|
||||
|
||||
getLastXMoves(turnCount: integer = 0): TurnMove[] {
|
||||
/**
|
||||
* Returns a list of the most recent move entries in this Pokemon's move history.
|
||||
* The retrieved move entries are sorted in order from NEWEST to OLDEST.
|
||||
* @param turnCount The number of move entries to retrieve. If `0`, retrieve exactly 1 move entry. If negative, retrieve the Pokemon's entire move history. Default is `1`.
|
||||
* @returns A list of {@linkcode TurnMove}, as specified above.
|
||||
*/
|
||||
getLastXMoves(turnCount: integer = 1): TurnMove[] {
|
||||
const moveHistory = this.getMoveHistory();
|
||||
return moveHistory.slice(turnCount >= 0 ? Math.max(moveHistory.length - (turnCount || 1), 0) : 0, moveHistory.length).reverse();
|
||||
if (turnCount >= 0) {
|
||||
return moveHistory.slice(Math.max(moveHistory.length - (turnCount || 1), 0)).reverse();
|
||||
} else {
|
||||
return moveHistory.slice(0).reverse();
|
||||
}
|
||||
}
|
||||
|
||||
getMoveQueue(): QueuedMove[] {
|
||||
|
@ -8,7 +8,8 @@ import { Moves } from "#enums/moves";
|
||||
import { Species } from "#enums/species";
|
||||
import GameManager from "#test/utils/gameManager";
|
||||
import Phaser from "phaser";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { allMoves, RandomMoveAttr } from "#app/data/move";
|
||||
|
||||
// See also: TypeImmunityAbAttr
|
||||
describe("Abilities - Sap Sipper", () => {
|
||||
@ -27,20 +28,20 @@ describe("Abilities - Sap Sipper", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
game = new GameManager(phaserGame);
|
||||
game.override.battleType("single");
|
||||
game.override.disableCrits();
|
||||
game.override.battleType("single")
|
||||
.disableCrits()
|
||||
.ability(Abilities.SAP_SIPPER)
|
||||
.enemySpecies(Species.RATTATA)
|
||||
.enemyAbility(Abilities.SAP_SIPPER)
|
||||
.enemyMoveset(Moves.SPLASH);
|
||||
});
|
||||
|
||||
it("raises ATK stat stage by 1 and block effects when activated against a grass attack", async() => {
|
||||
const moveToUse = Moves.LEAFAGE;
|
||||
const enemyAbility = Abilities.SAP_SIPPER;
|
||||
|
||||
game.override.moveset([ moveToUse ]);
|
||||
game.override.enemyMoveset(Moves.SPLASH);
|
||||
game.override.enemySpecies(Species.DUSKULL);
|
||||
game.override.enemyAbility(enemyAbility);
|
||||
game.override.moveset(moveToUse);
|
||||
|
||||
await game.startBattle();
|
||||
await game.classicMode.startBattle([ Species.BULBASAUR ]);
|
||||
|
||||
const enemyPokemon = game.scene.getEnemyPokemon()!;
|
||||
const initialEnemyHp = enemyPokemon.hp;
|
||||
@ -55,14 +56,10 @@ describe("Abilities - Sap Sipper", () => {
|
||||
|
||||
it("raises ATK stat stage by 1 and block effects when activated against a grass status move", async() => {
|
||||
const moveToUse = Moves.SPORE;
|
||||
const enemyAbility = Abilities.SAP_SIPPER;
|
||||
|
||||
game.override.moveset([ moveToUse ]);
|
||||
game.override.enemyMoveset(Moves.SPLASH);
|
||||
game.override.enemySpecies(Species.RATTATA);
|
||||
game.override.enemyAbility(enemyAbility);
|
||||
game.override.moveset(moveToUse);
|
||||
|
||||
await game.startBattle();
|
||||
await game.classicMode.startBattle([ Species.BULBASAUR ]);
|
||||
|
||||
const enemyPokemon = game.scene.getEnemyPokemon()!;
|
||||
|
||||
@ -76,14 +73,10 @@ describe("Abilities - Sap Sipper", () => {
|
||||
|
||||
it("do not activate against status moves that target the field", async () => {
|
||||
const moveToUse = Moves.GRASSY_TERRAIN;
|
||||
const enemyAbility = Abilities.SAP_SIPPER;
|
||||
|
||||
game.override.moveset([ moveToUse ]);
|
||||
game.override.enemyMoveset(Moves.SPLASH);
|
||||
game.override.enemySpecies(Species.RATTATA);
|
||||
game.override.enemyAbility(enemyAbility);
|
||||
game.override.moveset(moveToUse);
|
||||
|
||||
await game.startBattle();
|
||||
await game.classicMode.startBattle([ Species.BULBASAUR ]);
|
||||
|
||||
game.move.select(moveToUse);
|
||||
|
||||
@ -96,14 +89,10 @@ describe("Abilities - Sap Sipper", () => {
|
||||
|
||||
it("activate once against multi-hit grass attacks", async () => {
|
||||
const moveToUse = Moves.BULLET_SEED;
|
||||
const enemyAbility = Abilities.SAP_SIPPER;
|
||||
|
||||
game.override.moveset([ moveToUse ]);
|
||||
game.override.enemyMoveset(Moves.SPLASH);
|
||||
game.override.enemySpecies(Species.RATTATA);
|
||||
game.override.enemyAbility(enemyAbility);
|
||||
game.override.moveset(moveToUse);
|
||||
|
||||
await game.startBattle();
|
||||
await game.classicMode.startBattle([ Species.BULBASAUR ]);
|
||||
|
||||
const enemyPokemon = game.scene.getEnemyPokemon()!;
|
||||
const initialEnemyHp = enemyPokemon.hp;
|
||||
@ -118,15 +107,10 @@ describe("Abilities - Sap Sipper", () => {
|
||||
|
||||
it("do not activate against status moves that target the user", async () => {
|
||||
const moveToUse = Moves.SPIKY_SHIELD;
|
||||
const ability = Abilities.SAP_SIPPER;
|
||||
|
||||
game.override.moveset([ moveToUse ]);
|
||||
game.override.ability(ability);
|
||||
game.override.enemyMoveset(Moves.SPLASH);
|
||||
game.override.enemySpecies(Species.RATTATA);
|
||||
game.override.enemyAbility(Abilities.NONE);
|
||||
game.override.moveset(moveToUse);
|
||||
|
||||
await game.startBattle();
|
||||
await game.classicMode.startBattle([ Species.BULBASAUR ]);
|
||||
|
||||
const playerPokemon = game.scene.getPlayerPokemon()!;
|
||||
|
||||
@ -142,18 +126,15 @@ describe("Abilities - Sap Sipper", () => {
|
||||
expect(game.phaseInterceptor.log).not.toContain("ShowAbilityPhase");
|
||||
});
|
||||
|
||||
// TODO Add METRONOME outcome override
|
||||
// To run this testcase, manually modify the METRONOME move to always give SAP_SIPPER, then uncomment
|
||||
it.todo("activate once against multi-hit grass attacks (metronome)", async () => {
|
||||
it("activate once against multi-hit grass attacks (metronome)", async () => {
|
||||
const moveToUse = Moves.METRONOME;
|
||||
const enemyAbility = Abilities.SAP_SIPPER;
|
||||
|
||||
game.override.moveset([ moveToUse ]);
|
||||
game.override.enemyMoveset([ Moves.SPLASH, Moves.NONE, Moves.NONE, Moves.NONE ]);
|
||||
game.override.enemySpecies(Species.RATTATA);
|
||||
game.override.enemyAbility(enemyAbility);
|
||||
const randomMoveAttr = allMoves[Moves.METRONOME].findAttr(attr => attr instanceof RandomMoveAttr) as RandomMoveAttr;
|
||||
vi.spyOn(randomMoveAttr, "getMoveOverride").mockReturnValue(Moves.BULLET_SEED);
|
||||
|
||||
await game.startBattle();
|
||||
game.override.moveset(moveToUse);
|
||||
|
||||
await game.classicMode.startBattle([ Species.BULBASAUR ]);
|
||||
|
||||
const enemyPokemon = game.scene.getEnemyPokemon()!;
|
||||
const initialEnemyHp = enemyPokemon.hp;
|
||||
@ -168,11 +149,8 @@ describe("Abilities - Sap Sipper", () => {
|
||||
|
||||
it("still activates regardless of accuracy check", async () => {
|
||||
game.override.moveset(Moves.LEAF_BLADE);
|
||||
game.override.enemyMoveset(Moves.SPLASH);
|
||||
game.override.enemySpecies(Species.MAGIKARP);
|
||||
game.override.enemyAbility(Abilities.SAP_SIPPER);
|
||||
|
||||
await game.classicMode.startBattle();
|
||||
await game.classicMode.startBattle([ Species.BULBASAUR ]);
|
||||
|
||||
const enemyPokemon = game.scene.getEnemyPokemon()!;
|
||||
|
||||
|
@ -4,9 +4,10 @@ import { Species } from "#enums/species";
|
||||
import { MoveResult, PokemonMove } from "#app/field/pokemon";
|
||||
import GameManager from "#test/utils/gameManager";
|
||||
import Phaser from "phaser";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { StatusEffect } from "#app/enums/status-effect";
|
||||
import { BattlerIndex } from "#app/battle";
|
||||
import { allMoves, RandomMoveAttr } from "#app/data/move";
|
||||
|
||||
describe("Moves - Sketch", () => {
|
||||
let phaserGame: Phaser.Game;
|
||||
@ -76,4 +77,22 @@ describe("Moves - Sketch", () => {
|
||||
expect(playerPokemon.moveset[0]?.moveId).toBe(Moves.SPLASH);
|
||||
expect(playerPokemon.moveset[1]?.moveId).toBe(Moves.GROWL);
|
||||
});
|
||||
|
||||
it("should sketch moves that call other moves", async () => {
|
||||
const randomMoveAttr = allMoves[Moves.METRONOME].findAttr(attr => attr instanceof RandomMoveAttr) as RandomMoveAttr;
|
||||
vi.spyOn(randomMoveAttr, "getMoveOverride").mockReturnValue(Moves.FALSE_SWIPE);
|
||||
|
||||
game.override.enemyMoveset([ Moves.METRONOME ]);
|
||||
await game.classicMode.startBattle([ Species.REGIELEKI ]);
|
||||
const playerPokemon = game.scene.getPlayerPokemon()!;
|
||||
playerPokemon.moveset = [ new PokemonMove(Moves.SKETCH) ];
|
||||
|
||||
// Opponent uses Metronome -> False Swipe, then player uses Sketch, which should sketch Metronome
|
||||
game.move.select(Moves.SKETCH);
|
||||
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]);
|
||||
await game.phaseInterceptor.to("TurnEndPhase");
|
||||
expect(playerPokemon.getLastXMoves()[0].result).toBe(MoveResult.SUCCESS);
|
||||
expect(playerPokemon.moveset[0]?.moveId).toBe(Moves.METRONOME);
|
||||
expect(playerPokemon.hp).toBeLessThan(playerPokemon.getMaxHp()); // Make sure opponent actually used False Swipe
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user