From 68a9d785aa4b3d67675166f76824d910d37c01d7 Mon Sep 17 00:00:00 2001 From: Bertie690 Date: Fri, 8 Aug 2025 17:46:02 -0400 Subject: [PATCH] Fixed a few more bugs and such --- src/data/moves/move.ts | 10 +++++----- test/@types/vitest.d.ts | 8 +++++--- test/moves/swallow-spit-up.test.ts | 7 ++++--- test/test-utils/matchers/to-have-hp.ts | 12 +++++++++++- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/data/moves/move.ts b/src/data/moves/move.ts index 6ec7703c3ca..678abd5d618 100644 --- a/src/data/moves/move.ts +++ b/src/data/moves/move.ts @@ -2040,7 +2040,7 @@ export class VariableHealAttr extends HealAttr { selfTarget = true, failOnFullHp = true, ) { - super(1, showAnim, selfTarget, selfTarget); + super(1, showAnim, selfTarget, failOnFullHp); this.healFunc = healFunc; } @@ -8091,16 +8091,16 @@ const shoreUpHealRatioFunc = (): number => { } const swallowHealFunc = (user: Pokemon): number => { - const tag = user.getTag(StockpilingTag); + const tag = user.getTag(BattlerTagType.STOCKPILING); if (!tag || tag.stockpiledCount <= 0) { return 0; } switch (tag.stockpiledCount) { case 1: - return 0.25 + return 0.25; case 2: - return 0.5 + return 0.5; case 3: default: // in case we ever get more stacks return 1; @@ -9307,7 +9307,7 @@ export function initMoves() { .condition(hasStockpileStacksCondition) .attr(RemoveBattlerTagAttr, [ BattlerTagType.STOCKPILING ], true), new SelfStatusMove(MoveId.SWALLOW, PokemonType.NORMAL, -1, 10, -1, 0, 3) - .attr(VariableHealAttr, swallowHealFunc, false, true, true) + .attr(VariableHealAttr, swallowHealFunc, false, true, false) .condition(hasStockpileStacksCondition) .attr(RemoveBattlerTagAttr, [ BattlerTagType.STOCKPILING ], true) .triageMove(), diff --git a/test/@types/vitest.d.ts b/test/@types/vitest.d.ts index 7b756c45a57..afa8072764d 100644 --- a/test/@types/vitest.d.ts +++ b/test/@types/vitest.d.ts @@ -1,4 +1,5 @@ import type { TerrainType } from "#app/data/terrain"; +import type Overrides from "#app/overrides"; import type { AbilityId } from "#enums/ability-id"; import type { BattlerTagType } from "#enums/battler-tag-type"; import type { MoveId } from "#enums/move-id"; @@ -7,14 +8,14 @@ import type { BattleStat, EffectiveStat, Stat } from "#enums/stat"; import type { StatusEffect } from "#enums/status-effect"; import type { WeatherType } from "#enums/weather-type"; import type { Pokemon } from "#field/pokemon"; +import type { PokemonMove } from "#moves/pokemon-move"; import type { ToHaveEffectiveStatMatcherOptions } from "#test/test-utils/matchers/to-have-effective-stat"; import type { expectedStatusType } from "#test/test-utils/matchers/to-have-status-effect"; import type { toHaveTypesOptions } from "#test/test-utils/matchers/to-have-types"; import type { TurnMove } from "#types/turn-move"; import type { AtLeastOne } from "#types/type-helpers"; +import type { toDmgValue } from "#utils/common"; import type { expect } from "vitest"; -import type Overrides from "#app/overrides"; -import type { PokemonMove } from "#moves/pokemon-move"; declare module "vitest" { interface Assertion { @@ -113,8 +114,9 @@ declare module "vitest" { /** * Check whether a {@linkcode Pokemon} has a specific amount of {@linkcode Stat.HP | HP}. * @param expectedHp - The expected amount of {@linkcode Stat.HP | HP} to have + * @param roundDown - Whether to round down {@linkcode expectedDamageTaken} with {@linkcode toDmgValue}; default `true` */ - toHaveHp(expectedHp: number): void; + toHaveHp(expectedHp: number, roundDown?: boolean): void; /** * Check whether a {@linkcode Pokemon} is currently fainted (as determined by {@linkcode Pokemon.isFainted}). diff --git a/test/moves/swallow-spit-up.test.ts b/test/moves/swallow-spit-up.test.ts index 0324c13aa3e..5f20664279e 100644 --- a/test/moves/swallow-spit-up.test.ts +++ b/test/moves/swallow-spit-up.test.ts @@ -63,7 +63,7 @@ describe("Moves - Swallow & Spit Up - ", () => { game.move.use(MoveId.SWALLOW); await game.toEndOfTurn(); - expect(swalot).toHaveHp((swalot.getMaxHp() * healPercent) / 100 + 1); + expect(swalot).toHaveHp(Math.min(swalot.getMaxHp(), Math.round((swalot.getMaxHp() * healPercent) / 100) + 1)); expect(swalot).not.toHaveBattlerTag(BattlerTagType.STOCKPILING); }, ); @@ -137,7 +137,7 @@ describe("Moves - Swallow & Spit Up - ", () => { await game.toEndOfTurn(); expect(spitUpSpy).toHaveReturnedWith(power); - expect(swalot.getTag(StockpilingTag)).toBeUndefined(); + expect(swalot).not.toHaveBattlerTag(BattlerTagType.STOCKPILING); }); it("should fail without Stockpile stacks", async () => { @@ -207,6 +207,7 @@ describe("Moves - Swallow & Spit Up - ", () => { }); it("should invert stat drops when gaining Contrary", async () => { + game.override.enemyAbility(AbilityId.CONTRARY); await game.classicMode.startBattle([SpeciesId.ABOMASNOW]); const player = game.field.getPlayerPokemon(); @@ -218,7 +219,7 @@ describe("Moves - Swallow & Spit Up - ", () => { expect(player).toHaveStatStage(Stat.DEF, 1); expect(player).toHaveStatStage(Stat.SPDEF, 1); - expect(player).toHaveAbilityApplied(AbilityId.CONTRARY); + expect(player.hasAbility(AbilityId.CONTRARY)).toBe(true); game.move.use(MoveId.SPIT_UP); await game.move.forceEnemyMove(MoveId.SPLASH); diff --git a/test/test-utils/matchers/to-have-hp.ts b/test/test-utils/matchers/to-have-hp.ts index 20d171b23ce..e67242e56e4 100644 --- a/test/test-utils/matchers/to-have-hp.ts +++ b/test/test-utils/matchers/to-have-hp.ts @@ -2,15 +2,22 @@ import { getPokemonNameWithAffix } from "#app/messages"; // biome-ignore lint/correctness/noUnusedImports: TSDoc import type { Pokemon } from "#field/pokemon"; import { isPokemonInstance, receivedStr } from "#test/test-utils/test-utils"; +import { toDmgValue } from "#utils/common"; import type { MatcherState, SyncExpectationResult } from "@vitest/expect"; /** * Matcher that checks if a Pokemon has a specific amount of HP. * @param received - The object to check. Should be a {@linkcode Pokemon}. * @param expectedHp - The expected amount of HP the {@linkcode Pokemon} has + * @param roundDown - Whether to round down {@linkcode expectedDamageTaken} with {@linkcode toDmgValue}; default `true` * @returns Whether the matcher passed */ -export function toHaveHp(this: MatcherState, received: unknown, expectedHp: number): SyncExpectationResult { +export function toHaveHp( + this: MatcherState, + received: unknown, + expectedHp: number, + roundDown = true, +): SyncExpectationResult { if (!isPokemonInstance(received)) { return { pass: false, @@ -18,6 +25,9 @@ export function toHaveHp(this: MatcherState, received: unknown, expectedHp: numb }; } + if (roundDown) { + expectedHp = toDmgValue(expectedHp); + } const actualHp = received.hp; const pass = actualHp === expectedHp;