[P1 Bug] Fix multi lens granting infinite Future Sight hits

This commit is contained in:
Michael Li 2024-12-02 08:23:28 -05:00
parent e930536efe
commit aaef47bc7d
3 changed files with 47 additions and 5 deletions

View File

@ -56,7 +56,7 @@ import {
PokemonMultiHitModifier,
} from "#app/modifier/modifier";
import { PokemonPhase } from "#app/phases/pokemon-phase";
import { BooleanHolder, executeIf, NumberHolder } from "#app/utils";
import { BooleanHolder, executeIf, isNullOrUndefined, NumberHolder } from "#app/utils";
import { BattlerTagType } from "#enums/battler-tag-type";
import { Moves } from "#enums/moves";
import i18next from "i18next";
@ -106,7 +106,9 @@ export class MoveEffectPhase extends PokemonPhase {
*/
return super.end();
}
user.resetTurnData();
if (isNullOrUndefined(user.turnData)) {
user.resetTurnData();
}
}
}

View File

@ -1,5 +1,5 @@
import { Type } from "#enums/type";
import { BattlerTagType } from "#app/enums/battler-tag-type";
import { BattlerTagType } from "#enums/battler-tag-type";
import { toDmgValue } from "#app/utils";
import { Abilities } from "#enums/abilities";
import { Moves } from "#enums/moves";
@ -8,7 +8,7 @@ import { Stat } from "#enums/stat";
import { StatusEffect } from "#enums/status-effect";
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";
describe("Abilities - Parental Bond", () => {
@ -470,4 +470,24 @@ describe("Abilities - Parental Bond", () => {
expect(enemyPokemon.getStatStage(Stat.SPATK)).toBe(1);
}
);
it("should cause Future Sight to hit exactly twice if the user switches out", async () => {
game.override.enemyLevel(1000)
.moveset(Moves.FUTURE_SIGHT);
await game.classicMode.startBattle([ Species.BULBASAUR, Species.CHARMANDER, Species.SQUIRTLE ]);
const enemyPokemon = game.scene.getEnemyPokemon()!;
vi.spyOn(enemyPokemon, "damageAndUpdate");
game.move.select(Moves.FUTURE_SIGHT);
await game.toNextTurn();
game.doSwitchPokemon(1);
await game.toNextTurn();
game.doSwitchPokemon(2);
await game.toNextTurn();
expect(enemyPokemon.damageAndUpdate).toHaveBeenCalledTimes(2);
});
});

View File

@ -24,7 +24,7 @@ describe("Items - Multi Lens", () => {
beforeEach(() => {
game = new GameManager(phaserGame);
game.override
.moveset([ Moves.TACKLE, Moves.TRAILBLAZE, Moves.TACHYON_CUTTER ])
.moveset([ Moves.TACKLE, Moves.TRAILBLAZE, Moves.TACHYON_CUTTER, Moves.FUTURE_SIGHT ])
.ability(Abilities.BALL_FETCH)
.startingHeldItems([{ name: "MULTI_LENS" }])
.battleType("single")
@ -170,6 +170,7 @@ describe("Items - Multi Lens", () => {
await game.phaseInterceptor.to("MoveEndPhase");
expect(enemyPokemon.getHpRatio()).toBeCloseTo(0.5, 5);
});
it("should result in correct damage for hp% attacks with 2 lenses + Parental Bond", async () => {
game.override.startingHeldItems([{ name: "MULTI_LENS", count: 2 }])
.moveset(Moves.SUPER_FANG)
@ -188,4 +189,23 @@ describe("Items - Multi Lens", () => {
await game.phaseInterceptor.to("MoveEndPhase");
expect(enemyPokemon.getHpRatio()).toBeCloseTo(0.25, 5);
});
it("should cause Future Sight to hit exactly twice if the user switches out", async () => {
game.override.enemyLevel(1000);
await game.classicMode.startBattle([ Species.BULBASAUR, Species.CHARMANDER, Species.SQUIRTLE ]);
const enemyPokemon = game.scene.getEnemyPokemon()!;
vi.spyOn(enemyPokemon, "damageAndUpdate");
game.move.select(Moves.FUTURE_SIGHT);
await game.toNextTurn();
game.doSwitchPokemon(1);
await game.toNextTurn();
game.doSwitchPokemon(2);
await game.toNextTurn();
expect(enemyPokemon.damageAndUpdate).toHaveBeenCalledTimes(2);
});
});