From 2d740f1952340b335afc6edf6794a8be8111a8cf Mon Sep 17 00:00:00 2001 From: Xavion3 Date: Tue, 7 May 2024 14:35:15 +1000 Subject: [PATCH] Implement once per battle restriction on abilities Currently just Intrepid Sword and Dauntless Shield --- src/data/ability.ts | 22 ++++++++++++++++++++-- src/field/pokemon.ts | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index 07aecbdcc..7f82ad01b 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -1826,6 +1826,19 @@ function getAnticipationCondition(): AbAttrCondition { }; } +/** + * Creates an ability condition that causes the ability to fail if that ability + * has already been used by that pokemon that battle. It requires an ability to + * be specified due to current limitations in how conditions on abilities work. + * @param {Abilities} ability The ability to check if it's already been applied + * @returns {AbAttrCondition} The condition + */ +function getOncePerBattleCondition(ability: Abilities): AbAttrCondition { + return (pokemon: Pokemon) => { + return !pokemon.battleData?.abilitiesApplied.includes(ability); + } +} + export class ForewarnAbAttr extends PostSummonAbAttr { constructor() { super(true); @@ -2522,6 +2535,9 @@ function applyAbAttrsInternal(attrType: { new(...args: any return applyNextAbAttr(); pokemon.scene.setPhaseQueueSplice(); const onApplySuccess = () => { + if (pokemon.battleData && !pokemon.battleData.abilitiesApplied.includes(ability.id)) { + pokemon.battleData.abilitiesApplied.push(ability.id); + } if (attr.showAbility && !quiet) { if (showAbilityInstant) pokemon.scene.abilityBar.showAbility(pokemon, passive); @@ -3379,9 +3395,11 @@ export function initAbilities() { new Ability(Abilities.NEUROFORCE, 7) .attr(MovePowerBoostAbAttr, (user, target, move) => target.getAttackTypeEffectiveness(move.type, user) >= 2, 1.25), new Ability(Abilities.INTREPID_SWORD, 8) - .attr(PostSummonStatChangeAbAttr, BattleStat.ATK, 1, true), + .attr(PostSummonStatChangeAbAttr, BattleStat.ATK, 1, true) + .condition(getOncePerBattleCondition(Abilities.INTREPID_SWORD)), new Ability(Abilities.DAUNTLESS_SHIELD, 8) - .attr(PostSummonStatChangeAbAttr, BattleStat.DEF, 1, true), + .attr(PostSummonStatChangeAbAttr, BattleStat.DEF, 1, true) + .condition(getOncePerBattleCondition(Abilities.DAUNTLESS_SHIELD)), new Ability(Abilities.LIBERO, 8) .unimplemented(), new Ability(Abilities.BALL_FETCH, 8) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 5f7ac90b0..da67cd700 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -3133,6 +3133,7 @@ export class PokemonBattleData { public hitCount: integer = 0; public endured: boolean = false; public berriesEaten: BerryType[] = []; + public abilitiesApplied: Abilities[] = []; } export class PokemonBattleSummonData {