diff --git a/src/phases/faint-phase.ts b/src/phases/faint-phase.ts index dc9d67c740f..60dbbbfea0f 100644 --- a/src/phases/faint-phase.ts +++ b/src/phases/faint-phase.ts @@ -30,12 +30,12 @@ export class FaintPhase extends PokemonPhase { /** * Destiny Bond tag belonging to the currently fainting Pokemon, if applicable */ - private destinyTag: DestinyBondTag | undefined; + private destinyTag?: DestinyBondTag; /** - * The source that dealt fatal damage and should get KO'd by Destiny Bond, if applicable + * The source Pokemon that dealt fatal damage and should get KO'd by Destiny Bond, if applicable */ - private source: Pokemon | undefined; + private source?: Pokemon; constructor(scene: BattleScene, battlerIndex: BattlerIndex, preventEndure: boolean = false, destinyTag?: DestinyBondTag, source?: Pokemon) { super(scene, battlerIndex); diff --git a/src/test/moves/destiny_bond.test.ts b/src/test/moves/destiny_bond.test.ts index 98c798f7587..4b4c8782862 100644 --- a/src/test/moves/destiny_bond.test.ts +++ b/src/test/moves/destiny_bond.test.ts @@ -43,7 +43,7 @@ describe("Moves - Destiny Bond", () => { it("should KO the opponent on the same turn", async () => { const moveToUse = Moves.TACKLE; - vi.spyOn(allMoves[moveToUse], "accuracy", "get").mockReturnValue(100); + game.override.moveset(moveToUse); await game.classicMode.startBattle(defaultParty); @@ -60,7 +60,7 @@ describe("Moves - Destiny Bond", () => { it("should KO the opponent on the next turn", async () => { const moveToUse = Moves.TACKLE; - vi.spyOn(allMoves[moveToUse], "accuracy", "get").mockReturnValue(100); + game.override.moveset([ Moves.SPLASH, moveToUse ]); await game.classicMode.startBattle(defaultParty); @@ -86,7 +86,7 @@ describe("Moves - Destiny Bond", () => { it("should fail if used twice in a row", async () => { const moveToUse = Moves.TACKLE; - vi.spyOn(allMoves[moveToUse], "accuracy", "get").mockReturnValue(100); + game.override.moveset([ Moves.SPLASH, moveToUse ]); await game.classicMode.startBattle(defaultParty); @@ -113,7 +113,7 @@ describe("Moves - Destiny Bond", () => { it("should not KO the opponent if the user dies to weather", async () => { // Opponent will be reduced to 1 HP by False Swipe, then faint to Sandstorm const moveToUse = Moves.FALSE_SWIPE; - vi.spyOn(allMoves[moveToUse], "accuracy", "get").mockReturnValue(100); + game.override.moveset(moveToUse) .ability(Abilities.SAND_STREAM); await game.classicMode.startBattle(defaultParty); @@ -131,7 +131,7 @@ describe("Moves - Destiny Bond", () => { it("should not KO the opponent if the user had another turn", async () => { const moveToUse = Moves.TACKLE; - vi.spyOn(allMoves[moveToUse], "accuracy", "get").mockReturnValue(100); + game.override.moveset([ Moves.SPORE, moveToUse ]); await game.classicMode.startBattle(defaultParty); @@ -157,9 +157,7 @@ describe("Moves - Destiny Bond", () => { }); it("should not KO an ally", async () => { - const movesToUse = [ Moves.DESTINY_BOND, Moves.CRUNCH ]; - vi.spyOn(allMoves[movesToUse[1]], "accuracy", "get").mockReturnValue(100); - game.override.moveset(movesToUse) + game.override.moveset([ Moves.DESTINY_BOND, Moves.CRUNCH ]) .battleType("double"); await game.classicMode.startBattle([ Species.SHEDINJA, Species.BULBASAUR, Species.SQUIRTLE ]); @@ -168,9 +166,10 @@ describe("Moves - Destiny Bond", () => { const playerPokemon0 = game.scene.getPlayerField()[0]; const playerPokemon1 = game.scene.getPlayerField()[1]; - game.move.select(movesToUse[0], 0); - game.move.select(movesToUse[1], 1, BattlerIndex.PLAYER); - await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER, BattlerIndex.PLAYER_2 ]); + // Shedinja uses Destiny Bond, then ally Bulbasaur KO's Shedinja with Crunch + game.move.select(Moves.DESTINY_BOND, 0); + game.move.select(Moves.CRUNCH, 1, BattlerIndex.PLAYER); + await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2 ]); await game.phaseInterceptor.to("BerryPhase"); expect(enemyPokemon0?.isFainted()).toBe(false); @@ -182,6 +181,7 @@ describe("Moves - Destiny Bond", () => { it("should not cause a crash if the user is KO'd by Ceaseless Edge", async () => { const moveToUse = Moves.CEASELESS_EDGE; vi.spyOn(allMoves[moveToUse], "accuracy", "get").mockReturnValue(100); + game.override.moveset(moveToUse); await game.classicMode.startBattle(defaultParty); @@ -202,10 +202,7 @@ describe("Moves - Destiny Bond", () => { }); it("should not cause a crash if the user is KO'd by Pledge moves", async () => { - const movesToUse = [ Moves.GRASS_PLEDGE, Moves.WATER_PLEDGE ]; - vi.spyOn(allMoves[movesToUse[0]], "accuracy", "get").mockReturnValue(100); - vi.spyOn(allMoves[movesToUse[1]], "accuracy", "get").mockReturnValue(100); - game.override.moveset(movesToUse) + game.override.moveset([ Moves.GRASS_PLEDGE, Moves.WATER_PLEDGE ]) .battleType("double"); await game.classicMode.startBattle(defaultParty); @@ -214,8 +211,8 @@ describe("Moves - Destiny Bond", () => { const playerPokemon0 = game.scene.getPlayerField()[0]; const playerPokemon1 = game.scene.getPlayerField()[1]; - game.move.select(movesToUse[0], 0, BattlerIndex.ENEMY); - game.move.select(movesToUse[1], 1, BattlerIndex.ENEMY); + game.move.select(Moves.GRASS_PLEDGE, 0, BattlerIndex.ENEMY); + game.move.select(Moves.WATER_PLEDGE, 1, BattlerIndex.ENEMY); await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER, BattlerIndex.PLAYER_2 ]); await game.phaseInterceptor.to("BerryPhase"); @@ -236,7 +233,7 @@ describe("Moves - Destiny Bond", () => { */ it("should not allow the opponent to revive via Reviver Seed", async () => { const moveToUse = Moves.TACKLE; - vi.spyOn(allMoves[moveToUse], "accuracy", "get").mockReturnValue(100); + game.override.moveset(moveToUse) .startingHeldItems([{ name: "REVIVER_SEED" }]); await game.classicMode.startBattle(defaultParty);