Minor changes

This commit is contained in:
Dean 2025-03-12 18:20:01 -07:00
parent 63005359a8
commit 9008e3754b
5 changed files with 51 additions and 58 deletions

View File

@ -2913,7 +2913,11 @@ export default class BattleScene extends SceneBase {
* @param show Whether to show or hide the bar * @param show Whether to show or hide the bar
*/ */
public queueAbilityDisplay(pokemon: Pokemon, passive: boolean, show: boolean): void { 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(); this.clearPhaseQueueSplice();
} }
@ -3146,11 +3150,7 @@ export default class BattleScene extends SceneBase {
return false; return false;
} }
canTransferHeldItemModifier( canTransferHeldItemModifier(itemModifier: PokemonHeldItemModifier, target: Pokemon, transferQuantity = 1): boolean {
itemModifier: PokemonHeldItemModifier,
target: Pokemon,
transferQuantity: number = 1,
): boolean {
const mod = itemModifier.clone() as PokemonHeldItemModifier; const mod = itemModifier.clone() as PokemonHeldItemModifier;
const source = mod.pokemonId ? mod.getPokemon() : null; const source = mod.pokemonId ? mod.getPokemon() : null;
const cancelled = new Utils.BooleanHolder(false); const cancelled = new Utils.BooleanHolder(false);
@ -3164,10 +3164,7 @@ export default class BattleScene extends SceneBase {
} }
const matchingModifier = this.findModifier( const matchingModifier = this.findModifier(
(m) => m => m instanceof PokemonHeldItemModifier && m.matchType(mod) && m.pokemonId === target.id,
m instanceof PokemonHeldItemModifier
&& m.matchType(mod)
&& m.pokemonId === target.id,
target.isPlayer(), target.isPlayer(),
) as PokemonHeldItemModifier; ) as PokemonHeldItemModifier;
@ -3176,11 +3173,7 @@ export default class BattleScene extends SceneBase {
if (matchingModifier.stackCount >= maxStackCount) { if (matchingModifier.stackCount >= maxStackCount) {
return false; return false;
} }
const countTaken = Math.min( const countTaken = Math.min(transferQuantity, mod.stackCount, maxStackCount - matchingModifier.stackCount);
transferQuantity,
mod.stackCount,
maxStackCount - matchingModifier.stackCount,
);
mod.stackCount -= countTaken; mod.stackCount -= countTaken;
} else { } else {
const countTaken = Math.min(transferQuantity, mod.stackCount); 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; const modifiers = !enemy ? this.modifiers : this.enemyModifiers;
return modifiers.indexOf(modifier) > -1; return modifiers.indexOf(modifier) > -1;
} }

View File

