From d67ccd24a6ed84052c8641a1487f3fd92d46e96a Mon Sep 17 00:00:00 2001 From: Shriansh Chari <30420527+shrianshChari@users.noreply.github.com> Date: Mon, 30 Sep 2024 13:08:59 -0400 Subject: [PATCH] Mold Breaker shouldn't remove abilities that don't affect direct damage --- calc/src/mechanics/gen4.ts | 10 ++++++++++ calc/src/mechanics/gen56.ts | 10 ++++++++++ calc/src/mechanics/gen789.ts | 15 +++++++++++++-- calc/src/test/calc.test.ts | 26 ++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/calc/src/mechanics/gen4.ts b/calc/src/mechanics/gen4.ts index a1e3e1eca..5ea927f0e 100644 --- a/calc/src/mechanics/gen4.ts +++ b/calc/src/mechanics/gen4.ts @@ -66,6 +66,8 @@ export function calculateDPP( return result; } + const tempAbility = defender.ability; + if (attacker.hasAbility('Mold Breaker')) { defender.ability = '' as AbilityName; desc.attackerAbility = attacker.ability; @@ -196,6 +198,14 @@ export function calculateDPP( const attack = calculateAttackDPP(gen, attacker, defender, move, field, desc, isCritical); // #endregion + + // Restores the defender's ability after disabling it for Mold Breaker purposes. + // This will make abilities like Rain Dish and Dry Skin work + // even when the attacker has Mold Breaker. + if (attacker.hasAbility('Mold Breaker')) { + defender.ability = tempAbility; + } + // #region (Special) Defense const defense = calculateDefenseDPP(gen, attacker, defender, move, field, desc, isCritical); diff --git a/calc/src/mechanics/gen56.ts b/calc/src/mechanics/gen56.ts index bb4fc1f45..0bac4c3b4 100644 --- a/calc/src/mechanics/gen56.ts +++ b/calc/src/mechanics/gen56.ts @@ -95,6 +95,8 @@ export function calculateBWXY( return result; } + const tempAbility = defender.ability; + if (attacker.hasAbility('Mold Breaker', 'Teravolt', 'Turboblaze')) { defender.ability = '' as AbilityName; desc.attackerAbility = attacker.ability; @@ -285,6 +287,14 @@ export function calculateBWXY( const attackStat = move.category === 'Special' ? 'spa' : 'atk'; // #endregion + + // Restores the defender's ability after disabling it for Mold Breaker purposes. + // This will make abilities like Rain Dish and Dry Skin work + // even when the attacker has Mold Breaker. + if (attacker.hasAbility('Mold Breaker', 'Teravolt', 'Turboblaze')) { + defender.ability = tempAbility; + } + // #region (Special) Defense const defense = calculateDefenseBWXY(gen, attacker, defender, move, field, desc, isCritical); diff --git a/calc/src/mechanics/gen789.ts b/calc/src/mechanics/gen789.ts index cea9d87c9..114c207b7 100644 --- a/calc/src/mechanics/gen789.ts +++ b/calc/src/mechanics/gen789.ts @@ -169,8 +169,10 @@ export function calculateSMSSSV( 'Searing Sunraze Smash', 'Sunsteel Strike' ); - if (!defenderIgnoresAbility && !defender.hasAbility('Poison Heal') && - (attackerIgnoresAbility || moveIgnoresAbility)) { + + const tempAbility = defender.ability; + + if (!defenderIgnoresAbility && (attackerIgnoresAbility || moveIgnoresAbility)) { if (attackerIgnoresAbility) desc.attackerAbility = attacker.ability; if (defender.hasItem('Ability Shield')) { desc.defenderItem = defender.item; @@ -555,6 +557,15 @@ export function calculateSMSSSV( ? 'spa' : 'atk'; // #endregion + + // Restores the defender's ability after disabling it for the purposes of + // Mold Breaker and other moves that ignore abilities. + // This will make abilities like Rain Dish and Quark Drive work + // even when the attacker has Mold Breaker. + if (attackerIgnoresAbility || moveIgnoresAbility) { + defender.ability = tempAbility; + } + // #region (Special) Defense const defense = calculateDefenseSMSSSV(gen, attacker, defender, move, field, desc, isCritical); diff --git a/calc/src/test/calc.test.ts b/calc/src/test/calc.test.ts index 589f6c27e..487a6c276 100644 --- a/calc/src/test/calc.test.ts +++ b/calc/src/test/calc.test.ts @@ -722,6 +722,32 @@ describe('calc', () => { 'Lvl 90 Chansey Seismic Toss vs. Lvl 30 0 HP 0 IVs Mew: 90-90 (90 - 90%) -- guaranteed OHKO after sandstorm damage and burn damage' ); }); + + inGens(4, 9, ({gen, calculate, Pokemon, Move, Field}) => { + test(`Mold Breaker does not disable abilities that don't affect direct damage (gen ${gen})`, () => { + const attacker = Pokemon('Rampardos', { + ability: 'Mold Breaker', + }); + + const defender = Pokemon('Blastoise', { + ability: 'Rain Dish', + }); + + const field = Field({ + weather: 'Rain', + }); + + const move = Move('Stone Edge'); + + const result = calculate(attacker, defender, move, field); + + expect(result.defender.ability).toBe('Rain Dish'); + + expect(result.desc()).toBe( + '0 Atk Mold Breaker Rampardos Stone Edge vs. 0 HP / 0 Def Blastoise: 168-198 (56.1 - 66.2%) -- guaranteed 2HKO after Rain Dish recovery' + ); + }); + }); }); });