From 53a709822ddf028e4099173b0b37b21966adaa75 Mon Sep 17 00:00:00 2001 From: Madi Simpson Date: Sat, 4 May 2024 12:49:07 -0700 Subject: [PATCH] abilities: make ability bars pop in to some success --- src/data/ability.ts | 106 +++++++++++++++++++++++--------------------- src/data/move.ts | 16 ++++--- 2 files changed, 65 insertions(+), 57 deletions(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index a317d40b841..d9ea707c42d 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -1269,6 +1269,36 @@ export class IgnoreOpponentStatChangesAbAttr extends AbAttr { } } +export class IntimidateImmunityAbAttr extends AbAttr { + apply(pokemon: Pokemon, passive: boolean, cancelled: Utils.BooleanHolder, args: any[]): boolean { + cancelled.value = true; + return true; + } + + getTriggerMessage(pokemon: Pokemon, abilityName: string, ...args: any[]): string { + return getPokemonMessage(pokemon, `'s Attack was not lowered!`); + } +} + +export class PostIntimidateStatChangeAbAttr extends AbAttr { + private stats: BattleStat[]; + private levels: integer; + private overwrites: boolean; + + constructor(stats: BattleStat[], levels: integer, overwrites?: boolean) { + super(true) + this.stats = stats + this.levels = levels + this.overwrites = !!overwrites + } + + apply(pokemon: Pokemon, passive: boolean, cancelled: Utils.BooleanHolder, args: any[]): boolean { + pokemon.scene.pushPhase(new StatChangePhase(pokemon.scene, pokemon.getBattlerIndex(), false, this.stats, this.levels)); + cancelled.value = this.overwrites; + return true; + } +} + export class PostSummonAbAttr extends AbAttr { applyPostSummon(pokemon: Pokemon, passive: boolean, args: any[]): boolean | Promise { return false; @@ -1321,40 +1351,28 @@ export class PostSummonStatChangeAbAttr extends PostSummonAbAttr { : stats as BattleStat[]; this.levels = levels; this.selfTarget = !!selfTarget; - this.intimidate = intimidate + this.intimidate = !!intimidate; } applyPostSummon(pokemon: Pokemon, passive: boolean, args: any[]): boolean { - const statChangePhases: StatChangePhase[] = []; - const intimidateImmune: Pokemon[] = [] - - if (this.selfTarget) - statChangePhases.push(new StatChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, this.stats, this.levels)); - else { - for (let opponent of pokemon.getOpponents()) { - const cancelled = new Utils.BooleanHolder(false) - if (this.intimidate) { - if (opponent.hasAbilityWithAttr(IntimidateImmunityAbAttr)) { - cancelled.value = true; - intimidateImmune.push(opponent); - } - applyAbAttrs(PostIntimidateStatChangeAbAttr, opponent, cancelled) - } - if (!cancelled.value) - statChangePhases.push(new StatChangePhase(pokemon.scene, opponent.getBattlerIndex(), false, this.stats, this.levels)); + if (this.selfTarget) { + pokemon.scene.pushPhase(new StatChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, this.stats, this.levels)); + return true; + } + for (let opponent of pokemon.getOpponents()) { + const cancelled = new Utils.BooleanHolder(false) + if (this.intimidate) { + applyAbAttrs(IntimidateImmunityAbAttr, opponent, cancelled); + applyAbAttrs(PostIntimidateStatChangeAbAttr, opponent, cancelled); + } + if (!cancelled.value) { + const statChangePhase = new StatChangePhase(pokemon.scene, opponent.getBattlerIndex(), false, this.stats, this.levels); + if (!statChangePhase.getPokemon().summonData) + pokemon.scene.pushPhase(statChangePhase); // TODO: This causes the ability bar to be shown at the wrong time + else + pokemon.scene.unshiftPhase(statChangePhase); } } - - for (let statChangePhase of statChangePhases) { - if (!this.selfTarget && !statChangePhase.getPokemon().summonData) - pokemon.scene.pushPhase(statChangePhase); // TODO: This causes the ability bar to be shown at the wrong time - else - pokemon.scene.unshiftPhase(statChangePhase); - } - - for (let opponent of intimidateImmune) - pokemon.scene.queueMessage(getPokemonMessage(opponent, ` can't be Intimidated!`)); - return true; } } @@ -1382,25 +1400,6 @@ export class PostSummonAllyHealAbAttr extends PostSummonAbAttr { } } -export class PostIntimidateStatChangeAbAttr extends AbAttr { - private stats: BattleStat[]; - private levels: integer; - private overwrites: boolean; - - constructor(stats: BattleStat[], levels: integer, overwrites?: boolean) { - super(true) - this.stats = stats - this.levels = levels - this.overwrites = !!overwrites - } - - apply(pokemon: Pokemon, passive: boolean, cancelled: Utils.BooleanHolder, args: any[]): boolean { - pokemon.scene.pushPhase(new StatChangePhase(pokemon.scene, pokemon.getBattlerIndex(), false, this.stats, this.levels)); - cancelled.value = this.overwrites; - return true; - } -} - export class DownloadAbAttr extends PostSummonAbAttr { private enemyDef: integer; private enemySpDef: integer; @@ -2289,9 +2288,16 @@ export class FlinchStatChangeAbAttr extends FlinchEffectAbAttr { export class IncreasePpAbAttr extends AbAttr { } -export class IntimidateImmunityAbAttr extends AbAttr { } +export class ForceSwitchOutImmunityAbAttr extends AbAttr { + apply(pokemon: Pokemon, passive: boolean, cancelled: Utils.BooleanHolder, args: any[]): boolean { + cancelled.value = true; + return true; + } -export class ForceSwitchOutImmunityAbAttr extends AbAttr { } + getTriggerMessage(pokemon: Pokemon, abilityName: string, ...args: any[]): string { + return getPokemonMessage(pokemon, `'s ${abilityName} prevents it from being switched out!`) + } +} export class ReduceBerryUseThresholdAbAttr extends AbAttr { constructor() { diff --git a/src/data/move.ts b/src/data/move.ts index 4e17b8c2bd8..5d4eddc2832 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -2887,8 +2887,13 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise { return new Promise(resolve => { - if (!this.user && (target.isMax())) - return resolve(false); + + 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)) { @@ -2943,9 +2948,9 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { resolve(true); }); } - + getCondition(): MoveConditionFunc { - return (user, target, move) => move.category !== MoveCategory.STATUS || this.getSwitchOutCondition()(user, target, move); + return (user, target, move) => (move.category !== MoveCategory.STATUS || this.getSwitchOutCondition()(user, target, move)); } getSwitchOutCondition(): MoveConditionFunc { @@ -2953,9 +2958,6 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { const switchOutTarget = (this.user ? user : target); const player = switchOutTarget instanceof PlayerPokemon; - if (!this.user && target.hasAbilityWithAttr(ForceSwitchOutImmunityAbAttr)) - return false; - if (!player && !user.scene.currentBattle.battleType) { if (this.batonPass) return false;