From 6437a5a8011c97f6e590b08d151cc4574193bf35 Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Sun, 1 Sep 2024 23:52:08 -0700 Subject: [PATCH 01/12] Attempt to merge changes --- src/phases/move-phase.ts | 471 +++++++++++++++++++++++---------------- 1 file changed, 281 insertions(+), 190 deletions(-) diff --git a/src/phases/move-phase.ts b/src/phases/move-phase.ts index e2893d587a7..d841825b333 100644 --- a/src/phases/move-phase.ts +++ b/src/phases/move-phase.ts @@ -32,6 +32,10 @@ export class MovePhase extends BattlePhase { protected failed: boolean; protected cancelled: boolean; + /** + * @param followUp Indicates that the move being uses is a "follow-up" - for example, a move being used by Metronome or Dancer. + * Follow-ups bypass a few failure conditions, including flinches, sleep/paralysis/freeze and volatile status checks, etc. + */ constructor(scene: BattleScene, pokemon: Pokemon, targets: BattlerIndex[], move: PokemonMove, followUp?: boolean, ignorePp?: boolean) { super(scene); @@ -63,189 +67,72 @@ export class MovePhase extends BattlePhase { console.log(Moves[this.move.moveId]); + /** + * Check if move is disabled or unusable (e.g. because it's out of PP due to a mid-turn Spite). + */ if (!this.canMove()) { if (this.move.moveId && this.pokemon.summonData?.disabledMove === this.move.moveId) { - this.scene.queueMessage(i18next.t("battle:moveDisabled", { moveName: this.move.getName() })); - } - 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.scene.queueMessage(`${this.move.getName()} is disabled!`); + + } else { this.showMoveText(); this.showFailedText(); } + return this.end(); } + this.pokemon.turnData.acted = true; + + // Reset hit-related turn data when starting follow-up moves (e.g. Metronomed moves, Dancer repeats) + if (this.followUp) { + this.pokemon.turnData.hitsLeft = undefined; + this.pokemon.turnData.hitCount = undefined; + } + + /** + * Check move to see if arena.ignoreAbilities should be true. + */ if (!this.followUp) { - if (this.move.getMove().checkFlag(MoveFlags.IGNORE_ABILITIES, this.pokemon, null)) { - this.scene.arena.setIgnoreAbilities(); - } + this.scene.arena.ignoreAbilities = this.move.getMove().checkFlag(MoveFlags.IGNORE_ABILITIES, this.pokemon, null); + } + + this.resolveRedirectTarget(); + + this.resolveCounterAttackTarget(); + + this.resolvePreMoveStatusEffects(); + + this.resolveFinalPreMoveCancellationChecks(); + + if (this.cancelled || this.failed) { + this.handlePreMoveFailures(); } else { - this.pokemon.turnData.hitsLeft = 0; // TODO: is `0` correct? - this.pokemon.turnData.hitCount = 0; // TODO: is `0` correct? + this.useMove(); } - // Move redirection abilities (ie. Storm Drain) only support single target moves - const moveTarget = this.targets.length === 1 - ? new Utils.IntegerHolder(this.targets[0]) - : null; - if (moveTarget) { - const oldTarget = moveTarget.value; - this.scene.getField(true).filter(p => p !== this.pokemon).forEach(p => applyAbAttrs(RedirectMoveAbAttr, p, null, false, this.move.moveId, moveTarget)); - this.pokemon.getOpponents().forEach(p => { - const redirectTag = p.getTag(CenterOfAttentionTag) as CenterOfAttentionTag; - if (redirectTag && (!redirectTag.powder || (!this.pokemon.isOfType(Type.GRASS) && !this.pokemon.hasAbility(Abilities.OVERCOAT)))) { - moveTarget.value = p.getBattlerIndex(); - } - }); - //Check if this move is immune to being redirected, and restore its target to the intended target if it is. - if ((this.pokemon.hasAbilityWithAttr(BlockRedirectAbAttr) || this.move.getMove().hasAttr(BypassRedirectAttr))) { - //If an ability prevented this move from being redirected, display its ability pop up. - if ((this.pokemon.hasAbilityWithAttr(BlockRedirectAbAttr) && !this.move.getMove().hasAttr(BypassRedirectAttr)) && oldTarget !== moveTarget.value) { - this.scene.unshiftPhase(new ShowAbilityPhase(this.scene, this.pokemon.getBattlerIndex(), this.pokemon.getPassiveAbility().hasAttr(BlockRedirectAbAttr))); - } - moveTarget.value = oldTarget; - } - this.targets[0] = moveTarget.value; + this.end(); + } + + resolveFinalPreMoveCancellationChecks() { + const targets = this.getActiveTargetPokemon(); + const moveQueue = this.pokemon.getMoveQueue(); + + // Cancellation edge cases - no targets remaining, or Moves.NONE is on the queue (TODO: when does this happen?) + if (targets.length === 0 || (moveQueue.length && moveQueue[0].move === Moves.NONE)) { + this.showFailedText(); + this.cancelled = true; } + } - // Check for counterattack moves to switch target - 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.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.getField()[this.targets[0]].hp === 0) { - const opposingField = this.pokemon.isPlayer() ? this.scene.getEnemyField() : this.scene.getPlayerField(); - //@ts-ignore - this.targets[0] = opposingField.find(p => p.hp > 0)?.getBattlerIndex(); //TODO: fix ts-ignore - } - } - } - if (this.targets[0] === BattlerIndex.ATTACKER) { - this.fail(); // Marks the move as failed for later in doMove - this.showMoveText(); - this.showFailedText(); - } - } - - const targets = this.scene.getField(true).filter(p => { - if (this.targets.indexOf(p.getBattlerIndex()) > -1) { - return true; - } - return false; - }); - - const doMove = () => { - this.pokemon.turnData.acted = true; // Record that the move was attempted, even if it fails - - this.pokemon.lapseTags(BattlerTagLapseType.PRE_MOVE); - - let ppUsed = 1; - // Filter all opponents to include only those this move is targeting - const targetedOpponents = this.pokemon.getOpponents().filter(o => this.targets.includes(o.getBattlerIndex())); - for (const opponent of targetedOpponents) { - if (this.move.ppUsed + ppUsed >= this.move.getMovePp()) { // If we're already at max PP usage, stop checking - break; - } - if (opponent.hasAbilityWithAttr(IncreasePpAbAttr)) { // Accounting for abilities like Pressure - ppUsed++; - } - } - - if (!this.followUp && this.canMove() && !this.cancelled) { - this.pokemon.lapseTags(BattlerTagLapseType.MOVE); - } - - const moveQueue = this.pokemon.getMoveQueue(); - if (this.cancelled || this.failed) { - if (this.failed) { - this.move.usePp(ppUsed); // Only use PP if the move failed - this.scene.eventTarget.dispatchEvent(new MoveUsedEvent(this.pokemon?.id, this.move.getMove(), this.move.ppUsed)); - } - - // Record a failed move so Abilities like Truant don't trigger next turn and soft-lock - this.pokemon.pushMoveHistory({ move: Moves.NONE, result: MoveResult.FAIL }); - - this.pokemon.lapseTags(BattlerTagLapseType.MOVE_EFFECT); // Remove any tags from moves like Fly/Dive/etc. - moveQueue.shift(); // Remove the second turn of charge moves - return this.end(); - } - - this.scene.triggerPokemonFormChange(this.pokemon, SpeciesFormChangePreMoveTrigger); - - if (this.move.moveId) { - this.showMoveText(); - } - - // This should only happen when there are no valid targets left on the field - if ((moveQueue.length && moveQueue[0].move === Moves.NONE) || !targets.length) { - this.showFailedText(); - this.cancel(); - - // Record a failed move so Abilities like Truant don't trigger next turn and soft-lock - this.pokemon.pushMoveHistory({ move: Moves.NONE, result: MoveResult.FAIL }); - - this.pokemon.lapseTags(BattlerTagLapseType.MOVE_EFFECT); // Remove any tags from moves like Fly/Dive/etc. - - moveQueue.shift(); - return this.end(); - } - - if ((!moveQueue.length || !moveQueue.shift()?.ignorePP) && !this.ignorePp) { // using .shift here clears out two turn moves once they've been used - this.move.usePp(ppUsed); - this.scene.eventTarget.dispatchEvent(new MoveUsedEvent(this.pokemon?.id, this.move.getMove(), this.move.ppUsed)); - } - - if (!allMoves[this.move.moveId].hasAttr(CopyMoveAttr)) { - this.scene.currentBattle.lastMove = this.move.moveId; - } - - // Assume conditions affecting targets only apply to moves with a single target - let success = this.move.getMove().applyConditions(this.pokemon, targets[0], this.move.getMove()); - const cancelled = new Utils.BooleanHolder(false); - let failedText = this.move.getMove().getFailedText(this.pokemon, targets[0], this.move.getMove(), cancelled); - if (success && this.scene.arena.isMoveWeatherCancelled(this.move.getMove())) { - success = false; - } else if (success && this.scene.arena.isMoveTerrainCancelled(this.pokemon, this.targets, this.move.getMove())) { - success = false; - if (failedText === null) { - failedText = getTerrainBlockMessage(targets[0], this.scene.arena.terrain?.terrainType!); // TODO: is this bang correct? - } - } - - /** - * Trigger pokemon type change before playing the move animation - * Will still change the user's type when using Roar, Whirlwind, Trick-or-Treat, and Forest's Curse, - * regardless of whether the move successfully executes or not. - */ - if (success || [Moves.ROAR, Moves.WHIRLWIND, Moves.TRICK_OR_TREAT, Moves.FORESTS_CURSE].includes(this.move.moveId)) { - applyPreAttackAbAttrs(PokemonTypeChangeAbAttr, this.pokemon, null, this.move.getMove()); - } - - if (success) { - this.scene.unshiftPhase(this.getEffectPhase()); - } else { - this.pokemon.pushMoveHistory({ move: this.move.moveId, targets: this.targets, result: MoveResult.FAIL, virtual: this.move.virtual }); - if (!cancelled.value) { - this.showFailedText(failedText); - } - } - // Checks if Dancer ability is triggered - if (this.move.getMove().hasFlag(MoveFlags.DANCE_MOVE) && !this.followUp) { - // Pokemon with Dancer can be on either side of the battle so we check in both cases - this.scene.getPlayerField().forEach(pokemon => { - applyPostMoveUsedAbAttrs(PostMoveUsedAbAttr, pokemon, this.move, this.pokemon, this.targets); - }); - this.scene.getEnemyField().forEach(pokemon => { - applyPostMoveUsedAbAttrs(PostMoveUsedAbAttr, pokemon, this.move, this.pokemon, this.targets); - }); - } - this.end(); - }; + getActiveTargetPokemon() { + return this.scene.getField(true).filter(p => this.targets.includes(p.getBattlerIndex())); + } + /** + * Handles Sleep/Paralysis/Freeze rolls and side effects, along with lapsing volatile statuses. + */ + resolvePreMoveStatusEffects() { if (!this.followUp && this.pokemon.status && !this.pokemon.status.isPostTurn()) { this.pokemon.status.incrementTurn(); let activated = false; @@ -274,25 +161,237 @@ export class MovePhase extends BattlePhase { if (activated) { this.scene.queueMessage(getStatusEffectActivationText(this.pokemon.status.effect, getPokemonNameWithAffix(this.pokemon))); this.scene.unshiftPhase(new CommonAnimPhase(this.scene, this.pokemon.getBattlerIndex(), undefined, CommonAnim.POISON + (this.pokemon.status.effect - 1))); - doMove(); - } else { - if (healed) { - this.scene.queueMessage(getStatusEffectHealText(this.pokemon.status.effect, getPokemonNameWithAffix(this.pokemon))); - this.pokemon.resetStatus(); - this.pokemon.updateInfo(); - } - doMove(); + } else if (healed) { + this.scene.queueMessage(getStatusEffectHealText(this.pokemon.status.effect, getPokemonNameWithAffix(this.pokemon))); + this.pokemon.resetStatus(); + this.pokemon.updateInfo(); } - } else { - doMove(); + } + + // Lapse tags that triggered before a move is used, regardless of whether or not it failed. + this.pokemon.lapseTags(BattlerTagLapseType.PRE_MOVE); + + // TODO: does this intentionally happen before the no targets/Moves.NONE on queue cancellation case is checked? + if (!this.followUp && this.canMove() && !this.cancelled) { + this.pokemon.lapseTags(BattlerTagLapseType.MOVE); } } - getEffectPhase(): MoveEffectPhase { - return new MoveEffectPhase(this.scene, this.pokemon.getBattlerIndex(), this.targets, this.move); + useMove() { + const targets = this.getActiveTargetPokemon(); + const moveQueue = this.pokemon.getMoveQueue(); + + // form changes happen even before we know that the move wll execute. + this.scene.triggerPokemonFormChange(this.pokemon, SpeciesFormChangePreMoveTrigger); + + this.showMoveText(); + + // TODO: Clean up implementation of two-turn moves. + if (moveQueue.length > 0) { // Using .shift here clears out two turn moves once they've been used + this.ignorePp = moveQueue.shift().ignorePP; + } + + // "commit" to using the move, deducting PP. + if (!this.ignorePp) { + const ppUsed = 1 + this.getPpIncreaseFromPressure(targets); + + this.move.usePp(ppUsed); + this.scene.eventTarget.dispatchEvent(new MoveUsedEvent(this.pokemon?.id, this.move.getMove(), ppUsed)); + } + + // Update the battle's "last move" pointer, unless we're currently mimicking a move. + // TODO: what does this accomplish? what would break if we didn't do it? + if (!allMoves[this.move.moveId].hasAttr(CopyMoveAttr)) { + this.scene.currentBattle.lastMove = this.move.moveId; + } + + /** + * Determine if the move is successful (meaning that its damage/effects can be attempted) + * by checking that all of the following are true: + * - Conditional attributes of the move are all met + * - The target's `ForceSwitchOutImmunityAbAttr` is not triggered (see {@linkcode Move.prototype.applyConditions}) + * - Weather does not block the move + * - Terrain does not block the move + * + * TODO: These steps are straightforward, but the implementation below is extremely convoluted. + */ + + const move = this.move.getMove(); + + // Move conditions assume the move has a single target (is this sustainable?) + const passesConditions = move.applyConditions(this.pokemon, targets[0], move); + const failureMessage = move.getFailedText(this.pokemon, targets[0], move, null); + + const failedWithMessage = failureMessage !== null && failureMessage !== undefined; + let failedDueToWeather: boolean, failedDueToTerrain: boolean; + + if (!failedWithMessage) { + failedDueToWeather = this.scene.arena.isMoveWeatherCancelled(move); + + if (!failedDueToWeather) { + failedDueToTerrain = this.scene.arena.isMoveTerrainCancelled(this.pokemon, this.targets, move); + } + } + + const success = passesConditions && !failedWithMessage && !failedDueToWeather && !failedDueToTerrain; + + /** + * If the move has not failed, trigger ability-based user type changes and then execute it. + * + * Notably, Roar, Whirlwind, Trick-or-Treat, and Forest's Curse will trigger these type changes even + * if the move fails. + * + * TODO: Should these exceptions have a move flag? + */ + if (success) { + applyPreAttackAbAttrs(PokemonTypeChangeAbAttr, this.pokemon, null, this.move.getMove()); + this.scene.unshiftPhase(new MoveEffectPhase(this.scene, this.pokemon.getBattlerIndex(), this.targets, this.move)); + + } else { + if ([Moves.ROAR, Moves.WHIRLWIND, Moves.TRICK_OR_TREAT, Moves.FORESTS_CURSE].includes(this.move.moveId)) { + applyPreAttackAbAttrs(PokemonTypeChangeAbAttr, this.pokemon, null, this.move.getMove()); + } + + this.pokemon.pushMoveHistory({ move: this.move.moveId, targets: this.targets, result: MoveResult.FAIL, virtual: this.move.virtual }); + + let failedText: string | undefined; + + if (failedWithMessage) { + failedText = failureMessage; + + } else if (failedDueToTerrain) { + failedText = getTerrainBlockMessage(this.pokemon, this.scene.arena.getTerrainType()); + } + + this.showFailedText(failedText); + } + + // Handle Dance, which triggers immediately after a move is used (rather than waiting on this.end()). + // Note that the !this.followUp check here prevents an infinite Dancer loop. + if (this.move.getMove().hasFlag(MoveFlags.DANCE_MOVE) && !this.followUp) { + this.scene.getField(true).forEach(pokemon => { + applyPostMoveUsedAbAttrs(PostMoveUsedAbAttr, pokemon, this.move, this.pokemon, this.targets); + }); + } + } + + end() { + if (!this.followUp && this.canMove()) { + this.scene.unshiftPhase(new MoveEndPhase(this.scene, this.pokemon.getBattlerIndex())); + } + + super.end(); + } + + /** + * Applies PP increasing abilities (so, Pressure) if they exist on the target pokemon. + * Note that targets must include only active pokemon. + * + * TODO: This hardcodes the PP increase at 1 per opponent, rather than deferring to the ability. + */ + getPpIncreaseFromPressure(targets: Pokemon[]) { + const foesWithPressure = this.pokemon.getOpponents().filter(o => targets.includes(o) && o.isActive(true) && o.hasAbilityWithAttr(IncreasePpAbAttr)); + return foesWithPressure.length; + } + + /** + * Modifies this.targets in place, based upon: + * - Move redirection abilities, effects, etc. + * - Counterattacks, which pass a special value into the `targets` constructor param (`[BattlerIndex.ATTACKER]`). + */ + resolveRedirectTarget() { + if (this.targets.length === 1) { + const currentTarget = this.targets[0]; + const redirectTarget = new Utils.IntegerHolder(currentTarget); + + // check move redirection abilities of every pokemon *except* the user. + this.scene.getField(true).filter(p => p !== this.pokemon).forEach(p => applyAbAttrs(RedirectMoveAbAttr, p, null, this.move.moveId, redirectTarget)); + + // check for center-of-attention tags (note that this will override redirect abilities) + this.pokemon.getOpponents().forEach(p => { + const redirectTag = p.getTag(CenterOfAttentionTag) as CenterOfAttentionTag; + + // TODO: don't hardcode this interaction. + // Handle interaction between the rage powder center-of-attention tag and moves used by grass types/overcoat-havers (which are immune to RP's redirect) + if (redirectTag && (!redirectTag.powder || (!this.pokemon.isOfType(Type.GRASS) && !this.pokemon.hasAbility(Abilities.OVERCOAT)))) { + redirectTarget.value = p.getBattlerIndex(); + } + }); + + if (currentTarget !== redirectTarget.value) { + if (this.move.getMove().hasAttr(BypassRedirectAttr)) { + redirectTarget.value = currentTarget; + + } else if (this.pokemon.hasAbilityWithAttr(BlockRedirectAbAttr)) { + redirectTarget.value = currentTarget; + this.scene.unshiftPhase(new ShowAbilityPhase(this.scene, this.pokemon.getBattlerIndex(), this.pokemon.getPassiveAbility().hasAttr(BlockRedirectAbAttr))); + } + + this.targets[0] = redirectTarget.value; + } + } + } + + /** + * Counter-attacking moves pass in `[BattlerIndex.ATTACKER]` into the constructor's `targets` param. + * This function modifies `this.targets` to reflect the actual battler index of the user's last + * attacker. + * + * If there is no last attacker, or they are no longer on the field, a message is displayed and the + * move is marked for failure. + */ + resolveCounterAttackTarget() { + 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.fail(); + this.showMoveText(); + this.showFailedText(); + } + } + } + + handlePreMoveFailures() { + if (this.cancelled || this.failed) { + if (this.failed) { + const ppUsed = this.ignorePp ? 0 : 1; // note that failed move PP usage isn't affected by pressure + + if (ppUsed) { + this.move.usePp(); + } + + this.scene.eventTarget.dispatchEvent(new MoveUsedEvent(this.pokemon?.id, this.move.getMove(), ppUsed)); + } + + // Record a cancelled OR failed move in move history, so Abilities like Truant don't trigger on the + // next turn and soft-lock. + this.pokemon.pushMoveHistory({ move: Moves.NONE, result: MoveResult.FAIL }); + + // Semi-invulnerable battler tags (Fly/Dive/etc.) are intended to lapse on move effects, but also need + // to lapse on move failure/cancellation. + // TODO: ...this seems weird. + this.pokemon.lapseTags(BattlerTagLapseType.MOVE_EFFECT); + + // Remove the second turn of charge moves + // TODO: handle charge moves more gracefully + this.pokemon.getMoveQueue().shift(); + } } showMoveText(): void { + if (this.move.moveId === Moves.NONE) { + return; + } + if (this.move.getMove().hasAttr(ChargeAttr)) { const lastMove = this.pokemon.getLastXMoves() as TurnMove[]; if (!lastMove.length || lastMove[0].move !== this.move.getMove().id || lastMove[0].result !== MoveResult.OTHER) { @@ -312,18 +411,10 @@ export class MovePhase extends BattlePhase { pokemonNameWithAffix: getPokemonNameWithAffix(this.pokemon), moveName: this.move.getName() }), 500); - applyMoveAttrs(PreMoveMessageAttr, this.pokemon, this.pokemon.getOpponents().find(() => true)!, this.move.getMove()); //TODO: is the bang correct here? + applyMoveAttrs(PreMoveMessageAttr, this.pokemon, this.pokemon.getOpponents().find(() => true), this.move.getMove()); } - showFailedText(failedText: string | null = null): void { + showFailedText(failedText: string = null): void { this.scene.queueMessage(failedText || i18next.t("battle:attackFailed")); } - - end() { - if (!this.followUp && this.canMove()) { - this.scene.unshiftPhase(new MoveEndPhase(this.scene, this.pokemon.getBattlerIndex())); - } - - super.end(); - } } From c3821c0ef3edf28ee439e1a1f9d0a4a8c903eebf Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Mon, 2 Sep 2024 00:20:21 -0700 Subject: [PATCH 02/12] Fix errors --- src/field/arena.ts | 12 ++++---- src/field/pokemon.ts | 4 +-- src/phases/move-phase.ts | 65 ++++++++++++++++++++-------------------- 3 files changed, 41 insertions(+), 40 deletions(-) diff --git a/src/field/arena.ts b/src/field/arena.ts index e8defbd1a8e..8d0906c649f 100644 --- a/src/field/arena.ts +++ b/src/field/arena.ts @@ -391,16 +391,16 @@ export class Arena { return true; } - isMoveWeatherCancelled(move: Move) { - return this.weather && !this.weather.isEffectSuppressed(this.scene) && this.weather.isMoveWeatherCancelled(move); + isMoveWeatherCancelled(move: Move): boolean { + return (this.weather && !this.weather.isEffectSuppressed(this.scene) && this.weather.isMoveWeatherCancelled(move)) as boolean; } - isMoveTerrainCancelled(user: Pokemon, targets: BattlerIndex[], move: Move) { - return this.terrain && this.terrain.isMoveTerrainCancelled(user, targets, move); + isMoveTerrainCancelled(user: Pokemon, targets: BattlerIndex[], move: Move): boolean { + return (this.terrain && this.terrain.isMoveTerrainCancelled(user, targets, move)) as boolean; } - getTerrainType() : TerrainType { - return this.terrain?.terrainType || TerrainType.NONE; + getTerrainType(): TerrainType { + return this.terrain?.terrainType ?? TerrainType.NONE; } getAttackTypeMultiplier(attackType: Type, grounded: boolean): number { diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 8594d5b769b..34eb6b7a512 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -4368,8 +4368,8 @@ export class PokemonBattleSummonData { export class PokemonTurnData { public flinched: boolean = false; public acted: boolean = false; - public hitCount: number; - public hitsLeft: number; + public hitCount: number = 0; + public hitsLeft: number = 0; public damageDealt: number = 0; public currDamageDealt: number = 0; public damageTaken: number = 0; diff --git a/src/phases/move-phase.ts b/src/phases/move-phase.ts index d841825b333..cba5d18fa2e 100644 --- a/src/phases/move-phase.ts +++ b/src/phases/move-phase.ts @@ -1,27 +1,27 @@ -import BattleScene from "#app/battle-scene.js"; -import { BattlerIndex } from "#app/battle.js"; -import { applyAbAttrs, applyPostMoveUsedAbAttrs, applyPreAttackAbAttrs, BlockRedirectAbAttr, IncreasePpAbAttr, PokemonTypeChangeAbAttr, PostMoveUsedAbAttr, RedirectMoveAbAttr } from "#app/data/ability.js"; -import { CommonAnim } from "#app/data/battle-anims.js"; -import { BattlerTagLapseType, CenterOfAttentionTag } from "#app/data/battler-tags.js"; -import { allMoves, applyMoveAttrs, BypassRedirectAttr, BypassSleepAttr, ChargeAttr, CopyMoveAttr, HealStatusEffectAttr, MoveFlags, PreMoveMessageAttr } from "#app/data/move.js"; -import { SpeciesFormChangePreMoveTrigger } from "#app/data/pokemon-forms.js"; -import { getStatusEffectActivationText, getStatusEffectHealText } from "#app/data/status-effect.js"; -import { Type } from "#app/data/type.js"; -import { getTerrainBlockMessage } from "#app/data/weather.js"; -import { Abilities } from "#app/enums/abilities.js"; -import { BattlerTagType } from "#app/enums/battler-tag-type.js"; -import { Moves } from "#app/enums/moves.js"; -import { StatusEffect } from "#app/enums/status-effect.js"; -import { MoveUsedEvent } from "#app/events/battle-scene.js"; -import Pokemon, { MoveResult, PokemonMove, TurnMove } from "#app/field/pokemon.js"; -import { getPokemonNameWithAffix } from "#app/messages.js"; -import * as Utils from "#app/utils.js"; +import { BattlerIndex } from "#app/battle"; +import BattleScene from "#app/battle-scene"; +import { applyAbAttrs, applyPostMoveUsedAbAttrs, applyPreAttackAbAttrs, BlockRedirectAbAttr, IncreasePpAbAttr, PokemonTypeChangeAbAttr, PostMoveUsedAbAttr, RedirectMoveAbAttr } from "#app/data/ability"; +import { CommonAnim } from "#app/data/battle-anims"; +import { BattlerTagLapseType, CenterOfAttentionTag } from "#app/data/battler-tags"; +import { allMoves, applyMoveAttrs, BypassRedirectAttr, BypassSleepAttr, ChargeAttr, CopyMoveAttr, HealStatusEffectAttr, MoveFlags, PreMoveMessageAttr } from "#app/data/move"; +import { SpeciesFormChangePreMoveTrigger } from "#app/data/pokemon-forms"; +import { getStatusEffectActivationText, getStatusEffectHealText } from "#app/data/status-effect"; +import { Type } from "#app/data/type"; +import { getTerrainBlockMessage } from "#app/data/weather"; +import { Abilities } from "#app/enums/abilities"; +import { BattlerTagType } from "#app/enums/battler-tag-type"; +import { Moves } from "#app/enums/moves"; +import { StatusEffect } from "#app/enums/status-effect"; +import { MoveUsedEvent } from "#app/events/battle-scene"; +import Pokemon, { MoveResult, PokemonMove, TurnMove } from "#app/field/pokemon"; +import { getPokemonNameWithAffix } from "#app/messages"; +import { BattlePhase } from "#app/phases/battle-phase"; +import { CommonAnimPhase } from "#app/phases/common-anim-phase"; +import { MoveEffectPhase } from "#app/phases/move-effect-phase"; +import { MoveEndPhase } from "#app/phases/move-end-phase"; +import { ShowAbilityPhase } from "#app/phases/show-ability-phase"; +import * as Utils from "#app/utils"; import i18next from "i18next"; -import { BattlePhase } from "./battle-phase"; -import { CommonAnimPhase } from "./common-anim-phase"; -import { MoveEffectPhase } from "./move-effect-phase"; -import { MoveEndPhase } from "./move-end-phase"; -import { ShowAbilityPhase } from "./show-ability-phase"; export class MovePhase extends BattlePhase { public pokemon: Pokemon; @@ -86,8 +86,8 @@ export class MovePhase extends BattlePhase { // Reset hit-related turn data when starting follow-up moves (e.g. Metronomed moves, Dancer repeats) if (this.followUp) { - this.pokemon.turnData.hitsLeft = undefined; - this.pokemon.turnData.hitCount = undefined; + this.pokemon.turnData.hitsLeft = 0; + this.pokemon.turnData.hitCount = 0; } /** @@ -188,7 +188,7 @@ export class MovePhase extends BattlePhase { // TODO: Clean up implementation of two-turn moves. if (moveQueue.length > 0) { // Using .shift here clears out two turn moves once they've been used - this.ignorePp = moveQueue.shift().ignorePP; + this.ignorePp = moveQueue.shift()?.ignorePP ?? false; } // "commit" to using the move, deducting PP. @@ -220,7 +220,7 @@ export class MovePhase extends BattlePhase { // Move conditions assume the move has a single target (is this sustainable?) const passesConditions = move.applyConditions(this.pokemon, targets[0], move); - const failureMessage = move.getFailedText(this.pokemon, targets[0], move, null); + const failureMessage = move.getFailedText(this.pokemon, targets[0], move, new Utils.BooleanHolder(false)); const failedWithMessage = failureMessage !== null && failureMessage !== undefined; let failedDueToWeather: boolean, failedDueToTerrain: boolean; @@ -233,6 +233,7 @@ export class MovePhase extends BattlePhase { } } + // @ts-expect-error const success = passesConditions && !failedWithMessage && !failedDueToWeather && !failedDueToTerrain; /** @@ -258,7 +259,7 @@ export class MovePhase extends BattlePhase { if (failedWithMessage) { failedText = failureMessage; - + // @ts-expect-error } else if (failedDueToTerrain) { failedText = getTerrainBlockMessage(this.pokemon, this.scene.arena.getTerrainType()); } @@ -305,7 +306,7 @@ export class MovePhase extends BattlePhase { const redirectTarget = new Utils.IntegerHolder(currentTarget); // check move redirection abilities of every pokemon *except* the user. - this.scene.getField(true).filter(p => p !== this.pokemon).forEach(p => applyAbAttrs(RedirectMoveAbAttr, p, null, this.move.moveId, redirectTarget)); + this.scene.getField(true).filter(p => p !== this.pokemon).forEach(p => applyAbAttrs(RedirectMoveAbAttr, p, null, false, this.move.moveId, redirectTarget)); // check for center-of-attention tags (note that this will override redirect abilities) this.pokemon.getOpponents().forEach(p => { @@ -411,10 +412,10 @@ export class MovePhase extends BattlePhase { pokemonNameWithAffix: getPokemonNameWithAffix(this.pokemon), moveName: this.move.getName() }), 500); - applyMoveAttrs(PreMoveMessageAttr, this.pokemon, this.pokemon.getOpponents().find(() => true), this.move.getMove()); + applyMoveAttrs(PreMoveMessageAttr, this.pokemon, this.pokemon.getOpponents().find(() => true) ?? null, this.move.getMove()); } - showFailedText(failedText: string = null): void { - this.scene.queueMessage(failedText || i18next.t("battle:attackFailed")); + showFailedText(failedText?: string): void { + this.scene.queueMessage(failedText ?? i18next.t("battle:attackFailed")); } } From 841f032e450ab50d9191179cefbe21045e547050 Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Fri, 6 Sep 2024 00:17:38 -0700 Subject: [PATCH 03/12] Add some missing code from updates --- src/phases/move-phase.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/phases/move-phase.ts b/src/phases/move-phase.ts index 6206a0f870c..e94bf3557d3 100644 --- a/src/phases/move-phase.ts +++ b/src/phases/move-phase.ts @@ -29,8 +29,8 @@ export class MovePhase extends BattlePhase { public targets: BattlerIndex[]; protected followUp: boolean; protected ignorePp: boolean; - protected failed: boolean; - protected cancelled: boolean; + protected failed: boolean = false; + protected cancelled: boolean = false; /** * @param followUp Indicates that the move being uses is a "follow-up" - for example, a move being used by Metronome or Dancer. @@ -44,8 +44,6 @@ export class MovePhase extends BattlePhase { this.move = move; this.followUp = followUp ?? false; this.ignorePp = ignorePp ?? false; - this.failed = false; - this.cancelled = false; } canMove(ignoreDisableTags?: boolean): boolean { @@ -213,7 +211,8 @@ export class MovePhase extends BattlePhase { const move = this.move.getMove(); - // Move conditions assume the move has a single target (is this sustainable?) + // Move conditions assume the move has a single target + // TODO: is this sustainable? const passesConditions = move.applyConditions(this.pokemon, targets[0], move); const failureMessage = move.getFailedText(this.pokemon, targets[0], move, new Utils.BooleanHolder(false)); @@ -298,7 +297,7 @@ export class MovePhase extends BattlePhase { resolveRedirectTarget() { if (this.targets.length === 1) { const currentTarget = this.targets[0]; - const redirectTarget = new Utils.IntegerHolder(currentTarget); + const redirectTarget = new Utils.NumberHolder(currentTarget); // check move redirection abilities of every pokemon *except* the user. this.scene.getField(true).filter(p => p !== this.pokemon).forEach(p => applyAbAttrs(RedirectMoveAbAttr, p, null, false, this.move.moveId, redirectTarget)); @@ -339,13 +338,20 @@ export class MovePhase extends BattlePhase { resolveCounterAttackTarget() { 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; + const attacker = this.pokemon.scene.getPokemonById(this.pokemon.turnData.attacksReceived[0].sourceId); if (attacker?.isActive(true)) { this.targets[0] = attacker.getBattlerIndex(); } + + // 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.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() ?? BattlerIndex.ATTACKER; + } + } } if (this.targets[0] === BattlerIndex.ATTACKER) { From 9f2a785fddb995401a663202794a3f635091b4ae Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Fri, 6 Sep 2024 00:37:42 -0700 Subject: [PATCH 04/12] Separate tag lapsing out of the status resolution function --- src/phases/move-phase.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/phases/move-phase.ts b/src/phases/move-phase.ts index e94bf3557d3..a2573abf3a1 100644 --- a/src/phases/move-phase.ts +++ b/src/phases/move-phase.ts @@ -96,6 +96,8 @@ export class MovePhase extends BattlePhase { this.resolvePreMoveStatusEffects(); + this.lapsePreMoveAndMoveTags(); + this.resolveFinalPreMoveCancellationChecks(); if (this.cancelled || this.failed) { @@ -160,8 +162,13 @@ export class MovePhase extends BattlePhase { this.pokemon.updateInfo(); } } + } - // Lapse tags that triggered before a move is used, regardless of whether or not it failed. + /** + * Lapse `PRE_MOVE` tags that trigger before a move is used, regardless of whether or not it failed. + * Also lapse `MOVE` tags if the move should be successful. + */ + lapsePreMoveAndMoveTags() { this.pokemon.lapseTags(BattlerTagLapseType.PRE_MOVE); // TODO: does this intentionally happen before the no targets/Moves.NONE on queue cancellation case is checked? From 006c918e0bc6fce78fa86f29c84f9f7d232aa763 Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Fri, 6 Sep 2024 01:08:50 -0700 Subject: [PATCH 05/12] Fix multi-hit moves --- src/field/pokemon.ts | 2 +- src/phases/move-effect-phase.ts | 2 +- src/phases/move-phase.ts | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index f163755eb53..f98b8f2c008 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -4537,7 +4537,7 @@ export class PokemonTurnData { public flinched: boolean = false; public acted: boolean = false; public hitCount: number = 0; - public hitsLeft: number = 0; + public hitsLeft: number = -1; public damageDealt: number = 0; public currDamageDealt: number = 0; public damageTaken: number = 0; diff --git a/src/phases/move-effect-phase.ts b/src/phases/move-effect-phase.ts index 9b22c520e19..e0ab8bb3ee6 100644 --- a/src/phases/move-effect-phase.ts +++ b/src/phases/move-effect-phase.ts @@ -69,7 +69,7 @@ export class MoveEffectPhase extends PokemonPhase { * resolve the move's total hit count. This block combines the * effects of the move itself, Parental Bond, and Multi-Lens to do so. */ - if (user.turnData.hitsLeft === undefined) { + if (user.turnData.hitsLeft === -1) { const hitCount = new Utils.IntegerHolder(1); // Assume single target for multi hit applyMoveAttrs(MultiHitAttr, user, this.getTarget() ?? null, move, hitCount); diff --git a/src/phases/move-phase.ts b/src/phases/move-phase.ts index a2573abf3a1..a2a72061053 100644 --- a/src/phases/move-phase.ts +++ b/src/phases/move-phase.ts @@ -83,11 +83,11 @@ export class MovePhase extends BattlePhase { this.pokemon.turnData.hitCount = 0; } - /** - * Check move to see if arena.ignoreAbilities should be true. - */ + // Check move to see if arena.ignoreAbilities should be true. if (!this.followUp) { - this.scene.arena.ignoreAbilities = this.move.getMove().checkFlag(MoveFlags.IGNORE_ABILITIES, this.pokemon, null); + if (this.move.getMove().checkFlag(MoveFlags.IGNORE_ABILITIES, this.pokemon, null)) { + this.scene.arena.setIgnoreAbilities(); + } } this.resolveRedirectTarget(); From 3aea343dc543b6fedb0681a66fe1dcb4b800b375 Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Fri, 6 Sep 2024 02:22:37 -0700 Subject: [PATCH 06/12] Fix multi-hit moves called from Metronome/etc, fixes #3914 --- src/phases/move-phase.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/phases/move-phase.ts b/src/phases/move-phase.ts index a2a72061053..5e35025413a 100644 --- a/src/phases/move-phase.ts +++ b/src/phases/move-phase.ts @@ -79,7 +79,7 @@ export class MovePhase extends BattlePhase { // Reset hit-related turn data when starting follow-up moves (e.g. Metronomed moves, Dancer repeats) if (this.followUp) { - this.pokemon.turnData.hitsLeft = 0; + this.pokemon.turnData.hitsLeft = -1; this.pokemon.turnData.hitCount = 0; } From da34c6e5f25aa89725aee11e34835fa2d281a3d7 Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Fri, 6 Sep 2024 02:29:18 -0700 Subject: [PATCH 07/12] Replace `.find()` with `[0]` --- src/phases/move-phase.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/phases/move-phase.ts b/src/phases/move-phase.ts index 5e35025413a..b774c533a34 100644 --- a/src/phases/move-phase.ts +++ b/src/phases/move-phase.ts @@ -420,7 +420,7 @@ export class MovePhase extends BattlePhase { pokemonNameWithAffix: getPokemonNameWithAffix(this.pokemon), moveName: this.move.getName() }), 500); - applyMoveAttrs(PreMoveMessageAttr, this.pokemon, this.pokemon.getOpponents().find(() => true) ?? null, this.move.getMove()); + applyMoveAttrs(PreMoveMessageAttr, this.pokemon, this.pokemon.getOpponents()[0], this.move.getMove()); } showFailedText(failedText?: string): void { From 9635c4b62fc49aad7b0072ad72ee2cae5d497028 Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Fri, 6 Sep 2024 02:34:51 -0700 Subject: [PATCH 08/12] Remove a "TODO" comment (answer: it's for moves like Copycat/etc) --- src/phases/move-phase.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/phases/move-phase.ts b/src/phases/move-phase.ts index b774c533a34..507e45ac7b8 100644 --- a/src/phases/move-phase.ts +++ b/src/phases/move-phase.ts @@ -200,7 +200,6 @@ export class MovePhase extends BattlePhase { } // Update the battle's "last move" pointer, unless we're currently mimicking a move. - // TODO: what does this accomplish? what would break if we didn't do it? if (!allMoves[this.move.moveId].hasAttr(CopyMoveAttr)) { this.scene.currentBattle.lastMove = this.move.moveId; } From 5bd259335bc5a56ec819952655989cfc5aba8982 Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Sat, 7 Sep 2024 01:25:02 -0700 Subject: [PATCH 09/12] Move some comments to tsdocs, add tsdocs for `canMove()` --- src/phases/move-phase.ts | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/phases/move-phase.ts b/src/phases/move-phase.ts index 507e45ac7b8..35be5513d9e 100644 --- a/src/phases/move-phase.ts +++ b/src/phases/move-phase.ts @@ -46,6 +46,11 @@ export class MovePhase extends BattlePhase { this.ignorePp = ignorePp ?? false; } + /** + * Checks if the pokemon is active, if the move is usable, and that the move is targetting something. + * @param ignoreDisableTags `true` to not check if the move is disabled + * @returns `true` if all the checks pass + */ canMove(ignoreDisableTags?: boolean): boolean { return this.pokemon.isActive(true) && this.move.isUsable(this.pokemon, this.ignorePp, ignoreDisableTags) && !!this.targets.length; } @@ -109,11 +114,11 @@ export class MovePhase extends BattlePhase { this.end(); } + /** Check for cancellation edge cases - no targets remaining, or Moves.NONE is on the queue (TODO: when does this happen?) */ resolveFinalPreMoveCancellationChecks() { const targets = this.getActiveTargetPokemon(); const moveQueue = this.pokemon.getMoveQueue(); - // Cancellation edge cases - no targets remaining, or Moves.NONE is on the queue (TODO: when does this happen?) if (targets.length === 0 || (moveQueue.length && moveQueue[0].move === Moves.NONE)) { this.showFailedText(); this.cancelled = true; @@ -124,9 +129,7 @@ export class MovePhase extends BattlePhase { return this.scene.getField(true).filter(p => this.targets.includes(p.getBattlerIndex())); } - /** - * Handles Sleep/Paralysis/Freeze rolls and side effects, along with lapsing volatile statuses. - */ + /** Handles Sleep/Paralysis/Freeze rolls and side effects, along with lapsing volatile statuses. */ resolvePreMoveStatusEffects() { if (!this.followUp && this.pokemon.status && !this.pokemon.status.isPostTurn()) { this.pokemon.status.incrementTurn(); @@ -368,10 +371,24 @@ export class MovePhase extends BattlePhase { } } + /** + * Handles the case where the move was cancelled or failed: + * - Uses PP if the move failed (not cancelled) and should use PP (failed moves are not affected by Pressure) + * - Records a cancelled OR failed move in move history, so Abilities like Truant don't trigger on the + * next turn and soft-lock. + * - Lapses `MOVE_EFFECT` tags: + * - Semi-invulnerable battler tags (Fly/Dive/etc.) are intended to lapse on move effects, but also need + * to lapse on move failure/cancellation. + * + * TODO: ...this seems weird. + * - Removes the second turn of charge moves + * + * TODO: handle charge moves more gracefully + */ handlePreMoveFailures() { if (this.cancelled || this.failed) { if (this.failed) { - const ppUsed = this.ignorePp ? 0 : 1; // note that failed move PP usage isn't affected by pressure + const ppUsed = this.ignorePp ? 0 : 1; if (ppUsed) { this.move.usePp(); @@ -380,17 +397,10 @@ export class MovePhase extends BattlePhase { this.scene.eventTarget.dispatchEvent(new MoveUsedEvent(this.pokemon?.id, this.move.getMove(), ppUsed)); } - // Record a cancelled OR failed move in move history, so Abilities like Truant don't trigger on the - // next turn and soft-lock. this.pokemon.pushMoveHistory({ move: Moves.NONE, result: MoveResult.FAIL }); - // Semi-invulnerable battler tags (Fly/Dive/etc.) are intended to lapse on move effects, but also need - // to lapse on move failure/cancellation. - // TODO: ...this seems weird. this.pokemon.lapseTags(BattlerTagLapseType.MOVE_EFFECT); - // Remove the second turn of charge moves - // TODO: handle charge moves more gracefully this.pokemon.getMoveQueue().shift(); } } From 7d340f21907fc6d89f5fcceccc8cf80e7210d0e6 Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Sat, 7 Sep 2024 01:34:02 -0700 Subject: [PATCH 10/12] Make `pokemon`, `move` and `targets` fields `protected set`/`public get` --- src/phases/move-phase.ts | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/phases/move-phase.ts b/src/phases/move-phase.ts index 35be5513d9e..cf99742b17d 100644 --- a/src/phases/move-phase.ts +++ b/src/phases/move-phase.ts @@ -24,14 +24,38 @@ import * as Utils from "#app/utils"; import i18next from "i18next"; export class MovePhase extends BattlePhase { - public pokemon: Pokemon; - public move: PokemonMove; - public targets: BattlerIndex[]; + protected _pokemon: Pokemon; + protected _move: PokemonMove; + protected _targets: BattlerIndex[]; protected followUp: boolean; protected ignorePp: boolean; protected failed: boolean = false; protected cancelled: boolean = false; + public get pokemon(): Pokemon { + return this._pokemon; + } + + protected set pokemon(pokemon: Pokemon) { + this._pokemon = pokemon; + } + + public get move(): PokemonMove { + return this._move; + } + + protected set move(move: PokemonMove) { + this._move = move; + } + + public get targets(): BattlerIndex[] { + return this._targets; + } + + protected set targets(targets: BattlerIndex[]) { + this._targets = targets; + } + /** * @param followUp Indicates that the move being uses is a "follow-up" - for example, a move being used by Metronome or Dancer. * Follow-ups bypass a few failure conditions, including flinches, sleep/paralysis/freeze and volatile status checks, etc. From f131d99715f2e3e04541b9aa37f2536b536580b2 Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Tue, 10 Sep 2024 05:07:29 -0700 Subject: [PATCH 11/12] Remove unused function `BattleScene.pushMovePhase` --- src/battle-scene.ts | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index ff4258a13f5..cbf9703e979 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -15,7 +15,7 @@ import { TextStyle, addTextObject, getTextColor } from "./ui/text"; import { allMoves } from "./data/move"; import { ModifierPoolType, getDefaultModifierTypeForTier, getEnemyModifierTypesForWave, getLuckString, getLuckTextTint, getModifierPoolForType, getModifierType, getPartyLuckValue, modifierTypes } from "./modifier/modifier-type"; import AbilityBar from "./ui/ability-bar"; -import { BlockItemTheftAbAttr, DoubleBattleChanceAbAttr, ChangeMovePriorityAbAttr, PostBattleInitAbAttr, applyAbAttrs, applyPostBattleInitAbAttrs } from "./data/ability"; +import { BlockItemTheftAbAttr, DoubleBattleChanceAbAttr, PostBattleInitAbAttr, applyAbAttrs, applyPostBattleInitAbAttrs } from "./data/ability"; import { allAbilities } from "./data/ability"; import Battle, { BattleType, FixedBattleConfig } from "./battle"; import { GameMode, GameModes, getGameMode } from "./game-mode"; @@ -2215,17 +2215,6 @@ export default class BattleScene extends SceneBase { return false; } - pushMovePhase(movePhase: MovePhase, priorityOverride?: integer): void { - const movePriority = new Utils.IntegerHolder(priorityOverride !== undefined ? priorityOverride : movePhase.move.getMove().priority); - applyAbAttrs(ChangeMovePriorityAbAttr, movePhase.pokemon, null, false, movePhase.move.getMove(), movePriority); - const lowerPriorityPhase = this.phaseQueue.find(p => p instanceof MovePhase && p.move.getMove().priority < movePriority.value); - if (lowerPriorityPhase) { - this.phaseQueue.splice(this.phaseQueue.indexOf(lowerPriorityPhase), 0, movePhase); - } else { - this.pushPhase(movePhase); - } - } - /** * Tries to add the input phase to index before target phase in the phaseQueue, else simply calls unshiftPhase() * @param phase {@linkcode Phase} the phase to be added From ea39ca8706537da17152150746988f2bcc49ecf0 Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Sat, 14 Sep 2024 04:56:55 -0700 Subject: [PATCH 12/12] Don't use failure text as a condition for move success A move defining potential failure text doesn't mean it failed --- src/phases/move-phase.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/phases/move-phase.ts b/src/phases/move-phase.ts index ce376d27918..04cdedbd6ed 100644 --- a/src/phases/move-phase.ts +++ b/src/phases/move-phase.ts @@ -244,15 +244,16 @@ export class MovePhase extends BattlePhase { const move = this.move.getMove(); - // Move conditions assume the move has a single target - // TODO: is this sustainable? + /** + * Move conditions assume the move has a single target + * TODO: is this sustainable? + */ const passesConditions = move.applyConditions(this.pokemon, targets[0], move); - const failureMessage = move.getFailedText(this.pokemon, targets[0], move, new Utils.BooleanHolder(false)); - const failedWithMessage = failureMessage !== null && failureMessage !== undefined; - let failedDueToWeather: boolean, failedDueToTerrain: boolean; + let failedDueToWeather: boolean = false; + let failedDueToTerrain: boolean = false; - if (!failedWithMessage) { + if (!passesConditions) { failedDueToWeather = this.scene.arena.isMoveWeatherCancelled(this.pokemon, move); if (!failedDueToWeather) { @@ -260,8 +261,7 @@ export class MovePhase extends BattlePhase { } } - // @ts-expect-error - const success = passesConditions && !failedWithMessage && !failedDueToWeather && !failedDueToTerrain; + const success = passesConditions && !failedDueToWeather && !failedDueToTerrain; /** * If the move has not failed, trigger ability-based user type changes and then execute it. @@ -283,10 +283,10 @@ export class MovePhase extends BattlePhase { this.pokemon.pushMoveHistory({ move: this.move.moveId, targets: this.targets, result: MoveResult.FAIL, virtual: this.move.virtual }); let failedText: string | undefined; + const failureMessage = move.getFailedText(this.pokemon, targets[0], move, new Utils.BooleanHolder(false)); - if (failedWithMessage) { + if (failureMessage) { failedText = failureMessage; - // @ts-expect-error } else if (failedDueToTerrain) { failedText = getTerrainBlockMessage(this.pokemon, this.scene.arena.getTerrainType()); } @@ -405,6 +405,8 @@ export class MovePhase extends BattlePhase { * to lapse on move failure/cancellation. * * TODO: ...this seems weird. + * - Lapses `AFTER_MOVE` tags: + * - This handles the effects of {@linkcode Moves.SUBSTITUTE} * - Removes the second turn of charge moves * * TODO: handle charge moves more gracefully @@ -424,6 +426,7 @@ export class MovePhase extends BattlePhase { this.pokemon.pushMoveHistory({ move: Moves.NONE, result: MoveResult.FAIL }); this.pokemon.lapseTags(BattlerTagLapseType.MOVE_EFFECT); + this.pokemon.lapseTags(BattlerTagLapseType.AFTER_MOVE); this.pokemon.getMoveQueue().shift(); }