[Move][Bug] Fix Enemy Fake Out and Force Switch Interaction (#1251)

* fix force switch move

* add check if switched out pokemon is not fainted with force switch move

* improve code documentation

* refactor if statement
This commit is contained in:
Adrian T 2024-05-31 22:23:28 +08:00 committed by GitHub
parent 92afcdea8f
commit bb7af15c4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 2 deletions

View File

@ -1548,11 +1548,16 @@ export class SwitchSummonPhase extends SummonPhase {
super.onEnd();
const pokemon = this.getPokemon();
const moveId = pokemon.scene.currentBattle.turnCommands[this.fieldIndex]?.move?.move;
const moveId = this.lastPokemon?.scene.currentBattle.lastMove;
const lastUsedMove = moveId ? allMoves[moveId] : undefined;
const currentCommand = pokemon.scene.currentBattle.turnCommands[this.fieldIndex]?.command;
const lastPokemonIsForceSwitchedAndNotFainted = !!lastUsedMove?.findAttr(attr => attr instanceof ForceSwitchOutAttr) && !this.lastPokemon.isFainted();
// Compensate for turn spent summoning
if (pokemon.scene.currentBattle.turnCommands[this.fieldIndex]?.command === Command.POKEMON || !!lastUsedMove?.findAttr(attr => attr instanceof ForceSwitchOutAttr)) { //check if hard switch OR pivot move was used
// Or compensate for force switch move if switched out pokemon is not fainted
if (currentCommand === Command.POKEMON || lastPokemonIsForceSwitchedAndNotFainted) {
pokemon.battleSummonData.turnCount--;
}