mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-05-05 16:05:01 +01:00
[Bug] Fix #5358 Abilities that Redirect Moves Consider Move-Typings before Ability Modifiers (#5464)
This commit is contained in:
parent
572556b7b9
commit
929392fe8b
@ -4571,9 +4571,19 @@ export class PostFaintHPDamageAbAttr extends PostFaintAbAttr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redirects a move to the pokemon with this ability if it meets the conditions
|
||||||
|
*/
|
||||||
export class RedirectMoveAbAttr extends AbAttr {
|
export class RedirectMoveAbAttr extends AbAttr {
|
||||||
|
/**
|
||||||
|
* @param pokemon - The Pokemon with the redirection ability
|
||||||
|
* @param args - The args passed to the `AbAttr`:
|
||||||
|
* - `[0]` - The id of the {@linkcode Move} used
|
||||||
|
* - `[1]` - The target's battler index (before redirection)
|
||||||
|
* - `[2]` - The Pokemon that used the move being redirected
|
||||||
|
*/
|
||||||
apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): boolean {
|
apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): boolean {
|
||||||
if (this.canRedirect(args[0] as Moves)) {
|
if (this.canRedirect(args[0] as Moves, args[2] as Pokemon)) {
|
||||||
const target = args[1] as Utils.NumberHolder;
|
const target = args[1] as Utils.NumberHolder;
|
||||||
const newTarget = pokemon.getBattlerIndex();
|
const newTarget = pokemon.getBattlerIndex();
|
||||||
if (target.value !== newTarget) {
|
if (target.value !== newTarget) {
|
||||||
@ -4585,7 +4595,7 @@ export class RedirectMoveAbAttr extends AbAttr {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
canRedirect(moveId: Moves): boolean {
|
canRedirect(moveId: Moves, user: Pokemon): boolean {
|
||||||
const move = allMoves[moveId];
|
const move = allMoves[moveId];
|
||||||
return !![ MoveTarget.NEAR_OTHER, MoveTarget.OTHER ].find(t => move.moveTarget === t);
|
return !![ MoveTarget.NEAR_OTHER, MoveTarget.OTHER ].find(t => move.moveTarget === t);
|
||||||
}
|
}
|
||||||
@ -4599,8 +4609,8 @@ export class RedirectTypeMoveAbAttr extends RedirectMoveAbAttr {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
canRedirect(moveId: Moves): boolean {
|
canRedirect(moveId: Moves, user: Pokemon): boolean {
|
||||||
return super.canRedirect(moveId) && allMoves[moveId].type === this.type;
|
return super.canRedirect(moveId, user) && user.getMoveType(allMoves[moveId]) === this.type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,7 +504,7 @@ export class MovePhase extends BattlePhase {
|
|||||||
globalScene
|
globalScene
|
||||||
.getField(true)
|
.getField(true)
|
||||||
.filter(p => p !== this.pokemon)
|
.filter(p => p !== this.pokemon)
|
||||||
.forEach(p => applyAbAttrs(RedirectMoveAbAttr, p, null, false, this.move.moveId, redirectTarget));
|
.forEach(p => applyAbAttrs(RedirectMoveAbAttr, p, null, false, this.move.moveId, redirectTarget, this.pokemon));
|
||||||
|
|
||||||
/** `true` if an Ability is responsible for redirecting the move to another target; `false` otherwise */
|
/** `true` if an Ability is responsible for redirecting the move to another target; `false` otherwise */
|
||||||
let redirectedByAbility = currentTarget !== redirectTarget.value;
|
let redirectedByAbility = currentTarget !== redirectTarget.value;
|
||||||
|
115
test/abilities/lightningrod.test.ts
Normal file
115
test/abilities/lightningrod.test.ts
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
import { BattlerIndex } from "#app/battle";
|
||||||
|
import { Abilities } from "#enums/abilities";
|
||||||
|
import { Moves } from "#enums/moves";
|
||||||
|
import { Species } from "#enums/species";
|
||||||
|
import { Stat } from "#enums/stat";
|
||||||
|
import GameManager from "#test/testUtils/gameManager";
|
||||||
|
import Phaser from "phaser";
|
||||||
|
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
describe("Abilities - Lightningrod", () => {
|
||||||
|
let phaserGame: Phaser.Game;
|
||||||
|
let game: GameManager;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
phaserGame = new Phaser.Game({
|
||||||
|
type: Phaser.HEADLESS,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
game.phaseInterceptor.restoreOg();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
game = new GameManager(phaserGame);
|
||||||
|
game.override
|
||||||
|
.moveset([ Moves.SPLASH, Moves.SHOCK_WAVE ])
|
||||||
|
.ability(Abilities.BALL_FETCH)
|
||||||
|
.battleType("double")
|
||||||
|
.disableCrits()
|
||||||
|
.enemySpecies(Species.MAGIKARP)
|
||||||
|
.enemyAbility(Abilities.BALL_FETCH)
|
||||||
|
.enemyMoveset(Moves.SPLASH);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should redirect electric type moves", async () => {
|
||||||
|
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]);
|
||||||
|
|
||||||
|
const enemy1 = game.scene.getEnemyField()[0];
|
||||||
|
const enemy2 = game.scene.getEnemyField()[1];
|
||||||
|
|
||||||
|
enemy2.summonData.ability = Abilities.LIGHTNING_ROD;
|
||||||
|
|
||||||
|
game.move.select(Moves.SHOCK_WAVE, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
|
||||||
|
game.move.select(Moves.SPLASH, BattlerIndex.PLAYER_2);
|
||||||
|
await game.phaseInterceptor.to("BerryPhase");
|
||||||
|
|
||||||
|
expect(enemy1.isFullHp()).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not redirect non-electric type moves", async () => {
|
||||||
|
game.override.moveset([ Moves.SPLASH, Moves.AERIAL_ACE ]);
|
||||||
|
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]);
|
||||||
|
|
||||||
|
const enemy1 = game.scene.getEnemyField()[0];
|
||||||
|
const enemy2 = game.scene.getEnemyField()[1];
|
||||||
|
|
||||||
|
enemy2.summonData.ability = Abilities.LIGHTNING_ROD;
|
||||||
|
|
||||||
|
game.move.select(Moves.AERIAL_ACE, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
|
||||||
|
game.move.select(Moves.SPLASH, BattlerIndex.PLAYER_2);
|
||||||
|
await game.phaseInterceptor.to("BerryPhase");
|
||||||
|
|
||||||
|
expect(enemy1.isFullHp()).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should boost the user's spatk without damaging", async () => {
|
||||||
|
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]);
|
||||||
|
|
||||||
|
const enemy2 = game.scene.getEnemyField()[1];
|
||||||
|
|
||||||
|
enemy2.summonData.ability = Abilities.LIGHTNING_ROD;
|
||||||
|
|
||||||
|
game.move.select(Moves.SHOCK_WAVE, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
|
||||||
|
game.move.select(Moves.SPLASH, BattlerIndex.PLAYER_2);
|
||||||
|
await game.phaseInterceptor.to("BerryPhase");
|
||||||
|
|
||||||
|
expect(enemy2.isFullHp()).toBe(true);
|
||||||
|
expect(enemy2.getStatStage(Stat.SPATK)).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not redirect moves changed from electric type via ability", async () => {
|
||||||
|
game.override.ability(Abilities.NORMALIZE);
|
||||||
|
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]);
|
||||||
|
|
||||||
|
const enemy1 = game.scene.getEnemyField()[0];
|
||||||
|
const enemy2 = game.scene.getEnemyField()[1];
|
||||||
|
|
||||||
|
enemy2.summonData.ability = Abilities.LIGHTNING_ROD;
|
||||||
|
|
||||||
|
game.move.select(Moves.SHOCK_WAVE, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
|
||||||
|
game.move.select(Moves.SPLASH, BattlerIndex.PLAYER_2);
|
||||||
|
await game.phaseInterceptor.to("BerryPhase");
|
||||||
|
|
||||||
|
expect(enemy1.isFullHp()).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should redirect moves changed to electric type via ability", async () => {
|
||||||
|
game.override.ability(Abilities.GALVANIZE)
|
||||||
|
.moveset(Moves.TACKLE);
|
||||||
|
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]);
|
||||||
|
|
||||||
|
const enemy1 = game.scene.getEnemyField()[0];
|
||||||
|
const enemy2 = game.scene.getEnemyField()[1];
|
||||||
|
|
||||||
|
enemy2.summonData.ability = Abilities.LIGHTNING_ROD;
|
||||||
|
|
||||||
|
game.move.select(Moves.TACKLE, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
|
||||||
|
game.move.select(Moves.SPLASH, BattlerIndex.PLAYER_2);
|
||||||
|
await game.phaseInterceptor.to("BerryPhase");
|
||||||
|
|
||||||
|
expect(enemy1.isFullHp()).toBe(true);
|
||||||
|
expect(enemy2.getStatStage(Stat.SPATK)).toBe(1);
|
||||||
|
});
|
||||||
|
});
|
115
test/abilities/storm_drain.test.ts
Normal file
115
test/abilities/storm_drain.test.ts
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
import { BattlerIndex } from "#app/battle";
|
||||||
|
import { Abilities } from "#enums/abilities";
|
||||||
|
import { Moves } from "#enums/moves";
|
||||||
|
import { Species } from "#enums/species";
|
||||||
|
import { Stat } from "#enums/stat";
|
||||||
|
import GameManager from "#test/testUtils/gameManager";
|
||||||
|
import Phaser from "phaser";
|
||||||
|
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
describe("Abilities - Storm Drain", () => {
|
||||||
|
let phaserGame: Phaser.Game;
|
||||||
|
let game: GameManager;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
phaserGame = new Phaser.Game({
|
||||||
|
type: Phaser.HEADLESS,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
game.phaseInterceptor.restoreOg();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
game = new GameManager(phaserGame);
|
||||||
|
game.override
|
||||||
|
.moveset([ Moves.SPLASH, Moves.WATER_GUN ])
|
||||||
|
.ability(Abilities.BALL_FETCH)
|
||||||
|
.battleType("double")
|
||||||
|
.disableCrits()
|
||||||
|
.enemySpecies(Species.MAGIKARP)
|
||||||
|
.enemyAbility(Abilities.BALL_FETCH)
|
||||||
|
.enemyMoveset(Moves.SPLASH);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should redirect water type moves", async () => {
|
||||||
|
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]);
|
||||||
|
|
||||||
|
const enemy1 = game.scene.getEnemyField()[0];
|
||||||
|
const enemy2 = game.scene.getEnemyField()[1];
|
||||||
|
|
||||||
|
enemy2.summonData.ability = Abilities.STORM_DRAIN;
|
||||||
|
|
||||||
|
game.move.select(Moves.WATER_GUN, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
|
||||||
|
game.move.select(Moves.SPLASH, BattlerIndex.PLAYER_2);
|
||||||
|
await game.phaseInterceptor.to("BerryPhase");
|
||||||
|
|
||||||
|
expect(enemy1.isFullHp()).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not redirect non-water type moves", async () => {
|
||||||
|
game.override.moveset([ Moves.SPLASH, Moves.AERIAL_ACE ]);
|
||||||
|
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]);
|
||||||
|
|
||||||
|
const enemy1 = game.scene.getEnemyField()[0];
|
||||||
|
const enemy2 = game.scene.getEnemyField()[1];
|
||||||
|
|
||||||
|
enemy2.summonData.ability = Abilities.STORM_DRAIN;
|
||||||
|
|
||||||
|
game.move.select(Moves.AERIAL_ACE, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
|
||||||
|
game.move.select(Moves.SPLASH, BattlerIndex.PLAYER_2);
|
||||||
|
await game.phaseInterceptor.to("BerryPhase");
|
||||||
|
|
||||||
|
expect(enemy1.isFullHp()).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should boost the user's spatk without damaging", async () => {
|
||||||
|
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]);
|
||||||
|
|
||||||
|
const enemy2 = game.scene.getEnemyField()[1];
|
||||||
|
|
||||||
|
enemy2.summonData.ability = Abilities.STORM_DRAIN;
|
||||||
|
|
||||||
|
game.move.select(Moves.WATER_GUN, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
|
||||||
|
game.move.select(Moves.SPLASH, BattlerIndex.PLAYER_2);
|
||||||
|
await game.phaseInterceptor.to("BerryPhase");
|
||||||
|
|
||||||
|
expect(enemy2.isFullHp()).toBe(true);
|
||||||
|
expect(enemy2.getStatStage(Stat.SPATK)).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not redirect moves changed from water type via ability", async () => {
|
||||||
|
game.override.ability(Abilities.NORMALIZE);
|
||||||
|
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]);
|
||||||
|
|
||||||
|
const enemy1 = game.scene.getEnemyField()[0];
|
||||||
|
const enemy2 = game.scene.getEnemyField()[1];
|
||||||
|
|
||||||
|
enemy2.summonData.ability = Abilities.STORM_DRAIN;
|
||||||
|
|
||||||
|
game.move.select(Moves.WATER_GUN, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
|
||||||
|
game.move.select(Moves.SPLASH, BattlerIndex.PLAYER_2);
|
||||||
|
await game.phaseInterceptor.to("BerryPhase");
|
||||||
|
|
||||||
|
expect(enemy1.isFullHp()).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should redirect moves changed to water type via ability", async () => {
|
||||||
|
game.override.ability(Abilities.LIQUID_VOICE)
|
||||||
|
.moveset(Moves.PSYCHIC_NOISE);
|
||||||
|
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]);
|
||||||
|
|
||||||
|
const enemy1 = game.scene.getEnemyField()[0];
|
||||||
|
const enemy2 = game.scene.getEnemyField()[1];
|
||||||
|
|
||||||
|
enemy2.summonData.ability = Abilities.STORM_DRAIN;
|
||||||
|
|
||||||
|
game.move.select(Moves.PSYCHIC_NOISE, BattlerIndex.PLAYER, BattlerIndex.ENEMY);
|
||||||
|
game.move.select(Moves.SPLASH, BattlerIndex.PLAYER_2);
|
||||||
|
await game.phaseInterceptor.to("BerryPhase");
|
||||||
|
|
||||||
|
expect(enemy1.isFullHp()).toBe(true);
|
||||||
|
expect(enemy2.getStatStage(Stat.SPATK)).toBe(1);
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user