Skip to content

Commit

Permalink
[Bug] Fix critical hits not bypassing screens (#5470)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidtc1 authored Mar 6, 2025
1 parent ba617ad commit 7a9b1e5
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 19 deletions.
6 changes: 5 additions & 1 deletion src/field/pokemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2886,7 +2886,11 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {

/** Reduces damage if this Pokemon has a relevant screen (e.g. Light Screen for special attacks) */
const screenMultiplier = new Utils.NumberHolder(1);
globalScene.arena.applyTagsForSide(WeakenMoveScreenTag, defendingSide, simulated, source, moveCategory, screenMultiplier);

// Critical hits should bypass screens
if (!isCritical) {
globalScene.arena.applyTagsForSide(WeakenMoveScreenTag, defendingSide, simulated, source, moveCategory, screenMultiplier);
}

/**
* For each {@linkcode HitsTagAttr} the move has, doubles the damage of the move if:
Expand Down
41 changes: 34 additions & 7 deletions test/moves/aurora_veil.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type BattleScene from "#app/battle-scene";
import { ArenaTagSide } from "#app/data/arena-tag";
import type Move from "#app/data/move";
import { allMoves } from "#app/data/move";
import { allMoves, CritOnlyAttr } from "#app/data/move";
import { ArenaTagType } from "#app/enums/arena-tag-type";
import type Pokemon from "#app/field/pokemon";
import { TurnEndPhase } from "#app/phases/turn-end-phase";
Expand All @@ -12,7 +12,7 @@ import { Species } from "#enums/species";
import { WeatherType } from "#enums/weather-type";
import GameManager from "#test/testUtils/gameManager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";

let globalScene: BattleScene;

Expand Down Expand Up @@ -47,7 +47,7 @@ describe("Moves - Aurora Veil", () => {

it("reduces damage of physical attacks by half in a single battle", async () => {
const moveToUse = Moves.TACKLE;
await game.startBattle([ Species.SHUCKLE ]);
await game.classicMode.startBattle([ Species.SHUCKLE ]);

game.move.select(moveToUse);

Expand All @@ -61,7 +61,7 @@ describe("Moves - Aurora Veil", () => {
game.override.battleType("double");

const moveToUse = Moves.ROCK_SLIDE;
await game.startBattle([ Species.SHUCKLE, Species.SHUCKLE ]);
await game.classicMode.startBattle([ Species.SHUCKLE, Species.SHUCKLE ]);

game.move.select(moveToUse);
game.move.select(moveToUse, 1);
Expand All @@ -74,7 +74,7 @@ describe("Moves - Aurora Veil", () => {

it("reduces damage of special attacks by half in a single battle", async () => {
const moveToUse = Moves.ABSORB;
await game.startBattle([ Species.SHUCKLE ]);
await game.classicMode.startBattle([ Species.SHUCKLE ]);

game.move.select(moveToUse);

Expand All @@ -89,7 +89,7 @@ describe("Moves - Aurora Veil", () => {
game.override.battleType("double");

const moveToUse = Moves.DAZZLING_GLEAM;
await game.startBattle([ Species.SHUCKLE, Species.SHUCKLE ]);
await game.classicMode.startBattle([ Species.SHUCKLE, Species.SHUCKLE ]);

game.move.select(moveToUse);
game.move.select(moveToUse, 1);
Expand All @@ -99,6 +99,31 @@ describe("Moves - Aurora Veil", () => {

expect(mockedDmg).toBe(allMoves[moveToUse].power * doubleBattleMultiplier);
});

it("does not affect physical critical hits", async () => {
game.override.moveset([ Moves.WICKED_BLOW ]);
const moveToUse = Moves.WICKED_BLOW;
await game.classicMode.startBattle([ Species.SHUCKLE ]);

game.move.select(moveToUse);
await game.phaseInterceptor.to(TurnEndPhase);

const mockedDmg = getMockedMoveDamage(game.scene.getEnemyPokemon()!, game.scene.getPlayerPokemon()!, allMoves[moveToUse]);
expect(mockedDmg).toBe(allMoves[moveToUse].power);
});

it("does not affect critical hits", async () => {
game.override.moveset([ Moves.FROST_BREATH ]);
const moveToUse = Moves.FROST_BREATH;
vi.spyOn(allMoves[Moves.FROST_BREATH], "accuracy", "get").mockReturnValue(100);
await game.classicMode.startBattle([ Species.SHUCKLE ]);

game.move.select(moveToUse);
await game.phaseInterceptor.to(TurnEndPhase);

const mockedDmg = getMockedMoveDamage(game.scene.getEnemyPokemon()!, game.scene.getPlayerPokemon()!, allMoves[moveToUse]);
expect(mockedDmg).toBe(allMoves[moveToUse].power);
});
});

/**
Expand All @@ -115,7 +140,9 @@ const getMockedMoveDamage = (defender: Pokemon, attacker: Pokemon, move: Move) =
const side = defender.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY;

if (globalScene.arena.getTagOnSide(ArenaTagType.AURORA_VEIL, side)) {
globalScene.arena.applyTagsForSide(ArenaTagType.AURORA_VEIL, side, false, attacker, move.category, multiplierHolder);
if (move.getAttrs(CritOnlyAttr).length === 0) {
globalScene.arena.applyTagsForSide(ArenaTagType.AURORA_VEIL, side, false, attacker, move.category, multiplierHolder);
}
}

return move.power * multiplierHolder.value;
Expand Down
27 changes: 21 additions & 6 deletions test/moves/light_screen.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type BattleScene from "#app/battle-scene";
import { ArenaTagSide } from "#app/data/arena-tag";
import type Move from "#app/data/move";
import { allMoves } from "#app/data/move";
import { allMoves, CritOnlyAttr } from "#app/data/move";
import { Abilities } from "#app/enums/abilities";
import { ArenaTagType } from "#app/enums/arena-tag-type";
import type Pokemon from "#app/field/pokemon";
Expand All @@ -11,7 +11,7 @@ import { Moves } from "#enums/moves";
import { Species } from "#enums/species";
import GameManager from "#test/testUtils/gameManager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";

let globalScene: BattleScene;

Expand Down Expand Up @@ -45,7 +45,7 @@ describe("Moves - Light Screen", () => {

it("reduces damage of special attacks by half in a single battle", async () => {
const moveToUse = Moves.ABSORB;
await game.startBattle([ Species.SHUCKLE ]);
await game.classicMode.startBattle([ Species.SHUCKLE ]);

game.move.select(moveToUse);

Expand All @@ -60,7 +60,7 @@ describe("Moves - Light Screen", () => {
game.override.battleType("double");

const moveToUse = Moves.DAZZLING_GLEAM;
await game.startBattle([ Species.SHUCKLE, Species.SHUCKLE ]);
await game.classicMode.startBattle([ Species.SHUCKLE, Species.SHUCKLE ]);

game.move.select(moveToUse);
game.move.select(moveToUse, 1);
Expand All @@ -73,7 +73,7 @@ describe("Moves - Light Screen", () => {

it("does not affect physical attacks", async () => {
const moveToUse = Moves.TACKLE;
await game.startBattle([ Species.SHUCKLE ]);
await game.classicMode.startBattle([ Species.SHUCKLE ]);

game.move.select(moveToUse);

Expand All @@ -82,6 +82,19 @@ describe("Moves - Light Screen", () => {

expect(mockedDmg).toBe(allMoves[moveToUse].power);
});

it("does not affect critical hits", async () => {
game.override.moveset([ Moves.FROST_BREATH ]);
const moveToUse = Moves.FROST_BREATH;
vi.spyOn(allMoves[Moves.FROST_BREATH], "accuracy", "get").mockReturnValue(100);
await game.classicMode.startBattle([ Species.SHUCKLE ]);

game.move.select(moveToUse);
await game.phaseInterceptor.to(TurnEndPhase);

const mockedDmg = getMockedMoveDamage(game.scene.getEnemyPokemon()!, game.scene.getPlayerPokemon()!, allMoves[moveToUse]);
expect(mockedDmg).toBe(allMoves[moveToUse].power);
});
});

/**
Expand All @@ -98,7 +111,9 @@ const getMockedMoveDamage = (defender: Pokemon, attacker: Pokemon, move: Move) =
const side = defender.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY;

if (globalScene.arena.getTagOnSide(ArenaTagType.LIGHT_SCREEN, side)) {
globalScene.arena.applyTagsForSide(ArenaTagType.LIGHT_SCREEN, side, false, attacker, move.category, multiplierHolder);
if (move.getAttrs(CritOnlyAttr).length === 0) {
globalScene.arena.applyTagsForSide(ArenaTagType.LIGHT_SCREEN, side, false, attacker, move.category, multiplierHolder);
}
}

return move.power * multiplierHolder.value;
Expand Down
24 changes: 19 additions & 5 deletions test/moves/reflect.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type BattleScene from "#app/battle-scene";
import { ArenaTagSide } from "#app/data/arena-tag";
import type Move from "#app/data/move";
import { allMoves } from "#app/data/move";
import { allMoves, CritOnlyAttr } from "#app/data/move";
import { Abilities } from "#app/enums/abilities";
import { ArenaTagType } from "#app/enums/arena-tag-type";
import type Pokemon from "#app/field/pokemon";
Expand Down Expand Up @@ -45,7 +45,7 @@ describe("Moves - Reflect", () => {

it("reduces damage of physical attacks by half in a single battle", async () => {
const moveToUse = Moves.TACKLE;
await game.startBattle([ Species.SHUCKLE ]);
await game.classicMode.startBattle([ Species.SHUCKLE ]);

game.move.select(moveToUse);

Expand All @@ -59,7 +59,7 @@ describe("Moves - Reflect", () => {
game.override.battleType("double");

const moveToUse = Moves.ROCK_SLIDE;
await game.startBattle([ Species.SHUCKLE, Species.SHUCKLE ]);
await game.classicMode.startBattle([ Species.SHUCKLE, Species.SHUCKLE ]);

game.move.select(moveToUse);
game.move.select(moveToUse, 1);
Expand All @@ -72,7 +72,7 @@ describe("Moves - Reflect", () => {

it("does not affect special attacks", async () => {
const moveToUse = Moves.ABSORB;
await game.startBattle([ Species.SHUCKLE ]);
await game.classicMode.startBattle([ Species.SHUCKLE ]);

game.move.select(moveToUse);

Expand All @@ -82,6 +82,18 @@ describe("Moves - Reflect", () => {

expect(mockedDmg).toBe(allMoves[moveToUse].power);
});

it("does not affect critical hits", async () => {
game.override.moveset([ Moves.WICKED_BLOW ]);
const moveToUse = Moves.WICKED_BLOW;
await game.classicMode.startBattle([ Species.SHUCKLE ]);

game.move.select(moveToUse);
await game.phaseInterceptor.to(TurnEndPhase);

const mockedDmg = getMockedMoveDamage(game.scene.getEnemyPokemon()!, game.scene.getPlayerPokemon()!, allMoves[moveToUse]);
expect(mockedDmg).toBe(allMoves[moveToUse].power);
});
});

/**
Expand All @@ -98,7 +110,9 @@ const getMockedMoveDamage = (defender: Pokemon, attacker: Pokemon, move: Move) =
const side = defender.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY;

if (globalScene.arena.getTagOnSide(ArenaTagType.REFLECT, side)) {
globalScene.arena.applyTagsForSide(ArenaTagType.REFLECT, side, false, attacker, move.category, multiplierHolder);
if (move.getAttrs(CritOnlyAttr).length === 0) {
globalScene.arena.applyTagsForSide(ArenaTagType.REFLECT, side, false, attacker, move.category, multiplierHolder);
}
}

return move.power * multiplierHolder.value;
Expand Down

0 comments on commit 7a9b1e5

Please sign in to comment.