Code review

This commit is contained in:
Dean 2025-07-23 11:49:42 -07:00
parent f771e29b0f
commit d798ebb545
4 changed files with 41 additions and 44 deletions

View File

@ -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} * {@link https://bulbapedia.bulbagarden.net/wiki/Healing_Wish_(move) | Healing Wish}
* or {@link https://bulbapedia.bulbagarden.net/wiki/Lunar_Dance_(move) | Lunar Dance}. * or {@link https://bulbapedia.bulbagarden.net/wiki/Lunar_Dance_(move) | Lunar Dance}.
*/ */
interface PendingHealEffect { 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; 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; 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; readonly restorePP: boolean;
/** The `i18n` key for the message to display when the effect activates */ /** The `i18n` key for the message to display when the effect activates */
readonly healMessageKey: string; readonly healMessageKey: string;

View File

@ -2076,16 +2076,15 @@ export class SacrificialFullRestoreAttr extends SacrificialAttr {
return false; 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; const tag = globalScene.arena.getTag(ArenaTagType.PENDING_HEAL) as PendingHealTag;
if (tag) { tag.queueHeal(user.getBattlerIndex(), {
tag.queueHeal(user.getBattlerIndex(), { sourceId: user.id,
sourceId: user.id, moveId: move.id,
moveId: move.id, restorePP: this.restorePP,
restorePP: this.restorePP, healMessageKey: i18next.t(this.moveMessage, { pokemonName: getPokemonNameWithAffix(user) }),
healMessageKey: i18next.t(this.moveMessage, { pokemonName: getPokemonNameWithAffix(user) }), });
});
}
return true; return true;
} }

View File

@ -265,7 +265,6 @@ export class PhaseManager {
/** /**
* Adds a phase to nextCommandPhaseQueue, as long as boolean passed in is false * Adds a phase to nextCommandPhaseQueue, as long as boolean passed in is false
* @param phase {@linkcode Phase} the phase to add * @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 { pushPhase(phase: Phase): void {
if (this.getDynamicPhaseType(phase) !== undefined) { if (this.getDynamicPhaseType(phase) !== undefined) {

View File

@ -45,9 +45,9 @@ describe("Moves - Lunar Dance and Healing Wish", () => {
await game.toNextTurn(); await game.toNextTurn();
expect(bulbasaur.isFullHp()); expect(bulbasaur.isFullHp()).toBe(true);
expect(charmander.isFainted()).toBeTruthy(); expect(charmander.isFainted()).toBe(true);
expect(squirtle.isFullHp()); expect(squirtle.isFullHp()).toBe(true);
}); });
it("should sacrifice the user to cure the switched in Pokemon's status", async () => { 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(); await game.toNextTurn();
expect(bulbasaur.status?.effect).toEqual(StatusEffect.BURN); expect(bulbasaur.status?.effect).toBe(StatusEffect.BURN);
expect(charmander.isFainted()).toBeTruthy(); expect(charmander.isFainted()).toBe(true);
expect(squirtle.status?.effect).toBeUndefined(); expect(squirtle.status?.effect).toBeUndefined();
}); });
@ -78,15 +78,15 @@ describe("Moves - Lunar Dance and Healing Wish", () => {
await game.toNextTurn(); await game.toNextTurn();
expect(bulbasaur.isFainted()).toBeTruthy(); expect(bulbasaur.isFainted()).toBe(true);
expect(charmander.isActive(true)).toBeTruthy(); expect(charmander.isActive(true)).toBe(true);
game.move.use(moveId); game.move.use(moveId);
await game.toEndOfTurn(); await game.toEndOfTurn();
expect(charmander.isFullHp()); 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 () => { 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); game.challengeMode.addChallenge(Challenges.SINGLE_TYPE, PokemonType.NORMAL + 1, 0);
await game.challengeMode.startBattle([SpeciesId.RATICATE, SpeciesId.ODDISH]); await game.challengeMode.startBattle([SpeciesId.RATICATE, SpeciesId.ODDISH]);
const [raticate] = game.scene.getPlayerParty(); const raticate = game.field.getPlayerPokemon();
game.move.use(moveId); game.move.use(moveId);
await game.toNextTurn(); await game.toNextTurn();
expect(raticate.isFullHp()); expect(raticate.isFullHp()).toBe(true);
expect(raticate.getLastXMoves()[0].result).toEqual(MoveResult.FAIL); 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"); game.override.battleStyle("single");
await game.classicMode.startBattle([SpeciesId.BULBASAUR, SpeciesId.CHARMANDER, SpeciesId.SQUIRTLE]); 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.move.use(moveId);
game.doSelectPartyPokemon(1); game.doSelectPartyPokemon(1);
await game.toEndOfTurn(); await game.toNextTurn();
expect(bulbasaur.isFainted()).toBeTruthy(); // Bulbasaur fainted and stored a healing effect
expect(charmander.isFullHp()); expect(bulbasaur.isFainted()).toBe(true);
expect(charmander.isFullHp()).toBe(true);
expect(game.phaseInterceptor.log).not.toContain("PokemonHealPhase"); expect(game.phaseInterceptor.log).not.toContain("PokemonHealPhase");
expect(game.scene.arena.getTag(ArenaTagType.PENDING_HEAL)).toBeDefined(); expect(game.scene.arena.getTag(ArenaTagType.PENDING_HEAL)).toBeDefined();
await game.toNextTurn(); await game.toNextTurn();
// Switch to damaged Squirtle. HW/LD's effect should activate // Switch to damaged Squirtle. HW/LD's effect should activate
game.doSwitchPokemon(2);
await game.toEndOfTurn(); await game.toEndOfTurn();
expect(squirtle.isFullHp()).toBe(true);
expect(squirtle.isFullHp());
expect(game.scene.arena.getTag(ArenaTagType.PENDING_HEAL)).toBeUndefined(); expect(game.scene.arena.getTag(ArenaTagType.PENDING_HEAL)).toBeUndefined();
// Set Charmander's HP to 1, then switch back to Charmander. // 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); game.doSelectPartyPokemon(1);
await game.toNextTurn(); await game.toNextTurn();
expect(bulbasaur.isFainted()).toBeTruthy(); expect(bulbasaur.isFainted()).toBe(true);
expect(charmander.isFullHp()).toBe(true);
expect(charmander.isFullHp()); expect(charmander.isFullHp());
expect(game.phaseInterceptor.log).not.toContain("PokemonHealPhase"); expect(game.phaseInterceptor.log).not.toContain("PokemonHealPhase");
expect(game.scene.arena.getTag(ArenaTagType.PENDING_HEAL)).toBeDefined(); 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.move.use(moveId);
game.doSelectPartyPokemon(2); game.doSelectPartyPokemon(2);
await game.toNextTurn(); expect(charmander.isFainted()).toBe(true);
expect(charmander.isFainted()).toBeTruthy(); expect(squirtle.isFullHp()).toBe(true);
expect(squirtle.isFullHp()); expect(squirtle.isFullHp());
// Switch again to Pikachu. HW/LD's effect shouldn't be present // Switch again to Pikachu. HW/LD's effect shouldn't be present
game.doSwitchPokemon(3); game.doSwitchPokemon(3);
await game.toEndOfTurn(); expect(pikachu.isFullHp()).toBe(false);
expect(pikachu.isFullHp()).not.toBeTruthy();
}); });
}); });
@ -184,16 +183,16 @@ describe("Moves - Lunar Dance and Healing Wish", () => {
game.override.battleStyle("single"); game.override.battleStyle("single");
await game.classicMode.startBattle([SpeciesId.BULBASAUR, SpeciesId.CHARMANDER]); 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(); await game.toNextTurn();
game.doSwitchPokemon(1); game.doSwitchPokemon(1);
await game.toNextTurn(); await game.toNextTurn();
game.move.select(MoveId.LUNAR_DANCE); game.move.use(MoveId.LUNAR_DANCE);
game.doSelectPartyPokemon(1); game.doSelectPartyPokemon(1);
await game.toNextTurn(); await game.toNextTurn();
@ -221,8 +220,8 @@ describe("Moves - Lunar Dance and Healing Wish", () => {
game.doSelectPartyPokemon(1); game.doSelectPartyPokemon(1);
await game.toNextTurn(); await game.toNextTurn();
expect(bulbasaur.isFainted()).toBeTruthy(); expect(bulbasaur.isFainted()).toBe(true);
expect(charmander.isFullHp()); expect(charmander.isFullHp()).toBe(true);
expect(game.phaseInterceptor.log).not.toContain("PokemonHealPhase"); expect(game.phaseInterceptor.log).not.toContain("PokemonHealPhase");
expect(game.scene.arena.getTag(ArenaTagType.PENDING_HEAL)).toBeDefined(); 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 // Lunar Dance should apply first since it was used first, restoring Squirtle's HP and PP
await game.toNextTurn(); await game.toNextTurn();
expect(squirtle.isFullHp()); expect(squirtle.isFullHp()).toBe(true);
squirtle.getMoveset().forEach(mv => expect(mv.ppUsed).toBe(0)); squirtle.getMoveset().forEach(mv => expect(mv.ppUsed).toBe(0));
expect(game.scene.arena.getTag(ArenaTagType.PENDING_HEAL)).toBeDefined(); 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 // Healing Wish should apply on the next switch, restoring Pikachu's HP
await game.toEndOfTurn(); await game.toEndOfTurn();
expect(pikachu.isFullHp()); expect(pikachu.isFullHp()).toBe(true);
pikachu.getMoveset().forEach(mv => expect(mv.ppUsed).toBe(1)); pikachu.getMoveset().forEach(mv => expect(mv.ppUsed).toBe(1));
expect(game.scene.arena.getTag(ArenaTagType.PENDING_HEAL)).toBeUndefined(); expect(game.scene.arena.getTag(ArenaTagType.PENDING_HEAL)).toBeUndefined();
}); });