Skip to content

Commit

Permalink
Simplify Gen 5 Magic Bounce inheritance (#10880)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrebastosdias authored Feb 10, 2025
1 parent 8ecd61e commit e11af80
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
14 changes: 1 addition & 13 deletions data/mods/gen5/abilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,8 @@ export const Abilities: import('../../../sim/dex-abilities').ModdedAbilityDataTa
},
magicbounce: {
inherit: true,
onTryHit(target, source, move) {
if (target === source || move.hasBounced || !move.flags['reflectable'] ||
(target.isSemiInvulnerable() && move.target !== 'foeSide')) {
return;
}
const newMove = this.dex.getActiveMove(move.id);
newMove.hasBounced = true;
newMove.pranksterBoosted = false;
this.actions.useMove(newMove, target, {target: source});
return null;
},
onAllyTryHitSide(target, source, move) {
if (target.isAlly(source) || move.hasBounced || !move.flags['reflectable'] ||
(target.isSemiInvulnerable() && move.target !== 'foeSide')) {
if (target.isAlly(source) || move.hasBounced || !move.flags['reflectable']) {
return;
}
const newMove = this.dex.getActiveMove(move.id);
Expand Down
6 changes: 2 additions & 4 deletions data/mods/gen5/moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,7 @@ export const Moves: import('../../../sim/dex-moves').ModdedMoveDataTable = {
},
onTryHitPriority: 2,
onTryHit(target, source, move) {
if (target === source || move.hasBounced || !move.flags['reflectable'] ||
(target.isSemiInvulnerable() && move.target !== 'foeSide')) {
if (target === source || move.hasBounced || !move.flags['reflectable'] || target.isSemiInvulnerable()) {
return;
}
const newMove = this.dex.getActiveMove(move.id);
Expand All @@ -539,8 +538,7 @@ export const Moves: import('../../../sim/dex-moves').ModdedMoveDataTable = {
return null;
},
onAllyTryHitSide(target, source, move) {
if (target.isAlly(source) || move.hasBounced || !move.flags['reflectable'] ||
(target.isSemiInvulnerable() && move.target !== 'foeSide')) {
if (target.isAlly(source) || move.hasBounced || !move.flags['reflectable']) {
return;
}
const newMove = this.dex.getActiveMove(move.id);
Expand Down
17 changes: 17 additions & 0 deletions test/sim/abilities/magicbounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,21 @@ describe('Magic Bounce', function () {
assert.false(battle.p1.sideConditions['stealthrock']);
assert(battle.p2.sideConditions['stealthrock']);
});

it(`[Gen 5] should bounce moves that target the foe's side while semi-invulnerable`, function () {
battle = common.gen(5).createBattle({gameType: 'doubles'});
battle.setPlayer('p1', {team: [
{species: "Bulbasaur", ability: 'overgrow', moves: ['growl']},
{species: "Geodude", ability: 'rockhead', moves: ['stealthrock']},
]});
battle.setPlayer('p2', {team: [
{species: "Xatu", ability: 'magicbounce', moves: ['fly']},
{species: "Charmander", ability: 'blaze', moves: ['sleeptalk']},
]});
battle.makeChoices('auto', 'auto');
assert.statStage(battle.p1.active[0], 'atk', 0);
assert.statStage(battle.p2.active[0], 'atk', 0);
assert(battle.p1.sideConditions['stealthrock']);
assert.false(battle.p2.sideConditions['stealthrock']);
});
});

0 comments on commit e11af80

Please sign in to comment.