Skip to content

Commit

Permalink
Gen 5-7: Fix Snatch + Swallow interaction (#10698)
Browse files Browse the repository at this point in the history
  • Loading branch information
MathyFurret authored Nov 28, 2024
1 parent 554a59e commit 8f5efc2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
6 changes: 6 additions & 0 deletions data/mods/gen4/moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,12 @@ export const Moves: import('../../../sim/dex-moves').ModdedMoveDataTable = {
}
},
},
swallow: {
inherit: true,
onTry(source) {
return !!source.volatiles['stockpile'];
},
},
switcheroo: {
inherit: true,
onTryHit(target, source, move) {
Expand Down
6 changes: 4 additions & 2 deletions data/moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19284,12 +19284,14 @@ export const Moves: import('../sim/dex-moves').MoveDataTable = {
pp: 10,
priority: 0,
flags: {snatch: 1, heal: 1, metronome: 1},
onTry(source) {
onTry(source, target, move) {
if (move.sourceEffect === 'snatch') return;
return !!source.volatiles['stockpile'];
},
onHit(pokemon) {
const layers = pokemon.volatiles['stockpile']?.layers || 1;
const healAmount = [0.25, 0.5, 1];
const success = !!this.heal(this.modify(pokemon.maxhp, healAmount[(pokemon.volatiles['stockpile'].layers - 1)]));
const success = !!this.heal(this.modify(pokemon.maxhp, healAmount[layers - 1]));
if (!success) this.add('-fail', pokemon, 'heal');
pokemon.removeVolatile('stockpile');
return success || this.NOT_FAIL;
Expand Down
28 changes: 28 additions & 0 deletions test/sim/moves/snatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,34 @@ describe('Snatch', function () {
assert.atMost(battle.p1.active[1].hp, weavileHp, 'should not allow Snatch to bypass Heal Block');
assert(battle.log[battle.lastMoveLine + 2].startsWith('|cant'), 'should log that Recover failed');
});

it('should not snatch Swallow if the Swallow user has no Stockpiles', () => {
battle = common.createBattle({gameType: 'doubles'}, [[
{species: 'mandibuzz', moves: ['snatch']},
{species: 'accelgor', moves: ['swallow']},
], [
{species: 'surskit', moves: ['quickattack']},
{species: 'wingull', moves: ['quickattack']},
]]);

battle.makeChoices('auto', 'move quickattack 1, move quickattack 2');
for (const line of battle.log) {
assert(!line.includes('-activate'), `Snatch should not have activated, but found -activate message ${line}`);
}
});

it('Snatched Swallow should heal the snatcher by 25% if the snatcher has no Stockpiles', () => {
battle = common.createBattle([[
{species: 'clefable', moves: ['sleeptalk', 'bellydrum', 'snatch']},
], [
{species: 'dewgong', moves: ['stockpile', 'swallow']},
]]);
battle.makeChoices('move bellydrum', 'auto');
battle.makeChoices();
battle.makeChoices();
const targetHP = battle.modify(battle.p1.active[0].maxhp, 0.25);
assert.hurtsBy(battle.p1.active[0], -targetHP, () => battle.makeChoices('move snatch', 'move swallow'));
});
});

describe('Snatch [Gen 4]', function () {
Expand Down

0 comments on commit 8f5efc2

Please sign in to comment.