From e3fb55834f25eb2cc2be03e4ac4e794b7ff91bf0 Mon Sep 17 00:00:00 2001 From: NxKarim <43686802+NxKarim@users.noreply.github.com> Date: Mon, 29 Jul 2024 17:31:30 -0600 Subject: [PATCH] [Bug] [Fix] Metal Burst always hitting left target. (#3182) * [Fix] Metal Burst always hitting left target. Fixed Metal Burst always hitting left target, and the related freeze/crash. * Prevent enemy redirection to their ally. Co-Authored-By: innerthunder <168692175+innerthunder@users.noreply.github.com> * Rename attackingPosition per chriSS's comment --------- Co-authored-by: innerthunder <168692175+innerthunder@users.noreply.github.com> --- src/field/pokemon.ts | 4 ++-- src/phases.ts | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 6e00fa05ac9..c9dfae5d140 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -2084,7 +2084,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { source.turnData.damageDealt += damage.value; source.turnData.currDamageDealt = damage.value; this.battleData.hitCount++; - const attackResult = { move: move.id, result: result as DamageResult, damage: damage.value, critical: isCritical, sourceId: source.id, attackingPosition: source.getBattlerIndex() }; + const attackResult = { move: move.id, result: result as DamageResult, damage: damage.value, critical: isCritical, sourceId: source.id, sourceBattlerIndex: source.getBattlerIndex() }; this.turnData.attacksReceived.unshift(attackResult); if (source.isPlayer() && !this.isPlayer()) { this.scene.applyModifiers(DamageMoneyRewardModifier, true, source, damage); @@ -4021,7 +4021,7 @@ export interface AttackMoveResult { damage: integer; critical: boolean; sourceId: integer; - attackingPosition: BattlerIndex; + sourceBattlerIndex: BattlerIndex; } export class PokemonSummonData { diff --git a/src/phases.ts b/src/phases.ts index fad95951c26..dc5dcd0d167 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -2666,13 +2666,14 @@ export class MovePhase extends BattlePhase { if (this.targets.length === 1 && this.targets[0] === BattlerIndex.ATTACKER) { if (this.pokemon.turnData.attacksReceived.length) { const attack = this.pokemon.turnData.attacksReceived[0]; - this.targets[0] = attack.attackingPosition; + this.targets[0] = attack.sourceBattlerIndex; // 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.getEnemyField()[this.targets[0]]) { - this.targets[0] = this.scene.getEnemyField().find(p => p.isActive(true)).getBattlerIndex(); + if (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(); } } }