Added per-wave move history object to fix issues

@Jimmybald1 I added a commented out `console.log` in the protect code (L5797) for you to use for testing
This commit is contained in:
Bertie690 2025-05-25 15:37:30 -04:00
parent 00ab9eb225
commit 83f40d0c51
3 changed files with 22 additions and 31 deletions

View File

@ -5780,36 +5780,22 @@ export class ProtectAttr extends AddBattlerTagAttr {
getCondition(): MoveConditionFunc { getCondition(): MoveConditionFunc {
return ((user, target, move): boolean => { return ((user, target, move): boolean => {
// Protect rng resets on new waves, it always succeeds.
if (user.tempSummonData.waveTurnCount === 1) {
return true;
}
let timesUsed = 0; let timesUsed = 0;
const moveHistory = user.getLastXMoves(-1);
let turnMove: TurnMove | undefined;
while (moveHistory.length) { for (const turnMove of user.tempSummonData.waveMoveHistory) {
turnMove = moveHistory.shift(); if (
// Quick & Wide guard increment the Protect counter without using it for fail chance
if (!allMoves[turnMove?.move ?? Moves.NONE].hasAttr(ProtectAttr) || turnMove?.result !== MoveResult.SUCCESS) { !(allMoves[turnMove.move].hasAttr(ProtectAttr) || [Moves.QUICK_GUARD, Moves.WIDE_GUARD].includes(turnMove.move))
|| turnMove?.result !== MoveResult.SUCCESS
) {
break; break;
} }
timesUsed++; 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;
}
} }
if (timesUsed) { // console.log(`Wave Move History: ${user.tempSummonData.waveMoveHistory}\nTimes Used In Row: ${timesUsed}\nSuccess chance: 1 in ${Math.pow(3, timesUsed)}`)
return !user.randBattleSeedInt(Math.pow(3, timesUsed)); return timesUsed === 0 || user.randBattleSeedInt(Math.pow(3, timesUsed)) === 0;
}
return true;
}); });
} }
} }

View File

@ -5122,6 +5122,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
} }
turnMove.turn = globalScene.currentBattle?.turn; turnMove.turn = globalScene.currentBattle?.turn;
this.getMoveHistory().push(turnMove); this.getMoveHistory().push(turnMove);
this.tempSummonData.waveMoveHistory.push(turnMove)
} }
/** /**
@ -5774,6 +5775,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
*/ */
resetWaveData(): void { resetWaveData(): void {
this.waveData = new PokemonWaveData(); this.waveData = new PokemonWaveData();
this.tempSummonData.waveTurnCount = 1;
this.tempSummonData.waveMoveHistory = [];
} }
resetTera(): void { resetTera(): void {
@ -7887,12 +7890,20 @@ export class PokemonTempSummonData {
* The number of turns this pokemon has spent in the active position since the start of the wave * The number of turns this pokemon has spent in the active position since the start of the wave
* without switching out. * without switching out.
* Reset on switch and new wave, but not stored in `SummonData` to avoid being written to the save file. * 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 * Used to evaluate "first turn only" conditions such as
* {@linkcode Moves.FAKE_OUT | Fake Out} and {@linkcode Moves.FIRST_IMPRESSION | First Impression}). * {@linkcode Moves.FAKE_OUT | Fake Out} and {@linkcode Moves.FIRST_IMPRESSION | First Impression}).
*/ */
waveTurnCount = 1; 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[] = [];
} }
/** /**

View File

@ -58,12 +58,6 @@ export class BattleEndPhase extends BattlePhase {
globalScene.unshiftPhase(new GameOverPhase(true)); globalScene.unshiftPhase(new GameOverPhase(true));
} }
for (const pokemon of globalScene.getField()) {
if (pokemon) {
pokemon.tempSummonData.waveTurnCount = 1;
}
}
for (const pokemon of globalScene.getPokemonAllowedInBattle()) { for (const pokemon of globalScene.getPokemonAllowedInBattle()) {
applyPostBattleAbAttrs(PostBattleAbAttr, pokemon, false, this.isVictory); applyPostBattleAbAttrs(PostBattleAbAttr, pokemon, false, this.isVictory);
} }