Refactor Skill Swap to its own function (#11563)
Some checks failed
Node.js CI / build (18.x) (push) Has been cancelled

This commit is contained in:
Karthik Bandagonda 2026-02-06 06:47:29 -07:00 committed by GitHub
parent af4f85a33c
commit df367633bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 49 additions and 80 deletions

View File

@ -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",

View File

@ -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) {

View File

@ -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,

View File

@ -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",

View File

@ -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) {

View File

@ -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 &&