diff --git a/src/battle-scene.ts b/src/battle-scene.ts index aba94dc8468..a6c986d3d0f 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -2913,7 +2913,11 @@ export default class BattleScene extends SceneBase { * @param show Whether to show or hide the bar */ public queueAbilityDisplay(pokemon: Pokemon, passive: boolean, show: boolean): void { - this.unshiftPhase((show) ? new ShowAbilityPhase(pokemon.getBattlerIndex(), passive) : new HideAbilityPhase(pokemon.getBattlerIndex(), passive)); + this.unshiftPhase( + show + ? new ShowAbilityPhase(pokemon.getBattlerIndex(), passive) + : new HideAbilityPhase(pokemon.getBattlerIndex(), passive), + ); this.clearPhaseQueueSplice(); } @@ -3146,11 +3150,7 @@ export default class BattleScene extends SceneBase { return false; } - canTransferHeldItemModifier( - itemModifier: PokemonHeldItemModifier, - target: Pokemon, - transferQuantity: number = 1, - ): boolean { + canTransferHeldItemModifier(itemModifier: PokemonHeldItemModifier, target: Pokemon, transferQuantity = 1): boolean { const mod = itemModifier.clone() as PokemonHeldItemModifier; const source = mod.pokemonId ? mod.getPokemon() : null; const cancelled = new Utils.BooleanHolder(false); @@ -3164,10 +3164,7 @@ export default class BattleScene extends SceneBase { } const matchingModifier = this.findModifier( - (m) => - m instanceof PokemonHeldItemModifier - && m.matchType(mod) - && m.pokemonId === target.id, + m => m instanceof PokemonHeldItemModifier && m.matchType(mod) && m.pokemonId === target.id, target.isPlayer(), ) as PokemonHeldItemModifier; @@ -3176,11 +3173,7 @@ export default class BattleScene extends SceneBase { if (matchingModifier.stackCount >= maxStackCount) { return false; } - const countTaken = Math.min( - transferQuantity, - mod.stackCount, - maxStackCount - matchingModifier.stackCount, - ); + const countTaken = Math.min(transferQuantity, mod.stackCount, maxStackCount - matchingModifier.stackCount); mod.stackCount -= countTaken; } else { const countTaken = Math.min(transferQuantity, mod.stackCount); @@ -3349,7 +3342,7 @@ export default class BattleScene extends SceneBase { }); } - hasModifier(modifier: PersistentModifier, enemy: boolean = false): boolean { + hasModifier(modifier: PersistentModifier, enemy = false): boolean { const modifiers = !enemy ? this.modifiers : this.enemyModifiers; return modifiers.indexOf(modifier) > -1; } diff --git a/src/data/ability.ts b/src/data/ability.ts index 78382c0db87..d28c3229d9c 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -165,10 +165,10 @@ export abstract class AbAttr { /** * Applies ability effects without checking conditions - * @param pokemon The pokemon to apply this ability to - * @param passive Whether or not the ability is a passive - * @param simulated Whether the call is simulated - * @param args + * @param pokemon - The pokemon to apply this ability to + * @param passive - Whether or not the ability is a passive + * @param simulated - Whether the call is simulated + * @param args - Extra args passed to the function. Handled by child classes. * @see {@linkcode canApply} */ apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder | null, args: any[]): void {} @@ -188,11 +188,11 @@ export abstract class AbAttr { /** * Returns a boolean describing whether the ability can be applied under current conditions - * @param pokemon The pokemon to apply this ability to - * @param passive Whether or not the ability is a passive - * @param simulated Whether the call is simulated - * @param args - * @returns True if the ability can be applied, false otherwise + * @param pokemon - The pokemon to apply this ability to + * @param passive - Whether or not the ability is a passive + * @param simulated - Whether the call is simulated + * @param args - Extra args passed to the function. Handled by child classes. + * @returns `true` if the ability can be applied, `false` otherwise * @see {@linkcode apply} */ canApply(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { diff --git a/src/phases/hide-ability-phase.ts b/src/phases/hide-ability-phase.ts index 9d0276406d7..0745b3f832a 100644 --- a/src/phases/hide-ability-phase.ts +++ b/src/phases/hide-ability-phase.ts @@ -5,7 +5,7 @@ import { PokemonPhase } from "./pokemon-phase"; export class HideAbilityPhase extends PokemonPhase { private passive: boolean; - constructor(battlerIndex: BattlerIndex, passive: boolean = false) { + constructor(battlerIndex: BattlerIndex, passive = false) { super(battlerIndex); this.passive = passive; diff --git a/src/phases/show-ability-phase.ts b/src/phases/show-ability-phase.ts index 0f06122978e..1b3c6dde568 100644 --- a/src/phases/show-ability-phase.ts +++ b/src/phases/show-ability-phase.ts @@ -29,6 +29,10 @@ export class ShowAbilityPhase extends PokemonPhase { start() { super.start(); + if (!this.pokemonOnField || !this.getPokemon()) { + return this.end(); + } + // If the bar is already out, hide it before showing the new one if (globalScene.abilityBar.isVisible()) { globalScene.unshiftPhase(new HideAbilityPhase(this.battlerIndex, this.passive)); @@ -36,28 +40,21 @@ export class ShowAbilityPhase extends PokemonPhase { return this.end(); } - if (!this.pokemonOnField) { - return this.end(); - } const pokemon = this.getPokemon(); - if (pokemon) { - if (!pokemon.isPlayer()) { - /** If its an enemy pokemon, list it as last enemy to use ability or move */ - globalScene.currentBattle.lastEnemyInvolved = pokemon.getBattlerIndex() % 2; - } else { - globalScene.currentBattle.lastPlayerInvolved = pokemon.getBattlerIndex() % 2; + if (!pokemon.isPlayer()) { + /** If its an enemy pokemon, list it as last enemy to use ability or move */ + globalScene.currentBattle.lastEnemyInvolved = pokemon.getBattlerIndex() % 2; + } else { + globalScene.currentBattle.lastPlayerInvolved = pokemon.getBattlerIndex() % 2; + } + + globalScene.abilityBar.showAbility(this.pokemonName, this.abilityName, this.passive, this.player).then(() => { + if (pokemon?.battleData) { + pokemon.battleData.abilityRevealed = true; } - globalScene.abilityBar.showAbility(this.pokemonName, this.abilityName, this.passive, this.player).then(() => { - if (pokemon?.battleData) { - pokemon.battleData.abilityRevealed = true; - } - - this.end(); - }); - } else { this.end(); - } + }); } } diff --git a/src/ui/ability-bar.ts b/src/ui/ability-bar.ts index 67dc11ec049..5481791de64 100644 --- a/src/ui/ability-bar.ts +++ b/src/ui/ability-bar.ts @@ -21,7 +21,7 @@ export default class AbilityBar extends Phaser.GameObjects.Container { } setup(): void { - for (const key of [ "ability_bar_right", "ability_bar_left" ]) { + for (const key of ["ability_bar_right", "ability_bar_left"]) { const bar = globalScene.add.image(0, 0, key); bar.setOrigin(0, 0); bar.setVisible(false); @@ -52,7 +52,7 @@ export default class AbilityBar extends Phaser.GameObjects.Container { if (text) { this.abilityBarText.setText(text); } - return new Promise((resolve) => { + return new Promise(resolve => { globalScene.tweens.add({ ...config, onComplete: () => { @@ -60,13 +60,13 @@ export default class AbilityBar extends Phaser.GameObjects.Container { config.onComplete(); } resolve(); - } + }, }); }); } - public async showAbility(pokemonName: string, abilityName: string, passive: boolean = false, player: boolean = true): Promise { - const text = (`${i18next.t("fightUiHandler:abilityFlyInText", { pokemonName: pokemonName, passive: passive ? i18next.t("fightUiHandler:passive") : "", abilityName: abilityName })}`); + public async showAbility(pokemonName: string, abilityName: string, passive = false, player = true): Promise { + const text = `${i18next.t("fightUiHandler:abilityFlyInText", { pokemonName: pokemonName, passive: passive ? i18next.t("fightUiHandler:passive") : "", abilityName: abilityName })}`; this.screenRight = globalScene.scaledCanvas.width; if (player !== this.player) { // Move the bar if it has changed from the player to enemy side (or vice versa) @@ -77,20 +77,23 @@ export default class AbilityBar extends Phaser.GameObjects.Container { let y = baseY; if (this.player) { - y += (globalScene.currentBattle.double ? 14 : 0); + y += globalScene.currentBattle.double ? 14 : 0; } else { y -= globalScene.currentBattle.double ? 28 : 14; } this.setY(y); - return this.startTween({ - targets: this, - x: this.player ? screenLeft : this.screenRight - barWidth, - duration: 500, - ease: "Sine.easeOut", - hold: 1000, - }, text); + return this.startTween( + { + targets: this, + x: this.player ? screenLeft : this.screenRight - barWidth, + duration: 500, + ease: "Sine.easeOut", + hold: 1000, + }, + text, + ); } public async hide(): Promise { @@ -101,7 +104,7 @@ export default class AbilityBar extends Phaser.GameObjects.Container { ease: "Sine.easeIn", onComplete: () => { this.setVisible(false); - } + }, }); }