Skip to content

Commit

Permalink
Fix the order of many end-turn resolution effects (#8307)
Browse files Browse the repository at this point in the history
Co-authored-by: Marty-D <Marty-D@users.noreply.github.com>
  • Loading branch information
DaWoblefet and Marty-D committed May 17, 2021
1 parent 50054ef commit d946308
Show file tree
Hide file tree
Showing 19 changed files with 724 additions and 122 deletions.
37 changes: 20 additions & 17 deletions data/abilities.ts
Expand Up @@ -237,8 +237,8 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
num: 188,
},
baddreams: {
onResidualOrder: 26,
onResidualSubOrder: 1,
onResidualOrder: 28,
onResidualSubOrder: 2,
onResidual(pokemon) {
if (!pokemon.hp) return;
for (const target of pokemon.foes()) {
Expand Down Expand Up @@ -1387,8 +1387,8 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
},
harvest: {
name: "Harvest",
onResidualOrder: 26,
onResidualSubOrder: 1,
onResidualOrder: 28,
onResidualSubOrder: 2,
onResidual(pokemon) {
if (this.field.isWeather(['sunnyday', 'desolateland']) || this.randomChance(1, 2)) {
if (pokemon.hp && !pokemon.item && this.dex.items.get(pokemon.lastItem).isBerry) {
Expand All @@ -1404,7 +1404,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
healer: {
name: "Healer",
onResidualOrder: 5,
onResidualSubOrder: 4,
onResidualSubOrder: 3,
onResidual(pokemon) {
for (const allyActive of pokemon.adjacentAllies()) {
if (allyActive.status && this.randomChance(3, 10)) {
Expand Down Expand Up @@ -1458,6 +1458,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
num: 37,
},
hungerswitch: {
onResidualOrder: 29,
onResidual(pokemon) {
if (pokemon.species.baseSpecies !== 'Morpeko' || pokemon.transformed) return;
const targetForme = pokemon.species.name === 'Morpeko' ? 'Morpeko-Hangry' : 'Morpeko';
Expand Down Expand Up @@ -1485,7 +1486,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
},
hydration: {
onResidualOrder: 5,
onResidualSubOrder: 4,
onResidualSubOrder: 3,
onResidual(pokemon) {
if (pokemon.status && ['raindance', 'primordialsea'].includes(pokemon.effectiveWeather())) {
this.debug('hydration');
Expand Down Expand Up @@ -2160,8 +2161,8 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
num: 104,
},
moody: {
onResidualOrder: 26,
onResidualSubOrder: 1,
onResidualOrder: 28,
onResidualSubOrder: 2,
onResidual(pokemon) {
let stats: BoostID[] = [];
const boost: SparseBoostsTable = {};
Expand Down Expand Up @@ -2618,8 +2619,8 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
num: 124,
},
pickup: {
onResidualOrder: 26,
onResidualSubOrder: 1,
onResidualOrder: 28,
onResidualSubOrder: 2,
onResidual(pokemon) {
if (pokemon.item) return;
const pickupTargets = this.getAllActive().filter(target => (
Expand Down Expand Up @@ -2710,7 +2711,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
num: 143,
},
powerconstruct: {
onResidualOrder: 27,
onResidualOrder: 29,
onResidual(pokemon) {
if (pokemon.baseSpecies.baseSpecies !== 'Zygarde' || pokemon.transformed || !pokemon.hp) return;
if (pokemon.species.id === 'zygardecomplete' || pokemon.hp > pokemon.maxhp / 2) return;
Expand Down Expand Up @@ -3181,7 +3182,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
}
}
},
onResidualOrder: 27,
onResidualOrder: 29,
onResidual(pokemon) {
if (
pokemon.baseSpecies.baseSpecies !== 'Wishiwashi' || pokemon.level < 20 ||
Expand Down Expand Up @@ -3285,7 +3286,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
},
shedskin: {
onResidualOrder: 5,
onResidualSubOrder: 4,
onResidualSubOrder: 3,
onResidual(pokemon) {
if (pokemon.hp && pokemon.status && this.randomChance(33, 100)) {
this.debug('shed skin');
Expand Down Expand Up @@ -3346,7 +3347,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
}
}
},
onResidualOrder: 27,
onResidualOrder: 29,
onResidual(pokemon) {
if (pokemon.baseSpecies.baseSpecies !== 'Minior' || pokemon.transformed || !pokemon.hp) return;
if (pokemon.hp > pokemon.maxhp / 2) {
Expand Down Expand Up @@ -3413,6 +3414,8 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
},
condition: {
duration: 5,
onResidualOrder: 28,
onResidualSubOrder: 2,
onStart(target) {
this.add('-start', target, 'ability: Slow Start');
},
Expand Down Expand Up @@ -3533,8 +3536,8 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
num: 43,
},
speedboost: {
onResidualOrder: 26,
onResidualSubOrder: 1,
onResidualOrder: 28,
onResidualSubOrder: 2,
onResidual(pokemon) {
if (pokemon.activeTurns) {
this.boost({spe: 1});
Expand Down Expand Up @@ -4384,7 +4387,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
num: 147,
},
zenmode: {
onResidualOrder: 27,
onResidualOrder: 29,
onResidual(pokemon) {
if (pokemon.baseSpecies.baseSpecies !== 'Darmanitan' || pokemon.transformed) {
return;
Expand Down
4 changes: 2 additions & 2 deletions data/conditions.ts
Expand Up @@ -12,7 +12,7 @@ export const Conditions: {[k: string]: ConditionData} = {
}
},
// Damage reduction is handled directly in the sim/battle.js damage function
onResidualOrder: 9,
onResidualOrder: 10,
onResidual(pokemon) {
this.damage(pokemon.baseMaxhp / 16);
},
Expand Down Expand Up @@ -214,7 +214,7 @@ export const Conditions: {[k: string]: ConditionData} = {
this.add('-activate', pokemon, 'move: ' + this.effectState.sourceEffect, '[of] ' + source);
this.effectState.boundDivisor = source.hasItem('bindingband') ? 6 : 8;
},
onResidualOrder: 11,
onResidualOrder: 13,
onResidual(pokemon) {
const source = this.effectState.source;
// G-Max Centiferno and G-Max Sandblast continue even after the user leaves the field
Expand Down
16 changes: 8 additions & 8 deletions data/items.ts
Expand Up @@ -451,7 +451,7 @@ export const Items: {[itemid: string]: ItemData} = {
basePower: 30,
},
onResidualOrder: 5,
onResidualSubOrder: 5,
onResidualSubOrder: 4,
onResidual(pokemon) {
if (pokemon.hasType('Poison')) {
this.heal(pokemon.baseMaxhp / 16);
Expand Down Expand Up @@ -1772,8 +1772,8 @@ export const Items: {[itemid: string]: ItemData} = {
basePower: 30,
status: 'brn',
},
onResidualOrder: 26,
onResidualSubOrder: 2,
onResidualOrder: 28,
onResidualSubOrder: 3,
onResidual(pokemon) {
pokemon.trySetStatus('brn', pokemon);
},
Expand Down Expand Up @@ -2836,7 +2836,7 @@ export const Items: {[itemid: string]: ItemData} = {
basePower: 10,
},
onResidualOrder: 5,
onResidualSubOrder: 5,
onResidualSubOrder: 4,
onResidual(pokemon) {
this.heal(pokemon.baseMaxhp / 16);
},
Expand Down Expand Up @@ -5300,8 +5300,8 @@ export const Items: {[itemid: string]: ItemData} = {
fling: {
basePower: 80,
},
onResidualOrder: 26,
onResidualSubOrder: 2,
onResidualOrder: 28,
onResidualSubOrder: 3,
onResidual(pokemon) {
this.damage(pokemon.baseMaxhp / 8);
},
Expand Down Expand Up @@ -5499,8 +5499,8 @@ export const Items: {[itemid: string]: ItemData} = {
basePower: 30,
status: 'tox',
},
onResidualOrder: 26,
onResidualSubOrder: 2,
onResidualOrder: 28,
onResidualSubOrder: 3,
onResidual(pokemon) {
pokemon.trySetStatus('tox', pokemon);
},
Expand Down
16 changes: 16 additions & 0 deletions data/mods/gen2/conditions.ts
Expand Up @@ -68,6 +68,7 @@ export const Conditions: {[k: string]: ModdedConditionData} = {
onAfterMoveSecondarySelf(pokemon, target, move) {
if (move.flags['defrost']) pokemon.cureStatus();
},
onResidualOrder: 7,
onResidual(pokemon) {
if (this.randomChance(25, 256)) pokemon.cureStatus();
},
Expand Down Expand Up @@ -154,6 +155,8 @@ export const Conditions: {[k: string]: ModdedConditionData} = {
durationCallback(target, source) {
return this.random(3, 6);
},
onResidualOrder: 3,
onResidualSubOrder: 1,
},
lockedmove: {
name: 'lockedmove',
Expand Down Expand Up @@ -189,8 +192,21 @@ export const Conditions: {[k: string]: ModdedConditionData} = {
}
},
},
futuremove: {
inherit: true,
onResidualOrder: 1,
},
raindance: {
inherit: true,
onFieldResidualOrder: 2,
},
sunnyday: {
inherit: true,
onFieldResidualOrder: 2,
},
sandstorm: {
inherit: true,
onFieldResidualOrder: 2,
onWeather(target) {
this.damage(target.baseMaxhp / 8);
},
Expand Down
5 changes: 5 additions & 0 deletions data/mods/gen2/items.ts
Expand Up @@ -86,6 +86,11 @@ export const Items: {[k: string]: ModdedItemData} = {
}
},
},
leftovers: {
inherit: true,
onResidualOrder: 5,
onResidualSubOrder: 1,
},
lightball: {
inherit: true,
// In Gen 2 this happens in stat calculation directly.
Expand Down
59 changes: 57 additions & 2 deletions data/mods/gen2/moves.ts
Expand Up @@ -370,7 +370,7 @@ export const Moves: {[k: string]: ModdedMoveData} = {
onSideStart(side) {
this.add('-sidestart', side, 'move: Light Screen');
},
onSideResidualOrder: 21,
onSideResidualOrder: 9,
onSideEnd(side) {
this.add('-sideend', side, 'move: Light Screen');
},
Expand Down Expand Up @@ -516,6 +516,21 @@ export const Moves: {[k: string]: ModdedMoveData} = {
accuracy: true,
ignoreAccuracy: false,
},
perishsong: {
inherit: true,
condition: {
duration: 4,
onEnd(target) {
this.add('-start', target, 'perish0');
target.faint();
},
onResidualOrder: 4,
onResidual(pokemon) {
const duration = pokemon.volatiles['perishsong'].duration;
this.add('-start', pokemon, 'perish' + duration);
},
},
},
petaldance: {
inherit: true,
onMoveFail(target, source, move) {
Expand Down Expand Up @@ -565,7 +580,7 @@ export const Moves: {[k: string]: ModdedMoveData} = {
onSideStart(side) {
this.add('-sidestart', side, 'Reflect');
},
onSideResidualOrder: 21,
onSideResidualOrder: 9,
onSideEnd(side) {
this.add('-sideend', side, 'Reflect');
},
Expand Down Expand Up @@ -606,6 +621,46 @@ export const Moves: {[k: string]: ModdedMoveData} = {
},
priority: -1,
},
safeguard: {
inherit: true,
condition: {
duration: 5,
durationCallback(target, source, effect) {
if (source?.hasAbility('persistent')) {
this.add('-activate', source, 'ability: Persistent', effect);
return 7;
}
return 5;
},
onSetStatus(status, target, source, effect) {
if (!effect || !source) return;
if (effect.id === 'yawn') return;
if (effect.effectType === 'Move' && effect.infiltrates && !target.isAlly(source)) return;
if (target !== source) {
this.debug('interrupting setStatus');
if (effect.id === 'synchronize' || (effect.effectType === 'Move' && !effect.secondaries)) {
this.add('-activate', target, 'move: Safeguard');
}
return null;
}
},
onTryAddVolatile(status, target, source, effect) {
if (!effect || !source) return;
if (effect.effectType === 'Move' && effect.infiltrates && !target.isAlly(source)) return;
if ((status.id === 'confusion' || status.id === 'yawn') && target !== source) {
if (effect.effectType === 'Move' && !effect.secondaries) this.add('-activate', target, 'move: Safeguard');
return null;
}
},
onSideStart(side) {
this.add('-sidestart', side, 'Safeguard');
},
onSideResidualOrder: 8,
onSideEnd(side) {
this.add('-sideend', side, 'Safeguard');
},
},
},
selfdestruct: {
inherit: true,
noSketch: true,
Expand Down
11 changes: 11 additions & 0 deletions data/mods/gen3/abilities.ts
Expand Up @@ -125,6 +125,17 @@ export const Abilities: {[k: string]: ModdedAbilityData} = {
this.addSplit(pokemon.side.id, ['-ability', pokemon, 'Pressure', '[silent]']);
},
},
raindish: {
inherit: true,
onWeather() {},
onResidualOrder: 10,
onResidualSubOrder: 3,
onResidual(pokemon) {
if (['raindance', 'primordialsea'].includes(pokemon.effectiveWeather())) {
this.heal(pokemon.baseMaxhp / 16);
}
},
},
roughskin: {
inherit: true,
onDamagingHit(damage, target, source, move) {
Expand Down

0 comments on commit d946308

Please sign in to comment.