From f6b41e33f1b7ed3fbc581f848271eaac92f16821 Mon Sep 17 00:00:00 2001 From: Zach Day Date: Fri, 9 Aug 2024 19:50:32 -0400 Subject: [PATCH] Move cancellation logic back to tag Wanted to increase similarity to the existing code base to avoid that stupid hyper beam error but it's still happening here --- src/data/battler-tags.ts | 21 +++++++++++++++++---- src/field/pokemon.ts | 6 +++--- src/phases.ts | 13 ++++--------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/data/battler-tags.ts b/src/data/battler-tags.ts index b9e9bd71204..e71064a0187 100644 --- a/src/data/battler-tags.ts +++ b/src/data/battler-tags.ts @@ -101,13 +101,26 @@ export abstract class DisablingBattlerTag extends BattlerTag { public abstract moveIsDisabled(move: Moves): boolean; constructor(tagType: BattlerTagType, turnCount: integer, sourceMove?: Moves, sourceId?: integer) { - super(tagType, BattlerTagLapseType.TURN_END, turnCount, sourceMove, sourceId); + super(tagType, [ BattlerTagLapseType.PRE_MOVE, BattlerTagLapseType.TURN_END ], turnCount, sourceMove, sourceId); } lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { - if (!super.lapse(pokemon, lapseType)) { - // Duration has expired - return false; + if (lapseType === BattlerTagLapseType.PRE_MOVE) { + // Cancel the affected pokemon's selected move + const phase = pokemon.scene.getCurrentPhase() as MovePhase; + const move = phase.move; + + if (!this.moveIsDisabled(move.moveId)) { + return true; + } + + pokemon.scene.queueMessage(this.interruptedText(pokemon, move.moveId)); + phase.fail(); + } else if (lapseType === BattlerTagLapseType.TURN_END) { + // On turn end, subtract from lifetime and remove this tag if 0 + if (!super.lapse(pokemon, lapseType)) { + return false; + } } return true; diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index e24b58cac49..bfcdb10be25 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -3634,7 +3634,7 @@ export class PlayerPokemon extends Pokemon { if (!this.isFainted()) { // If this Pokemon hasn't fainted, make sure the HP wasn't set over the new maximum this.hp = Math.min(this.hp, this.stats[Stat.HP]); - this.status = getRandomStatus(this.status, pokemon.status); // Get a random valid status between the two + this.status = getRandomStatus(this.status!, pokemon.status!); // Get a random valid status between the two // TODO: are the bangs correct? } else if (!pokemon.isFainted()) { // If this Pokemon fainted but the other hasn't, make sure the HP wasn't set to zero this.hp = Math.max(this.hp, 1); @@ -4331,12 +4331,12 @@ export class PokemonMove { * @param ignorePp If true, skips the PP check * @returns True if the move can be selected and used by the Pokemon, otherwise false. */ - isUsable(pokemon: Pokemon, ignorePp?: boolean): boolean { + isUsable(pokemon: Pokemon, ignorePp?: boolean, ignoreDisableTags?: boolean): boolean { if (!this.moveId) { return false; } - if (pokemon.isMoveDisabled(this.moveId)) { + if (!ignoreDisableTags && pokemon.isMoveDisabled(this.moveId)) { return false; } diff --git a/src/phases.ts b/src/phases.ts index 7dfb45525bd..8a1508ce575 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -2666,8 +2666,8 @@ export class MovePhase extends BattlePhase { this.cancelled = false; } - canMove(): boolean { - return this.pokemon.isActive(true) && this.move.isUsable(this.pokemon, this.ignorePp) && !!this.targets.length; + canMove(ignoreDisableTags?: boolean): boolean { + return this.pokemon.isActive(true) && this.move.isUsable(this.pokemon, this.ignorePp, ignoreDisableTags) && !!this.targets.length; } /**Signifies the current move should fail but still use PP */ @@ -2685,13 +2685,8 @@ export class MovePhase extends BattlePhase { console.log(Moves[this.move.moveId]); - if (!this.canMove()) { - if (this.move.moveId && this.pokemon.isMoveDisabled(this.move.moveId)) { - const interruptingTag = this.pokemon.getDisablingTag(this.move.moveId)!; - this.scene.queueMessage(interruptingTag.interruptedText(this.pokemon, this.move.moveId)); - this.pokemon.pushMoveHistory({ move: this.move.moveId, result: MoveResult.FAIL, virtual: false }); - this.fail(); - } else if (this.pokemon.isActive(true) && this.move.ppUsed >= this.move.getMovePp()) { // if the move PP was reduced from Spite or otherwise, the move fails + if (!this.canMove(true)) { + if (this.pokemon.isActive(true) && this.move.ppUsed >= this.move.getMovePp()) { // if the move PP was reduced from Spite or otherwise, the move fails this.fail(); this.showMoveText(); this.showFailedText();