Skip to content

Commit d946308

Browse files
DaWoblefetMarty-D
andauthoredMay 17, 2021
Fix the order of many end-turn resolution effects (#8307)
Co-authored-by: Marty-D <Marty-D@users.noreply.github.com>
1 parent 50054ef commit d946308

19 files changed

+724
-122
lines changed
 

‎data/abilities.ts

+20-17
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
237237
num: 188,
238238
},
239239
baddreams: {
240-
onResidualOrder: 26,
241-
onResidualSubOrder: 1,
240+
onResidualOrder: 28,
241+
onResidualSubOrder: 2,
242242
onResidual(pokemon) {
243243
if (!pokemon.hp) return;
244244
for (const target of pokemon.foes()) {
@@ -1387,8 +1387,8 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
13871387
},
13881388
harvest: {
13891389
name: "Harvest",
1390-
onResidualOrder: 26,
1391-
onResidualSubOrder: 1,
1390+
onResidualOrder: 28,
1391+
onResidualSubOrder: 2,
13921392
onResidual(pokemon) {
13931393
if (this.field.isWeather(['sunnyday', 'desolateland']) || this.randomChance(1, 2)) {
13941394
if (pokemon.hp && !pokemon.item && this.dex.items.get(pokemon.lastItem).isBerry) {
@@ -1404,7 +1404,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
14041404
healer: {
14051405
name: "Healer",
14061406
onResidualOrder: 5,
1407-
onResidualSubOrder: 4,
1407+
onResidualSubOrder: 3,
14081408
onResidual(pokemon) {
14091409
for (const allyActive of pokemon.adjacentAllies()) {
14101410
if (allyActive.status && this.randomChance(3, 10)) {
@@ -1458,6 +1458,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
14581458
num: 37,
14591459
},
14601460
hungerswitch: {
1461+
onResidualOrder: 29,
14611462
onResidual(pokemon) {
14621463
if (pokemon.species.baseSpecies !== 'Morpeko' || pokemon.transformed) return;
14631464
const targetForme = pokemon.species.name === 'Morpeko' ? 'Morpeko-Hangry' : 'Morpeko';
@@ -1485,7 +1486,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
14851486
},
14861487
hydration: {
14871488
onResidualOrder: 5,
1488-
onResidualSubOrder: 4,
1489+
onResidualSubOrder: 3,
14891490
onResidual(pokemon) {
14901491
if (pokemon.status && ['raindance', 'primordialsea'].includes(pokemon.effectiveWeather())) {
14911492
this.debug('hydration');
@@ -2160,8 +2161,8 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
21602161
num: 104,
21612162
},
21622163
moody: {
2163-
onResidualOrder: 26,
2164-
onResidualSubOrder: 1,
2164+
onResidualOrder: 28,
2165+
onResidualSubOrder: 2,
21652166
onResidual(pokemon) {
21662167
let stats: BoostID[] = [];
21672168
const boost: SparseBoostsTable = {};
@@ -2618,8 +2619,8 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
26182619
num: 124,
26192620
},
26202621
pickup: {
2621-
onResidualOrder: 26,
2622-
onResidualSubOrder: 1,
2622+
onResidualOrder: 28,
2623+
onResidualSubOrder: 2,
26232624
onResidual(pokemon) {
26242625
if (pokemon.item) return;
26252626
const pickupTargets = this.getAllActive().filter(target => (
@@ -2710,7 +2711,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
27102711
num: 143,
27112712
},
27122713
powerconstruct: {
2713-
onResidualOrder: 27,
2714+
onResidualOrder: 29,
27142715
onResidual(pokemon) {
27152716
if (pokemon.baseSpecies.baseSpecies !== 'Zygarde' || pokemon.transformed || !pokemon.hp) return;
27162717
if (pokemon.species.id === 'zygardecomplete' || pokemon.hp > pokemon.maxhp / 2) return;
@@ -3181,7 +3182,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
31813182
}
31823183
}
31833184
},
3184-
onResidualOrder: 27,
3185+
onResidualOrder: 29,
31853186
onResidual(pokemon) {
31863187
if (
31873188
pokemon.baseSpecies.baseSpecies !== 'Wishiwashi' || pokemon.level < 20 ||
@@ -3285,7 +3286,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
32853286
},
32863287
shedskin: {
32873288
onResidualOrder: 5,
3288-
onResidualSubOrder: 4,
3289+
onResidualSubOrder: 3,
32893290
onResidual(pokemon) {
32903291
if (pokemon.hp && pokemon.status && this.randomChance(33, 100)) {
32913292
this.debug('shed skin');
@@ -3346,7 +3347,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
33463347
}
33473348
}
33483349
},
3349-
onResidualOrder: 27,
3350+
onResidualOrder: 29,
33503351
onResidual(pokemon) {
33513352
if (pokemon.baseSpecies.baseSpecies !== 'Minior' || pokemon.transformed || !pokemon.hp) return;
33523353
if (pokemon.hp > pokemon.maxhp / 2) {
@@ -3413,6 +3414,8 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
34133414
},
34143415
condition: {
34153416
duration: 5,
3417+
onResidualOrder: 28,
3418+
onResidualSubOrder: 2,
34163419
onStart(target) {
34173420
this.add('-start', target, 'ability: Slow Start');
34183421
},
@@ -3533,8 +3536,8 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
35333536
num: 43,
35343537
},
35353538
speedboost: {
3536-
onResidualOrder: 26,
3537-
onResidualSubOrder: 1,
3539+
onResidualOrder: 28,
3540+
onResidualSubOrder: 2,
35383541
onResidual(pokemon) {
35393542
if (pokemon.activeTurns) {
35403543
this.boost({spe: 1});
@@ -4384,7 +4387,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
43844387
num: 147,
43854388
},
43864389
zenmode: {
4387-
onResidualOrder: 27,
4390+
onResidualOrder: 29,
43884391
onResidual(pokemon) {
43894392
if (pokemon.baseSpecies.baseSpecies !== 'Darmanitan' || pokemon.transformed) {
43904393
return;

‎data/conditions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const Conditions: {[k: string]: ConditionData} = {
1212
}
1313
},
1414
// Damage reduction is handled directly in the sim/battle.js damage function
15-
onResidualOrder: 9,
15+
onResidualOrder: 10,
1616
onResidual(pokemon) {
1717
this.damage(pokemon.baseMaxhp / 16);
1818
},
@@ -214,7 +214,7 @@ export const Conditions: {[k: string]: ConditionData} = {
214214
this.add('-activate', pokemon, 'move: ' + this.effectState.sourceEffect, '[of] ' + source);
215215
this.effectState.boundDivisor = source.hasItem('bindingband') ? 6 : 8;
216216
},
217-
onResidualOrder: 11,
217+
onResidualOrder: 13,
218218
onResidual(pokemon) {
219219
const source = this.effectState.source;
220220
// G-Max Centiferno and G-Max Sandblast continue even after the user leaves the field

‎data/items.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ export const Items: {[itemid: string]: ItemData} = {
451451
basePower: 30,
452452
},
453453
onResidualOrder: 5,
454-
onResidualSubOrder: 5,
454+
onResidualSubOrder: 4,
455455
onResidual(pokemon) {
456456
if (pokemon.hasType('Poison')) {
457457
this.heal(pokemon.baseMaxhp / 16);
@@ -1772,8 +1772,8 @@ export const Items: {[itemid: string]: ItemData} = {
17721772
basePower: 30,
17731773
status: 'brn',
17741774
},
1775-
onResidualOrder: 26,
1776-
onResidualSubOrder: 2,
1775+
onResidualOrder: 28,
1776+
onResidualSubOrder: 3,
17771777
onResidual(pokemon) {
17781778
pokemon.trySetStatus('brn', pokemon);
17791779
},
@@ -2836,7 +2836,7 @@ export const Items: {[itemid: string]: ItemData} = {
28362836
basePower: 10,
28372837
},
28382838
onResidualOrder: 5,
2839-
onResidualSubOrder: 5,
2839+
onResidualSubOrder: 4,
28402840
onResidual(pokemon) {
28412841
this.heal(pokemon.baseMaxhp / 16);
28422842
},
@@ -5300,8 +5300,8 @@ export const Items: {[itemid: string]: ItemData} = {
53005300
fling: {
53015301
basePower: 80,
53025302
},
5303-
onResidualOrder: 26,
5304-
onResidualSubOrder: 2,
5303+
onResidualOrder: 28,
5304+
onResidualSubOrder: 3,
53055305
onResidual(pokemon) {
53065306
this.damage(pokemon.baseMaxhp / 8);
53075307
},
@@ -5499,8 +5499,8 @@ export const Items: {[itemid: string]: ItemData} = {
54995499
basePower: 30,
55005500
status: 'tox',
55015501
},
5502-
onResidualOrder: 26,
5503-
onResidualSubOrder: 2,
5502+
onResidualOrder: 28,
5503+
onResidualSubOrder: 3,
55045504
onResidual(pokemon) {
55055505
pokemon.trySetStatus('tox', pokemon);
55065506
},

‎data/mods/gen2/conditions.ts

+16
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export const Conditions: {[k: string]: ModdedConditionData} = {
6868
onAfterMoveSecondarySelf(pokemon, target, move) {
6969
if (move.flags['defrost']) pokemon.cureStatus();
7070
},
71+
onResidualOrder: 7,
7172
onResidual(pokemon) {
7273
if (this.randomChance(25, 256)) pokemon.cureStatus();
7374
},
@@ -154,6 +155,8 @@ export const Conditions: {[k: string]: ModdedConditionData} = {
154155
durationCallback(target, source) {
155156
return this.random(3, 6);
156157
},
158+
onResidualOrder: 3,
159+
onResidualSubOrder: 1,
157160
},
158161
lockedmove: {
159162
name: 'lockedmove',
@@ -189,8 +192,21 @@ export const Conditions: {[k: string]: ModdedConditionData} = {
189192
}
190193
},
191194
},
195+
futuremove: {
196+
inherit: true,
197+
onResidualOrder: 1,
198+
},
199+
raindance: {
200+
inherit: true,
201+
onFieldResidualOrder: 2,
202+
},
203+
sunnyday: {
204+
inherit: true,
205+
onFieldResidualOrder: 2,
206+
},
192207
sandstorm: {
193208
inherit: true,
209+
onFieldResidualOrder: 2,
194210
onWeather(target) {
195211
this.damage(target.baseMaxhp / 8);
196212
},

‎data/mods/gen2/items.ts

+5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ export const Items: {[k: string]: ModdedItemData} = {
8686
}
8787
},
8888
},
89+
leftovers: {
90+
inherit: true,
91+
onResidualOrder: 5,
92+
onResidualSubOrder: 1,
93+
},
8994
lightball: {
9095
inherit: true,
9196
// In Gen 2 this happens in stat calculation directly.

‎data/mods/gen2/moves.ts

+57-2
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ export const Moves: {[k: string]: ModdedMoveData} = {
370370
onSideStart(side) {
371371
this.add('-sidestart', side, 'move: Light Screen');
372372
},
373-
onSideResidualOrder: 21,
373+
onSideResidualOrder: 9,
374374
onSideEnd(side) {
375375
this.add('-sideend', side, 'move: Light Screen');
376376
},
@@ -516,6 +516,21 @@ export const Moves: {[k: string]: ModdedMoveData} = {
516516
accuracy: true,
517517
ignoreAccuracy: false,
518518
},
519+
perishsong: {
520+
inherit: true,
521+
condition: {
522+
duration: 4,
523+
onEnd(target) {
524+
this.add('-start', target, 'perish0');
525+
target.faint();
526+
},
527+
onResidualOrder: 4,
528+
onResidual(pokemon) {
529+
const duration = pokemon.volatiles['perishsong'].duration;
530+
this.add('-start', pokemon, 'perish' + duration);
531+
},
532+
},
533+
},
519534
petaldance: {
520535
inherit: true,
521536
onMoveFail(target, source, move) {
@@ -565,7 +580,7 @@ export const Moves: {[k: string]: ModdedMoveData} = {
565580
onSideStart(side) {
566581
this.add('-sidestart', side, 'Reflect');
567582
},
568-
onSideResidualOrder: 21,
583+
onSideResidualOrder: 9,
569584
onSideEnd(side) {
570585
this.add('-sideend', side, 'Reflect');
571586
},
@@ -606,6 +621,46 @@ export const Moves: {[k: string]: ModdedMoveData} = {
606621
},
607622
priority: -1,
608623
},
624+
safeguard: {
625+
inherit: true,
626+
condition: {
627+
duration: 5,
628+
durationCallback(target, source, effect) {
629+
if (source?.hasAbility('persistent')) {
630+
this.add('-activate', source, 'ability: Persistent', effect);
631+
return 7;
632+
}
633+
return 5;
634+
},
635+
onSetStatus(status, target, source, effect) {
636+
if (!effect || !source) return;
637+
if (effect.id === 'yawn') return;
638+
if (effect.effectType === 'Move' && effect.infiltrates && !target.isAlly(source)) return;
639+
if (target !== source) {
640+
this.debug('interrupting setStatus');
641+
if (effect.id === 'synchronize' || (effect.effectType === 'Move' && !effect.secondaries)) {
642+
this.add('-activate', target, 'move: Safeguard');
643+
}
644+
return null;
645+
}
646+
},
647+
onTryAddVolatile(status, target, source, effect) {
648+
if (!effect || !source) return;
649+
if (effect.effectType === 'Move' && effect.infiltrates && !target.isAlly(source)) return;
650+
if ((status.id === 'confusion' || status.id === 'yawn') && target !== source) {
651+
if (effect.effectType === 'Move' && !effect.secondaries) this.add('-activate', target, 'move: Safeguard');
652+
return null;
653+
}
654+
},
655+
onSideStart(side) {
656+
this.add('-sidestart', side, 'Safeguard');
657+
},
658+
onSideResidualOrder: 8,
659+
onSideEnd(side) {
660+
this.add('-sideend', side, 'Safeguard');
661+
},
662+
},
663+
},
609664
selfdestruct: {
610665
inherit: true,
611666
noSketch: true,

‎data/mods/gen3/abilities.ts

+11
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ export const Abilities: {[k: string]: ModdedAbilityData} = {
125125
this.addSplit(pokemon.side.id, ['-ability', pokemon, 'Pressure', '[silent]']);
126126
},
127127
},
128+
raindish: {
129+
inherit: true,
130+
onWeather() {},
131+
onResidualOrder: 10,
132+
onResidualSubOrder: 3,
133+
onResidual(pokemon) {
134+
if (['raindance', 'primordialsea'].includes(pokemon.effectiveWeather())) {
135+
this.heal(pokemon.baseMaxhp / 16);
136+
}
137+
},
138+
},
128139
roughskin: {
129140
inherit: true,
130141
onDamagingHit(damage, target, source, move) {

0 commit comments

Comments
 (0)
Please sign in to comment.