diff --git a/data/abilities.ts b/data/abilities.ts index 21a8a105d9164..1359a660aa5bb 100644 --- a/data/abilities.ts +++ b/data/abilities.ts @@ -3156,7 +3156,7 @@ export const Abilities: import('../sim/dex-abilities').AbilityDataTable = { num: 253, }, pickpocket: { - onAfterMoveSecondary(target, source, move) { + onAfterMoveSecondaryLast(target, source, move) { if (source && source !== target && move?.flags['contact']) { if (target.item || target.switchFlag || target.forceSwitchFlag || source.switchFlag === true) { return; diff --git a/data/moves.ts b/data/moves.ts index 05c508d1244d8..28847f54cce69 100644 --- a/data/moves.ts +++ b/data/moves.ts @@ -9761,13 +9761,8 @@ export const Moves: import('../sim/dex-moves').MoveDataTable = { pp: 15, priority: 0, flags: { contact: 1, protect: 1, mirror: 1, metronome: 1 }, - onAfterHit(target, source) { - if (source.hp) { - this.field.clearTerrain(); - } - }, - onAfterSubDamage(damage, target, source) { - if (source.hp) { + onAfterMoveSecondaryLast(target, source) { + if (source.hp && !source.forceSwitchFlag) { this.field.clearTerrain(); } }, diff --git a/sim/battle-actions.ts b/sim/battle-actions.ts index 9576f33a34990..65701c2063e13 100644 --- a/sim/battle-actions.ts +++ b/sim/battle-actions.ts @@ -528,7 +528,7 @@ export class BattleActions { !(move.hasSheerForce && pokemon.hasAbility('sheerforce')) && !move.flags['futuremove'] ) { - const originalHp = pokemon.hp; + let originalHp = pokemon.hp; this.battle.singleEvent('AfterMoveSecondarySelf', move, null, pokemon, target, move); this.battle.runEvent('AfterMoveSecondarySelf', pokemon, target, move); if (pokemon && pokemon !== target && move.category !== 'Status') { @@ -536,6 +536,14 @@ export class BattleActions { this.battle.runEvent('EmergencyExit', pokemon, pokemon); } } + for (const curTarget of targets) { + originalHp = curTarget.hp; + this.battle.singleEvent('AfterMoveSecondaryLast', move, null, curTarget, pokemon, move); + this.battle.runEvent('AfterMoveSecondaryLast', curTarget, pokemon, move); + if (curTarget.hp <= curTarget.maxhp / 2 && originalHp > curTarget.maxhp / 2) { + this.battle.runEvent('EmergencyExit', curTarget, curTarget); + } + } } return true; diff --git a/sim/dex-conditions.ts b/sim/dex-conditions.ts index 7e0da2ecba54d..16ba74ea98162 100644 --- a/sim/dex-conditions.ts +++ b/sim/dex-conditions.ts @@ -24,6 +24,7 @@ export interface EventMethods { onAfterTakeItem?: (this: Battle, item: Item, pokemon: Pokemon) => void; onAfterBoost?: (this: Battle, boost: SparseBoostsTable, target: Pokemon, source: Pokemon, effect: Effect) => void; onAfterFaint?: (this: Battle, length: number, target: Pokemon, source: Pokemon, effect: Effect) => void; + onAfterMoveSecondaryLast?: MoveEventMethods['onAfterMoveSecondaryLast']; onAfterMoveSecondarySelf?: MoveEventMethods['onAfterMoveSecondarySelf']; onAfterMoveSecondary?: MoveEventMethods['onAfterMoveSecondary']; onAfterMove?: MoveEventMethods['onAfterMove']; diff --git a/sim/dex-moves.ts b/sim/dex-moves.ts index 6895740e96f93..bca828f192d7a 100644 --- a/sim/dex-moves.ts +++ b/sim/dex-moves.ts @@ -112,6 +112,7 @@ export interface MoveEventMethods { onAfterHit?: CommonHandlers['VoidSourceMove']; onAfterSubDamage?: (this: Battle, damage: number, target: Pokemon, source: Pokemon, move: ActiveMove) => void; + onAfterMoveSecondaryLast?: CommonHandlers['VoidMove']; onAfterMoveSecondarySelf?: CommonHandlers['VoidSourceMove']; onAfterMoveSecondary?: CommonHandlers['VoidMove']; onAfterMove?: CommonHandlers['VoidSourceMove']; diff --git a/test/sim/abilities/pickpocket.js b/test/sim/abilities/pickpocket.js index 9e94e9f21519f..e89678b19283a 100644 --- a/test/sim/abilities/pickpocket.js +++ b/test/sim/abilities/pickpocket.js @@ -46,7 +46,7 @@ describe('Pickpocket', () => { assert.holdsItem(battle.p2.active[0]); }); - it.skip(`should steal items back and forth when hit by a Magician user`, () => { + it(`should steal items back and forth when hit by a Magician user`, () => { battle = common.createBattle([[ { species: 'Weavile', ability: 'pickpocket', item: 'cheriberry', moves: ['agility'] }, ], [ diff --git a/test/sim/moves/icespinner.js b/test/sim/moves/icespinner.js index d1916dbd36ae1..2c44daad8e4f2 100644 --- a/test/sim/moves/icespinner.js +++ b/test/sim/moves/icespinner.js @@ -21,7 +21,19 @@ describe(`Ice Spinner`, () => { assert.false(battle.field.isTerrain('psychicterrain')); }); - it.skip(`should not remove Terrains if the user faints from Life Orb`, () => { + it(`should remove Terrains if target has a substitute`, () => { + battle = common.createBattle([[ + { species: 'wynaut', moves: ['sleeptalk', 'icespinner'] }, + ], [ + { species: 'registeel', ability: 'psychicsurge', moves: ['substitute', 'sleeptalk'] }, + ]]); + + battle.makeChoices('move sleeptalk', 'move substitute'); + battle.makeChoices('move ice spinner', 'move sleeptalk'); + assert.false(battle.field.isTerrain('psychicterrain')); + }); + + it(`should not remove Terrains if the user faints from Life Orb`, () => { battle = common.createBattle([[ { species: 'shedinja', item: 'lifeorb', moves: ['icespinner'] }, { species: 'wynaut', moves: ['sleeptalk'] }, @@ -45,7 +57,7 @@ describe(`Ice Spinner`, () => { assert(battle.field.isTerrain('psychicterrain')); }); - it.skip(`should not remove Terrains if the user is forced out via Red Card`, () => { + it(`should not remove Terrains if the user is forced out via Red Card`, () => { battle = common.createBattle([[ { species: 'shedinja', moves: ['icespinner'] }, { species: 'wynaut', moves: ['sleeptalk'] },