diff --git a/data/mods/gen1/conditions.ts b/data/mods/gen1/conditions.ts index ea7d52cfe5..bee80bc6f8 100644 --- a/data/mods/gen1/conditions.ts +++ b/data/mods/gen1/conditions.ts @@ -23,9 +23,6 @@ export const Conditions: import('../../../sim/dex-conditions').ModdedConditionDa this.hint("In Gen 1, Toxic's counter is retained after Rest and applies to PSN/BRN.", true); } }, - onAfterSwitchInSelf(pokemon) { - this.damage(this.clampIntRange(Math.floor(pokemon.maxhp / 16), 1)); - }, }, par: { name: 'par', @@ -119,9 +116,6 @@ export const Conditions: import('../../../sim/dex-conditions').ModdedConditionDa this.hint("In Gen 1, Toxic's counter is retained after Rest and applies to PSN/BRN.", true); } }, - onAfterSwitchInSelf(pokemon) { - this.damage(this.clampIntRange(Math.floor(pokemon.maxhp / 16), 1)); - }, }, tox: { inherit: true, diff --git a/data/mods/gen1/scripts.ts b/data/mods/gen1/scripts.ts index 83812bfa95..1e2676b905 100644 --- a/data/mods/gen1/scripts.ts +++ b/data/mods/gen1/scripts.ts @@ -157,11 +157,6 @@ export const Scripts: ModdedBattleScriptsData = { } } - const abortMove = () => { - this.battle.clearActiveMove(true); - this.battle.runEvent('AfterMoveSelf', pokemon, target, move); - }; - if (move.id === 'cannotmove') { if (pokemon.status === 'slp') { this.battle.hint( @@ -179,7 +174,7 @@ export const Scripts: ModdedBattleScriptsData = { "the move execution will never resolve." ); } - abortMove(); + this.battle.clearActiveMove(true); return; } @@ -188,11 +183,11 @@ export const Scripts: ModdedBattleScriptsData = { this.battle.setActiveMove(move, pokemon, target); if (pokemon.moveThisTurn || !this.battle.runEvent('BeforeMove', pokemon, target, move)) { - abortMove(); + this.battle.clearActiveMove(true); return; } if (move.beforeMoveCallback?.call(this.battle, pokemon, target, move)) { - abortMove(); + this.battle.clearActiveMove(true); return; } @@ -212,7 +207,7 @@ export const Scripts: ModdedBattleScriptsData = { this.battle.hint( "In Gen 1, a Pokémon might default to using a move that doesn't match the move of the slot it last selected.", ); - abortMove(); + this.battle.clearActiveMove(true); return; } } @@ -268,9 +263,6 @@ export const Scripts: ModdedBattleScriptsData = { pokemon.side.lastMove = move; this.battle.runEvent('AfterMove', pokemon, target, move); - if (!target || target.hp > 0) { - this.battle.runEvent('AfterMoveSelf', pokemon, target, move); - } } } return moveResult; diff --git a/data/mods/gen1stadium/conditions.ts b/data/mods/gen1stadium/conditions.ts index f39ad0fbe0..00c540befe 100644 --- a/data/mods/gen1stadium/conditions.ts +++ b/data/mods/gen1stadium/conditions.ts @@ -9,9 +9,6 @@ export const Conditions: import('../../../sim/dex-conditions').ModdedConditionDa onAfterMoveSelf(pokemon) { this.damage(this.clampIntRange(Math.floor(pokemon.maxhp / 16), 1)); }, - onAfterSwitchInSelf(pokemon) { - this.damage(this.clampIntRange(Math.floor(pokemon.maxhp / 16), 1)); - }, }, par: { name: 'par', @@ -88,9 +85,6 @@ export const Conditions: import('../../../sim/dex-conditions').ModdedConditionDa onAfterMoveSelf(pokemon) { this.damage(this.clampIntRange(Math.floor(pokemon.maxhp / 16), 1)); }, - onAfterSwitchInSelf(pokemon) { - this.damage(this.clampIntRange(Math.floor(pokemon.maxhp / 16), 1)); - }, }, confusion: { inherit: true, diff --git a/data/mods/gen1stadium/scripts.ts b/data/mods/gen1stadium/scripts.ts index fb6380a046..bde61c34b1 100644 --- a/data/mods/gen1stadium/scripts.ts +++ b/data/mods/gen1stadium/scripts.ts @@ -83,8 +83,6 @@ export const Scripts: ModdedBattleScriptsData = { if (pokemon.moveThisTurn || !this.battle.runEvent('BeforeMove', pokemon, target, move)) { this.battle.debug(`${pokemon.fullname} move interrupted; movedThisTurn: ${pokemon.moveThisTurn}`); this.battle.clearActiveMove(true); - // This is only run for sleep - this.battle.runEvent('AfterMoveSelf', pokemon, target, move); return; } if (move.beforeMoveCallback) { @@ -142,8 +140,6 @@ export const Scripts: ModdedBattleScriptsData = { // If target fainted if (target && target.hp <= 0) { delete pokemon.volatiles['partialtrappinglock']; - } else { - this.battle.runEvent('AfterMoveSelf', pokemon, target, move); } if (pokemon.volatiles['mustrecharge']) this.battle.add('-mustrecharge', pokemon); diff --git a/data/mods/gen2/conditions.ts b/data/mods/gen2/conditions.ts index f30c844f9f..878f4c43d5 100644 --- a/data/mods/gen2/conditions.ts +++ b/data/mods/gen2/conditions.ts @@ -9,9 +9,6 @@ export const Conditions: import('../../../sim/dex-conditions').ModdedConditionDa onAfterMoveSelf(pokemon) { residualdmg(this, pokemon); }, - onAfterSwitchInSelf(pokemon) { - residualdmg(this, pokemon); - }, }, par: { name: 'par', @@ -87,9 +84,6 @@ export const Conditions: import('../../../sim/dex-conditions').ModdedConditionDa onAfterMoveSelf(pokemon) { residualdmg(this, pokemon); }, - onAfterSwitchInSelf(pokemon) { - residualdmg(this, pokemon); - }, }, tox: { name: 'tox', @@ -109,9 +103,6 @@ export const Conditions: import('../../../sim/dex-conditions').ModdedConditionDa pokemon.status = 'psn' as ID; this.add('-status', pokemon, 'psn', '[silent]'); }, - onAfterSwitchInSelf(pokemon) { - this.damage(this.clampIntRange(Math.floor(pokemon.maxhp / 16), 1)); - }, }, confusion: { inherit: true, @@ -245,9 +236,6 @@ export const Conditions: import('../../../sim/dex-conditions').ModdedConditionDa onAfterMoveSelf(pokemon) { if (['brn', 'psn', 'tox'].includes(pokemon.status)) pokemon.volatiles['residualdmg'].counter++; }, - onAfterSwitchInSelf(pokemon) { - if (['brn', 'psn', 'tox'].includes(pokemon.status)) pokemon.volatiles['residualdmg'].counter++; - }, }, }; diff --git a/data/mods/gen2/moves.ts b/data/mods/gen2/moves.ts index c75e5a214f..a09c4e90df 100644 --- a/data/mods/gen2/moves.ts +++ b/data/mods/gen2/moves.ts @@ -412,7 +412,7 @@ export const Moves: import('../../../sim/dex-moves').ModdedMoveDataTable = { onResidual: undefined, // no inherit onAfterMoveSelfPriority: 1, onAfterMoveSelf(pokemon) { - if (pokemon.status === 'slp') this.damage(pokemon.baseMaxhp / 4); + if (this.effectState.source.hp) this.damage(pokemon.baseMaxhp / 4); }, }, }, diff --git a/data/mods/gen2/scripts.ts b/data/mods/gen2/scripts.ts index 5bb79245ba..2dbf54843f 100644 --- a/data/mods/gen2/scripts.ts +++ b/data/mods/gen2/scripts.ts @@ -114,8 +114,6 @@ export const Scripts: ModdedBattleScriptsData = { if (!this.battle.runEvent('BeforeMove', pokemon, target, move)) { this.battle.runEvent('MoveAborted', pokemon, target, move); this.battle.clearActiveMove(true); - // This is only run for sleep and fully paralysed. - this.battle.runEvent('AfterMoveSelf', pokemon, target, move); return; } if (move.beforeMoveCallback) { @@ -136,7 +134,6 @@ export const Scripts: ModdedBattleScriptsData = { pokemon.moveUsed(move); this.battle.actions.useMove(move, pokemon, { target, sourceEffect: options?.sourceEffect }); this.battle.singleEvent('AfterMove', move, null, pokemon, target, move); - if (!move.selfSwitch && pokemon.side.foe.active[0].hp) this.battle.runEvent('AfterMoveSelf', pokemon, target, move); }, tryMoveHit(target, pokemon, move) { const positiveBoostTable = [1, 1.33, 1.66, 2, 2.33, 2.66, 3]; diff --git a/data/mods/gen2stadium2/conditions.ts b/data/mods/gen2stadium2/conditions.ts index 0ea3d92f0e..91d1d868cf 100644 --- a/data/mods/gen2stadium2/conditions.ts +++ b/data/mods/gen2stadium2/conditions.ts @@ -19,9 +19,6 @@ export const Conditions: import('../../../sim/dex-conditions').ModdedConditionDa onSwitchIn(pokemon) { pokemon.addVolatile('brnattackdrop'); }, - onAfterSwitchInSelf(pokemon) { - residualdmg(this, pokemon); - }, }, par: { name: 'par', @@ -118,9 +115,6 @@ export const Conditions: import('../../../sim/dex-conditions').ModdedConditionDa onAfterMoveSelf(pokemon) { if (['brn', 'psn', 'tox'].includes(pokemon.status)) pokemon.volatiles['residualdmg'].counter++; }, - onAfterSwitchInSelf(pokemon) { - if (['brn', 'psn', 'tox'].includes(pokemon.status)) pokemon.volatiles['residualdmg'].counter++; - }, }, }; diff --git a/data/mods/gen4/scripts.ts b/data/mods/gen4/scripts.ts index c28929177d..4934554cd3 100644 --- a/data/mods/gen4/scripts.ts +++ b/data/mods/gen4/scripts.ts @@ -16,10 +16,6 @@ export const Scripts: ModdedBattleScriptsData = { actions: { inherit: true, runSwitch(pokemon) { - this.battle.runEvent('EntryHazard', pokemon); - - this.battle.runEvent('SwitchIn', pokemon); - if (this.battle.gen <= 2) { // pokemon.lastMove is reset for all Pokemon on the field after a switch. This affects Mirror Move. for (const poke of this.battle.getAllActive()) poke.lastMove = null; @@ -33,9 +29,6 @@ export const Scripts: ModdedBattleScriptsData = { } } } - if (!pokemon.side.faintedThisTurn && pokemon.draggedIn !== this.battle.turn) { - this.battle.runEvent('AfterSwitchInSelf', pokemon); - } } if (!pokemon.hp) return false; pokemon.isStarted = true; diff --git a/sim/battle-actions.ts b/sim/battle-actions.ts index 66fd617e6d..1af3ca8c8a 100644 --- a/sim/battle-actions.ts +++ b/sim/battle-actions.ts @@ -150,7 +150,11 @@ export class BattleActions { if (isDrag && this.battle.gen === 2) pokemon.draggedIn = this.battle.turn; pokemon.previouslySwitchedIn++; - if (isDrag && this.battle.gen >= 5) { + if (this.battle.gen <= 4) { + this.battle.runEvent('EntryHazard', pokemon); + this.battle.runEvent('SwitchIn', pokemon); + } + if (isDrag) { // runSwitch happens immediately so that Mold Breaker can make hazards bypass Clear Body and Levitate this.runSwitch(pokemon); } else { diff --git a/sim/battle-queue.ts b/sim/battle-queue.ts index 59e5f80650..fa640e176e 100644 --- a/sim/battle-queue.ts +++ b/sim/battle-queue.ts @@ -65,7 +65,7 @@ export interface SwitchAction { pokemon: Pokemon; /** pokemon to switch to */ target: Pokemon; - /** effect that called the switch (eg U */ + /** effect that called the switch (eg U-turn) */ sourceEffect: Effect | null; } diff --git a/sim/battle.ts b/sim/battle.ts index 7a4d67aa65..24bbf39c95 100644 --- a/sim/battle.ts +++ b/sim/battle.ts @@ -2839,6 +2839,17 @@ export class Battle { break; } + if (this.gen <= 2) { + if (action.choice === 'move' && !action.pokemon.switchFlag) { + this.runEvent('AfterMoveSelf', action.pokemon); + } else if (action.choice === 'switch' || (action.choice === 'instaswitch' && action.sourceEffect)) { + this.runEvent('AfterMoveSelf', action.target); + } + } + + // Gen 4 and earlier: clear active move so Mold Breaker doesn't allow hazards to bypass Clear Body and Levitate + if (this.gen <= 4) this.clearActiveMove(); + // phazing (Roar, etc) for (const side of this.sides) { for (const pokemon of side.active) { @@ -2849,7 +2860,7 @@ export class Battle { } } - this.clearActiveMove(); + if (this.gen > 4) this.clearActiveMove(); // fainting diff --git a/sim/dex-conditions.ts b/sim/dex-conditions.ts index 9445d46083..035fac7c57 100644 --- a/sim/dex-conditions.ts +++ b/sim/dex-conditions.ts @@ -18,7 +18,6 @@ export interface EventMethods { onAfterMega?: (this: Battle, pokemon: Pokemon) => void; onAfterSetStatus?: (this: Battle, status: Condition, target: Pokemon, source: Pokemon, effect: Effect) => void; onAfterSubDamage?: MoveEventMethods['onAfterSubDamage']; - onAfterSwitchInSelf?: (this: Battle, pokemon: Pokemon) => void; onAfterTerastallization?: (this: Battle, pokemon: Pokemon) => void; onAfterUseItem?: (this: Battle, item: Item, pokemon: Pokemon) => void; onAfterTakeItem?: (this: Battle, item: Item, pokemon: Pokemon) => void; @@ -27,7 +26,7 @@ export interface EventMethods { onAfterMoveSecondarySelf?: MoveEventMethods['onAfterMoveSecondarySelf']; onAfterMoveSecondary?: MoveEventMethods['onAfterMoveSecondary']; onAfterMove?: MoveEventMethods['onAfterMove']; - onAfterMoveSelf?: CommonHandlers['VoidSourceMove']; + onAfterMoveSelf?: (this: Battle, pokemon: Pokemon) => void; onAttract?: (this: Battle, target: Pokemon, source: Pokemon) => void; onAccuracy?: ( this: Battle, accuracy: number, target: Pokemon, source: Pokemon, move: ActiveMove @@ -130,7 +129,6 @@ export interface EventMethods { onFoeAfterHit?: MoveEventMethods['onAfterHit']; onFoeAfterSetStatus?: (this: Battle, status: Condition, target: Pokemon, source: Pokemon, effect: Effect) => void; onFoeAfterSubDamage?: MoveEventMethods['onAfterSubDamage']; - onFoeAfterSwitchInSelf?: (this: Battle, pokemon: Pokemon) => void; onFoeAfterUseItem?: (this: Battle, item: Item, pokemon: Pokemon) => void; onFoeAfterBoost?: (this: Battle, boost: SparseBoostsTable, target: Pokemon, source: Pokemon, effect: Effect) => void; onFoeAfterFaint?: (this: Battle, length: number, target: Pokemon, source: Pokemon, effect: Effect) => void; @@ -228,7 +226,6 @@ export interface EventMethods { onSourceAfterHit?: MoveEventMethods['onAfterHit']; onSourceAfterSetStatus?: (this: Battle, status: Condition, target: Pokemon, source: Pokemon, effect: Effect) => void; onSourceAfterSubDamage?: MoveEventMethods['onAfterSubDamage']; - onSourceAfterSwitchInSelf?: (this: Battle, pokemon: Pokemon) => void; onSourceAfterUseItem?: (this: Battle, item: Item, pokemon: Pokemon) => void; onSourceAfterBoost?: (this: Battle, boost: SparseBoostsTable, target: Pokemon, source: Pokemon, effect: Effect) => void; onSourceAfterFaint?: (this: Battle, length: number, target: Pokemon, source: Pokemon, effect: Effect) => void; @@ -328,7 +325,6 @@ export interface EventMethods { onAnyAfterHit?: MoveEventMethods['onAfterHit']; onAnyAfterSetStatus?: (this: Battle, status: Condition, target: Pokemon, source: Pokemon, effect: Effect) => void; onAnyAfterSubDamage?: MoveEventMethods['onAfterSubDamage']; - onAnyAfterSwitchInSelf?: (this: Battle, pokemon: Pokemon) => void; onAnyAfterUseItem?: (this: Battle, item: Item, pokemon: Pokemon) => void; onAnyAfterBoost?: (this: Battle, boost: SparseBoostsTable, target: Pokemon, source: Pokemon, effect: Effect) => void; onAnyAfterFaint?: (this: Battle, length: number, target: Pokemon, source: Pokemon, effect: Effect) => void; @@ -504,7 +500,6 @@ export interface PokemonEventMethods extends EventMethods { onAllyAfterHit?: MoveEventMethods['onAfterHit']; onAllyAfterSetStatus?: (this: Battle, status: Condition, target: Pokemon, source: Pokemon, effect: Effect) => void; onAllyAfterSubDamage?: MoveEventMethods['onAfterSubDamage']; - onAllyAfterSwitchInSelf?: (this: Battle, pokemon: Pokemon) => void; onAllyAfterUseItem?: (this: Battle, item: Item, pokemon: Pokemon) => void; onAllyAfterBoost?: (this: Battle, boost: SparseBoostsTable, target: Pokemon, source: Pokemon, effect: Effect) => void; onAllyAfterFaint?: (this: Battle, length: number, target: Pokemon, source: Pokemon, effect: Effect) => void;