mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-03-21 17:25:10 -05:00
Refactor Skill Swap to its own function (#11563)
Some checks failed
Node.js CI / build (18.x) (push) Has been cancelled
Some checks failed
Node.js CI / build (18.x) (push) Has been cancelled
This commit is contained in:
parent
af4f85a33c
commit
df367633bc
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 &&
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user