diff --git a/data/abilities.ts b/data/abilities.ts index 51be75b7eb..c54de73b98 100644 --- a/data/abilities.ts +++ b/data/abilities.ts @@ -2333,10 +2333,7 @@ export const Abilities: import('../sim/dex-abilities').AbilityDataTable = { return; } if (this.checkMoveMakesContact(move, source, target, !source.isAlly(target))) { - const oldAbility = source.setAbility('lingeringaroma', target); - if (oldAbility) { - this.add('-activate', target, 'ability: Lingering Aroma', this.dex.abilities.get(oldAbility).name, `[of] ${source}`); - } + source.setAbility('lingeringaroma', target); } }, flags: {}, @@ -2714,10 +2711,7 @@ export const Abilities: import('../sim/dex-abilities').AbilityDataTable = { return; } if (this.checkMoveMakesContact(move, source, target, !source.isAlly(target))) { - const oldAbility = source.setAbility('mummy', target); - if (oldAbility) { - this.add('-activate', target, 'ability: Mummy', this.dex.abilities.get(oldAbility).name, `[of] ${source}`); - } + source.setAbility('mummy', target); } }, flags: {}, @@ -5270,20 +5264,7 @@ export const Abilities: import('../sim/dex-abilities').AbilityDataTable = { }, wanderingspirit: { onDamagingHit(damage, target, source, move) { - if (source.getAbility().flags['failskillswap'] || target.volatiles['dynamax']) return; - - if (this.checkMoveMakesContact(move, source, target)) { - const targetCanBeSet = this.runEvent('SetAbility', target, source, this.effect, source.ability); - if (!targetCanBeSet) return targetCanBeSet; - const sourceAbility = source.setAbility('wanderingspirit', target); - if (!sourceAbility) return; - if (target.isAlly(source)) { - this.add('-activate', target, 'Skill Swap', '', '', `[of] ${source}`); - } else { - this.add('-activate', target, 'ability: Wandering Spirit', this.dex.abilities.get(sourceAbility).name, 'Wandering Spirit', `[of] ${source}`); - } - target.setAbility(sourceAbility); - } + if (this.checkMoveMakesContact(move, source, target)) this.skillSwap(source, target); }, flags: {}, name: "Wandering Spirit", diff --git a/data/mods/gen4/moves.ts b/data/mods/gen4/moves.ts index 3caeea4ac3..1e5db1ae5e 100644 --- a/data/mods/gen4/moves.ts +++ b/data/mods/gen4/moves.ts @@ -1554,19 +1554,6 @@ export const Moves: import('../../../sim/dex-moves').ModdedMoveDataTable = { this.add('-activate', source, 'move: Mimic', move.name); }, }, - skillswap: { - inherit: true, - onHit(target, source) { - const targetAbility = target.ability; - const sourceAbility = source.ability; - if (targetAbility === sourceAbility || source.hasItem('griseousorb') || target.hasItem('griseousorb')) { - return false; - } - this.add('-activate', source, 'move: Skill Swap'); - source.setAbility(targetAbility); - target.setAbility(sourceAbility); - }, - }, sleeptalk: { inherit: true, onTryHit(pokemon) { diff --git a/data/mods/gen5/moves.ts b/data/mods/gen5/moves.ts index ab4cc6060f..4328d70e1e 100644 --- a/data/mods/gen5/moves.ts +++ b/data/mods/gen5/moves.ts @@ -794,19 +794,6 @@ export const Moves: import('../../../sim/dex-moves').ModdedMoveDataTable = { inherit: true, flags: { protect: 1, reflectable: 1, mirror: 1, sound: 1, metronome: 1 }, }, - skillswap: { - inherit: true, - onHit(target, source) { - const targetAbility = target.ability; - const sourceAbility = source.ability; - if (targetAbility === sourceAbility) { - return false; - } - this.add('-activate', source, 'move: Skill Swap', this.dex.abilities.get(targetAbility), this.dex.abilities.get(sourceAbility), `[of] ${target}`); - source.setAbility(targetAbility); - target.setAbility(sourceAbility); - }, - }, skullbash: { inherit: true, basePower: 100, diff --git a/data/moves.ts b/data/moves.ts index e19821ac7f..8004f48dfb 100644 --- a/data/moves.ts +++ b/data/moves.ts @@ -17209,35 +17209,8 @@ export const Moves: import('../sim/dex-moves').MoveDataTable = { pp: 10, priority: 0, flags: { protect: 1, mirror: 1, bypasssub: 1, allyanim: 1, metronome: 1 }, - onTryHit(target, source) { - const targetAbility = target.getAbility(); - const sourceAbility = source.getAbility(); - if (sourceAbility.flags['failskillswap'] || targetAbility.flags['failskillswap'] || target.volatiles['dynamax']) { - return false; - } - const sourceCanBeSet = this.runEvent('SetAbility', source, source, this.effect, targetAbility); - if (!sourceCanBeSet) return sourceCanBeSet; - const targetCanBeSet = this.runEvent('SetAbility', target, source, this.effect, sourceAbility); - if (!targetCanBeSet) return targetCanBeSet; - }, onHit(target, source, move) { - const targetAbility = target.getAbility(); - const sourceAbility = source.getAbility(); - if (target.isAlly(source)) { - this.add('-activate', source, 'move: Skill Swap', '', '', `[of] ${target}`); - } else { - this.add('-activate', source, 'move: Skill Swap', targetAbility, sourceAbility, `[of] ${target}`); - } - this.singleEvent('End', sourceAbility, source.abilityState, source); - this.singleEvent('End', targetAbility, target.abilityState, target); - source.ability = targetAbility.id; - target.ability = sourceAbility.id; - source.abilityState = this.initEffectState({ id: this.toID(source.ability), target: source }); - target.abilityState = this.initEffectState({ id: this.toID(target.ability), target }); - source.volatileStaleness = undefined; - if (!target.isAlly(source)) target.volatileStaleness = 'external'; - this.singleEvent('Start', targetAbility, source.abilityState, source); - this.singleEvent('Start', sourceAbility, target.abilityState, target); + return this.skillSwap(source, target); }, secondary: null, target: "normal", diff --git a/sim/battle.ts b/sim/battle.ts index e4c6e2ee87..cbfbda0de2 100644 --- a/sim/battle.ts +++ b/sim/battle.ts @@ -1298,6 +1298,39 @@ export class Battle { return !!move.flags['contact']; } + skillSwap(source: Pokemon, target: Pokemon) { + if (source.fainted || target.fainted) return false; + if (source.volatiles['dynamax'] || target.volatiles['dynamax']) return false; + const sourceAbility = source.getAbility(); + const targetAbility = target.getAbility(); + if (sourceAbility.flags['failskillswap'] || targetAbility.flags['failskillswap']) return false; + if (this.gen <= 5 && sourceAbility.id === targetAbility.id) return false; + + const sourceEffect = this.dex.conditions.get('skillswap'); + const targetCanBeSet = this.runEvent('SetAbility', target, source, sourceEffect, sourceAbility); + if (!targetCanBeSet) return targetCanBeSet; + const sourceCanBeSet = this.runEvent('SetAbility', source, source, sourceEffect, targetAbility); + if (!sourceCanBeSet) return sourceCanBeSet; + + if (this.gen <= 4 || source.isAlly(target)) { + this.add('-activate', source, 'Skill Swap'); + } else { + this.add('-activate', source, 'Skill Swap', target, `[ability] ${targetAbility.name}`, `[ability2] ${sourceAbility.name}`); + } + this.singleEvent('End', sourceAbility, source.abilityState, source); + this.singleEvent('End', targetAbility, target.abilityState, target); + source.ability = targetAbility.id; + target.ability = sourceAbility.id; + source.abilityState = this.initEffectState({ id: toID(source.ability), target: source }); + target.abilityState = this.initEffectState({ id: toID(target.ability), target }); + source.volatileStaleness = undefined; + if (!source.isAlly(target)) target.volatileStaleness = 'external'; + if (this.gen > 3) { + this.singleEvent('Start', sourceAbility, target.abilityState, target); + this.singleEvent('Start', targetAbility, source.abilityState, source); + } + } + getPokemon(fullname: string | Pokemon) { if (typeof fullname !== 'string') fullname = fullname.fullname; for (const side of this.sides) { diff --git a/sim/pokemon.ts b/sim/pokemon.ts index ba51b073a0..418bdc3bd2 100644 --- a/sim/pokemon.ts +++ b/sim/pokemon.ts @@ -1900,10 +1900,18 @@ export class Pokemon { this.ability = ability.id; this.abilityState = this.battle.initEffectState({ id: ability.id, target: this }); if (sourceEffect && !isFromFormeChange && !isTransform) { - if (source) { - this.battle.add('-ability', this, ability.name, oldAbility.name, `[from] ${sourceEffect.fullname}`, `[of] ${source}`); - } else { - this.battle.add('-ability', this, ability.name, oldAbility.name, `[from] ${sourceEffect.fullname}`); + switch (sourceEffect.id) { + case 'mummy': + case 'lingeringaroma': + this.battle.add('-activate', source, sourceEffect.fullname, this, '[ability] ' + oldAbility.name); + break; + default: + if (source) { + this.battle.add('-ability', this, ability.name, oldAbility.name, `[from] ${sourceEffect.fullname}`, `[of] ${source}`); + } else { + this.battle.add('-ability', this, ability.name, oldAbility.name, `[from] ${sourceEffect.fullname}`); + } + break; } } if (ability.id && this.battle.gen > 3 &&