Reverted swallow test

fixing in other prs
This commit is contained in:
Bertie690 2025-06-14 13:39:55 -04:00
parent c919ea78cb
commit 2eae68785d

View File

@ -3,12 +3,14 @@ import { StockpilingTag } from "#app/data/battler-tags";
import { BattlerTagType } from "#app/enums/battler-tag-type"; import { BattlerTagType } from "#app/enums/battler-tag-type";
import type { TurnMove } from "#app/field/pokemon"; import type { TurnMove } from "#app/field/pokemon";
import { MoveResult } from "#enums/move-result"; import { MoveResult } from "#enums/move-result";
import { MovePhase } from "#app/phases/move-phase";
import { TurnInitPhase } from "#app/phases/turn-init-phase";
import { AbilityId } from "#enums/ability-id"; import { AbilityId } from "#enums/ability-id";
import { MoveId } from "#enums/move-id"; import { MoveId } from "#enums/move-id";
import { SpeciesId } from "#enums/species-id"; import { SpeciesId } from "#enums/species-id";
import GameManager from "#test/testUtils/gameManager"; import GameManager from "#test/testUtils/gameManager";
import Phaser from "phaser"; import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
describe("Moves - Swallow", () => { describe("Moves - Swallow", () => {
let phaserGame: Phaser.Game; let phaserGame: Phaser.Game;
@ -29,41 +31,99 @@ describe("Moves - Swallow", () => {
.battleStyle("single") .battleStyle("single")
.enemySpecies(SpeciesId.RATTATA) .enemySpecies(SpeciesId.RATTATA)
.enemyMoveset(MoveId.SPLASH) .enemyMoveset(MoveId.SPLASH)
.enemyAbility(AbilityId.BALL_FETCH) .enemyAbility(AbilityId.NONE)
.enemyLevel(1000) .enemyLevel(2000)
.startingLevel(1000) .moveset(MoveId.SWALLOW)
.ability(AbilityId.BALL_FETCH); .ability(AbilityId.NONE);
}); });
it.each<{ stackCount: number; healPercent: number }>([ describe("consumes all stockpile stacks to heal (scaling with stacks)", () => {
{ stackCount: 1, healPercent: 25 }, it("1 stack -> 25% heal", async () => {
{ stackCount: 2, healPercent: 50 }, const stacksToSetup = 1;
{ stackCount: 3, healPercent: 100 }, const expectedHeal = 25;
])(
"should heal the user by $healPercent% max HP when consuming $count stockpile stacks",
async ({ stackCount, healPercent }) => {
await game.classicMode.startBattle([SpeciesId.SWALOT]);
const swalot = game.field.getPlayerPokemon(); await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
swalot.hp = 1;
for (let i = 0; i < stackCount; i++) { const pokemon = game.scene.getPlayerPokemon()!;
swalot.addTag(BattlerTagType.STOCKPILING); vi.spyOn(pokemon, "getMaxHp").mockReturnValue(100);
} pokemon["hp"] = 1;
const stockpilingTag = swalot.getTag(StockpilingTag)!; pokemon.addTag(BattlerTagType.STOCKPILING);
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined(); expect(stockpilingTag).toBeDefined();
expect(stockpilingTag.stockpiledCount).toBe(stackCount); expect(stockpilingTag.stockpiledCount).toBe(stacksToSetup);
game.move.use(MoveId.SWALLOW); vi.spyOn(pokemon, "heal");
await game.toEndOfTurn();
expect(swalot.getHpRatio()).toBeCloseTo(healPercent / 100, 1); game.move.select(MoveId.SWALLOW);
expect(swalot.getTag(StockpilingTag)).toBeUndefined(); await game.phaseInterceptor.to(TurnInitPhase);
},
);
it("should fail without stacks", async () => { expect(pokemon.heal).toHaveBeenCalledOnce();
expect(pokemon.heal).toHaveReturnedWith(expectedHeal);
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
});
it("2 stacks -> 50% heal", async () => {
const stacksToSetup = 2;
const expectedHeal = 50;
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const pokemon = game.scene.getPlayerPokemon()!;
vi.spyOn(pokemon, "getMaxHp").mockReturnValue(100);
pokemon["hp"] = 1;
pokemon.addTag(BattlerTagType.STOCKPILING);
pokemon.addTag(BattlerTagType.STOCKPILING);
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
expect(stockpilingTag.stockpiledCount).toBe(stacksToSetup);
vi.spyOn(pokemon, "heal");
game.move.select(MoveId.SWALLOW);
await game.phaseInterceptor.to(TurnInitPhase);
expect(pokemon.heal).toHaveBeenCalledOnce();
expect(pokemon.heal).toHaveReturnedWith(expectedHeal);
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
});
it("3 stacks -> 100% heal", async () => {
const stacksToSetup = 3;
const expectedHeal = 100;
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const pokemon = game.scene.getPlayerPokemon()!;
vi.spyOn(pokemon, "getMaxHp").mockReturnValue(100);
pokemon["hp"] = 0.0001;
pokemon.addTag(BattlerTagType.STOCKPILING);
pokemon.addTag(BattlerTagType.STOCKPILING);
pokemon.addTag(BattlerTagType.STOCKPILING);
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
expect(stockpilingTag.stockpiledCount).toBe(stacksToSetup);
vi.spyOn(pokemon, "heal");
game.move.select(MoveId.SWALLOW);
await game.phaseInterceptor.to(TurnInitPhase);
expect(pokemon.heal).toHaveBeenCalledOnce();
expect(pokemon.heal).toHaveReturnedWith(expect.closeTo(expectedHeal));
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
});
});
it("fails without stacks", async () => {
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]); await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const pokemon = game.scene.getPlayerPokemon()!; const pokemon = game.scene.getPlayerPokemon()!;
@ -71,17 +131,17 @@ describe("Moves - Swallow", () => {
const stockpilingTag = pokemon.getTag(StockpilingTag)!; const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeUndefined(); expect(stockpilingTag).toBeUndefined();
game.move.use(MoveId.SWALLOW); game.move.select(MoveId.SWALLOW);
await game.toEndOfTurn(); await game.phaseInterceptor.to(TurnInitPhase);
expect(pokemon.getLastXMoves()[0]).toMatchObject({ expect(pokemon.getMoveHistory().at(-1)).toMatchObject<TurnMove>({
move: MoveId.SWALLOW, move: MoveId.SWALLOW,
result: MoveResult.FAIL, result: MoveResult.FAIL,
targets: [pokemon.getBattlerIndex()], targets: [pokemon.getBattlerIndex()],
}); });
}); });
describe("should reset stat stage boosts granted by stacks", () => { describe("restores stat stage boosts granted by stacks", () => {
it("decreases stats based on stored values (both boosts equal)", async () => { it("decreases stats based on stored values (both boosts equal)", async () => {
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]); await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
@ -90,13 +150,16 @@ describe("Moves - Swallow", () => {
const stockpilingTag = pokemon.getTag(StockpilingTag)!; const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined(); expect(stockpilingTag).toBeDefined();
game.move.select(MoveId.SWALLOW);
await game.phaseInterceptor.to(MovePhase);
expect(pokemon.getStatStage(Stat.DEF)).toBe(1); expect(pokemon.getStatStage(Stat.DEF)).toBe(1);
expect(pokemon.getStatStage(Stat.SPDEF)).toBe(1); expect(pokemon.getStatStage(Stat.SPDEF)).toBe(1);
game.move.use(MoveId.SWALLOW); await game.phaseInterceptor.to(TurnInitPhase);
await game.toEndOfTurn();
expect(pokemon.getLastXMoves()[0]).toMatchObject({ expect(pokemon.getMoveHistory().at(-1)).toMatchObject<TurnMove>({
move: MoveId.SWALLOW, move: MoveId.SWALLOW,
result: MoveResult.SUCCESS, result: MoveResult.SUCCESS,
targets: [pokemon.getBattlerIndex()], targets: [pokemon.getBattlerIndex()],
@ -104,6 +167,8 @@ describe("Moves - Swallow", () => {
expect(pokemon.getStatStage(Stat.DEF)).toBe(0); expect(pokemon.getStatStage(Stat.DEF)).toBe(0);
expect(pokemon.getStatStage(Stat.SPDEF)).toBe(0); expect(pokemon.getStatStage(Stat.SPDEF)).toBe(0);
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
}); });
it("lower stat stages based on stored values (different boosts)", async () => { it("lower stat stages based on stored values (different boosts)", async () => {
@ -114,16 +179,18 @@ describe("Moves - Swallow", () => {
const stockpilingTag = pokemon.getTag(StockpilingTag)!; const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined(); expect(stockpilingTag).toBeDefined();
// for the sake of simplicity (and because other tests cover the setup), set boost amounts directly // for the sake of simplicity (and because other tests cover the setup), set boost amounts directly
stockpilingTag.statChangeCounts = { stockpilingTag.statChangeCounts = {
[Stat.DEF]: -1, [Stat.DEF]: -1,
[Stat.SPDEF]: 2, [Stat.SPDEF]: 2,
}; };
game.move.use(MoveId.SWALLOW); game.move.select(MoveId.SWALLOW);
await game.toEndOfTurn();
expect(pokemon.getLastXMoves()[0]).toMatchObject<TurnMove>({ await game.phaseInterceptor.to(TurnInitPhase);
expect(pokemon.getMoveHistory().at(-1)).toMatchObject<TurnMove>({
move: MoveId.SWALLOW, move: MoveId.SWALLOW,
result: MoveResult.SUCCESS, result: MoveResult.SUCCESS,
targets: [pokemon.getBattlerIndex()], targets: [pokemon.getBattlerIndex()],
@ -131,6 +198,8 @@ describe("Moves - Swallow", () => {
expect(pokemon.getStatStage(Stat.DEF)).toBe(1); expect(pokemon.getStatStage(Stat.DEF)).toBe(1);
expect(pokemon.getStatStage(Stat.SPDEF)).toBe(-2); expect(pokemon.getStatStage(Stat.SPDEF)).toBe(-2);
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
}); });
}); });
}); });