From b16bd89f17c73b7886e502aed8ad5e8af0552112 Mon Sep 17 00:00:00 2001 From: ReneGV Date: Tue, 2 Jul 2024 19:54:59 -0600 Subject: [PATCH 1/6] [bug][ui] Fix eternatus candy count and display hatched egg count (#2761) * Display eternatus eggs * Trigger Build --- src/ui/starter-select-ui-handler.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ui/starter-select-ui-handler.ts b/src/ui/starter-select-ui-handler.ts index db014432b13..687f65281b4 100644 --- a/src/ui/starter-select-ui-handler.ts +++ b/src/ui/starter-select-ui-handler.ts @@ -2077,9 +2077,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.pokemonHatchedIcon, this.pokemonHatchedCountText ].map(c => c.setVisible(false)); - } else if (species.speciesId === Species.ETERNATUS) { - this.pokemonHatchedIcon.setVisible(false); - this.pokemonHatchedCountText.setVisible(false); + this.pokemonFormText.setY(25); } else { this.pokemonCaughtHatchedContainer.setY(25); this.pokemonShinyIcon.setY(117); @@ -2091,6 +2089,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.pokemonCandyCountText.setText(`x${this.scene.gameData.starterData[species.speciesId].candyCount}`); this.pokemonCandyCountText.setVisible(true); this.pokemonFormText.setVisible(true); + this.pokemonFormText.setY(42); this.pokemonHatchedIcon.setVisible(true); this.pokemonHatchedCountText.setVisible(true); From cc36cdb1a86b8d83e0b87396c46a42375d8ce0a8 Mon Sep 17 00:00:00 2001 From: flx-sta <50131232+flx-sta@users.noreply.github.com> Date: Tue, 2 Jul 2024 19:00:44 -0700 Subject: [PATCH 2/6] [Tests] add unit tests for accounts (#2748) * add unit tests for accounts * only import from vitest (not node:test) * resolve comments * improve test coverage for accounts.updateUserInfo * add test coverage for account.initLoggedInUser() * code style improvements --- src/test/account.spec.ts | 74 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/test/account.spec.ts diff --git a/src/test/account.spec.ts b/src/test/account.spec.ts new file mode 100644 index 00000000000..28e48ce9933 --- /dev/null +++ b/src/test/account.spec.ts @@ -0,0 +1,74 @@ +import * as battleScene from "#app/battle-scene.js"; +import { describe, expect, it, vi } from "vitest"; +import { initLoggedInUser, loggedInUser, updateUserInfo } from "../account"; +import * as utils from "../utils"; + +describe("account", () => { + describe("initLoggedInUser", () => { + it("should set loggedInUser to Guest and lastSessionSlot to -1", () => { + initLoggedInUser(); + + expect(loggedInUser.username).toBe("Guest"); + expect(loggedInUser.lastSessionSlot).toBe(-1); + }); + }); + + describe("updateUserInfo", () => { + it("should set loggedInUser to Guest if bypassLogin is true", async () => { + vi.spyOn(battleScene, "bypassLogin", "get").mockReturnValue(true); + + const [success, status] = await updateUserInfo(); + + expect(success).toBe(true); + expect(status).toBe(200); + expect(loggedInUser.username).toBe("Guest"); + expect(loggedInUser.lastSessionSlot).toBe(-1); + }); + + it("should fetch user info from the API if bypassLogin is false", async () => { + vi.spyOn(battleScene, "bypassLogin", "get").mockReturnValue(false); + vi.spyOn(utils, "apiFetch").mockResolvedValue( + new Response( + JSON.stringify({ + username: "test", + lastSessionSlot: 99, + }), + { + status: 200, + } + ) + ); + + const [success, status] = await updateUserInfo(); + + expect(success).toBe(true); + expect(status).toBe(200); + expect(loggedInUser.username).toBe("test"); + expect(loggedInUser.lastSessionSlot).toBe(99); + }); + + it("should handle resolved API errors", async () => { + vi.spyOn(battleScene, "bypassLogin", "get").mockReturnValue(false); + vi.spyOn(utils, "apiFetch").mockResolvedValue( + new Response(null, { status: 401 }) + ); + + const [success, status] = await updateUserInfo(); + + expect(success).toBe(false); + expect(status).toBe(401); + }); + + it("should handle rejected API errors", async () => { + const consoleErrorSpy = vi.spyOn(console, "error"); + vi.spyOn(battleScene, "bypassLogin", "get").mockReturnValue(false); + vi.spyOn(utils, "apiFetch").mockRejectedValue(new Error("Api failed!")); + + const [success, status] = await updateUserInfo(); + + expect(success).toBe(false); + expect(status).toBe(500); + expect(consoleErrorSpy).toHaveBeenCalled(); + }); + }); +}); From 63599ef52ec377f113e44997932628f4a3ab536f Mon Sep 17 00:00:00 2001 From: chaosgrimmon <31082757+chaosgrimmon@users.noreply.github.com> Date: Wed, 3 Jul 2024 12:45:43 -0400 Subject: [PATCH 3/6] [Sprite] Female Scyther missing variant palettes (#2770) * [Sprite] Missing female Scyther front variant palettes Taken from existing male counterpart. * [Sprite] Missing female Scyther back variant palettes Taken from existing male counterpart. * [Sprite] Adding female Scyther variants --- .../images/pokemon/variant/_masterlist.json | 10 ++++ .../pokemon/variant/back/female/123.json | 47 +++++++++++++++++++ public/images/pokemon/variant/female/123.json | 44 +++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 public/images/pokemon/variant/back/female/123.json create mode 100644 public/images/pokemon/variant/female/123.json diff --git a/public/images/pokemon/variant/_masterlist.json b/public/images/pokemon/variant/_masterlist.json index 0c48fed625b..f3e690395e1 100644 --- a/public/images/pokemon/variant/_masterlist.json +++ b/public/images/pokemon/variant/_masterlist.json @@ -3265,6 +3265,11 @@ 1, 1 ], + "123": [ + 1, + 1, + 1 + ], "129": [ 0, 1, @@ -6638,6 +6643,11 @@ 1, 1 ], + "123": [ + 1, + 1, + 1 + ], "129": [ 0, 1, diff --git a/public/images/pokemon/variant/back/female/123.json b/public/images/pokemon/variant/back/female/123.json new file mode 100644 index 00000000000..049e6e23435 --- /dev/null +++ b/public/images/pokemon/variant/back/female/123.json @@ -0,0 +1,47 @@ +{ + "0": { + "425a21": "632929", + "bde673": "e67373", + "e6d6ad": "b5b5ce", + "9c8c31": "632929", + "8cce73": "f76b6b", + "101010": "101010", + "fff7d6": "ffffff", + "5a9c4a": "d63a3a", + "bdbdbd": "bdbdbd", + "c5a573": "b5b5ce", + "dedede": "dedede", + "ffffff": "ffffff", + "737373": "737373" + }, + "1": { + "425a21": "484e75", + "bde673": "bdbdbd", + "e6d6ad": "e6d6ad", + "9c8c31": "9c8c31", + "8cce73": "92b0db", + "101010": "101010", + "fff7d6": "fff7d6", + "5a9c4a": "7b94d6", + "bdbdbd": "ffffff", + "c5a573": "9cc5ff", + "dedede": "dedede", + "ffffff": "ffffff", + "737373": "737373" + }, + "2": { + "425a21": "8f3907", + "bde673": "f8f581", + "e6d6ad": "e6d6ad", + "9c8c31": "9c8c31", + "8cce73": "f0c947", + "101010": "101010", + "fff7d6": "fff7d6", + "5a9c4a": "e6a027", + "bdbdbd": "bdbdbd", + "c5a573": "c5a573", + "dedede": "dedede", + "ffffff": "ffffff", + "737373": "737373" + } +} \ No newline at end of file diff --git a/public/images/pokemon/variant/female/123.json b/public/images/pokemon/variant/female/123.json new file mode 100644 index 00000000000..5fbefd72224 --- /dev/null +++ b/public/images/pokemon/variant/female/123.json @@ -0,0 +1,44 @@ +{ + "0": { + "425a21": "632929", + "bde673": "f76b6b", + "101010": "101010", + "9c8c31": "9494a5", + "fff7d6": "ffffff", + "8cce73": "d63a3a", + "e6d6ad": "b5b5ce", + "5a9c4a": "a52929", + "ffffff": "ffffff", + "dedede": "dedede", + "bdbdbd": "bdbdbd", + "737373": "737373" + }, + "1": { + "425a21": "484e75", + "bde673": "7c9ac5", + "101010": "101010", + "9c8c31": "9c8c31", + "fff7d6": "fff7d6", + "8cce73": "92b0db", + "e6d6ad": "e6d6ad", + "5a9c4a": "7b94d6", + "ffffff": "ffffff", + "dedede": "dedede", + "bdbdbd": "bdbdbd", + "737373": "737373" + }, + "2": { + "425a21": "8f3907", + "bde673": "f8f581", + "101010": "101010", + "9c8c31": "9c8c31", + "fff7d6": "fff7d6", + "8cce73": "f0c947", + "e6d6ad": "e6d6ad", + "5a9c4a": "e6a027", + "ffffff": "ffffff", + "dedede": "f0c947", + "bdbdbd": "bdbdbd", + "737373": "737373" + } +} \ No newline at end of file From 4c4e2bc792f1744582227af18f6a57ddec06b543 Mon Sep 17 00:00:00 2001 From: innerthunder <168692175+innerthunder@users.noreply.github.com> Date: Wed, 3 Jul 2024 09:49:12 -0700 Subject: [PATCH 4/6] [Bug] Fix evasion multiplier in hit check (#2765) * Fix evasion multiplier in hit check * Make Sand Veil test more future-proof --- src/phases.ts | 2 +- src/test/abilities/sand_veil.test.ts | 83 +++++++++++++++++++++ src/test/lokalisation/status-effect.test.ts | 3 +- 3 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 src/test/abilities/sand_veil.test.ts diff --git a/src/phases.ts b/src/phases.ts index 9f069a60dc5..dd400c22076 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -3095,7 +3095,7 @@ export class MoveEffectPhase extends PokemonPhase { applyBattleStatMultiplierAbAttrs(BattleStatMultiplierAbAttr, user, BattleStat.ACC, accuracyMultiplier, this.move.getMove()); const evasionMultiplier = new Utils.NumberHolder(1); - applyBattleStatMultiplierAbAttrs(BattleStatMultiplierAbAttr, this.getTarget(), BattleStat.EVA, evasionMultiplier); + applyBattleStatMultiplierAbAttrs(BattleStatMultiplierAbAttr, target, BattleStat.EVA, evasionMultiplier); accuracyMultiplier.value /= evasionMultiplier.value; diff --git a/src/test/abilities/sand_veil.test.ts b/src/test/abilities/sand_veil.test.ts new file mode 100644 index 00000000000..221d48d3ca1 --- /dev/null +++ b/src/test/abilities/sand_veil.test.ts @@ -0,0 +1,83 @@ +import Phaser from "phaser"; +import { afterEach, beforeAll, beforeEach, describe, expect, test, vi } from "vitest"; +import GameManager from "../utils/gameManager"; +import * as Overrides from "#app/overrides"; +import { Species } from "#enums/species"; +import { Abilities } from "#enums/abilities"; +import { Moves } from "#enums/moves"; +import { getMovePosition } from "../utils/gameManagerUtils"; +import { CommandPhase, MoveEffectPhase, MoveEndPhase } from "#app/phases.js"; +import { BattleStat } from "#app/data/battle-stat.js"; +import { WeatherType } from "#app/data/weather.js"; +import { BattleStatMultiplierAbAttr, allAbilities } from "#app/data/ability.js"; + +const TIMEOUT = 20 * 1000; + +describe("Abilities - Sand Veil", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + + beforeAll(() => { + phaserGame = new Phaser.Game({ + type: Phaser.HEADLESS, + }); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + + beforeEach(() => { + game = new GameManager(phaserGame); + vi.spyOn(Overrides, "DOUBLE_BATTLE_OVERRIDE", "get").mockReturnValue(true); + vi.spyOn(Overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([Moves.SPLASH]); + vi.spyOn(Overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.MEOWSCARADA); + vi.spyOn(Overrides, "OPP_ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.INSOMNIA); + vi.spyOn(Overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.TWISTER, Moves.TWISTER, Moves.TWISTER, Moves.TWISTER]); + vi.spyOn(Overrides, "STARTING_LEVEL_OVERRIDE", "get").mockReturnValue(100); + vi.spyOn(Overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(100); + vi.spyOn(Overrides, "WEATHER_OVERRIDE", "get").mockReturnValue(WeatherType.SANDSTORM); + }); + + test( + "ability should increase the evasiveness of the source", + async () => { + await game.startBattle([Species.SNORLAX, Species.BLISSEY]); + + const leadPokemon = game.scene.getPlayerField(); + leadPokemon.forEach(p => expect(p).toBeDefined()); + + const enemyPokemon = game.scene.getEnemyField(); + enemyPokemon.forEach(p => expect(p).toBeDefined()); + + vi.spyOn(leadPokemon[0], "getAbility").mockReturnValue(allAbilities[Abilities.SAND_VEIL]); + + const sandVeilAttr = allAbilities[Abilities.SAND_VEIL].getAttrs(BattleStatMultiplierAbAttr)[0]; + vi.spyOn(sandVeilAttr, "applyBattleStat").mockImplementation( + (pokemon, passive, battleStat, statValue, args) => { + if (battleStat === BattleStat.EVA && game.scene.arena.weather?.weatherType === WeatherType.SANDSTORM) { + statValue.value *= -1; // will make all attacks miss + return true; + } + return false; + } + ); + + expect(leadPokemon[0].hasAbility(Abilities.SAND_VEIL)).toBe(true); + expect(leadPokemon[1].hasAbility(Abilities.SAND_VEIL)).toBe(false); + + game.doAttack(getMovePosition(game.scene, 0, Moves.SPLASH)); + + await game.phaseInterceptor.to(CommandPhase); + + game.doAttack(getMovePosition(game.scene, 1, Moves.SPLASH)); + + await game.phaseInterceptor.to(MoveEffectPhase, false); + + await game.phaseInterceptor.to(MoveEndPhase, false); + + expect(leadPokemon[0].hp).toBe(leadPokemon[0].getMaxHp()); + expect(leadPokemon[1].hp).toBeLessThan(leadPokemon[1].getMaxHp()); + }, TIMEOUT + ); +}); diff --git a/src/test/lokalisation/status-effect.test.ts b/src/test/lokalisation/status-effect.test.ts index 4c79dacbff7..b4267ea7b8b 100644 --- a/src/test/lokalisation/status-effect.test.ts +++ b/src/test/lokalisation/status-effect.test.ts @@ -1,4 +1,4 @@ -import { beforeAll, describe, expect, it, vi } from "vitest"; +import { beforeAll, describe, afterEach, expect, it, vi } from "vitest"; import { StatusEffect, getStatusEffectActivationText, @@ -8,7 +8,6 @@ import { getStatusEffectOverlapText, } from "#app/data/status-effect"; import i18next, { ParseKeys } from "i18next"; -import { afterEach } from "node:test"; const tMock = (key: ParseKeys) => key; const pokemonName = "PKM"; From dad065cbae22cd709fcc80bf237a1d082077acbc Mon Sep 17 00:00:00 2001 From: Adrian T <68144167+torranx@users.noreply.github.com> Date: Thu, 4 Jul 2024 00:55:39 +0800 Subject: [PATCH 5/6] [Ability] Fully Implement Steely Spirit (#2749) * implement steely spirit * add unit test * cleanup * cleanup and add another test --- src/data/ability.ts | 17 +++- src/field/pokemon.ts | 5 +- src/test/abilities/steely_spirit.test.ts | 115 +++++++++++++++++++++++ 3 files changed, 133 insertions(+), 4 deletions(-) create mode 100644 src/test/abilities/steely_spirit.test.ts diff --git a/src/data/ability.ts b/src/data/ability.ts index eb55f661e66..4f4807ed614 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -1446,7 +1446,7 @@ export class FieldMovePowerBoostAbAttr extends AbAttr { * Boosts the power of a specific type of move. * @extends FieldMovePowerBoostAbAttr */ -export class FieldMoveTypePowerBoostAbAttr extends FieldMovePowerBoostAbAttr { +export class PreAttackFieldMoveTypePowerBoostAbAttr extends FieldMovePowerBoostAbAttr { /** * @param boostedType - The type of move that will receive the power boost. * @param powerMultiplier - The multiplier to apply to the move's power, defaults to 1.5 if not provided. @@ -1456,6 +1456,18 @@ export class FieldMoveTypePowerBoostAbAttr extends FieldMovePowerBoostAbAttr { } } +/** + * Boosts the power of a specific type of move for all Pokemon in the field. + * @extends PreAttackFieldMoveTypePowerBoostAbAttr + */ +export class FieldMoveTypePowerBoostAbAttr extends PreAttackFieldMoveTypePowerBoostAbAttr { } + +/** + * Boosts the power of a specific type of move for the user and its allies. + * @extends PreAttackFieldMoveTypePowerBoostAbAttr + */ +export class UserFieldMoveTypePowerBoostAbAttr extends PreAttackFieldMoveTypePowerBoostAbAttr { } + /** * Boosts the power of moves in specified categories. * @extends FieldMovePowerBoostAbAttr @@ -4964,8 +4976,7 @@ export function initAbilities() { new Ability(Abilities.SCREEN_CLEANER, 8) .attr(PostSummonRemoveArenaTagAbAttr, [ArenaTagType.AURORA_VEIL, ArenaTagType.LIGHT_SCREEN, ArenaTagType.REFLECT]), new Ability(Abilities.STEELY_SPIRIT, 8) - .attr(MoveTypePowerBoostAbAttr, Type.STEEL) - .partial(), + .attr(UserFieldMoveTypePowerBoostAbAttr, Type.STEEL), new Ability(Abilities.PERISH_BODY, 8) .attr(PostDefendPerishSongAbAttr, 4), new Ability(Abilities.WANDERING_SPIRIT, 8) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 88d7f6b73a8..2c05492c2c6 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -23,7 +23,7 @@ import { BattlerTag, BattlerTagLapseType, EncoreTag, GroundedTag, HelpingHandTag import { WeatherType } from "../data/weather"; import { TempBattleStat } from "../data/temp-battle-stat"; import { ArenaTagSide, WeakenMoveScreenTag, WeakenMoveTypeTag } from "../data/arena-tag"; -import { Ability, AbAttr, BattleStatMultiplierAbAttr, BlockCritAbAttr, BonusCritAbAttr, BypassBurnDamageReductionAbAttr, FieldPriorityMoveImmunityAbAttr, IgnoreOpponentStatChangesAbAttr, MoveImmunityAbAttr, MoveTypeChangeAttr, PreApplyBattlerTagAbAttr, PreDefendFullHpEndureAbAttr, ReceivedMoveDamageMultiplierAbAttr, ReduceStatusEffectDurationAbAttr, StabBoostAbAttr, StatusEffectImmunityAbAttr, TypeImmunityAbAttr, VariableMovePowerAbAttr, WeightMultiplierAbAttr, allAbilities, applyAbAttrs, applyBattleStatMultiplierAbAttrs, applyPreApplyBattlerTagAbAttrs, applyPreAttackAbAttrs, applyPreDefendAbAttrs, applyPreSetStatusAbAttrs, UnsuppressableAbilityAbAttr, SuppressFieldAbilitiesAbAttr, NoFusionAbilityAbAttr, MultCritAbAttr, IgnoreTypeImmunityAbAttr, DamageBoostAbAttr, IgnoreTypeStatusEffectImmunityAbAttr, ConditionalCritAbAttr, applyFieldBattleStatMultiplierAbAttrs, FieldMultiplyBattleStatAbAttr, AllyMoveCategoryPowerBoostAbAttr, FieldMoveTypePowerBoostAbAttr, AddSecondStrikeAbAttr } from "../data/ability"; +import { Ability, AbAttr, BattleStatMultiplierAbAttr, BlockCritAbAttr, BonusCritAbAttr, BypassBurnDamageReductionAbAttr, FieldPriorityMoveImmunityAbAttr, IgnoreOpponentStatChangesAbAttr, MoveImmunityAbAttr, MoveTypeChangeAttr, PreApplyBattlerTagAbAttr, PreDefendFullHpEndureAbAttr, ReceivedMoveDamageMultiplierAbAttr, ReduceStatusEffectDurationAbAttr, StabBoostAbAttr, StatusEffectImmunityAbAttr, TypeImmunityAbAttr, VariableMovePowerAbAttr, WeightMultiplierAbAttr, allAbilities, applyAbAttrs, applyBattleStatMultiplierAbAttrs, applyPreApplyBattlerTagAbAttrs, applyPreAttackAbAttrs, applyPreDefendAbAttrs, applyPreSetStatusAbAttrs, UnsuppressableAbilityAbAttr, SuppressFieldAbilitiesAbAttr, NoFusionAbilityAbAttr, MultCritAbAttr, IgnoreTypeImmunityAbAttr, DamageBoostAbAttr, IgnoreTypeStatusEffectImmunityAbAttr, ConditionalCritAbAttr, applyFieldBattleStatMultiplierAbAttrs, FieldMultiplyBattleStatAbAttr, AllyMoveCategoryPowerBoostAbAttr, FieldMoveTypePowerBoostAbAttr, AddSecondStrikeAbAttr, UserFieldMoveTypePowerBoostAbAttr } from "../data/ability"; import PokemonData from "../system/pokemon-data"; import { BattlerIndex } from "../battle"; import { Mode } from "../ui/ui"; @@ -1788,6 +1788,9 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { aura.applyPreAttack(null, null, null, move, [power]); } + const alliedField: Pokemon[] = source instanceof PlayerPokemon ? this.scene.getPlayerField() : this.scene.getEnemyField(); + alliedField.forEach(p => applyPreAttackAbAttrs(UserFieldMoveTypePowerBoostAbAttr, p, this, move, power)); + power.value *= typeChangeMovePowerMultiplier.value; if (!typeless) { diff --git a/src/test/abilities/steely_spirit.test.ts b/src/test/abilities/steely_spirit.test.ts new file mode 100644 index 00000000000..e9c673a102a --- /dev/null +++ b/src/test/abilities/steely_spirit.test.ts @@ -0,0 +1,115 @@ +import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; +import Phaser from "phaser"; +import GameManager from "#app/test/utils/gameManager"; +import * as overrides from "#app/overrides"; +import { Species } from "#enums/species"; +import { Moves } from "#enums/moves"; +import { getMovePosition } from "#app/test/utils/gameManagerUtils"; +import Pokemon, { PlayerPokemon } from "#app/field/pokemon.js"; +import Move, { allMoves } from "#app/data/move.js"; +import { NumberHolder } from "#app/utils.js"; +import { allAbilities, applyPreAttackAbAttrs, UserFieldMoveTypePowerBoostAbAttr } from "#app/data/ability.js"; +import { Abilities } from "#app/enums/abilities.js"; + +describe("Abilities - Steely Spirit", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + const steelySpiritMultiplier = 1.5; + const moveToCheck = Moves.IRON_HEAD; + + beforeAll(() => { + phaserGame = new Phaser.Game({ + type: Phaser.HEADLESS, + }); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + + beforeEach(() => { + game = new GameManager(phaserGame); + vi.spyOn(overrides, "DOUBLE_BATTLE_OVERRIDE", "get").mockReturnValue(true); + vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.MAGIKARP); + vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([Moves.IRON_HEAD, Moves.SPLASH]); + vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.SPLASH, Moves.SPLASH, Moves.SPLASH, Moves.SPLASH]); + }); + + it("increases Steel-type moves used by the user and its allies", async () => { + await game.startBattle([Species.MAGIKARP, Species.PERRSERKER]); + const perserrker = game.scene.getPlayerField()[1]; + + vi.spyOn(perserrker, "getAbility").mockReturnValue(allAbilities[Abilities.STEELY_SPIRIT]); + + expect(perserrker.hasAbility(Abilities.STEELY_SPIRIT)).toBe(true); + + game.doAttack(getMovePosition(game.scene, 0, moveToCheck)); + game.doAttack(getMovePosition(game.scene, 1, Moves.SPLASH)); + + const mockedMovePower = getMockedMovePower(game.scene.getEnemyPokemon(), perserrker, allMoves[moveToCheck]); + + expect(mockedMovePower).toBe(allMoves[moveToCheck].power * steelySpiritMultiplier); + }); + + it("stacks if multiple users with this ability are on the field.", async () => { + await game.startBattle([Species.PERRSERKER, Species.PERRSERKER]); + + game.scene.getPlayerField().forEach(p => { + vi.spyOn(p, "getAbility").mockReturnValue(allAbilities[Abilities.STEELY_SPIRIT]); + }); + + expect(game.scene.getPlayerField().every(p => p.hasAbility(Abilities.STEELY_SPIRIT))).toBe(true); + + game.doAttack(getMovePosition(game.scene, 0, moveToCheck)); + game.doAttack(getMovePosition(game.scene, 1, Moves.SPLASH)); + + const mockedMovePower = getMockedMovePower(game.scene.getEnemyPokemon(), game.scene.getPlayerPokemon(), allMoves[moveToCheck]); + + expect(mockedMovePower).toBe(allMoves[moveToCheck].power * Math.pow(steelySpiritMultiplier, 2)); + }); + + it("does not take effect when suppressed", async () => { + await game.startBattle([Species.MAGIKARP, Species.PERRSERKER]); + const perserrker = game.scene.getPlayerField()[1]; + + vi.spyOn(perserrker, "getAbility").mockReturnValue(allAbilities[Abilities.STEELY_SPIRIT]); + expect(perserrker.hasAbility(Abilities.STEELY_SPIRIT)).toBe(true); + + perserrker.summonData.abilitySuppressed = true; + + expect(perserrker.hasAbility(Abilities.STEELY_SPIRIT)).toBe(false); + expect(perserrker.summonData.abilitySuppressed).toBe(true); + + game.doAttack(getMovePosition(game.scene, 0, moveToCheck)); + game.doAttack(getMovePosition(game.scene, 1, Moves.SPLASH)); + + const mockedMovePower = getMockedMovePower(game.scene.getEnemyPokemon(), perserrker, allMoves[moveToCheck]); + + expect(mockedMovePower).toBe(allMoves[moveToCheck].power); + }); +}); + +/** + * Calculates the mocked power of a move. + * Note this does not consider other damage calculations + * except the power multiplier from Steely Spirit. + * + * @param defender - The defending Pokémon. + * @param attacker - The attacking Pokémon. + * @param move - The move being used by the attacker. + * @returns The adjusted power of the move. + */ +const getMockedMovePower = (defender: Pokemon, attacker: Pokemon, move: Move) => { + const powerHolder = new NumberHolder(move.power); + + /** + * Check if pokemon has the specified ability and is in effect. + * See Pokemon.hasAbility {@linkcode Pokemon.hasAbility} + */ + if (attacker.hasAbility(Abilities.STEELY_SPIRIT)) { + const alliedField: Pokemon[] = attacker instanceof PlayerPokemon ? attacker.scene.getPlayerField() : attacker.scene.getEnemyField(); + alliedField.forEach(p => applyPreAttackAbAttrs(UserFieldMoveTypePowerBoostAbAttr, p, this, move, powerHolder)); + } + + return powerHolder.value; +}; From 126174efe4162693f17fbb44116ce1723bacc0bb Mon Sep 17 00:00:00 2001 From: innerthunder <168692175+innerthunder@users.noreply.github.com> Date: Wed, 3 Jul 2024 11:48:41 -0700 Subject: [PATCH 6/6] [Bug] Fix Grip Claw sometimes stealing from the wrong enemy (#2766) * Fix Grip Claw stealing from the wrong enemy * Document held item transfer modifiers --- src/modifier/modifier.ts | 51 +++++++++++++++++++++- src/phases.ts | 2 +- src/test/items/grip_claw.test.ts | 75 ++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 src/test/items/grip_claw.test.ts diff --git a/src/modifier/modifier.ts b/src/modifier/modifier.ts index f7c23406179..0b339906cc5 100644 --- a/src/modifier/modifier.ts +++ b/src/modifier/modifier.ts @@ -2116,14 +2116,38 @@ export class SwitchEffectTransferModifier extends PokemonHeldItemModifier { } } +/** + * Abstract class for held items that steal other Pokemon's items. + * @see {@linkcode TurnHeldItemTransferModifier} + * @see {@linkcode ContactHeldItemTransferChanceModifier} + */ export abstract class HeldItemTransferModifier extends PokemonHeldItemModifier { constructor(type: ModifierType, pokemonId: integer, stackCount?: integer) { super(type, pokemonId, stackCount); } + /** + * Determines the targets to transfer items from when this applies. + * @param args\[0\] the {@linkcode Pokemon} holding this item + * @returns the opponents of the source {@linkcode Pokemon} + */ + getTargets(args: any[]): Pokemon[] { + const pokemon = args[0]; + + return pokemon instanceof Pokemon + ? pokemon.getOpponents() + : []; + } + + /** + * Steals an item from a set of target Pokemon. + * This prioritizes high-tier held items when selecting the item to steal. + * @param args \[0\] The {@linkcode Pokemon} holding this item + * @returns true if an item was stolen; false otherwise. + */ apply(args: any[]): boolean { const pokemon = args[0] as Pokemon; - const opponents = pokemon.getOpponents(); + const opponents = this.getTargets(args); if (!opponents.length) { return false; @@ -2180,6 +2204,11 @@ export abstract class HeldItemTransferModifier extends PokemonHeldItemModifier { abstract getTransferMessage(pokemon: Pokemon, targetPokemon: Pokemon, item: ModifierTypes.ModifierType): string; } +/** + * Modifier for held items that steal items from the enemy at the end of + * each turn. + * @see {@linkcode modifierTypes[MINI_BLACK_HOLE]} + */ export class TurnHeldItemTransferModifier extends HeldItemTransferModifier { constructor(type: ModifierType, pokemonId: integer, stackCount?: integer) { super(type, pokemonId, stackCount); @@ -2210,6 +2239,12 @@ export class TurnHeldItemTransferModifier extends HeldItemTransferModifier { } } +/** + * Modifier for held items that add a chance to steal items from the target of a + * successful attack. + * @see {@linkcode modifierTypes[GRIP_CLAW]} + * @see {@linkcode HeldItemTransferModifier} + */ export class ContactHeldItemTransferChanceModifier extends HeldItemTransferModifier { private chance: number; @@ -2219,6 +2254,20 @@ export class ContactHeldItemTransferChanceModifier extends HeldItemTransferModif this.chance = chancePercent / 100; } + /** + * Determines the target to steal items from when this applies. + * @param args\[0\] The {@linkcode Pokemon} holding this item + * @param args\[1\] The {@linkcode Pokemon} the holder is targeting with an attack + * @returns The target (args[1]) stored in array format for use in {@linkcode HeldItemTransferModifier.apply} + */ + getTargets(args: any[]): Pokemon[] { + const target = args[1]; + + return target instanceof Pokemon + ? [ target ] + : []; + } + matchType(modifier: Modifier): boolean { return modifier instanceof ContactHeldItemTransferChanceModifier; } diff --git a/src/phases.ts b/src/phases.ts index dd400c22076..df7314e6285 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -2966,7 +2966,7 @@ export class MoveEffectPhase extends PokemonPhase { })).then(() => { applyPostAttackAbAttrs(PostAttackAbAttr, user, target, this.move.getMove(), hitResult).then(() => { if (this.move.getMove() instanceof AttackMove) { - this.scene.applyModifiers(ContactHeldItemTransferChanceModifier, this.player, user, target.getFieldIndex()); + this.scene.applyModifiers(ContactHeldItemTransferChanceModifier, this.player, user, target); } resolve(); }); diff --git a/src/test/items/grip_claw.test.ts b/src/test/items/grip_claw.test.ts new file mode 100644 index 00000000000..ae621770da6 --- /dev/null +++ b/src/test/items/grip_claw.test.ts @@ -0,0 +1,75 @@ +import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; +import Phase from "phaser"; +import GameManager from "#app/test/utils/gameManager"; +import * as overrides from "#app/overrides"; +import { Moves } from "#app/enums/moves.js"; +import { Species } from "#app/enums/species.js"; +import { BerryType } from "#app/enums/berry-type.js"; +import { Abilities } from "#app/enums/abilities.js"; +import { getMovePosition } from "../utils/gameManagerUtils"; +import { CommandPhase, MoveEndPhase, SelectTargetPhase } from "#app/phases.js"; +import { BattlerIndex } from "#app/battle.js"; +import { allMoves } from "#app/data/move.js"; + +const TIMEOUT = 20 * 1000; // 20 seconds + +describe("Items - Grip Claw", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + + beforeAll(() => { + phaserGame = new Phase.Game({ + type: Phaser.HEADLESS, + }); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + + beforeEach(() => { + game = new GameManager(phaserGame); + + vi.spyOn(overrides, "DOUBLE_BATTLE_OVERRIDE", "get").mockReturnValue(true); + vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([ Moves.POPULATION_BOMB, Moves.SPLASH ]); + vi.spyOn(overrides, "STARTING_HELD_ITEMS_OVERRIDE", "get").mockReturnValue([{name: "GRIP_CLAW", count: 5}, {name: "MULTI_LENS", count: 3}]); + vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.SNORLAX); + vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.KLUTZ); + vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([ Moves.SPLASH, Moves.SPLASH, Moves.SPLASH, Moves.SPLASH ]); + vi.spyOn(overrides, "OPP_HELD_ITEMS_OVERRIDE", "get").mockReturnValue([ + {name: "BERRY", type: BerryType.SITRUS, count: 2}, + {name: "BERRY", type: BerryType.LUM, count: 2} + ]); + vi.spyOn(overrides, "STARTING_LEVEL_OVERRIDE", "get").mockReturnValue(100); + vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(100); + + vi.spyOn(allMoves[Moves.POPULATION_BOMB], "accuracy", "get").mockReturnValue(100); + }); + + it( + "should only steal items from the attack target", + async () => { + await game.startBattle([Species.PANSEAR, Species.ROWLET, Species.PANPOUR, Species.PANSAGE, Species.CHARMANDER, Species.SQUIRTLE]); + + const playerPokemon = game.scene.getPlayerField(); + playerPokemon.forEach(p => expect(p).toBeDefined()); + + const enemyPokemon = game.scene.getEnemyField(); + enemyPokemon.forEach(p => expect(p).toBeDefined()); + + const enemyHeldItemCt = enemyPokemon.map(p => p.getHeldItems.length); + + game.doAttack(getMovePosition(game.scene, 0, Moves.POPULATION_BOMB)); + + await game.phaseInterceptor.to(SelectTargetPhase, false); + game.doSelectTarget(BattlerIndex.ENEMY); + + await game.phaseInterceptor.to(CommandPhase, false); + game.doAttack(getMovePosition(game.scene, 1, Moves.SPLASH)); + + await game.phaseInterceptor.to(MoveEndPhase, false); + + expect(enemyPokemon[1].getHeldItems.length).toBe(enemyHeldItemCt[1]); + }, TIMEOUT + ); +});