Add/update code from previous PR

This commit is contained in:
NightKev 2024-09-15 23:58:39 -07:00
parent 0a475849fc
commit b990e57d78
3 changed files with 164 additions and 4 deletions

View File

@ -2186,11 +2186,11 @@ export class HealBlockTag extends BattlerTag {
super(BattlerTagType.HEAL_BLOCK, BattlerTagLapseType.TURN_END, 5, Moves.HEAL_BLOCK); super(BattlerTagType.HEAL_BLOCK, BattlerTagLapseType.TURN_END, 5, Moves.HEAL_BLOCK);
} }
onAdd(pokemon: Pokemon): void { override onAdd(pokemon: Pokemon): void {
super.onAdd(pokemon); super.onAdd(pokemon);
} }
lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { override lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean {
return super.lapse(pokemon, lapseType); return super.lapse(pokemon, lapseType);
} }
@ -2198,7 +2198,7 @@ export class HealBlockTag extends BattlerTag {
return i18next.t("battle:battlerTagsHealBlock", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }); return i18next.t("battle:battlerTagsHealBlock", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) });
} }
onRemove(pokemon: Pokemon): void { override onRemove(pokemon: Pokemon): void {
super.onRemove(pokemon); super.onRemove(pokemon);
pokemon.scene.queueMessage(i18next.t("battle:battlerTagsHealBlockOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), null, false, null); pokemon.scene.queueMessage(i18next.t("battle:battlerTagsHealBlockOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), null, false, null);

View File

@ -10,6 +10,8 @@ import { HealAchv } from "#app/system/achv";
import i18next from "i18next"; import i18next from "i18next";
import * as Utils from "#app/utils"; import * as Utils from "#app/utils";
import { CommonAnimPhase } from "./common-anim-phase"; import { CommonAnimPhase } from "./common-anim-phase";
import { BattlerTagType } from "#app/enums/battler-tag-type";
import { HealBlockTag } from "#app/data/battler-tags";
export class PokemonHealPhase extends CommonAnimPhase { export class PokemonHealPhase extends CommonAnimPhase {
private hpHealed: integer; private hpHealed: integer;
@ -50,9 +52,14 @@ export class PokemonHealPhase extends CommonAnimPhase {
const hasMessage = !!this.message; const hasMessage = !!this.message;
const healOrDamage = (!pokemon.isFullHp() || this.hpHealed < 0); const healOrDamage = (!pokemon.isFullHp() || this.hpHealed < 0);
const healBlock = pokemon.getTag(BattlerTagType.HEAL_BLOCK) as HealBlockTag;
let lastStatusEffect = StatusEffect.NONE; let lastStatusEffect = StatusEffect.NONE;
if (healOrDamage) { if (healBlock && this.hpHealed > 0) {
this.scene.queueMessage(healBlock.onActivation(pokemon));
this.message = null;
super.end();
} else if (healOrDamage) {
const hpRestoreMultiplier = new Utils.IntegerHolder(1); const hpRestoreMultiplier = new Utils.IntegerHolder(1);
if (!this.revive) { if (!this.revive) {
this.scene.applyModifiers(HealingBoosterModifier, this.player, hpRestoreMultiplier); this.scene.applyModifiers(HealingBoosterModifier, this.player, hpRestoreMultiplier);

View File

@ -0,0 +1,153 @@
import { BattlerIndex } from "#app/battle";
import { ArenaTagSide } from "#app/data/arena-tag";
import { WeatherType } from "#app/data/weather";
import GameManager from "#app/test/utils/gameManager";
import { Abilities } from "#enums/abilities";
import { ArenaTagType } from "#enums/arena-tag-type";
import { BattlerTagType } from "#enums/battler-tag-type";
import { Moves } from "#enums/moves";
import { Species } from "#enums/species";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
const TIMEOUT = 20 * 1000;
// Bulbapedia Reference: https://bulbapedia.bulbagarden.net/wiki/Heal_Block_(move)
describe("Moves - Heal Block", () => {
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.ABSORB, Moves.WISH, Moves.SPLASH, Moves.AQUA_RING])
.enemyMoveset(Moves.HEAL_BLOCK)
.ability(Abilities.NO_GUARD)
.enemyAbility(Abilities.BALL_FETCH)
.enemySpecies(Species.BLISSEY)
.disableCrits();
});
it("shouldn't stop damage from HP-drain attacks, just HP restoration", async() => {
await game.classicMode.startBattle([Species.CHARIZARD]);
const player = game.scene.getPlayerPokemon()!;
const enemy = game.scene.getEnemyPokemon()!;
player.damageAndUpdate(enemy.getMaxHp() - 1);
game.move.select(Moves.ABSORB);
await game.setTurnOrder([BattlerIndex.ENEMY, BattlerIndex.PLAYER]);
await game.phaseInterceptor.to("TurnEndPhase");
expect(player.hp).toBe(1);
expect(enemy.hp).toBeLessThan(enemy.getMaxHp());
}, TIMEOUT
);
it("shouldn't stop Liquid Ooze from dealing damage", async() => {
game.override.enemyAbility(Abilities.LIQUID_OOZE);
await game.classicMode.startBattle([Species.CHARIZARD]);
const player = game.scene.getPlayerPokemon()!;
const enemy = game.scene.getEnemyPokemon()!;
game.move.select(Moves.ABSORB);
await game.setTurnOrder([BattlerIndex.ENEMY, BattlerIndex.PLAYER]);
await game.phaseInterceptor.to("TurnEndPhase");
expect(player.isFullHp()).toBe(false);
expect(enemy.isFullHp()).toBe(false);
}, TIMEOUT);
it("should stop delayed heals, such as from Wish", async() => {
await game.classicMode.startBattle([Species.CHARIZARD]);
const player = game.scene.getPlayerPokemon()!;
player.damageAndUpdate(player.getMaxHp() - 1);
game.move.select(Moves.WISH);
await game.phaseInterceptor.to("TurnEndPhase");
expect(game.scene.arena.getTagOnSide(ArenaTagType.WISH, ArenaTagSide.PLAYER)).toBeDefined();
while (game.scene.arena.getTagOnSide(ArenaTagType.WISH, ArenaTagSide.PLAYER)) {
game.move.select(Moves.SPLASH);
await game.phaseInterceptor.to("TurnEndPhase");
}
expect(player.hp).toBe(1);
}, TIMEOUT);
it("should prevent Grassy Terrain from restoring HP", async() => {
game.override.enemyAbility(Abilities.GRASSY_SURGE);
await game.classicMode.startBattle([Species.CHARIZARD]);
const player = game.scene.getPlayerPokemon()!;
player.damageAndUpdate(player.getMaxHp() - 1);
game.move.select(Moves.SPLASH);
await game.phaseInterceptor.to("TurnEndPhase");
expect(player.hp).toBe(1);
}, TIMEOUT);
it("should prevent healing from heal-over-time moves", async() => {
await game.classicMode.startBattle([Species.CHARIZARD]);
const player = game.scene.getPlayerPokemon()!;
player.damageAndUpdate(player.getMaxHp() - 1);
game.move.select(Moves.AQUA_RING);
await game.phaseInterceptor.to("TurnEndPhase");
expect(player.getTag(BattlerTagType.AQUA_RING)).toBeDefined();
expect(player.hp).toBe(1);
}, TIMEOUT);
it("should prevent abilities from restoring HP", async() => {
game.override
.weather(WeatherType.RAIN)
.ability(Abilities.RAIN_DISH);
await game.classicMode.startBattle([Species.CHARIZARD]);
const player = game.scene.getPlayerPokemon()!;
player.damageAndUpdate(player.getMaxHp() - 1);
game.move.select(Moves.SPLASH);
await game.phaseInterceptor.to("TurnEndPhase");
expect(player.hp).toBe(1);
}, TIMEOUT);
it("should stop healing from items", async() => {
game.override.startingHeldItems([{name: "LEFTOVERS"}]);
await game.classicMode.startBattle([Species.CHARIZARD]);
const player = game.scene.getPlayerPokemon()!;
player.damageAndUpdate(player.getMaxHp() - 1);
game.move.select(Moves.SPLASH);
await game.phaseInterceptor.to("TurnEndPhase");
expect(player.hp).toBe(1);
}, TIMEOUT);
});