@ -165,10 +165,10 @@ export abstract class AbAttr {
/** /**
* Applies ability effects without checking conditions * Applies ability effects without checking conditions
* @param pokemon The pokemon to apply this ability to * @param pokemon - The pokemon to apply this ability to
* @param passive Whether or not the ability is a passive * @param passive - Whether or not the ability is a passive
* @param simulated Whether the call is simulated * @param simulated - Whether the call is simulated
* @param args * @param args - Extra args passed to the function. Handled by child classes.
* @see {@linkcode canApply} * @see {@linkcode canApply}
*/ */
apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder | null, args: any[]): void {} 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 * Returns a boolean describing whether the ability can be applied under current conditions
* @param pokemon The pokemon to apply this ability to * @param pokemon - The pokemon to apply this ability to
* @param passive Whether or not the ability is a passive * @param passive - Whether or not the ability is a passive
* @param simulated Whether the call is simulated * @param simulated - Whether the call is simulated
* @param args * @param args - Extra args passed to the function. Handled by child classes.
* @returns True if the ability can be applied, false otherwise * @returns `true` if the ability can be applied, `false` otherwise
* @see {@linkcode apply} * @see {@linkcode apply}
*/ */
canApply(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { canApply(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean {

View File

@ -5,7 +5,7 @@ import { PokemonPhase } from "./pokemon-phase";
export class HideAbilityPhase extends PokemonPhase { export class HideAbilityPhase extends PokemonPhase {
private passive: boolean; private passive: boolean;
constructor(battlerIndex: BattlerIndex, passive: boolean = false) { constructor(battlerIndex: BattlerIndex, passive = false) {
super(battlerIndex); super(battlerIndex);
this.passive = passive; this.passive = passive;

View File

@ -29,6 +29,10 @@ export class ShowAbilityPhase extends PokemonPhase {
start() { start() {
super.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 the bar is already out, hide it before showing the new one
if (globalScene.abilityBar.isVisible()) { if (globalScene.abilityBar.isVisible()) {
globalScene.unshiftPhase(new HideAbilityPhase(this.battlerIndex, this.passive)); globalScene.unshiftPhase(new HideAbilityPhase(this.battlerIndex, this.passive));
@ -36,28 +40,21 @@ export class ShowAbilityPhase extends PokemonPhase {
return this.end(); return this.end();
} }
if (!this.pokemonOnField) {
return this.end();
}
const pokemon = this.getPokemon(); const pokemon = this.getPokemon();
if (pokemon) { if (!pokemon.isPlayer()) {
if (!pokemon.isPlayer()) { /** If its an enemy pokemon, list it as last enemy to use ability or move */
/** If its an enemy pokemon, list it as last enemy to use ability or move */ globalScene.currentBattle.lastEnemyInvolved = pokemon.getBattlerIndex() % 2;
globalScene.currentBattle.lastEnemyInvolved = pokemon.getBattlerIndex() % 2; } else {
} else { globalScene.currentBattle.lastPlayerInvolved = pokemon.getBattlerIndex() % 2;
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(); this.end();
} });
} }
} }

View File

@ -21,7 +21,7 @@ export default class AbilityBar extends Phaser.GameObjects.Container {
} }
setup(): void { 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); const bar = globalScene.add.image(0, 0, key);
bar.setOrigin(0, 0); bar.setOrigin(0, 0);
bar.setVisible(false); bar.setVisible(false);
@ -52,7 +52,7 @@ export default class AbilityBar extends Phaser.GameObjects.Container {
if (text) { if (text) {
this.abilityBarText.setText(text); this.abilityBarText.setText(text);
} }
return new Promise((resolve) => { return new Promise(resolve => {
globalScene.tweens.add({ globalScene.tweens.add({
...config, ...config,
onComplete: () => { onComplete: () => {
@ -60,13 +60,13 @@ export default class AbilityBar extends Phaser.GameObjects.Container {
config.onComplete(); config.onComplete();
} }
resolve(); resolve();
} },
}); });
}); });
} }
public async showAbility(pokemonName: string, abilityName: string, passive: boolean = false, player: boolean = true): Promise<void> { public async showAbility(pokemonName: string, abilityName: string, passive = false, player = true): Promise<void> {
const text = (`${i18next.t("fightUiHandler:abilityFlyInText", { pokemonName: pokemonName, passive: passive ? i18next.t("fightUiHandler:passive") : "", abilityName: abilityName })}`); const text = `${i18next.t("fightUiHandler:abilityFlyInText", { pokemonName: pokemonName, passive: passive ? i18next.t("fightUiHandler:passive") : "", abilityName: abilityName })}`;
this.screenRight = globalScene.scaledCanvas.width; this.screenRight = globalScene.scaledCanvas.width;
if (player !== this.player) { if (player !== this.player) {
// Move the bar if it has changed from the player to enemy side (or vice versa) // 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; let y = baseY;
if (this.player) { if (this.player) {
y += (globalScene.currentBattle.double ? 14 : 0); y += globalScene.currentBattle.double ? 14 : 0;
} else { } else {
y -= globalScene.currentBattle.double ? 28 : 14; y -= globalScene.currentBattle.double ? 28 : 14;
} }
this.setY(y); this.setY(y);
return this.startTween({ return this.startTween(
targets: this, {
x: this.player ? screenLeft : this.screenRight - barWidth, targets: this,
duration: 500, x: this.player ? screenLeft : this.screenRight - barWidth,
ease: "Sine.easeOut", duration: 500,
hold: 1000, ease: "Sine.easeOut",
}, text); hold: 1000,
},
text,
);
} }
public async hide(): Promise<void> { public async hide(): Promise<void> {
@ -101,7 +104,7 @@ export default class AbilityBar extends Phaser.GameObjects.Container {
ease: "Sine.easeIn", ease: "Sine.easeIn",
onComplete: () => { onComplete: () => {
this.setVisible(false); this.setVisible(false);
} },
}); });
} }