From 3afd43375a96800c01d1ffe0065c9c0fa0f8211e Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Wed, 5 Jul 2023 22:23:50 -0400 Subject: [PATCH] Attempt fixing some issues with move effects --- src/battle-phases.ts | 33 ++++++++++++++++++--------------- src/data/move.ts | 13 +++++++++++-- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/battle-phases.ts b/src/battle-phases.ts index 87a0c21f4..6998a0225 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -1324,23 +1324,26 @@ class MoveEffectPhase extends PokemonPhase { const hitResult = !isProtected ? target.apply(user, this.move) : HitResult.NO_EFFECT; - if (hitResult !== HitResult.NO_EFFECT && hitResult !== HitResult.FAIL) { + if (hitResult !== HitResult.FAIL) { const chargeEffect = !!this.move.getMove().getAttrs(ChargeAttr).find(ca => (ca as ChargeAttr).chargeEffect); // Charge attribute with charge effect takes all effect attributes and applies them to charge stage, so ignore them if this is present if (!chargeEffect) - applyMoveAttrs(MoveEffectAttr, user, target, this.move.getMove()); - if (hitResult < HitResult.NO_EFFECT) { - const flinched = new Utils.BooleanHolder(false); - user.scene.applyModifiers(FlinchChanceModifier, user.isPlayer(), user, flinched); - if (flinched.value) - target.addTag(BattlerTagType.FLINCHED, undefined, this.move.moveId, user.id); - } - if (!isProtected && !chargeEffect) { - applyFilteredMoveAttrs((attr: MoveAttr) => attr instanceof MoveHitEffectAttr && (!!target.hp || (attr as MoveHitEffectAttr).selfTarget), user, target, this.move.getMove()); - if (!target.isFainted()) - applyPostDefendAbAttrs(PostDefendAbAttr, target, user, this.move, hitResult); - if (this.move.getMove().hasFlag(MoveFlags.MAKES_CONTACT)) - this.scene.applyModifiers(ContactHeldItemTransferChanceModifier, this.player, user, target.getFieldIndex()); + applyFilteredMoveAttrs((attr: MoveAttr) => attr instanceof MoveEffectAttr && (attr as MoveEffectAttr).selfTarget, user, target, this.move.getMove()); + if (hitResult !== HitResult.NO_EFFECT) { + applyFilteredMoveAttrs((attr: MoveAttr) => attr instanceof MoveEffectAttr && !(attr as MoveEffectAttr).selfTarget, user, target, this.move.getMove()); + if (hitResult < HitResult.NO_EFFECT) { + const flinched = new Utils.BooleanHolder(false); + user.scene.applyModifiers(FlinchChanceModifier, user.isPlayer(), user, flinched); + if (flinched.value) + target.addTag(BattlerTagType.FLINCHED, undefined, this.move.moveId, user.id); + } + if (!isProtected && !chargeEffect) { + applyMoveAttrs(MoveHitEffectAttr, user, target, this.move.getMove()); + if (!target.isFainted()) + applyPostDefendAbAttrs(PostDefendAbAttr, target, user, this.move, hitResult); + if (this.move.getMove().hasFlag(MoveFlags.MAKES_CONTACT)) + this.scene.applyModifiers(ContactHeldItemTransferChanceModifier, this.player, user, target.getFieldIndex()); + } } } } @@ -1773,7 +1776,7 @@ export class FaintPhase extends PokemonPhase { else if (nonFaintedPartyMemberCount >= this.scene.currentBattle.getBattlerCount()) this.scene.unshiftPhase(new SwitchPhase(this.scene, this.fieldIndex, true, false)); else if (nonFaintedPartyMemberCount === 1 && this.scene.currentBattle.double) - this.scene.unshiftPhase(new ToggleDoublePositionPhase(this.scene, false)); + this.scene.unshiftPhase(new ToggleDoublePositionPhase(this.scene, true)); } else this.scene.unshiftPhase(new VictoryPhase(this.scene, this.battlerIndex)); diff --git a/src/data/move.ts b/src/data/move.ts index 4d54668b6..e85f01c35 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -849,6 +849,15 @@ export class MoveHitEffectAttr extends MoveAttr { this.selfTarget = !!selfTarget; } + + canApply(user: Pokemon, target: Pokemon, move: Move, args: any[]) { + return !!(this.selfTarget ? user.hp : target.hp) + && (this.selfTarget || !target.getTag(BattlerTagType.PROTECTED) || move.hasFlag(MoveFlags.IGNORE_PROTECT)); + } + + apply(user: Pokemon, target: Pokemon, move: Move, args: any[]) { + return this.canApply(user, target, move, args); + } } export class HighCritAttr extends MoveAttr { @@ -1333,7 +1342,7 @@ export class SolarBeamChargeAttr extends ChargeAttr { } } -export class StatChangeAttr extends MoveEffectAttr { +export class StatChangeAttr extends MoveHitEffectAttr { public stats: BattleStat[]; public levels: integer; @@ -1651,7 +1660,7 @@ export class DisableMoveAttr extends MoveEffectAttr { } } -export class FrenzyAttr extends MoveEffectAttr { +export class FrenzyAttr extends MoveHitEffectAttr { constructor() { super(true); }