From a0994c01514434d11c2994cf38c1ecac48343f03 Mon Sep 17 00:00:00 2001 From: frutescens Date: Wed, 6 Nov 2024 13:05:45 -0800 Subject: [PATCH] Added PRE_MOVE lapse code to handle early tag expiration from PP-less encored move --- src/data/battler-tags.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/data/battler-tags.ts b/src/data/battler-tags.ts index ab24d5bd867..4b77ec44601 100644 --- a/src/data/battler-tags.ts +++ b/src/data/battler-tags.ts @@ -917,7 +917,7 @@ export class EncoreTag extends MoveRestrictionBattlerTag { public moveId: Moves; constructor(sourceId: number) { - super(BattlerTagType.ENCORE, BattlerTagLapseType.AFTER_MOVE, 3, Moves.ENCORE, sourceId); + super(BattlerTagType.ENCORE, [ BattlerTagLapseType.PRE_MOVE, BattlerTagLapseType.AFTER_MOVE ], 3, Moves.ENCORE, sourceId); } /** @@ -973,6 +973,24 @@ export class EncoreTag extends MoveRestrictionBattlerTag { } } + /** + * If the encored move has run out of PP, Encore ends early. Otherwise, Encore lapses based on the AFTER_MOVE battler tag lapse type. + * @param pokemon + * @param lapseType + * @returns `true` to persist | `false` to end and be removed + */ + override lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { + if (lapseType === BattlerTagLapseType.PRE_MOVE) { + const encoredMove = pokemon.getMoveset().find(m => m?.moveId === this.moveId); + if (encoredMove && encoredMove?.getPpRatio() > 0) { + return true; + } + return false; + } else { + return super.lapse(pokemon, lapseType); + } + } + /** * Checks if the move matches the moveId stored within the tag and returns a boolean value * @param move {@linkcode Moves} the move selected