This commit is contained in:
Dean 2025-04-09 15:47:45 -05:00 committed by GitHub
commit cf0290f8e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 92 additions and 31 deletions

View File

@ -804,27 +804,32 @@ export class MoveImmunityStatStageChangeAbAttr extends MoveImmunityAbAttr {
* @see {@linkcode applyPostDefend}
*/
export class ReverseDrainAbAttr extends PostDefendAbAttr {
private attacker: Pokemon;
/**
* 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 to be damaged instead of healed
*/
override canApplyPostDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, hitResult: HitResult | null, 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 applyPostDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, hitResult: HitResult | null, args: any[]): void {
const cancelled = new Utils.BooleanHolder(false);
applyAbAttrs(BlockNonDirectDamageAbAttr, attacker, cancelled);
if (!cancelled.value) {
const damageAmount = move.getAttrs<HitHealAttr>(HitHealAttr)[0].getHealAmount(attacker, pokemon);
pokemon.turnData.damageTaken += damageAmount;
globalScene.unshiftPhase(new PokemonHealPhase(attacker.getBattlerIndex(), -damageAmount, null, false, true));
}
}
public override getTriggerMessage(pokemon: Pokemon, _abilityName: string, ..._args: any[]): string | null {
return i18next.t("abilityTriggers:reverseDrain", { pokemonNameWithAffix: getPokemonNameWithAffix(this.attacker) });
}
}
export class PostDefendStatStageChangeAbAttr extends PostDefendAbAttr {

View File

@ -2194,28 +2194,18 @@ export class HitHealAttr extends MoveEffectAttr {
* @returns true if the function succeeds
*/
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
let healAmount = 0;
if (target.hasAbilityWithAttr(ReverseDrainAbAttr)) {
return false;
}
const healAmount = this.getHealAmount(user, target);
let message = "";
const reverseDrain = target.hasAbilityWithAttr(ReverseDrainAbAttr, false);
if (this.healStat !== null) {
// Strength Sap formula
healAmount = target.getEffectiveStat(this.healStat);
message = i18next.t("battle:drainMessage", { pokemonName: getPokemonNameWithAffix(target) });
} else {
// Default healing formula used by draining moves like Absorb, Draining Kiss, Bitter Blade, etc.
healAmount = Utils.toDmgValue(user.turnData.singleHitDamageDealt * this.healRatio);
message = i18next.t("battle:regainHealth", { pokemonName: getPokemonNameWithAffix(user) });
}
if (reverseDrain) {
if (user.hasAbilityWithAttr(BlockNonDirectDamageAbAttr)) {
healAmount = 0;
message = "";
} else {
user.turnData.damageTaken += healAmount;
healAmount = healAmount * -1;
message = "";
}
}
globalScene.unshiftPhase(new PokemonHealPhase(user.getBattlerIndex(), healAmount, message, false, true));
return true;
}
@ -2234,6 +2224,10 @@ export class HitHealAttr extends MoveEffectAttr {
}
return Math.floor(Math.max((1 - user.getHpRatio()) - 0.33, 0) * (move.power / 4));
}
public getHealAmount(user: Pokemon, target: Pokemon): number {
return (this.healStat) ? target.getEffectiveStat(this.healStat) : Utils.toDmgValue(user.turnData.singleHitDamageDealt * this.healRatio);
}
}
/**

View File

@ -627,7 +627,6 @@ export class MoveEffectPhase extends PokemonPhase {
* @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()) {

View File

@ -0,0 +1,63 @@
import { Abilities } from "#enums/abilities";
import { Moves } from "#enums/moves";
import { Species } from "#enums/species";
import GameManager from "#test/testUtils/gameManager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
describe("Abilities - Liquid Ooze", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(() => {
game = new GameManager(phaserGame);
game.override
.moveset([Moves.SPLASH, Moves.GIGA_DRAIN])
.ability(Abilities.BALL_FETCH)
.battleType("single")
.disableCrits()
.enemyLevel(20)
.enemySpecies(Species.MAGIKARP)
.enemyAbility(Abilities.LIQUID_OOZE)
.enemyMoveset(Moves.SPLASH);
});
it("should drain the attacker's HP after a draining move", async () => {
await game.classicMode.startBattle([Species.FEEBAS]);
game.move.select(Moves.GIGA_DRAIN);
await game.phaseInterceptor.to("BerryPhase");
expect(game.scene.getPlayerPokemon()?.isFullHp()).toBe(false);
});
it("should not drain the attacker's HP if it ignores indirect damage", async () => {
game.override.ability(Abilities.MAGIC_GUARD);
await game.classicMode.startBattle([Species.FEEBAS]);
game.move.select(Moves.GIGA_DRAIN);
await game.phaseInterceptor.to("BerryPhase");
expect(game.scene.getPlayerPokemon()?.isFullHp()).toBe(true);
});
it("should not apply if suppressed", async () => {
game.override.ability(Abilities.NEUTRALIZING_GAS);
await game.classicMode.startBattle([Species.FEEBAS]);
game.move.select(Moves.GIGA_DRAIN);
await game.phaseInterceptor.to("BerryPhase");
expect(game.scene.getPlayerPokemon()?.isFullHp()).toBe(true);
});
});