[P2] Syrup Bomb effect is removed when user leaves the field (#4606)

* Syrup Bomb's effect expires when the move user leaves the field

* Add test

* Remove check for the affected pokemon being switched out
This commit is contained in:
NightKev 2024-10-10 10:19:05 -07:00 committed by GitHub
parent 6ad5ba972c
commit 5d0b361320
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 22 deletions

View File

@ -2640,16 +2640,16 @@ export class ImprisonTag extends MoveRestrictionBattlerTag {
/** /**
* Battler Tag that applies the effects of Syrup Bomb to the target Pokemon. * Battler Tag that applies the effects of Syrup Bomb to the target Pokemon.
* For three turns, starting from the turn of hit, at the end of each turn, the target Pokemon's speed will decrease by 1. * For three turns, starting from the turn of hit, at the end of each turn, the target Pokemon's speed will decrease by 1.
* The tag can also expire by taking the target Pokemon off the field. * The tag can also expire by taking the target Pokemon off the field, or the Pokemon that originally used the move.
*/ */
export class SyrupBombTag extends BattlerTag { export class SyrupBombTag extends BattlerTag {
constructor() { constructor(sourceId: number) {
super(BattlerTagType.SYRUP_BOMB, BattlerTagLapseType.TURN_END, 3, Moves.SYRUP_BOMB); super(BattlerTagType.SYRUP_BOMB, BattlerTagLapseType.TURN_END, 3, Moves.SYRUP_BOMB, sourceId);
} }
/** /**
* Adds the Syrup Bomb battler tag to the target Pokemon. * Adds the Syrup Bomb battler tag to the target Pokemon.
* @param {Pokemon} pokemon the target Pokemon * @param pokemon - The target {@linkcode Pokemon}
*/ */
override onAdd(pokemon: Pokemon) { override onAdd(pokemon: Pokemon) {
super.onAdd(pokemon); super.onAdd(pokemon);
@ -2658,15 +2658,16 @@ export class SyrupBombTag extends BattlerTag {
/** /**
* Applies the single-stage speed down to the target Pokemon and decrements the tag's turn count * Applies the single-stage speed down to the target Pokemon and decrements the tag's turn count
* @param {Pokemon} pokemon the target Pokemon * @param pokemon - The target {@linkcode Pokemon}
* @param {BattlerTagLapseType} _lapseType * @param _lapseType - N/A
* @returns `true` if the turnCount is still greater than 0 | `false` if the turnCount is 0 or the target Pokemon has been removed from the field * @returns `true` if the `turnCount` is still greater than `0`; `false` if the `turnCount` is `0` or the target or source Pokemon has been removed from the field
*/ */
override lapse(pokemon: Pokemon, _lapseType: BattlerTagLapseType): boolean { override lapse(pokemon: Pokemon, _lapseType: BattlerTagLapseType): boolean {
if (!pokemon.isActive(true)) { if (this.sourceId && !pokemon.scene.getPokemonById(this.sourceId)?.isActive(true)) {
return false; return false;
} }
pokemon.scene.queueMessage(i18next.t("battlerTags:syrupBombLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); // Custom message in lieu of an animation in mainline // Custom message in lieu of an animation in mainline
pokemon.scene.queueMessage(i18next.t("battlerTags:syrupBombLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }));
pokemon.scene.unshiftPhase(new StatStageChangePhase( pokemon.scene.unshiftPhase(new StatStageChangePhase(
pokemon.scene, pokemon.getBattlerIndex(), true, pokemon.scene, pokemon.getBattlerIndex(), true,
[ Stat.SPD ], -1, true, false, true [ Stat.SPD ], -1, true, false, true
@ -2677,12 +2678,8 @@ export class SyrupBombTag extends BattlerTag {
/** /**
* Retrieves a {@linkcode BattlerTag} based on the provided tag type, turn count, source move, and source ID. * Retrieves a {@linkcode BattlerTag} based on the provided tag type, turn count, source move, and source ID.
* * @param sourceId - The ID of the pokemon adding the tag
* @param {BattlerTagType} tagType the type of the {@linkcode BattlerTagType}. * @returns The corresponding {@linkcode BattlerTag} object.
* @param turnCount the turn count.
* @param {Moves} sourceMove the source {@linkcode Moves}.
* @param sourceId the source ID.
* @returns {BattlerTag} the corresponding {@linkcode BattlerTag} object.
*/ */
export function getBattlerTag(tagType: BattlerTagType, turnCount: number, sourceMove: Moves, sourceId: number): BattlerTag { export function getBattlerTag(tagType: BattlerTagType, turnCount: number, sourceMove: Moves, sourceId: number): BattlerTag {
switch (tagType) { switch (tagType) {
@ -2851,7 +2848,7 @@ export function getBattlerTag(tagType: BattlerTagType, turnCount: number, source
case BattlerTagType.IMPRISON: case BattlerTagType.IMPRISON:
return new ImprisonTag(sourceId); return new ImprisonTag(sourceId);
case BattlerTagType.SYRUP_BOMB: case BattlerTagType.SYRUP_BOMB:
return new SyrupBombTag(); return new SyrupBombTag(sourceId);
case BattlerTagType.NONE: case BattlerTagType.NONE:
default: default:
return new BattlerTag(tagType, BattlerTagLapseType.CUSTOM, turnCount, sourceMove, sourceId); return new BattlerTag(tagType, BattlerTagLapseType.CUSTOM, turnCount, sourceMove, sourceId);

View File

@ -1,4 +1,3 @@
import { allMoves } from "#app/data/move";
import { Moves } from "#enums/moves"; import { Moves } from "#enums/moves";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import { Abilities } from "#enums/abilities"; import { Abilities } from "#enums/abilities";
@ -7,7 +6,7 @@ import { Stat } from "#enums/stat";
import GameManager from "#test/utils/gameManager"; import GameManager from "#test/utils/gameManager";
import Phaser from "phaser"; import Phaser from "phaser";
import { BattlerIndex } from "#app/battle"; import { BattlerIndex } from "#app/battle";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
describe("Moves - SYRUP BOMB", () => { describe("Moves - SYRUP BOMB", () => {
let phaserGame: Phaser.Game; let phaserGame: Phaser.Game;
@ -26,20 +25,21 @@ describe("Moves - SYRUP BOMB", () => {
beforeEach(() => { beforeEach(() => {
game = new GameManager(phaserGame); game = new GameManager(phaserGame);
game.override game.override
.starterSpecies(Species.MAGIKARP) .battleType("single")
.enemySpecies(Species.SNORLAX) .enemySpecies(Species.SNORLAX)
.enemyAbility(Abilities.BALL_FETCH)
.ability(Abilities.BALL_FETCH)
.startingLevel(30) .startingLevel(30)
.enemyLevel(100) .enemyLevel(100)
.moveset([ Moves.SYRUP_BOMB, Moves.SPLASH ]) .moveset([ Moves.SYRUP_BOMB, Moves.SPLASH ])
.enemyMoveset(Moves.SPLASH); .enemyMoveset(Moves.SPLASH);
vi.spyOn(allMoves[Moves.SYRUP_BOMB], "accuracy", "get").mockReturnValue(100);
}); });
//Bulbapedia Reference: https://bulbapedia.bulbagarden.net/wiki/syrup_bomb_(move) //Bulbapedia Reference: https://bulbapedia.bulbagarden.net/wiki/syrup_bomb_(move)
it("decreases the target Pokemon's speed stat once per turn for 3 turns", it("decreases the target Pokemon's speed stat once per turn for 3 turns",
async () => { async () => {
await game.startBattle([ Species.MAGIKARP ]); await game.classicMode.startBattle([ Species.MAGIKARP ]);
const targetPokemon = game.scene.getEnemyPokemon()!; const targetPokemon = game.scene.getEnemyPokemon()!;
expect(targetPokemon.getStatStage(Stat.SPD)).toBe(0); expect(targetPokemon.getStatStage(Stat.SPD)).toBe(0);
@ -66,7 +66,7 @@ describe("Moves - SYRUP BOMB", () => {
it("does not affect Pokemon with the ability Bulletproof", it("does not affect Pokemon with the ability Bulletproof",
async () => { async () => {
game.override.enemyAbility(Abilities.BULLETPROOF); game.override.enemyAbility(Abilities.BULLETPROOF);
await game.startBattle([ Species.MAGIKARP ]); await game.classicMode.startBattle([ Species.MAGIKARP ]);
const targetPokemon = game.scene.getEnemyPokemon()!; const targetPokemon = game.scene.getEnemyPokemon()!;
@ -79,4 +79,18 @@ describe("Moves - SYRUP BOMB", () => {
expect(targetPokemon.getStatStage(Stat.SPD)).toBe(0); expect(targetPokemon.getStatStage(Stat.SPD)).toBe(0);
} }
); );
it("stops lowering the target's speed if the user leaves the field", async () => {
await game.classicMode.startBattle([ Species.FEEBAS, Species.MILOTIC ]);
game.move.select(Moves.SYRUP_BOMB);
await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]);
await game.move.forceHit();
await game.toNextTurn();
game.doSwitchPokemon(1);
await game.toNextTurn();
expect(game.scene.getEnemyPokemon()!.getStatStage(Stat.SPD)).toBe(-1);
});
}); });