From d798ebb54583f68c201ce606fe7141abf3bc6032 Mon Sep 17 00:00:00 2001 From: Dean Date: Wed, 23 Jul 2025 11:49:42 -0700 Subject: [PATCH] Code review --- src/data/arena-tag.ts | 8 +-- src/data/moves/move.ts | 17 +++--- src/phase-manager.ts | 1 - test/moves/healing-wish-lunar-dance.test.ts | 59 ++++++++++----------- 4 files changed, 41 insertions(+), 44 deletions(-) diff --git a/src/data/arena-tag.ts b/src/data/arena-tag.ts index f197ffe64fe..88e31fdfb78 100644 --- a/src/data/arena-tag.ts +++ b/src/data/arena-tag.ts @@ -1545,16 +1545,16 @@ export class SuppressAbilitiesTag extends ArenaTag { } /** - * Contains data related to a queued healing effect from + * Interface containing data related to a queued healing effect from * {@link https://bulbapedia.bulbagarden.net/wiki/Healing_Wish_(move) | Healing Wish} * or {@link https://bulbapedia.bulbagarden.net/wiki/Lunar_Dance_(move) | Lunar Dance}. */ interface PendingHealEffect { - /** The id for the {@linkcode Pokemon} that created the effect */ + /** The {@linkcode Pokemon.id | PID} of the {@linkcode Pokemon} that created the effect. */ readonly sourceId: number; - /** The {@linkcode MoveId | id} for the move that created the effect */ + /** The {@linkcode MoveId} of the move that created the effect. */ readonly moveId: MoveId; - /** If `true`, also restores the target's PP when the effect activates */ + /** If `true`, also restores the target's PP when the effect activates. */ readonly restorePP: boolean; /** The `i18n` key for the message to display when the effect activates */ readonly healMessageKey: string; diff --git a/src/data/moves/move.ts b/src/data/moves/move.ts index b208f4a273a..25e57f02ea5 100644 --- a/src/data/moves/move.ts +++ b/src/data/moves/move.ts @@ -2076,16 +2076,15 @@ export class SacrificialFullRestoreAttr extends SacrificialAttr { return false; } - globalScene.arena.addTag(ArenaTagType.PENDING_HEAL, 0, move.id, user.id); + // Add a tag to the field if it doesn't already exist, then queue a delayed healing effect in the user's current slot. + globalScene.arena.addTag(ArenaTagType.PENDING_HEAL, 0, move.id, user.id); // Arguments after first go completely unused const tag = globalScene.arena.getTag(ArenaTagType.PENDING_HEAL) as PendingHealTag; - if (tag) { - tag.queueHeal(user.getBattlerIndex(), { - sourceId: user.id, - moveId: move.id, - restorePP: this.restorePP, - healMessageKey: i18next.t(this.moveMessage, { pokemonName: getPokemonNameWithAffix(user) }), - }); - } + tag.queueHeal(user.getBattlerIndex(), { + sourceId: user.id, + moveId: move.id, + restorePP: this.restorePP, + healMessageKey: i18next.t(this.moveMessage, { pokemonName: getPokemonNameWithAffix(user) }), + }); return true; } diff --git a/src/phase-manager.ts b/src/phase-manager.ts index 95c41907522..4a4ec65da7b 100644 --- a/src/phase-manager.ts +++ b/src/phase-manager.ts @@ -265,7 +265,6 @@ export class PhaseManager { /** * Adds a phase to nextCommandPhaseQueue, as long as boolean passed in is false * @param phase {@linkcode Phase} the phase to add - * @param defer boolean on which queue to add to, defaults to false, and adds to phaseQueue */ pushPhase(phase: Phase): void { if (this.getDynamicPhaseType(phase) !== undefined) { diff --git a/test/moves/healing-wish-lunar-dance.test.ts b/test/moves/healing-wish-lunar-dance.test.ts index 128ba6da2af..33281cc5cac 100644 --- a/test/moves/healing-wish-lunar-dance.test.ts +++ b/test/moves/healing-wish-lunar-dance.test.ts @@ -45,9 +45,9 @@ describe("Moves - Lunar Dance and Healing Wish", () => { await game.toNextTurn(); - expect(bulbasaur.isFullHp()); - expect(charmander.isFainted()).toBeTruthy(); - expect(squirtle.isFullHp()); + expect(bulbasaur.isFullHp()).toBe(true); + expect(charmander.isFainted()).toBe(true); + expect(squirtle.isFullHp()).toBe(true); }); it("should sacrifice the user to cure the switched in Pokemon's status", async () => { @@ -62,8 +62,8 @@ describe("Moves - Lunar Dance and Healing Wish", () => { await game.toNextTurn(); - expect(bulbasaur.status?.effect).toEqual(StatusEffect.BURN); - expect(charmander.isFainted()).toBeTruthy(); + expect(bulbasaur.status?.effect).toBe(StatusEffect.BURN); + expect(charmander.isFainted()).toBe(true); expect(squirtle.status?.effect).toBeUndefined(); }); @@ -78,15 +78,15 @@ describe("Moves - Lunar Dance and Healing Wish", () => { await game.toNextTurn(); - expect(bulbasaur.isFainted()).toBeTruthy(); - expect(charmander.isActive(true)).toBeTruthy(); + expect(bulbasaur.isFainted()).toBe(true); + expect(charmander.isActive(true)).toBe(true); game.move.use(moveId); await game.toEndOfTurn(); expect(charmander.isFullHp()); - expect(charmander.getLastXMoves()[0].result).toEqual(MoveResult.FAIL); + expect(charmander.getLastXMoves()[0].result).toBe(MoveResult.FAIL); }); it("should fail if the user has no challenge-eligible allies", async () => { @@ -95,16 +95,16 @@ describe("Moves - Lunar Dance and Healing Wish", () => { game.challengeMode.addChallenge(Challenges.SINGLE_TYPE, PokemonType.NORMAL + 1, 0); await game.challengeMode.startBattle([SpeciesId.RATICATE, SpeciesId.ODDISH]); - const [raticate] = game.scene.getPlayerParty(); + const raticate = game.field.getPlayerPokemon(); game.move.use(moveId); await game.toNextTurn(); - expect(raticate.isFullHp()); + expect(raticate.isFullHp()).toBe(true); expect(raticate.getLastXMoves()[0].result).toEqual(MoveResult.FAIL); }); - it("should store its effect if the switched-in Pokemon is perfectly healthy", async () => { + it("should store its effect if the switched-in Pokemon would be unaffected", async () => { game.override.battleStyle("single"); await game.classicMode.startBattle([SpeciesId.BULBASAUR, SpeciesId.CHARMANDER, SpeciesId.SQUIRTLE]); @@ -115,21 +115,20 @@ describe("Moves - Lunar Dance and Healing Wish", () => { game.move.use(moveId); game.doSelectPartyPokemon(1); - await game.toEndOfTurn(); + await game.toNextTurn(); - expect(bulbasaur.isFainted()).toBeTruthy(); - expect(charmander.isFullHp()); + // Bulbasaur fainted and stored a healing effect + expect(bulbasaur.isFainted()).toBe(true); + expect(charmander.isFullHp()).toBe(true); expect(game.phaseInterceptor.log).not.toContain("PokemonHealPhase"); expect(game.scene.arena.getTag(ArenaTagType.PENDING_HEAL)).toBeDefined(); await game.toNextTurn(); // Switch to damaged Squirtle. HW/LD's effect should activate - game.doSwitchPokemon(2); await game.toEndOfTurn(); - - expect(squirtle.isFullHp()); + expect(squirtle.isFullHp()).toBe(true); expect(game.scene.arena.getTag(ArenaTagType.PENDING_HEAL)).toBeUndefined(); // Set Charmander's HP to 1, then switch back to Charmander. @@ -159,7 +158,8 @@ describe("Moves - Lunar Dance and Healing Wish", () => { game.doSelectPartyPokemon(1); await game.toNextTurn(); - expect(bulbasaur.isFainted()).toBeTruthy(); + expect(bulbasaur.isFainted()).toBe(true); + expect(charmander.isFullHp()).toBe(true); expect(charmander.isFullHp()); expect(game.phaseInterceptor.log).not.toContain("PokemonHealPhase"); expect(game.scene.arena.getTag(ArenaTagType.PENDING_HEAL)).toBeDefined(); @@ -168,15 +168,14 @@ describe("Moves - Lunar Dance and Healing Wish", () => { game.move.use(moveId); game.doSelectPartyPokemon(2); - await game.toNextTurn(); - expect(charmander.isFainted()).toBeTruthy(); + expect(charmander.isFainted()).toBe(true); + expect(squirtle.isFullHp()).toBe(true); expect(squirtle.isFullHp()); // Switch again to Pikachu. HW/LD's effect shouldn't be present game.doSwitchPokemon(3); - await game.toEndOfTurn(); - expect(pikachu.isFullHp()).not.toBeTruthy(); + expect(pikachu.isFullHp()).toBe(false); }); }); @@ -184,16 +183,16 @@ describe("Moves - Lunar Dance and Healing Wish", () => { game.override.battleStyle("single"); await game.classicMode.startBattle([SpeciesId.BULBASAUR, SpeciesId.CHARMANDER]); - const [bulbasaur, charmander] = game.scene.getPlayerParty(); - [bulbasaur, charmander].forEach(p => game.move.changeMoveset(p, [MoveId.LUNAR_DANCE, MoveId.SPLASH])); - game.move.select(MoveId.SPLASH); + const [bulbasaur, charmander] = game.scene.getPlayerParty(); + + game.move.use(MoveId.SPLASH); await game.toNextTurn(); game.doSwitchPokemon(1); await game.toNextTurn(); - game.move.select(MoveId.LUNAR_DANCE); + game.move.use(MoveId.LUNAR_DANCE); game.doSelectPartyPokemon(1); await game.toNextTurn(); @@ -221,8 +220,8 @@ describe("Moves - Lunar Dance and Healing Wish", () => { game.doSelectPartyPokemon(1); await game.toNextTurn(); - expect(bulbasaur.isFainted()).toBeTruthy(); - expect(charmander.isFullHp()); + expect(bulbasaur.isFainted()).toBe(true); + expect(charmander.isFullHp()).toBe(true); expect(game.phaseInterceptor.log).not.toContain("PokemonHealPhase"); expect(game.scene.arena.getTag(ArenaTagType.PENDING_HEAL)).toBeDefined(); @@ -231,7 +230,7 @@ describe("Moves - Lunar Dance and Healing Wish", () => { // Lunar Dance should apply first since it was used first, restoring Squirtle's HP and PP await game.toNextTurn(); - expect(squirtle.isFullHp()); + expect(squirtle.isFullHp()).toBe(true); squirtle.getMoveset().forEach(mv => expect(mv.ppUsed).toBe(0)); expect(game.scene.arena.getTag(ArenaTagType.PENDING_HEAL)).toBeDefined(); @@ -239,7 +238,7 @@ describe("Moves - Lunar Dance and Healing Wish", () => { // Healing Wish should apply on the next switch, restoring Pikachu's HP await game.toEndOfTurn(); - expect(pikachu.isFullHp()); + expect(pikachu.isFullHp()).toBe(true); pikachu.getMoveset().forEach(mv => expect(mv.ppUsed).toBe(1)); expect(game.scene.arena.getTag(ArenaTagType.PENDING_HEAL)).toBeUndefined(); });