Skip to content

Commit

Permalink
Mold Breaker shouldn't remove abilities that don't affect direct dama…
Browse files Browse the repository at this point in the history
…ge (#647)
  • Loading branch information
shrianshChari authored Oct 20, 2024
1 parent dfffc7e commit 27df82c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
10 changes: 10 additions & 0 deletions calc/src/mechanics/gen4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -199,6 +201,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);

Expand Down
10 changes: 10 additions & 0 deletions calc/src/mechanics/gen56.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -288,6 +290,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);
Expand Down
15 changes: 13 additions & 2 deletions calc/src/mechanics/gen789.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -563,6 +565,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);
Expand Down
26 changes: 26 additions & 0 deletions calc/src/test/calc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
});
});
});
});

Expand Down

0 comments on commit 27df82c

Please sign in to comment.