Fix counter and mirror coat implementation

pull/8/head
Flashfyre 2023-11-27 11:42:03 -05:00
parent 21c8a67b10
commit c34eb05083
3 changed files with 24 additions and 7 deletions

View File

@ -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()));

View File

@ -14,6 +14,7 @@ export enum BattleType {
}
export enum BattlerIndex {
ATTACKER = -1,
PLAYER,
PLAYER_2,
ENEMY,

View File

@ -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() ];