Attempt fixing some issues with move effects

This commit is contained in:
Flashfyre 2023-07-05 22:23:50 -04:00
parent 68282d28da
commit 3afd43375a
2 changed files with 29 additions and 17 deletions

View File

@ -1324,11 +1324,13 @@ class MoveEffectPhase extends PokemonPhase {
const hitResult = !isProtected ? target.apply(user, this.move) : HitResult.NO_EFFECT; 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); 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 // Charge attribute with charge effect takes all effect attributes and applies them to charge stage, so ignore them if this is present
if (!chargeEffect) if (!chargeEffect)
applyMoveAttrs(MoveEffectAttr, user, target, this.move.getMove()); 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) { if (hitResult < HitResult.NO_EFFECT) {
const flinched = new Utils.BooleanHolder(false); const flinched = new Utils.BooleanHolder(false);
user.scene.applyModifiers(FlinchChanceModifier, user.isPlayer(), user, flinched); user.scene.applyModifiers(FlinchChanceModifier, user.isPlayer(), user, flinched);
@ -1336,7 +1338,7 @@ class MoveEffectPhase extends PokemonPhase {
target.addTag(BattlerTagType.FLINCHED, undefined, this.move.moveId, user.id); target.addTag(BattlerTagType.FLINCHED, undefined, this.move.moveId, user.id);
} }
if (!isProtected && !chargeEffect) { if (!isProtected && !chargeEffect) {
applyFilteredMoveAttrs((attr: MoveAttr) => attr instanceof MoveHitEffectAttr && (!!target.hp || (attr as MoveHitEffectAttr).selfTarget), user, target, this.move.getMove()); applyMoveAttrs(MoveHitEffectAttr, user, target, this.move.getMove());
if (!target.isFainted()) if (!target.isFainted())
applyPostDefendAbAttrs(PostDefendAbAttr, target, user, this.move, hitResult); applyPostDefendAbAttrs(PostDefendAbAttr, target, user, this.move, hitResult);
if (this.move.getMove().hasFlag(MoveFlags.MAKES_CONTACT)) if (this.move.getMove().hasFlag(MoveFlags.MAKES_CONTACT))
@ -1344,6 +1346,7 @@ class MoveEffectPhase extends PokemonPhase {
} }
} }
} }
}
this.end(); this.end();
}); });
}); });
@ -1773,7 +1776,7 @@ export class FaintPhase extends PokemonPhase {
else if (nonFaintedPartyMemberCount >= this.scene.currentBattle.getBattlerCount()) else if (nonFaintedPartyMemberCount >= this.scene.currentBattle.getBattlerCount())
this.scene.unshiftPhase(new SwitchPhase(this.scene, this.fieldIndex, true, false)); this.scene.unshiftPhase(new SwitchPhase(this.scene, this.fieldIndex, true, false));
else if (nonFaintedPartyMemberCount === 1 && this.scene.currentBattle.double) 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 } else
this.scene.unshiftPhase(new VictoryPhase(this.scene, this.battlerIndex)); this.scene.unshiftPhase(new VictoryPhase(this.scene, this.battlerIndex));

View File

@ -849,6 +849,15 @@ export class MoveHitEffectAttr extends MoveAttr {
this.selfTarget = !!selfTarget; 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 { 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 stats: BattleStat[];
public levels: integer; public levels: integer;
@ -1651,7 +1660,7 @@ export class DisableMoveAttr extends MoveEffectAttr {
} }
} }
export class FrenzyAttr extends MoveEffectAttr { export class FrenzyAttr extends MoveHitEffectAttr {
constructor() { constructor() {
super(true); super(true);
} }