[P2] Fix Battle Bond continuing to affect Water Shuriken after Greninja returns to base form (#4602)

* [Bug] Fix Battle Bond continuing to buff Water Shuriken after Greninja returns to base form

* Test cleanup

* PR feedback

* Update test to use getMultiHitType()

* PR Feedback
This commit is contained in:
PigeonBar 2024-10-10 11:40:14 -04:00 committed by GitHub
parent 51894d46c2
commit 64147e4414
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 73 additions and 34 deletions

View File

@ -1938,12 +1938,21 @@ export class IncrementMovePriorityAttr extends MoveAttr {
* @see {@linkcode apply} * @see {@linkcode apply}
*/ */
export class MultiHitAttr extends MoveAttr { export class MultiHitAttr extends MoveAttr {
/** This move's intrinsic multi-hit type. It should never be modified. */
private readonly intrinsicMultiHitType: MultiHitType;
/** This move's current multi-hit type. It may be temporarily modified by abilities (e.g., Battle Bond). */
private multiHitType: MultiHitType; private multiHitType: MultiHitType;
constructor(multiHitType?: MultiHitType) { constructor(multiHitType?: MultiHitType) {
super(); super();
this.multiHitType = multiHitType !== undefined ? multiHitType : MultiHitType._2_TO_5; this.intrinsicMultiHitType = multiHitType !== undefined ? multiHitType : MultiHitType._2_TO_5;
this.multiHitType = this.intrinsicMultiHitType;
}
// Currently used by `battle_bond.test.ts`
getMultiHitType(): MultiHitType {
return this.multiHitType;
} }
/** /**
@ -1957,7 +1966,7 @@ export class MultiHitAttr extends MoveAttr {
* @returns True * @returns True
*/ */
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
const hitType = new Utils.NumberHolder(this.multiHitType); const hitType = new Utils.NumberHolder(this.intrinsicMultiHitType);
applyMoveAttrs(ChangeMultiHitTypeAttr, user, target, move, hitType); applyMoveAttrs(ChangeMultiHitTypeAttr, user, target, move, hitType);
this.multiHitType = hitType.value; this.multiHitType = hitType.value;

View File

@ -1,17 +1,19 @@
import { allMoves, MultiHitAttr, MultiHitType } from "#app/data/move";
import { Status, StatusEffect } from "#app/data/status-effect"; import { Status, StatusEffect } from "#app/data/status-effect";
import { QuietFormChangePhase } from "#app/phases/quiet-form-change-phase";
import { TurnEndPhase } from "#app/phases/turn-end-phase";
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 GameManager from "#test/utils/gameManager"; import GameManager from "#test/utils/gameManager";
import { afterEach, beforeAll, beforeEach, describe, expect, test } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
describe("Abilities - BATTLE BOND", () => { describe("Abilities - BATTLE BOND", () => {
let phaserGame: Phaser.Game; let phaserGame: Phaser.Game;
let game: GameManager; let game: GameManager;
const baseForm = 1;
const ashForm = 2;
beforeAll(() => { beforeAll(() => {
phaserGame = new Phaser.Game({ phaserGame = new Phaser.Game({
type: Phaser.HEADLESS, type: Phaser.HEADLESS,
@ -24,40 +26,68 @@ describe("Abilities - BATTLE BOND", () => {
beforeEach(() => { beforeEach(() => {
game = new GameManager(phaserGame); game = new GameManager(phaserGame);
const moveToUse = Moves.SPLASH; game.override.battleType("single")
game.override.battleType("single"); .startingWave(4) // Leads to arena reset on Wave 5 trainer battle
game.override.ability(Abilities.BATTLE_BOND); .ability(Abilities.BATTLE_BOND)
game.override.moveset([ moveToUse ]); .starterForms({ [Species.GRENINJA]: ashForm, })
game.override.enemyMoveset([ Moves.TACKLE, Moves.TACKLE, Moves.TACKLE, Moves.TACKLE ]); .moveset([ Moves.SPLASH, Moves.WATER_SHURIKEN ])
.enemySpecies(Species.BULBASAUR)
.enemyMoveset(Moves.SPLASH)
.startingLevel(100) // Avoid levelling up
.enemyLevel(1000); // Avoid opponent dying before `doKillOpponents()`
}); });
test( it("check if fainted pokemon switches to base form on arena reset", async () => {
"check if fainted pokemon switches to base form on arena reset", await game.classicMode.startBattle([ Species.MAGIKARP, Species.GRENINJA ]);
async () => {
const baseForm = 1;
const ashForm = 2;
game.override.startingWave(4);
game.override.starterForms({
[Species.GRENINJA]: ashForm,
});
await game.startBattle([ Species.MAGIKARP, Species.GRENINJA ]); const greninja = game.scene.getParty()[1];
expect(greninja.formIndex).toBe(ashForm);
const greninja = game.scene.getParty().find((p) => p.species.speciesId === Species.GRENINJA); greninja.hp = 0;
expect(greninja).toBeDefined(); greninja.status = new Status(StatusEffect.FAINT);
expect(greninja!.formIndex).toBe(ashForm); expect(greninja.isFainted()).toBe(true);
greninja!.hp = 0; game.move.select(Moves.SPLASH);
greninja!.status = new Status(StatusEffect.FAINT); await game.doKillOpponents();
expect(greninja!.isFainted()).toBe(true); await game.phaseInterceptor.to("TurnEndPhase");
game.doSelectModifier();
await game.phaseInterceptor.to("QuietFormChangePhase");
game.move.select(Moves.SPLASH); expect(greninja.formIndex).toBe(baseForm);
await game.doKillOpponents(); });
await game.phaseInterceptor.to(TurnEndPhase);
game.doSelectModifier();
await game.phaseInterceptor.to(QuietFormChangePhase);
expect(greninja!.formIndex).toBe(baseForm); it("should not keep buffing Water Shuriken after Greninja switches to base form", async () => {
}, await game.classicMode.startBattle([ Species.GRENINJA ]);
);
const waterShuriken = allMoves[Moves.WATER_SHURIKEN];
vi.spyOn(waterShuriken, "calculateBattlePower");
let actualMultiHitType: MultiHitType | null = null;
const multiHitAttr = waterShuriken.getAttrs(MultiHitAttr)[0];
vi.spyOn(multiHitAttr, "getHitCount").mockImplementation(() => {
actualMultiHitType = multiHitAttr.getMultiHitType();
return 3;
});
// Wave 4: Use Water Shuriken in Ash form
let expectedBattlePower = 20;
let expectedMultiHitType = MultiHitType._3;
game.move.select(Moves.WATER_SHURIKEN);
await game.phaseInterceptor.to("BerryPhase", false);
expect(waterShuriken.calculateBattlePower).toHaveLastReturnedWith(expectedBattlePower);
expect(actualMultiHitType).toBe(expectedMultiHitType);
await game.doKillOpponents();
await game.toNextWave();
// Wave 5: Use Water Shuriken in base form
expectedBattlePower = 15;
expectedMultiHitType = MultiHitType._2_TO_5;
game.move.select(Moves.WATER_SHURIKEN);
await game.phaseInterceptor.to("BerryPhase", false);
expect(waterShuriken.calculateBattlePower).toHaveLastReturnedWith(expectedBattlePower);
expect(actualMultiHitType).toBe(expectedMultiHitType);
});
}); });