diff --git a/src/data/ability.ts b/src/data/ability.ts index ab78d1dd06c..dac5ae2eaba 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -776,29 +776,28 @@ export class MoveImmunityStatStageChangeAbAttr extends MoveImmunityAbAttr { /** * Class for abilities that make drain moves deal damage to user instead of healing them. * @extends PostDefendAbAttr - * @see {@linkcode applyPostDefend} + * @see {@linkcode applyPreDefend} */ -export class ReverseDrainAbAttr extends PostDefendAbAttr { +export class ReverseDrainAbAttr extends PreDefendAbAttr { + private attacker: Pokemon; - override canApplyPostDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, hitResult: HitResult | null, args: any[]): boolean { + /** + * Determines if a damage and draining move was used + * Examples include: Absorb, Draining Kiss, Bitter Blade, etc. + * + * If so, this ability should cause the move user should be damaged instead of healed + */ + override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder, args: any[]): boolean { + this.attacker = attacker; return move.hasAttr(HitHealAttr) && !move.hitsSubstitute(attacker, pokemon); } - /** - * Determines if a damage and draining move was used to check if this ability should stop the healing. - * Examples include: Absorb, Draining Kiss, Bitter Blade, etc. - * Also displays a message to show this ability was activated. - * @param pokemon {@linkcode Pokemon} with this ability - * @param _passive N/A - * @param attacker {@linkcode Pokemon} that is attacking this Pokemon - * @param move {@linkcode PokemonMove} that is being used - * @param _hitResult N/A - * @param _args N/A - */ - override applyPostDefend(pokemon: Pokemon, _passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, _hitResult: HitResult, _args: any[]): void { - if (!simulated) { - globalScene.queueMessage(i18next.t("abilityTriggers:reverseDrain", { pokemonNameWithAffix: getPokemonNameWithAffix(attacker) })); - } + override applyPreDefend(pokemon: Pokemon, _passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder, args: any[]): void { + cancelled.value = true; + } + + public override getTriggerMessage(pokemon: Pokemon, _abilityName: string, ..._args: any[]): string | null { + return i18next.t("abilityTriggers:reverseDrain", { pokemonNameWithAffix: getPokemonNameWithAffix(this.attacker) }); } } diff --git a/src/data/moves/move.ts b/src/data/moves/move.ts index f2157ab65b7..f11d8fe2688 100644 --- a/src/data/moves/move.ts +++ b/src/data/moves/move.ts @@ -2176,7 +2176,8 @@ export class HitHealAttr extends MoveEffectAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { let healAmount = 0; let message = ""; - const reverseDrain = target.hasAbilityWithAttr(ReverseDrainAbAttr, false); + const reverseDrain = new Utils.BooleanHolder(false); + applyPreDefendAbAttrs(ReverseDrainAbAttr, target, user, move, reverseDrain); if (this.healStat !== null) { // Strength Sap formula healAmount = target.getEffectiveStat(this.healStat); @@ -2186,7 +2187,7 @@ export class HitHealAttr extends MoveEffectAttr { healAmount = Utils.toDmgValue(user.turnData.singleHitDamageDealt * this.healRatio); message = i18next.t("battle:regainHealth", { pokemonName: getPokemonNameWithAffix(user) }); } - if (reverseDrain) { + if (reverseDrain.value) { if (user.hasAbilityWithAttr(BlockNonDirectDamageAbAttr)) { healAmount = 0; message = ""; diff --git a/src/phases/move-effect-phase.ts b/src/phases/move-effect-phase.ts index 4152fc243f0..29874348bc8 100644 --- a/src/phases/move-effect-phase.ts +++ b/src/phases/move-effect-phase.ts @@ -608,11 +608,10 @@ export class MoveEffectPhase extends PokemonPhase { /** * Applies reactive effects that occur when a Pokémon is hit. - * (i.e. Effect Spore, Disguise, Liquid Ooze, Beak Blast) + * (i.e. Effect Spore, Disguise, Beak Blast) * @param user - The {@linkcode Pokemon} using this phase's invoked move * @param target - {@linkcode Pokemon} the current target of this phase's invoked move * @param hitResult - The {@linkcode HitResult} of the attempted move - * @returns a `Promise` intended to be passed into a `then()` call. */ protected applyOnGetHitAbEffects(user: Pokemon, target: Pokemon, hitResult: HitResult): void { if (!target.isFainted() || target.canApplyAbility()) {