mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-21 15:52:18 +02:00
Add proper type checking to RedirectMoveAbAttr
This commit is contained in:
parent
7f226df8d6
commit
85780e1472
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user