From f10cce7d3a93de6179251fe551ef4bf0593a4690 Mon Sep 17 00:00:00 2001 From: Madi Simpson Date: Sat, 4 May 2024 20:26:14 -0700 Subject: [PATCH] moves: add custom fail text, fix animation issues with Guard Dog/Roar --- src/data/ability.ts | 7 ++----- src/data/move.ts | 28 ++++++++++++++++++++-------- src/phases.ts | 9 ++++++--- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index e39306f85cf..e264dbcd98e 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -21,6 +21,7 @@ import { Abilities } from "./enums/abilities"; import i18next, { Localizable } from "#app/plugins/i18n.js"; import { Command } from "../ui/command-ui-handler"; import Battle from "#app/battle.js"; +import { ability } from "#app/locales/en/ability.js"; export class Ability implements Localizable { public id: Abilities; @@ -2353,13 +2354,9 @@ export class IncreasePpAbAttr extends AbAttr { } export class ForceSwitchOutImmunityAbAttr extends AbAttr { apply(pokemon: Pokemon, passive: boolean, cancelled: Utils.BooleanHolder, args: any[]): boolean { - cancelled.value = true; + pokemon.scene.queueMessage(getPokemonMessage(pokemon, ` can't be switched out!`)) return true; } - - getTriggerMessage(pokemon: Pokemon, abilityName: string, ...args: any[]): string { - return getPokemonMessage(pokemon, `'s ${abilityName} prevents it from being switched out!`) - } } export class ReduceBerryUseThresholdAbAttr extends AbAttr { diff --git a/src/data/move.ts b/src/data/move.ts index 9212a33c736..74eaec91306 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -326,6 +326,13 @@ export default class Move implements Localizable { return true; } + getFailedText(user: Pokemon, target: Pokemon, move: Move, cancelled: Utils.BooleanHolder): string | null { + let failedText = null; + for (let attr of this.attrs) + failedText = attr.getFailedText(user, target, move, cancelled); + return failedText; + } + getUserBenefitScore(user: Pokemon, target: Pokemon, move: Move): integer { let score = 0; @@ -422,6 +429,10 @@ export abstract class MoveAttr { return null; } + getFailedText(user: Pokemon, target: Pokemon, move: Move, cancelled: Utils.BooleanHolder): string | null { + return null; + } + getUserBenefitScore(user: Pokemon, target: Pokemon, move: Move): integer { return 0; } @@ -2934,16 +2945,9 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise { return new Promise(resolve => { - - const cancelled = new Utils.BooleanHolder(false); - if (!this.user) - applyAbAttrs(ForceSwitchOutImmunityAbAttr, target, cancelled) - if ((!this.user && target.isMax()) || cancelled.value) - return resolve(false); - // Check if the move category is not STATUS or if the switch out condition is not met - if (move.category !== MoveCategory.STATUS && !this.getSwitchOutCondition()(user, target, move)) { + if (!this.getCondition()(user, target, move)) { //Apply effects before switch out i.e. poison point, flame body, etc applyPostDefendAbAttrs(PostDefendContactApplyStatusEffectAbAttr, target, user, new PokemonMove(move.id), null); return resolve(false); @@ -3000,10 +3004,18 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { return (user, target, move) => (move.category !== MoveCategory.STATUS || this.getSwitchOutCondition()(user, target, move)); } + getFailedText(user: Pokemon, target: Pokemon, move: Move, cancelled: Utils.BooleanHolder): string | null { + applyAbAttrs(ForceSwitchOutImmunityAbAttr, target, cancelled); + return null; + } + getSwitchOutCondition(): MoveConditionFunc { return (user, target, move) => { const switchOutTarget = (this.user ? user : target); const player = switchOutTarget instanceof PlayerPokemon; + + if (!this.user && move.category == MoveCategory.STATUS && (target.hasAbilityWithAttr(ForceSwitchOutImmunityAbAttr) || target.isMax())) + return false; if (!player && !user.scene.currentBattle.battleType) { if (this.batonPass) diff --git a/src/phases.ts b/src/phases.ts index e65e76daa8a..d3781b6839b 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -2277,18 +2277,21 @@ export class MovePhase extends BattlePhase { // 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()); - let failedText = null; + let cancelled = new Utils.BooleanHolder(true); + 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.move.getMove())) { success = false; - failedText = getTerrainBlockMessage(targets[0], this.scene.arena.terrain.terrainType); + if (failedText == null) + failedText = getTerrainBlockMessage(targets[0], this.scene.arena.terrain.terrainType); } 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 }); - this.showFailedText(failedText); + if (!cancelled.value) + this.showFailedText(failedText); } this.end();