From ef0ff6a7055340340627b790b57c183094f43f76 Mon Sep 17 00:00:00 2001 From: f-raZ0R Date: Mon, 13 May 2024 20:33:38 -0400 Subject: [PATCH] Fix interaction with Virtuals. --- src/data/battler-tags.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/data/battler-tags.ts b/src/data/battler-tags.ts index e8af5bde2..8dfe4ef34 100644 --- a/src/data/battler-tags.ts +++ b/src/data/battler-tags.ts @@ -523,18 +523,27 @@ export class TormentedTag extends BattlerTag { pokemon.scene.queueMessage(getPokemonMessage(pokemon, 'is no longer\ntormented!')); } - //At the end of each turn, if this pokemon executed a move this turn, set its unselectableMove to that move, unless it is struggle, in which case unset it. + //At the end of each turn, set this pokemon's unselectableMove to the last move it executed. If this move is struggle, instead unset unselectableMove. If no valid move is found, do nothing. lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { const ret = lapseType !== BattlerTagLapseType.CUSTOM || super.lapse(pokemon, lapseType); if (ret) { - const lastMove = pokemon.getLastXMoves(1)[0]; - if (!lastMove || (lastMove.move === Moves.NONE)) - return ret; - if (lastMove.move === Moves.STRUGGLE) { - pokemon.summonData.unselectableMove = Moves.NONE; - } - else { - pokemon.summonData.unselectableMove = lastMove.move; + const moveQueue = pokemon.getLastXMoves(); + let turnMove: TurnMove; + while (moveQueue.length) { + turnMove = moveQueue.shift(); + if (turnMove.virtual && turnMove.move !== Moves.STRUGGLE) + continue; + if (turnMove.move === Moves.STRUGGLE) { + pokemon.summonData.unselectableMove = Moves.NONE; + return ret; + } + const moveIndex = pokemon.getMoveset().findIndex(m => m.moveId === turnMove.move); + if (moveIndex === -1) + return ret; + else { + pokemon.summonData.unselectableMove = turnMove.move; + return ret; + } } return ret; }