Fix for [Bug] Metal Burst causes game to crash if intended target faints #4575

This commit is contained in:
Sean Mon 2024-10-04 18:54:44 +01:00
parent 75bd730c04
commit 909264b6c0

View File

@ -376,7 +376,7 @@ export class MovePhase extends BattlePhase {
// account for metal burst and comeuppance hitting remaining targets in double battles
// counterattack will redirect to remaining ally if original attacker faints
if (this.scene.currentBattle.double && this.move.getMove().hasFlag(MoveFlags.REDIRECT_COUNTER)) {
if (this.scene.getField()[this.targets[0]].hp === 0) {
if (attacker?.isActive(true) && this.scene.getField()[this.targets[0]].hp === 0) {
const opposingField = this.pokemon.isPlayer() ? this.scene.getEnemyField() : this.scene.getPlayerField();
this.targets[0] = opposingField.find(p => p.hp > 0)?.getBattlerIndex() ?? BattlerIndex.ATTACKER;
}