From 747e4f9360c9a7f297aab82b3da85dbfc3c401e4 Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Sun, 18 Aug 2024 17:05:53 -0700 Subject: [PATCH] [Hotfix] Abilities that prevent ATK drops no longer stop other stat drops (#3624) * Abilities that prevent ATK drops no longer stop other stat drops * Apply suggestions from code review Co-authored-by: Mumble * Add `isNullOrUndefined()` utility function --------- --- src/data/ability.ts | 6 +-- src/test/abilities/hyper_cutter.test.ts | 58 +++++++++++++++++++++++++ src/utils.ts | 8 ++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 src/test/abilities/hyper_cutter.test.ts diff --git a/src/data/ability.ts b/src/data/ability.ts index cfd900d621c..38ca4eb25d0 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -2395,16 +2395,16 @@ export class PreStatChangeAbAttr extends AbAttr { } export class ProtectStatAbAttr extends PreStatChangeAbAttr { - private protectedStat: BattleStat | null; + private protectedStat?: BattleStat; constructor(protectedStat?: BattleStat) { super(); - this.protectedStat = protectedStat ?? null; + this.protectedStat = protectedStat; } applyPreStatChange(pokemon: Pokemon, passive: boolean, stat: BattleStat, cancelled: Utils.BooleanHolder, args: any[]): boolean { - if (!this.protectedStat || stat === this.protectedStat) { + if (Utils.isNullOrUndefined(this.protectedStat) || stat === this.protectedStat) { cancelled.value = true; return true; } diff --git a/src/test/abilities/hyper_cutter.test.ts b/src/test/abilities/hyper_cutter.test.ts new file mode 100644 index 00000000000..9637a80ddb4 --- /dev/null +++ b/src/test/abilities/hyper_cutter.test.ts @@ -0,0 +1,58 @@ +import { BattleStat } from "#app/data/battle-stat"; +import { Abilities } from "#enums/abilities"; +import { Moves } from "#enums/moves"; +import { Species } from "#enums/species"; +import GameManager from "#test/utils/gameManager"; +import { getMovePosition } from "#test/utils/gameManagerUtils"; +import { SPLASH_ONLY } from "#test/utils/testUtils"; +import Phaser from "phaser"; +import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; + +describe("Abilities - Hyper Cutter", () => { + 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 + .battleType("single") + .moveset([Moves.SAND_ATTACK, Moves.NOBLE_ROAR, Moves.DEFOG, Moves.OCTOLOCK]) + .ability(Abilities.BALL_FETCH) + .enemySpecies(Species.SHUCKLE) + .enemyAbility(Abilities.HYPER_CUTTER) + .enemyMoveset(SPLASH_ONLY); + }); + + // Reference Link: https://bulbapedia.bulbagarden.net/wiki/Hyper_Cutter_(Ability) + + it("only prevents ATK drops", async () => { + await game.startBattle(); + + const enemy = game.scene.getEnemyPokemon()!; + + game.doAttack(getMovePosition(game.scene, 0, Moves.OCTOLOCK)); + await game.toNextTurn(); + game.doAttack(getMovePosition(game.scene, 0, Moves.DEFOG)); + await game.toNextTurn(); + game.doAttack(getMovePosition(game.scene, 0, Moves.NOBLE_ROAR)); + await game.toNextTurn(); + game.doAttack(getMovePosition(game.scene, 0, Moves.SAND_ATTACK)); + await game.toNextTurn(); + game.override.moveset([Moves.STRING_SHOT]); + game.doAttack(getMovePosition(game.scene, 0, Moves.STRING_SHOT)); + await game.toNextTurn(); + + expect(enemy.summonData.battleStats[BattleStat.ATK]).toEqual(0); + [BattleStat.ACC, BattleStat.DEF, BattleStat.EVA, BattleStat.SPATK, BattleStat.SPDEF, BattleStat.SPD].forEach((stat: number) => expect(enemy.summonData.battleStats[stat]).toBeLessThan(0)); + }); +}); diff --git a/src/utils.ts b/src/utils.ts index aa45c091286..c51ac2b5b0b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -552,3 +552,11 @@ export function capitalizeString(str: string, sep: string, lowerFirstChar: boole } return null; } + +/** + * Returns if an object is null or undefined + * @param object + */ +export function isNullOrUndefined(object: any): boolean { + return null === object || undefined === object; +}