diff --git a/src/data/moves/move.ts b/src/data/moves/move.ts index 85fb7b8da46..23e10a248b7 100644 --- a/src/data/moves/move.ts +++ b/src/data/moves/move.ts @@ -5780,36 +5780,22 @@ export class ProtectAttr extends AddBattlerTagAttr { getCondition(): MoveConditionFunc { return ((user, target, move): boolean => { - // Protect rng resets on new waves, it always succeeds. - if (user.tempSummonData.waveTurnCount === 1) { - return true; - } - let timesUsed = 0; - const moveHistory = user.getLastXMoves(-1); - let turnMove: TurnMove | undefined; - while (moveHistory.length) { - turnMove = moveHistory.shift(); - - if (!allMoves[turnMove?.move ?? Moves.NONE].hasAttr(ProtectAttr) || turnMove?.result !== MoveResult.SUCCESS) { + for (const turnMove of user.tempSummonData.waveMoveHistory) { + if ( + // Quick & Wide guard increment the Protect counter without using it for fail chance + !(allMoves[turnMove.move].hasAttr(ProtectAttr) || [Moves.QUICK_GUARD, Moves.WIDE_GUARD].includes(turnMove.move)) + || turnMove?.result !== MoveResult.SUCCESS + ) { break; } - timesUsed++; - - // Break after first move used this wave. - // If no move was used on turn 1, then it would have broken in the attr check already. - if (turnMove?.turn === 1) { - break; - } + timesUsed++ } - if (timesUsed) { - return !user.randBattleSeedInt(Math.pow(3, timesUsed)); - } - - return true; + // console.log(`Wave Move History: ${user.tempSummonData.waveMoveHistory}\nTimes Used In Row: ${timesUsed}\nSuccess chance: 1 in ${Math.pow(3, timesUsed)}`) + return timesUsed === 0 || user.randBattleSeedInt(Math.pow(3, timesUsed)) === 0; }); } } diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 62ec8081c5d..bd9056dee41 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -5122,6 +5122,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } turnMove.turn = globalScene.currentBattle?.turn; this.getMoveHistory().push(turnMove); + this.tempSummonData.waveMoveHistory.push(turnMove) } /** @@ -5774,6 +5775,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { */ resetWaveData(): void { this.waveData = new PokemonWaveData(); + this.tempSummonData.waveTurnCount = 1; + this.tempSummonData.waveMoveHistory = []; } resetTera(): void { @@ -7883,16 +7886,24 @@ export class PokemonTempSummonData { */ turnCount: number = 1; - /** + /** * The number of turns this pokemon has spent in the active position since the start of the wave * without switching out. * Reset on switch and new wave, but not stored in `SummonData` to avoid being written to the save file. - + * * Used to evaluate "first turn only" conditions such as * {@linkcode Moves.FAKE_OUT | Fake Out} and {@linkcode Moves.FIRST_IMPRESSION | First Impression}). */ waveTurnCount = 1; + /** + * An array containing all moves this Pokemon has used since the start of the wave + * without switching out. + * Reset on switch and new wave, but not stored in `SummonData` to avoid being written to the save file. + + * Used to calculate {@link https://bulbapedia.bulbagarden.net/wiki/Protection | Protecting moves}' fail chances. + */ + waveMoveHistory: TurnMove[] = []; } /** diff --git a/src/phases/battle-end-phase.ts b/src/phases/battle-end-phase.ts index b4bb28fe55e..c49f02dea9a 100644 --- a/src/phases/battle-end-phase.ts +++ b/src/phases/battle-end-phase.ts @@ -58,12 +58,6 @@ export class BattleEndPhase extends BattlePhase { globalScene.unshiftPhase(new GameOverPhase(true)); } - for (const pokemon of globalScene.getField()) { - if (pokemon) { - pokemon.tempSummonData.waveTurnCount = 1; - } - } - for (const pokemon of globalScene.getPokemonAllowedInBattle()) { applyPostBattleAbAttrs(PostBattleAbAttr, pokemon, false, this.isVictory); }