From 24a9dba2c46e70fb2d06b87dec7dec952dc98686 Mon Sep 17 00:00:00 2001 From: Paul Beslin Date: Fri, 3 May 2024 00:18:05 +0200 Subject: [PATCH] Fix attacks with charge (solar beam, dig...) allowing to switch target on second turn --- src/data/battler-tags.ts | 8 ++++++++ src/data/enums/battler-tag-type.ts | 1 + src/data/move.ts | 5 ++++- src/phases.ts | 9 ++++++--- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/data/battler-tags.ts b/src/data/battler-tags.ts index 2521a0e03..8ff684394 100644 --- a/src/data/battler-tags.ts +++ b/src/data/battler-tags.ts @@ -391,6 +391,12 @@ export class FrenzyTag extends BattlerTag { } } +export class ChargingTag extends BattlerTag { + constructor(sourceMove: Moves, sourceId: integer) { + super(BattlerTagType.CHARGING, BattlerTagLapseType.CUSTOM, 1, sourceMove, sourceId); + } +} + export class EncoreTag extends BattlerTag { public moveId: Moves; @@ -1116,6 +1122,8 @@ export function getBattlerTag(tagType: BattlerTagType, turnCount: integer, sourc return new NightmareTag(); case BattlerTagType.FRENZY: return new FrenzyTag(sourceMove, sourceId); + case BattlerTagType.CHARGING: + return new ChargingTag(sourceMove, sourceId); case BattlerTagType.ENCORE: return new EncoreTag(sourceId); case BattlerTagType.HELPING_HAND: diff --git a/src/data/enums/battler-tag-type.ts b/src/data/enums/battler-tag-type.ts index f76e5526f..7a9f6ba8b 100644 --- a/src/data/enums/battler-tag-type.ts +++ b/src/data/enums/battler-tag-type.ts @@ -9,6 +9,7 @@ export enum BattlerTagType { SEEDED = "SEEDED", NIGHTMARE = "NIGHTMARE", FRENZY = "FRENZY", + CHARGING = "CHARGING", ENCORE = "ENCORE", HELPING_HAND = "HELPING_HAND", INGRAIN = "INGRAIN", diff --git a/src/data/move.ts b/src/data/move.ts index ea89788cf..21f376254 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -1325,10 +1325,13 @@ export class ChargeAttr extends OverrideMoveEffectAttr { user.getMoveQueue().push({ move: move.id, targets: [ target.getBattlerIndex() ], ignorePP: true }); if (this.sameTurn) user.scene.pushMovePhase(new MovePhase(user.scene, user, [ target.getBattlerIndex() ], user.moveset.find(m => m.moveId === move.id), true), this.followUpPriority); + user.addTag(BattlerTagType.CHARGING, 1, move.id, user.id); resolve(true); }); - } else + } else { + user.lapseTag(BattlerTagType.CHARGING); resolve(false); + } }); } diff --git a/src/phases.ts b/src/phases.ts index 40ab1f306..e4ed8d293 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -1686,6 +1686,8 @@ export class CommandPhase extends FieldPhase { console.log(moveTargets, playerPokemon.name); if (moveTargets.targets.length <= 1 || moveTargets.multiple) turnCommand.move.targets = moveTargets.targets; + else if(playerPokemon.getTag(BattlerTagType.CHARGING) && playerPokemon.getMoveQueue().length >= 1) + turnCommand.move.targets = playerPokemon.getMoveQueue()[0].targets; else this.scene.unshiftPhase(new SelectTargetPhase(this.scene, this.fieldIndex)); this.scene.currentBattle.turnCommands[this.fieldIndex] = turnCommand; @@ -2327,13 +2329,14 @@ export class MovePhase extends BattlePhase { showMoveText(): void { if (this.move.getMove().getAttrs(ChargeAttr).length) { - this.scene.queueMessage(getPokemonMessage(this.pokemon, ` used\n${this.move.getName()}!`), 500); const lastMove = this.pokemon.getLastXMoves() as TurnMove[]; - if (!lastMove.length || lastMove[0].move !== this.move.getMove().id || lastMove[0].result !== MoveResult.OTHER) + if (!lastMove.length || lastMove[0].move !== this.move.getMove().id || lastMove[0].result !== MoveResult.OTHER){ + this.scene.queueMessage(getPokemonMessage(this.pokemon, ` used\n${this.move.getName()}!`), 500); return; + } } - if (this.pokemon.getTag(BattlerTagType.RECHARGING|| BattlerTagType.INTERRUPTED)) + if (this.pokemon.getTag(BattlerTagType.RECHARGING || BattlerTagType.INTERRUPTED)) return; this.scene.queueMessage(getPokemonMessage(this.pokemon, ` used\n${this.move.getName()}!`), 500);