From ccdfd09cfb8d79ee67dd498b3434ea7d7285d52c Mon Sep 17 00:00:00 2001 From: Dean Date: Mon, 17 Mar 2025 23:52:45 -0700 Subject: [PATCH] Always create separate ability phases for passive and use boolean instead of priority number when applying --- src/data/ability.ts | 21 +++++++-------------- src/data/phase-priority-queue.ts | 4 ++-- src/field/pokemon.ts | 4 ++-- src/phases/post-summon-phase.ts | 12 +++++------- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index 1eb2d9764e6..9f72cb20bc1 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -5172,7 +5172,6 @@ function applySingleAbAttrs( args: any[], gainedMidTurn = false, simulated = false, - priorityCondition?: (p: number) => boolean, messages: string[] = [] ) { if (!pokemon?.canApplyAbility(passive) || (passive && (pokemon.getPassiveAbility().id === pokemon.getAbility().id))) { @@ -5180,10 +5179,7 @@ function applySingleAbAttrs( } const ability = passive ? pokemon.getPassiveAbility() : pokemon.getAbility(); - if ( - gainedMidTurn && ability.getAttrs(attrType).some(attr => attr instanceof PostSummonAbAttr && !attr.shouldActivateOnGain()) - || (priorityCondition && !priorityCondition(ability.postSummonPriority)) - ) { + if (gainedMidTurn && ability.getAttrs(attrType).some(attr => attr instanceof PostSummonAbAttr && !attr.shouldActivateOnGain())) { return; } @@ -5485,7 +5481,6 @@ export class PostDamageForceSwitchAbAttr extends PostDamageAbAttr { * @param simulated `true` if the call is simulated and the battle state should not be changes * @param messages Array of messages which will be added to if the ability displays a message * @param gainedMidTurn `true` if the ability is activating because it was gained during the battle - * @param priorityCondition If defined, only abilities with priority that meets the condition will be applied */ function applyAbAttrsInternal( attrType: Constructor, @@ -5496,11 +5491,10 @@ function applyAbAttrsInternal( simulated: boolean = false, messages: string[] = [], gainedMidTurn = false, - priorityCondition?: (p: number) => boolean ) { for (const passive of [ false, true ]) { if (pokemon) { - applySingleAbAttrs(pokemon, passive, attrType, applyFunc, successFunc, args, gainedMidTurn, simulated, priorityCondition, messages); + applySingleAbAttrs(pokemon, passive, attrType, applyFunc, successFunc, args, gainedMidTurn, simulated, messages); globalScene.clearPhaseQueueSplice(); } } @@ -5746,20 +5740,19 @@ export function applyPostVictoryAbAttrs( export function applyPostSummonAbAttrs( attrType: Constructor, pokemon: Pokemon, + passive = false, simulated = false, - priorityCondition?: (p: number) => boolean, ...args: any[] ): void { - applyAbAttrsInternal( - attrType, + applySingleAbAttrs( pokemon, + passive, + attrType, (attr, passive) => attr.applyPostSummon(pokemon, passive, simulated, args), (attr, passive) => attr.canApplyPostSummon(pokemon, passive, simulated, args), args, - simulated, - [], false, - priorityCondition + simulated ); } diff --git a/src/data/phase-priority-queue.ts b/src/data/phase-priority-queue.ts index 85d9793cbd9..0849bb1314d 100644 --- a/src/data/phase-priority-queue.ts +++ b/src/data/phase-priority-queue.ts @@ -70,8 +70,8 @@ export class PostSummonPhasePriorityQueue extends PhasePriorityQueue { private queueAbilityPhase(phase: PostSummonPhase): void { const phasePokemon = phase.getPokemon(); - phasePokemon.getAbilityPriorities().forEach(priority => { - this.queue.push(new PostSummonActivateAbilityPhase(phasePokemon.getBattlerIndex(), priority)); + phasePokemon.getAbilityPriorities().forEach((priority, idx) => { + this.queue.push(new PostSummonActivateAbilityPhase(phasePokemon.getBattlerIndex(), priority, !!idx)); globalScene.appendToPhase( new ActivatePriorityQueuePhase(DynamicPhaseType.POST_SUMMON), ActivatePriorityQueuePhase, diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index ec0a60c0108..69418c62f83 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -2265,8 +2265,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return false; } - public getAbilityPriorities(): Set { - return new Set([ this.getAbility().postSummonPriority, this.getPassiveAbility().postSummonPriority ]); + public getAbilityPriorities(): number[] { + return [this.getAbility().postSummonPriority, this.getPassiveAbility().postSummonPriority]; } /** diff --git a/src/phases/post-summon-phase.ts b/src/phases/post-summon-phase.ts index 173390fbdbd..e000cf10f0f 100644 --- a/src/phases/post-summon-phase.ts +++ b/src/phases/post-summon-phase.ts @@ -40,22 +40,20 @@ export class PostSummonPhase extends PokemonPhase { } /** - * Phase to apply (post-summon) ability attributes for abilities with nonzero priority - * - * Priority abilities activate before others and before hazards - * - * @see Example - {@link https://bulbapedia.bulbagarden.net/wiki/Neutralizing_Gas_(Ability) | Neutralizing Gas} + * Helper to {@linkcode PostSummonPhase} which applies abilities */ export class PostSummonActivateAbilityPhase extends PostSummonPhase { private priority: number; + private passive: boolean; - constructor(battlerIndex: BattlerIndex, priority: number) { + constructor(battlerIndex: BattlerIndex, priority: number, passive: boolean) { super(battlerIndex); this.priority = priority; + this.passive = passive; } start() { - applyPostSummonAbAttrs(PostSummonAbAttr, this.getPokemon(), false, (p: number) => p === this.priority); + applyPostSummonAbAttrs(PostSummonAbAttr, this.getPokemon(), this.passive, false); this.end(); }