diff --git a/src/data/ability.ts b/src/data/ability.ts index cb3db27ddc1..0605cb7aa20 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -4098,7 +4098,8 @@ async function applyAbAttrsInternal( applyFunc: AbAttrApplyFunc, args: any[], showAbilityInstant: boolean = false, - quiet: boolean = false, + isQuiet: boolean = false, + messages: string[] = [], ) { for (const passive of [false, true]) { if (!pokemon?.canApplyAbility(passive)) { @@ -4128,7 +4129,7 @@ async function applyAbAttrsInternal( pokemon.battleData.abilitiesApplied.push(ability.id); } - if (attr.showAbility && !quiet) { + if (attr.showAbility && !isQuiet) { if (showAbilityInstant) { pokemon.scene.abilityBar.showAbility(pokemon, passive); } else { @@ -4136,11 +4137,12 @@ async function applyAbAttrsInternal( } } - if (!quiet) { - const message = attr.getTriggerMessage(pokemon, ability.name, args); - if (message) { + const message = attr.getTriggerMessage(pokemon, ability.name, args); + if (message) { + if (!isQuiet) { pokemon.scene.queueMessage(message); } + messages.push(message); } } } @@ -4271,8 +4273,8 @@ export function applyPostTerrainChangeAbAttrs(attrType: Constructor, - pokemon: Pokemon, trapped: Utils.BooleanHolder, otherPokemon: Pokemon, ...args: any[]): Promise { - return applyAbAttrsInternal(attrType, pokemon, (attr, passive) => attr.applyCheckTrapped(pokemon, passive, trapped, otherPokemon, args), args); + pokemon: Pokemon, trapped: Utils.BooleanHolder, otherPokemon: Pokemon, isQuiet: boolean, messages: string[], ...args: any[]): Promise { + return applyAbAttrsInternal(attrType, pokemon, (attr, passive) => attr.applyCheckTrapped(pokemon, passive, trapped, otherPokemon, args), args, false, isQuiet, messages); } export function applyPostBattleAbAttrs(attrType: Constructor, diff --git a/src/phases.ts b/src/phases.ts index 73413b248a4..3550b3f599c 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -2095,8 +2095,9 @@ export class CommandPhase extends FieldPhase { const trapTag = playerPokemon.findTag(t => t instanceof TrappedTag) as TrappedTag; const trapped = new Utils.BooleanHolder(false); const batonPass = isSwitch && args[0] as boolean; + const trappedAbMessages: string[] = []; if (!batonPass) { - enemyField.forEach(enemyPokemon => applyCheckTrappedAbAttrs(CheckTrappedAbAttr, enemyPokemon, trapped, playerPokemon)); + enemyField.forEach(enemyPokemon => applyCheckTrappedAbAttrs(CheckTrappedAbAttr, enemyPokemon, trapped, playerPokemon, true, trappedAbMessages)); } if (batonPass || (!trapTag && !trapped.value)) { this.scene.currentBattle.turnCommands[this.fieldIndex] = isSwitch @@ -2126,11 +2127,21 @@ export class CommandPhase extends FieldPhase { }), null, () => { - this.scene.ui.showText("", 0); + this.scene.ui.showText(null, 0); if (!isSwitch) { this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); } }, null, true); + } else if (trapped.value && trappedAbMessages.length > 0) { + if (!isSwitch) { + this.scene.ui.setMode(Mode.MESSAGE); + } + this.scene.ui.showText(trappedAbMessages[0], null, () => { + this.scene.ui.showText(null, 0); + if (!isSwitch) { + this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); + } + }, null, true); } } break; @@ -2225,7 +2236,7 @@ export class EnemyCommandPhase extends FieldPhase { const trapTag = enemyPokemon.findTag(t => t instanceof TrappedTag) as TrappedTag; const trapped = new Utils.BooleanHolder(false); - opponents.forEach(playerPokemon => applyCheckTrappedAbAttrs(CheckTrappedAbAttr, playerPokemon, trapped, enemyPokemon)); + opponents.forEach(playerPokemon => applyCheckTrappedAbAttrs(CheckTrappedAbAttr, playerPokemon, trapped, enemyPokemon, true, [])); if (!trapTag && !trapped.value) { const partyMemberScores = trainer.getPartyMemberMatchupScores(enemyPokemon.trainerSlot, true); diff --git a/src/ui/party-ui-handler.ts b/src/ui/party-ui-handler.ts index 3a9b3463ef1..4dbb34fdc83 100644 --- a/src/ui/party-ui-handler.ts +++ b/src/ui/party-ui-handler.ts @@ -732,7 +732,7 @@ export default class PartyUiHandler extends MessageUiHandler { return changed; } - showText(text: string | null, delay?: integer | null, callback?: Function | null, callbackDelay?: integer | null, prompt?: boolean, promptDelay?: integer) { + showText(text: string | null, delay?: integer | null, callback?: Function | null, callbackDelay?: integer | null, prompt?: boolean | null, promptDelay?: integer | null) { if (text === null) { text = defaultMessage; } diff --git a/src/ui/ui.ts b/src/ui/ui.ts index 8ea4270deb3..9a8be426229 100644 --- a/src/ui/ui.ts +++ b/src/ui/ui.ts @@ -271,8 +271,8 @@ export default class UI extends Phaser.GameObjects.Container { return handler.processInput(button); } - showText(text: string, delay?: integer | null, callback?: Function | null, callbackDelay?: integer | null, prompt?: boolean | null, promptDelay?: integer | null): void { - if (prompt && text.indexOf("$") > -1) { + showText(text: string | null, delay?: integer | null, callback?: Function | null, callbackDelay?: integer | null, prompt?: boolean | null, promptDelay?: integer | null): void { + if (text && prompt && text.indexOf("$") > -1) { const messagePages = text.split(/\$/g).map(m => m.trim()); let showMessageAndCallback = () => callback && callback(); for (let p = messagePages.length - 1; p >= 0; p--) { @@ -282,10 +282,16 @@ export default class UI extends Phaser.GameObjects.Container { showMessageAndCallback(); } else { const handler = this.getHandler(); - if (handler instanceof MessageUiHandler) { - (handler as MessageUiHandler).showText(text, delay, callback, callbackDelay, prompt, promptDelay); - } else { - this.getMessageHandler().showText(text, delay, callback, callbackDelay, prompt, promptDelay); + if (handler instanceof PartyUiHandler) { + (handler as PartyUiHandler).showText(text, delay, callback, callbackDelay, prompt, promptDelay); + return; + } + if (text) { + if (handler instanceof MessageUiHandler) { + (handler as MessageUiHandler).showText(text, delay, callback, callbackDelay, prompt, promptDelay); + } else { + this.getMessageHandler().showText(text, delay, callback, callbackDelay, prompt, promptDelay); + } } } }