From 85780e1472d49293cfc2a3ae02fae0fa9331b0da Mon Sep 17 00:00:00 2001 From: Dean Date: Sat, 1 Mar 2025 01:26:52 -0800 Subject: [PATCH] Add proper type checking to RedirectMoveAbAttr --- src/data/ability.ts | 17 +++++++++++++---- src/phases/move-phase.ts | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index 0b4e5ddb2c4..02fe2c5704c 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -4571,9 +4571,18 @@ export class PostFaintHPDamageAbAttr extends PostFaintAbAttr { } } +/** + * Redirects a move to the pokemon with this ability if it meets the conditions + * + * @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 + */ export class RedirectMoveAbAttr extends AbAttr { 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 newTarget = pokemon.getBattlerIndex(); if (target.value !== newTarget) { @@ -4585,7 +4594,7 @@ export class RedirectMoveAbAttr extends AbAttr { return false; } - canRedirect(moveId: Moves): boolean { + canRedirect(moveId: Moves, user: Pokemon): boolean { const move = allMoves[moveId]; return !![ MoveTarget.NEAR_OTHER, MoveTarget.OTHER ].find(t => move.moveTarget === t); } @@ -4599,8 +4608,8 @@ export class RedirectTypeMoveAbAttr extends RedirectMoveAbAttr { this.type = type; } - canRedirect(moveId: Moves): boolean { - return super.canRedirect(moveId) && allMoves[moveId].type === this.type; + canRedirect(moveId: Moves, user: Pokemon): boolean { + return super.canRedirect(moveId, user) && user.getMoveType(allMoves[moveId]) === this.type; } } diff --git a/src/phases/move-phase.ts b/src/phases/move-phase.ts index 16802f8e0ff..f8edaa56981 100644 --- a/src/phases/move-phase.ts +++ b/src/phases/move-phase.ts @@ -504,7 +504,7 @@ export class MovePhase extends BattlePhase { globalScene .getField(true) .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 */ let redirectedByAbility = currentTarget !== redirectTarget.value;