2024-08-09 22:37:10 +08:00
|
|
|
import { vi } from "vitest";
|
|
|
|
import { GameManagerHelper } from "./gameManagerHelper";
|
2024-08-19 03:23:52 +01:00
|
|
|
import { MoveEffectPhase } from "#app/phases/move-effect-phase.js";
|
2024-08-09 22:37:10 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper to handle a Pokemon's move
|
|
|
|
*/
|
|
|
|
export class MoveHelper extends GameManagerHelper {
|
|
|
|
/**
|
|
|
|
* Intercepts `MoveEffectPhase` and mocks the hitCheck's
|
|
|
|
* return value to `true` {@linkcode MoveEffectPhase.hitCheck}.
|
|
|
|
* Used to force a move to hit.
|
|
|
|
*/
|
|
|
|
async forceHit(): Promise<void> {
|
|
|
|
await this.game.phaseInterceptor.to(MoveEffectPhase, false);
|
|
|
|
vi.spyOn(this.game.scene.getCurrentPhase() as MoveEffectPhase, "hitCheck").mockReturnValue(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Intercepts `MoveEffectPhase` and mocks the hitCheck's
|
|
|
|
* return value to `false` {@linkcode MoveEffectPhase.hitCheck}.
|
|
|
|
* Used to force a move to miss.
|
2024-08-09 23:07:55 +08:00
|
|
|
* @param firstTargetOnly Whether the move should force miss on the first target only, in the case of multi-target moves.
|
2024-08-09 22:37:10 +08:00
|
|
|
*/
|
|
|
|
async forceMiss(firstTargetOnly: boolean = false): Promise<void> {
|
|
|
|
await this.game.phaseInterceptor.to(MoveEffectPhase, false);
|
|
|
|
const hitCheck = vi.spyOn(this.game.scene.getCurrentPhase() as MoveEffectPhase, "hitCheck");
|
|
|
|
|
|
|
|
if (firstTargetOnly) {
|
|
|
|
hitCheck.mockReturnValueOnce(false);
|
|
|
|
} else {
|
|
|
|
hitCheck.mockReturnValue(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|