Fix interaction with multi-hits, update tests

This commit is contained in:
NightKev 2024-11-12 21:08:38 -08:00
parent b1eea52e72
commit 7c128e819a
6 changed files with 247 additions and 124 deletions

View File

@ -2408,6 +2408,24 @@ export default class BattleScene extends SceneBase {
}
}
/**
* Tries to add the input phase to index after target phase in the {@linkcode phaseQueue}, else simply calls {@linkcode unshiftPhase()}
* @param phase {@linkcode Phase} the phase to be added
* @param targetPhase {@linkcode Phase} the type of phase to search for in {@linkcode phaseQueue}
* @returns `true` if a `targetPhase` was found to append to
*/
appendToPhase(phase: Phase, targetPhase: Constructor<Phase>): boolean {
const targetIndex = this.phaseQueue.findIndex(ph => ph instanceof targetPhase);
if (targetIndex !== -1 && this.phaseQueue.length > targetIndex) {
this.phaseQueue.splice(targetIndex + 1, 0, phase);
return true;
} else {
this.unshiftPhase(phase);
return false;
}
}
/**
* Adds a MessagePhase, either to PhaseQueuePrepend or nextCommandPhaseQueue
* @param message string for MessagePhase

View File

@ -6634,22 +6634,23 @@ export class RepeatMoveAttr extends OverrideMoveEffectAttr {
*
* @param user {@linkcode Pokemon} that used the attack
* @param target {@linkcode Pokemon} targeted by the attack
* @param move {@linkcode Move} being used
* @param move N/A
* @param args N/A
* @returns {boolean} true if the move succeeds
* @returns `true` if the move succeeds
*/
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
// get the last move used (excluding status based failures) as well as the corresponding moveset slot
const lastMove = target.getLastXMoves(-1).find(m => m.move !== Moves.NONE);
const movesetMove = target.getMoveset().find(m => m?.moveId === lastMove?.move);
const moveTargets = lastMove?.targets;
const lastMove = target.getLastXMoves(-1).find(m => m.move !== Moves.NONE)!;
const movesetMove = target.getMoveset().find(m => m?.moveId === lastMove.move)!;
const moveTargets = lastMove.targets ?? [];
user.scene.queueMessage(i18next.t("moveTriggers:instructingMove", {
userPokemonName: getPokemonNameWithAffix(user),
targetPokemonName: getPokemonNameWithAffix(target)
}));
target.getMoveQueue().unshift({ move: lastMove?.move!, targets: moveTargets!, ignorePP: false });
target.scene.unshiftPhase(new MovePhase(target.scene, target, moveTargets!, movesetMove!, false, false));
target.getMoveQueue().unshift({ move: lastMove.move, targets: moveTargets, ignorePP: false });
target.turnData.extraTurns++;
target.scene.appendToPhase(new MovePhase(target.scene, target, moveTargets, movesetMove), MoveEndPhase);
return true;
}
@ -6659,7 +6660,7 @@ export class RepeatMoveAttr extends OverrideMoveEffectAttr {
// TODO: Confirm behavior of instructing move known by target but called by another move
const lastMove = target.getLastXMoves(-1).find(m => m.move !== Moves.NONE);
const movesetMove = target.getMoveset().find(m => m?.moveId === lastMove?.move);
const moveTargets = lastMove?.targets!;
const moveTargets = lastMove?.targets ?? [];
// TODO: Add a way of adding moves to list procedurally rather than a pre-defined blacklist
const unrepeatablemoves = [
// Locking/Continually Executed moves
@ -6716,11 +6717,11 @@ export class RepeatMoveAttr extends OverrideMoveEffectAttr {
// TODO: Add Z-move & Max Move blockage if/when they are implemented
];
if (!movesetMove || // called move not in target's moveset (dancer, forgetting the move, etc.)
movesetMove.ppUsed === movesetMove.getMovePp() || // move out of pp
allMoves[lastMove!.move].isChargingMove() || // called move is a charging/recharging move
!moveTargets.length || // called move has no targets
unrepeatablemoves.includes(lastMove?.move!)) { // called move is explicitly in the banlist
if (!movesetMove // called move not in target's moveset (dancer, forgetting the move, etc.)
|| movesetMove.ppUsed === movesetMove.getMovePp() // move out of pp
|| allMoves[lastMove?.move ?? Moves.NONE].isChargingMove() // called move is a charging/recharging move
|| !moveTargets.length // called move has no targets
|| unrepeatablemoves.includes(lastMove?.move ?? Moves.NONE)) { // called move is explicitly in the banlist
return false;
}
return true;

View File

@ -5237,6 +5237,7 @@ export class PokemonBattleSummonData {
export class PokemonTurnData {
public flinched: boolean = false;
public acted: boolean = false;
/** How many times the move should hit the target(s) */
public hitCount: number = 0;
/**
* - `-1` = Calculate how many hits are left
@ -5255,6 +5256,11 @@ export class PokemonTurnData {
public switchedInThisTurn: boolean = false;
public failedRunAway: boolean = false;
public joinedRound: boolean = false;
/**
* Used to make sure multi-hits occur properly when the user is
* forced to act again in the same turn
*/
public extraTurns: number = 0;
}
export enum AiType {

View File

@ -112,6 +112,14 @@ export class MoveEffectPhase extends PokemonPhase {
user.lapseTags(BattlerTagLapseType.MOVE_EFFECT);
// If the user is acting again (such as due to Instruct), reset hitsLeft/hitCount so that
// the move executes correctly (ensures all hits of a multi-hit are properly calculated)
if (user.turnData.hitsLeft === 0 && user.turnData.hitCount > 0 && user.turnData.extraTurns > 0) {
user.turnData.hitsLeft = -1;
user.turnData.hitCount = 0;
user.turnData.extraTurns--;
}
/**
* If this phase is for the first hit of the invoked move,
* resolve the move's total hit count. This block combines the

View File

@ -1,10 +1,10 @@
import { BattlerIndex } from "#app/battle";
import type Pokemon from "#app/field/pokemon";
import { MoveResult } from "#app/field/pokemon";
import { Abilities } from "#enums/abilities";
import { Moves } from "#enums/moves";
import { Species } from "#enums/species";
import { BattlerIndex } from "#app/battle";
import GameManager from "#test/utils/gameManager";
import { MoveResult } from "#app/field/pokemon";
import { Abilities } from "#app/enums/abilities";
import { StatusEffect } from "#app/enums/status-effect";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
@ -12,6 +12,12 @@ describe("Moves - Instruct", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
function instructSuccess(pokemon: Pokemon, move: Moves): void {
expect(pokemon.getLastXMoves(-1)[0].move).toBe(move);
expect(pokemon.getLastXMoves(-1)[1].move).toBe(pokemon.getLastXMoves()[0].move);
expect(pokemon.getMoveset().find(m => m?.moveId === move)?.ppUsed).toBe(2);
}
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
@ -24,108 +30,113 @@ describe("Moves - Instruct", () => {
beforeEach(() => {
game = new GameManager(phaserGame);
game.override.battleType("double");
game.override.enemySpecies(Species.KARTANA);
game.override.enemyAbility(Abilities.COMPOUND_EYES);
game.override.enemyLevel(100);
game.override.starterSpecies(Species.AMOONGUSS);
game.override.passiveAbility(Abilities.COMPOUND_EYES);
game.override.startingLevel(100);
game.override.removeEnemyStartingItems = true;
game.override.moveset([ Moves.INSTRUCT, Moves.SONIC_BOOM, Moves.SUBSTITUTE, Moves.TORMENT ]);
game.override.disableCrits();
game.override
.battleType("single")
.enemySpecies(Species.SHUCKLE)
.enemyAbility(Abilities.NO_GUARD)
.enemyLevel(100)
.startingLevel(100)
.ability(Abilities.BALL_FETCH)
.moveset([ Moves.INSTRUCT, Moves.SONIC_BOOM, Moves.SPLASH, Moves.TORMENT ])
.disableCrits();
});
it("should repeat enemy's attack move when moving last", async () => {
game.override.enemyMoveset([ Moves.SONIC_BOOM, Moves.PROTECT, Moves.SUBSTITUTE, Moves.HYPER_BEAM ]);
await game.classicMode.startBattle([ Species.AMOONGUSS ]);
const enemy = game.scene.getEnemyPokemon()!;
game.move.changeMoveset(enemy, Moves.SONIC_BOOM);
game.move.select(Moves.INSTRUCT, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
await game.forceEnemyMove(Moves.SONIC_BOOM, BattlerIndex.PLAYER);
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]);
await game.phaseInterceptor.to("TurnEndPhase", false);
// player lost 40 hp from 2 attacks
expect(game.scene.getPlayerPokemon()?.getInverseHp()).toBe(40);
instructSuccess(enemy, Moves.SONIC_BOOM);
});
it("should repeat enemy's move through substitute", async () => {
game.override.enemyMoveset([ Moves.SONIC_BOOM, Moves.PROTECT, Moves.SUBSTITUTE, Moves.HYPER_BEAM ]);
await game.classicMode.startBattle([ Species.AMOONGUSS ]);
game.move.select(Moves.INSTRUCT, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
await game.forceEnemyMove(Moves.SUBSTITUTE, BattlerIndex.ATTACKER);
const enemy = game.scene.getEnemyPokemon()!;
game.move.changeMoveset(enemy, [ Moves.SONIC_BOOM, Moves.SUBSTITUTE ]);
game.move.select(Moves.SPLASH);
await game.forceEnemyMove(Moves.SUBSTITUTE);
await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]);
await game.toNextTurn();
game.move.select(Moves.INSTRUCT, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
await game.forceEnemyMove(Moves.SONIC_BOOM, BattlerIndex.PLAYER);
game.move.select(Moves.INSTRUCT);
await game.forceEnemyMove(Moves.SONIC_BOOM);
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]);
await game.phaseInterceptor.to("TurnEndPhase", false);
// lost 40 hp from 2 attacks
expect(game.scene.getPlayerPokemon()?.getInverseHp()).toBe(40);
instructSuccess(game.scene.getEnemyPokemon()!, Moves.SONIC_BOOM);
});
it("should repeat ally's attack on enemy", async () => {
game.override.enemyMoveset([ Moves.SONIC_BOOM, Moves.PROTECT, Moves.SUBSTITUTE, Moves.HYPER_BEAM ]);
game.override
.battleType("double")
.moveset([]);
await game.classicMode.startBattle([ Species.AMOONGUSS, Species.SHUCKLE ]);
const [ amoonguss, shuckle ] = game.scene.getPlayerField();
game.move.changeMoveset(amoonguss, Moves.INSTRUCT);
game.move.changeMoveset(shuckle, Moves.SONIC_BOOM);
game.move.select(Moves.INSTRUCT, BattlerIndex.PLAYER, BattlerIndex.PLAYER_2);
game.move.select(Moves.SONIC_BOOM, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY);
await game.forceEnemyMove(Moves.VINE_WHIP);
await game.setTurnOrder([ BattlerIndex.PLAYER_2, BattlerIndex.PLAYER, BattlerIndex.ENEMY ]);
await game.forceEnemyMove(Moves.SPLASH);
await game.forceEnemyMove(Moves.SPLASH);
await game.setTurnOrder([ BattlerIndex.PLAYER_2, BattlerIndex.PLAYER, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2 ]);
await game.phaseInterceptor.to("TurnEndPhase", false);
// used 2 pp and spanked enemy twice
expect(game.scene.getPlayerField()[1].getMoveset().find(m => m?.moveId === Moves.SONIC_BOOM)!.ppUsed).toBe(2);
expect(game.scene.getEnemyPokemon()!.getInverseHp()).toBe(40);
expect(game.scene.getEnemyField()[0].getInverseHp()).toBe(40);
instructSuccess(shuckle, Moves.SONIC_BOOM);
});
/*
TODO: Re-add test case once gigaton hammer successfully gets unjanked
it("should repeat enemy's Gigaton Hammer", async () => {
game.override.enemyMoveset([ Moves.GIGATON_HAMMER, Moves.PROTECT, Moves.SUBSTITUTE, Moves.HYPER_BEAM ]);
await game.classicMode.startBattle([ Species.LUCARIO, Species.HISUI_AVALUGG ]);
game.move.select(Moves.INSTRUCT, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
game.move.select(Moves.SONIC_BOOM, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY);
await game.forceEnemyMove(Moves.GIGATON_HAMMER, BattlerIndex.PLAYER_2);
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER, BattlerIndex.PLAYER_2 ]);
await game.phaseInterceptor.to("TurnEndPhase", false);
// used 2 pp and spanked us twice, using 2 pp
const moveUsed = game.scene.getEnemyPokemon()?.getLastXMoves(-1)!;
expect(moveUsed[0].targets![0]).toBe(BattlerIndex.PLAYER_2);
// Gigaton hammer is guaranteed OHKO against avalugg 100% of the time,
// so the 2nd attack should redirect to pokemon #1
expect(game.scene.getPlayerParty()[1].isFainted()).toBe(true);
expect(game.scene.getPlayerField()[0].getInverseHp()).toBeGreaterThan(0);
expect(game.scene.getEnemyPokemon()!.getMoveset().find(m => m?.moveId === Moves.GIGATON_HAMMER)!.ppUsed).toBe(2);
});*/
it("should respect enemy's status condition & give chance to remove condition", async () => {
game.override.enemyStatusEffect(StatusEffect.FREEZE);
game.override.statusActivation(true);
game.override.enemyMoveset([ Moves.SONIC_BOOM, Moves.PROTECT, Moves.SUBSTITUTE, Moves.HYPER_BEAM ]);
// TODO: Enable test case once gigaton hammer (and blood moon) is fixed
it.todo("should repeat enemy's Gigaton Hammer", async () => {
game.override
.enemyLevel(5);
await game.classicMode.startBattle([ Species.AMOONGUSS ]);
const enemyPokemon = game.scene.getEnemyPokemon()!;
// fake move history
enemyPokemon.battleSummonData.moveHistory = [{ move: Moves.SONIC_BOOM, targets: [ BattlerIndex.PLAYER ], result: MoveResult.SUCCESS, virtual: false }];
const enemy = game.scene.getEnemyPokemon()!;
game.move.changeMoveset(enemy, Moves.GIGATON_HAMMER);
game.move.select(Moves.INSTRUCT, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
await game.forceEnemyMove(Moves.PROTECT);
game.move.select(Moves.INSTRUCT);
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]);
await game.phaseInterceptor.to("MovePhase", true);
game.override.statusActivation(false); // should cure freeze
await game.phaseInterceptor.to("TurnEndPhase", false);
// protect not recorded as last move due to full para blockage
// instructed sonic boom still works as pokemon was defrosted before attack
const moveUsed = game.scene.getEnemyPokemon()!.getLastXMoves(-1);
expect(moveUsed.find(m => m?.move !== Moves.NONE)?.move).toBe(Moves.SONIC_BOOM);
instructSuccess(enemy, Moves.GIGATON_HAMMER);
});
it("should respect enemy's status condition", async () => {
game.override
.moveset([ Moves.THUNDER_WAVE, Moves.INSTRUCT ])
.enemyMoveset([ Moves.SPLASH, Moves.SONIC_BOOM ]);
await game.classicMode.startBattle([ Species.AMOONGUSS ]);
game.move.select(Moves.THUNDER_WAVE);
await game.forceEnemyMove(Moves.SONIC_BOOM);
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]);
await game.toNextTurn();
game.move.select(Moves.INSTRUCT);
await game.forceEnemyMove(Moves.SPLASH);
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]);
await game.move.forceStatusActivation(true);
await game.phaseInterceptor.to("MovePhase");
await game.move.forceStatusActivation(false);
await game.phaseInterceptor.to("TurnEndPhase", false);
const moveHistory = game.scene.getEnemyPokemon()!.getMoveHistory();
expect(moveHistory.length).toBe(3);
expect(moveHistory[0].move).toBe(Moves.SONIC_BOOM);
expect(moveHistory[1].move).toBe(Moves.NONE);
expect(moveHistory[2].move).toBe(Moves.SONIC_BOOM);
});
it("should not repeat enemy's out of pp move", async () => {
@ -133,110 +144,170 @@ describe("Moves - Instruct", () => {
await game.classicMode.startBattle([ Species.AMOONGUSS ]);
const enemyPokemon = game.scene.getEnemyPokemon()!;
enemyPokemon.generateAndPopulateMoveset();
const moveUsed = enemyPokemon?.moveset.find(m => m?.moveId === Moves.HIDDEN_POWER)!;
moveUsed.ppUsed = moveUsed.getMovePp() - 1; // deduct all but 1 pp
game.move.changeMoveset(enemyPokemon, Moves.HIDDEN_POWER);
const moveUsed = enemyPokemon.moveset.find(m => m?.moveId === Moves.HIDDEN_POWER)!;
moveUsed.ppUsed = moveUsed.getMovePp() - 1;
game.move.select(Moves.INSTRUCT, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
await game.forceEnemyMove(Moves.HIDDEN_POWER, BattlerIndex.PLAYER);
game.move.select(Moves.INSTRUCT);
await game.forceEnemyMove(Moves.HIDDEN_POWER);
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]);
await game.phaseInterceptor.to("TurnEndPhase", false);
// instruct "should" fail as it tries to force the enemy to use an out of pp move
// TODO: Check showdown behavior of instructing out of pp moves
const playerMove = game.scene.getPlayerPokemon()!.getLastXMoves()!;
const enemyMove = enemyPokemon.getLastXMoves(2);
expect(enemyMove[0].result).toBe(MoveResult.SUCCESS);
expect(playerMove[0].result).toBe(MoveResult.FAIL);
expect(enemyPokemon.getMoveHistory().length).toBe(1);
});
it("should fail if no move has yet been used by target", async () => {
game.override.enemyMoveset([ Moves.SONIC_BOOM, Moves.PROTECT, Moves.SUBSTITUTE, Moves.HYPER_BEAM ]);
game.override.enemyMoveset(Moves.SPLASH);
await game.classicMode.startBattle([ Species.AMOONGUSS ]);
game.move.select(Moves.INSTRUCT, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
await game.forceEnemyMove(Moves.SONIC_BOOM, BattlerIndex.PLAYER);
game.move.select(Moves.INSTRUCT);
await game.forceEnemyMove(Moves.SPLASH);
await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]);
await game.phaseInterceptor.to("TurnEndPhase", false);
// should fail to execute
expect(game.scene.getPlayerPokemon()!.getLastXMoves()[0].result).toBe(MoveResult.FAIL);
});
it("should attempt to call enemy's disabled move, but move use itself should fail", async () => {
game.override.enemyMoveset([ Moves.SONIC_BOOM, Moves.PROTECT, Moves.SUBSTITUTE, Moves.HYPER_BEAM ]);
game.override.moveset([ Moves.INSTRUCT, Moves.SONIC_BOOM, Moves.DISABLE, Moves.SPLASH ]);
game.override
.moveset([ Moves.INSTRUCT, Moves.DISABLE ])
.battleType("double");
await game.classicMode.startBattle([ Species.AMOONGUSS, Species.DROWZEE ]);
const [ enemy1, enemy2 ] = game.scene.getEnemyField();
game.move.changeMoveset(enemy1, Moves.SONIC_BOOM);
game.move.changeMoveset(enemy2, Moves.SPLASH);
game.move.select(Moves.INSTRUCT, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
game.move.select(Moves.DISABLE, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY);
await game.forceEnemyMove(Moves.SONIC_BOOM, BattlerIndex.PLAYER);
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER_2, BattlerIndex.PLAYER ]);
await game.forceEnemyMove(Moves.SPLASH);
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER_2, BattlerIndex.PLAYER, BattlerIndex.ENEMY_2 ]);
await game.phaseInterceptor.to("TurnEndPhase", false);
// instruction should succeed but move itself should fail without consuming pp
expect(game.scene.getPlayerField()[0].getLastXMoves()[0].result).toBe(MoveResult.SUCCESS);
const enemyMove = game.scene.getEnemyPokemon()!.getLastXMoves()[0];
expect(enemyMove.result).toBe(MoveResult.FAIL);
expect(game.scene.getEnemyPokemon()!.getMoveset().find(m => m?.moveId === Moves.SONIC_BOOM)?.ppUsed).toBe(0);
expect(game.scene.getEnemyPokemon()!.getMoveset().find(m => m?.moveId === Moves.SONIC_BOOM)?.ppUsed).toBe(1);
});
it("should not repeat enemy's move through protect", async () => {
game.override.enemyMoveset([ Moves.SONIC_BOOM, Moves.PROTECT, Moves.SUBSTITUTE, Moves.HYPER_BEAM ]);
game.override.enemyMoveset([ Moves.SONIC_BOOM, Moves.PROTECT ]);
await game.classicMode.startBattle([ Species.AMOONGUSS ]);
const enemyPokemon = game.scene.getEnemyPokemon()!;
// fake move history
enemyPokemon.battleSummonData.moveHistory = [{ move: Moves.SONIC_BOOM, targets: [ BattlerIndex.PLAYER ], result: MoveResult.SUCCESS, virtual: false }];
game.move.select(Moves.INSTRUCT, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
await game.forceEnemyMove(Moves.PROTECT, BattlerIndex.ATTACKER);
game.move.select(Moves.INSTRUCT);
await game.forceEnemyMove(Moves.PROTECT);
await game.phaseInterceptor.to("TurnEndPhase", false);
// protect still last move as instruct was blocked from repeating anything
expect(game.scene.getEnemyPokemon()!.getLastXMoves()[0].move).toBe(Moves.PROTECT);
expect(enemyPokemon.getLastXMoves()[0].move).toBe(Moves.PROTECT);
});
it("should not repeat enemy's charging move", async () => {
game.override.enemyMoveset([ Moves.SONIC_BOOM, Moves.PROTECT, Moves.SUBSTITUTE, Moves.HYPER_BEAM ]);
await game.classicMode.startBattle([ Species.DUSKNOIR ]);
game.override
.enemyMoveset([ Moves.SONIC_BOOM, Moves.HYPER_BEAM ])
.enemyLevel(5);
await game.classicMode.startBattle([ Species.SHUCKLE ]);
const player = game.scene.getPlayerPokemon()!;
const enemyPokemon = game.scene.getEnemyPokemon()!;
enemyPokemon.battleSummonData.moveHistory = [{ move: Moves.SONIC_BOOM, targets: [ BattlerIndex.PLAYER ], result: MoveResult.SUCCESS, virtual: false }];
game.move.select(Moves.INSTRUCT, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
game.move.select(Moves.INSTRUCT);
await game.forceEnemyMove(Moves.HYPER_BEAM);
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]);
await game.phaseInterceptor.to("TurnEndPhase", false);
// hyper beam charging prevented instruct from working
expect(game.scene.getPlayerPokemon()!.getLastXMoves()[0]!.result).toBe(MoveResult.FAIL);
await game.toNextTurn();
game.move.select(Moves.INSTRUCT, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
await game.forceEnemyMove(Moves.HYPER_BEAM);
expect(player.getLastXMoves()[0].result).toBe(MoveResult.FAIL);
game.move.select(Moves.INSTRUCT);
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]);
await game.phaseInterceptor.to("TurnEndPhase", false);
// hyper beam charging prevented instruct from working
expect(game.scene.getPlayerPokemon()!.getLastXMoves()[0]!.result).toBe(MoveResult.FAIL);
expect(player.getLastXMoves()[0].result).toBe(MoveResult.FAIL);
});
it("should not repeat dance move not known by target", async () => {
game.override.enemyMoveset([ Moves.SONIC_BOOM, Moves.PROTECT, Moves.SUBSTITUTE, Moves.HYPER_BEAM ]);
game.override.moveset([ Moves.INSTRUCT, Moves.FIERY_DANCE, Moves.SUBSTITUTE, Moves.TORMENT ]);
game.override.enemyAbility(Abilities.DANCER);
await game.classicMode.startBattle([ Species.DUSKNOIR, Species.ABOMASNOW ]);
game.override
.battleType("double")
.moveset([ Moves.INSTRUCT, Moves.FIERY_DANCE ])
.enemyMoveset(Moves.SPLASH)
.enemyAbility(Abilities.DANCER);
await game.classicMode.startBattle([ Species.SHUCKLE, Species.SHUCKLE ]);
game.move.select(Moves.INSTRUCT, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
game.move.select(Moves.FIERY_DANCE, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY);
await game.forceEnemyMove(Moves.PROTECT, BattlerIndex.ATTACKER);
await game.setTurnOrder([ BattlerIndex.PLAYER_2, BattlerIndex.PLAYER, BattlerIndex.ENEMY ]);
await game.forceEnemyMove(Moves.SPLASH);
await game.forceEnemyMove(Moves.SPLASH);
await game.setTurnOrder([ BattlerIndex.PLAYER_2, BattlerIndex.PLAYER, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2 ]);
await game.phaseInterceptor.to("TurnEndPhase", false);
// Pokemon 2 uses dance; dancer reciprocates
// instruct fails as it cannot copy the unknown dance move
expect(game.scene.getPlayerPokemon()!.getLastXMoves()[0]!.result).toBe(MoveResult.FAIL);
expect(game.scene.getPlayerField()[0].getLastXMoves()[0].result).toBe(MoveResult.FAIL);
});
it("should cause multi-hit moves to hit the appropriate number of times in singles", async () => {
game.override
.enemyAbility(Abilities.SKILL_LINK)
.enemyMoveset(Moves.BULLET_SEED);
await game.classicMode.startBattle([ Species.BULBASAUR ]);
const player = game.scene.getPlayerPokemon()!;
game.move.select(Moves.SPLASH);
await game.toNextTurn();
game.move.select(Moves.INSTRUCT);
await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]);
await game.phaseInterceptor.to("BerryPhase");
expect(player.turnData.attacksReceived.length).toBe(10);
await game.toNextTurn();
game.move.select(Moves.INSTRUCT);
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]);
await game.phaseInterceptor.to("BerryPhase");
expect(player.turnData.attacksReceived.length).toBe(10);
});
it("should cause multi-hit moves to hit the appropriate number of times in doubles", async () => {
game.override
.battleType("double")
.enemyAbility(Abilities.SKILL_LINK)
.enemyMoveset([ Moves.BULLET_SEED, Moves.SPLASH ])
.enemyLevel(5);
await game.classicMode.startBattle([ Species.BULBASAUR, Species.IVYSAUR ]);
const [ , ivysaur ] = game.scene.getPlayerField();
game.move.select(Moves.SPLASH);
game.move.select(Moves.SPLASH, 1);
await game.forceEnemyMove(Moves.BULLET_SEED, BattlerIndex.PLAYER_2);
await game.forceEnemyMove(Moves.SPLASH);
await game.toNextTurn();
game.move.select(Moves.INSTRUCT, 0, BattlerIndex.ENEMY);
game.move.select(Moves.INSTRUCT, 1, BattlerIndex.ENEMY);
await game.forceEnemyMove(Moves.BULLET_SEED, BattlerIndex.PLAYER_2);
await game.forceEnemyMove(Moves.SPLASH);
await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2 ]);
await game.phaseInterceptor.to("BerryPhase");
expect(ivysaur.turnData.attacksReceived.length).toBe(15);
await game.toNextTurn();
game.move.select(Moves.INSTRUCT, 0, BattlerIndex.ENEMY);
game.move.select(Moves.INSTRUCT, 1, BattlerIndex.ENEMY);
await game.forceEnemyMove(Moves.BULLET_SEED, BattlerIndex.PLAYER_2);
await game.forceEnemyMove(Moves.SPLASH);
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER, BattlerIndex.PLAYER_2 ]);
await game.phaseInterceptor.to("BerryPhase");
expect(ivysaur.turnData.attacksReceived.length).toBe(15);
});
});

