Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AfterMoveSecondaryLast event #10899

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/abilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 2 additions & 7 deletions data/moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9759,13 +9759,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();
}
},
Expand Down
10 changes: 9 additions & 1 deletion sim/battle-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,14 +528,22 @@ 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);
Comment on lines 532 to 533
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how the other per-move AfterMoveSecondarySelf handlers should resolve priority compared to other AfterMoveSecondarySelf effects, but in case it helps, you can combine them in one priority system as follows:

Suggested change
this.battle.singleEvent('AfterMoveSecondarySelf', move, null, pokemon, target, move);
this.battle.runEvent('AfterMoveSecondarySelf', pokemon, target, move);
this.battle.runEvent('AfterMoveSecondarySelf', pokemon, target, move, null, true);

Copy link
Contributor Author

@andrebastosdias andrebastosdias Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That code isn't mine, so I'd prefer not to touch it. For AfterMoveSecondaryLast, I used the template from AfterMoveSecondary.

if (pokemon && pokemon !== target && move.category !== 'Status') {
if (pokemon.hp <= pokemon.maxhp / 2 && originalHp > pokemon.maxhp / 2) {
this.battle.runEvent('EmergencyExit', pokemon, pokemon);
}
}
for (const i of targets.keys()) {
originalHp = targets[i].hp;
this.battle.singleEvent('AfterMoveSecondaryLast', move, null, targets[i], pokemon, move);
this.battle.runEvent('AfterMoveSecondaryLast', targets[i], pokemon, move);
if (targets[i].hp <= targets[i].maxhp / 2 && originalHp > targets[i].maxhp / 2) {
this.battle.runEvent('EmergencyExit', targets[i], targets[i]);
}
}
}

return true;
Expand Down
1 change: 1 addition & 0 deletions sim/dex-conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
1 change: 1 addition & 0 deletions sim/dex-moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion test/sim/abilities/pickpocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('Pickpocket', function () {
assert.holdsItem(battle.p2.active[0]);
});

it.skip(`should steal items back and forth when hit by a Magician user`, function () {
it(`should steal items back and forth when hit by a Magician user`, function () {
battle = common.createBattle([[
{species: 'Weavile', ability: 'pickpocket', item: 'cheriberry', moves: ['agility']},
], [
Expand Down
16 changes: 14 additions & 2 deletions test/sim/moves/icespinner.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@ describe(`Ice Spinner`, function () {
assert.false(battle.field.isTerrain('psychicterrain'));
});

it.skip(`should not remove Terrains if the user faints from Life Orb`, function () {
it(`should remove Terrains if target has a substitute`, function () {
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`, function () {
battle = common.createBattle([[
{species: 'shedinja', item: 'lifeorb', moves: ['icespinner']},
{species: 'wynaut', moves: ['sleeptalk']},
Expand All @@ -45,7 +57,7 @@ describe(`Ice Spinner`, function () {
assert(battle.field.isTerrain('psychicterrain'));
});

it.skip(`should not remove Terrains if the user is forced out via Red Card`, function () {
it(`should not remove Terrains if the user is forced out via Red Card`, function () {
battle = common.createBattle([[
{species: 'shedinja', moves: ['icespinner']},
{species: 'wynaut', moves: ['sleeptalk']},
Expand Down