diff --git a/src/battle-phases.ts b/src/battle-phases.ts index 660b14b511b..482a2d139e0 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -1422,7 +1422,18 @@ export class MovePhase extends BattlePhase { return; } - console.log(this.targets); + if (this.targets.length === 1 && this.targets[0] === BattlerIndex.ATTACKER) { + if (this.pokemon.turnData.attacksReceived.length) { + const attacker = this.pokemon.turnData.attacksReceived.length ? this.pokemon.scene.getPokemonById(this.pokemon.turnData.attacksReceived[0].sourceId) : null; + if (attacker?.isActive(true)) + this.targets[0] = attacker.getBattlerIndex(); + } + if (this.targets[0] === BattlerIndex.ATTACKER) { + this.cancel(); + this.showMoveText(); + this.showFailedText(); + } + } const targets = this.scene.getField().filter(p => { if (p?.isActive(true) && this.targets.indexOf(p.getBattlerIndex()) > -1) { @@ -1446,6 +1457,7 @@ export class MovePhase extends BattlePhase { const moveQueue = this.pokemon.getMoveQueue(); + this.showMoveText(); if ((moveQueue.length && moveQueue[0].move === Moves.NONE) || !targets.length) { moveQueue.shift(); this.cancel(); @@ -1457,7 +1469,6 @@ export class MovePhase extends BattlePhase { return; } - this.scene.queueMessage(getPokemonMessage(this.pokemon, ` used\n${this.move.getName()}!`), 500); if (!moveQueue.length || !moveQueue.shift().ignorePP) { this.move.ppUsed++; for (let opponent of this.pokemon.getOpponents()) { @@ -1479,7 +1490,7 @@ export class MovePhase extends BattlePhase { this.scene.unshiftPhase(this.getEffectPhase()); else { this.pokemon.pushMoveHistory({ move: this.move.moveId, targets: this.targets, result: MoveResult.FAIL, virtual: this.move.virtual }); - this.scene.queueMessage('But it failed!'); + this.showFailedText(); } this.end(); @@ -1529,6 +1540,14 @@ export class MovePhase extends BattlePhase { return new MoveEffectPhase(this.scene, this.pokemon.getBattlerIndex(), this.targets, this.move); } + showMoveText(): void { + this.scene.queueMessage(getPokemonMessage(this.pokemon, ` used\n${this.move.getName()}!`), 500); + } + + showFailedText(): void { + this.scene.queueMessage('But it failed!'); + } + end() { if (!this.followUp && this.canMove()) this.scene.unshiftPhase(new MoveEndPhase(this.scene, this.pokemon.getBattlerIndex())); diff --git a/src/battle.ts b/src/battle.ts index 70c5c956f1f..7f8f50a8f24 100644 --- a/src/battle.ts +++ b/src/battle.ts @@ -14,6 +14,7 @@ export enum BattleType { } export enum BattlerIndex { + ATTACKER = -1, PLAYER, PLAYER_2, ENEMY, diff --git a/src/data/move.ts b/src/data/move.ts index 9db0cd70044..8511459a903 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -2356,10 +2356,7 @@ export function getMoveTargets(user: Pokemon, move: Moves): MoveTargetSet { set = [ opponents[Utils.randInt(opponents.length)] ]; break; case MoveTarget.ATTACKER: - set = user.turnData.attacksReceived.length - ? [ user.scene.getPokemonById(user.turnData.attacksReceived[0].sourceId) ] - : []; - break; + return { targets: [ -1 as BattlerIndex ], multiple: false }; case MoveTarget.NEAR_ALLY: case MoveTarget.ALLY: set = [ user.getAlly() ];