View File

@ -1,4 +1,6 @@
import { BattlerIndex } from "#app/battle";
import type Pokemon from "#app/field/pokemon";
import { PokemonMove } from "#app/field/pokemon";
import Overrides from "#app/overrides";
import { CommandPhase } from "#app/phases/command-phase";
import { MoveEffectPhase } from "#app/phases/move-effect-phase";
@ -71,4 +73,21 @@ export class MoveHelper extends GameManagerHelper {
await this.game.phaseInterceptor.to("MovePhase");
vi.spyOn(Overrides, "STATUS_ACTIVATION_OVERRIDE", "get").mockReturnValue(null);
}
/**
* Used when the normal moveset override can't be used (such as when it's necessary to check updated properties of the moveset).
* @param pokemon - The pokemon being modified
* @param moveset - The moveset to use
*/
public changeMoveset(pokemon: Pokemon, moveset: Moves | Moves[]): void {
if (!Array.isArray(moveset)) {
moveset = [ moveset ];
}
pokemon.moveset = [];
moveset.forEach((move) => {
pokemon.moveset.push(new PokemonMove(move));
});
const movesetStr = moveset.map((moveId) => Moves[moveId]).join(", ");
console.log(`Pokemon ${pokemon.species.name}'s moveset manually set to ${movesetStr} (=[${moveset.join(", ")}])!`);
}
}