Skip to content

Commit 55cbc52

Browse files
committed
Fix bugs with secondary/ability order
Fixes #6346 The `AfterDamage` event has been replaced with `DamagingHit`, which which happens for damaging moves after secondaries. The `AfterHit` event has also been moved after `DamagingHit`, to make sure Knock Off still procs after Rocky Helmet. `AfterHit` is no longer a valid event on `secondary` and `self` blocks, because it's meaningless in those blocks, anyway. All `self.onAfterHit` and `secondary.onAfterHit` handlers have been moved to `onHit`, which should have the same timing in practice.
1 parent 1f8b14c commit 55cbc52

17 files changed

+176
-210
lines changed

data/abilities.js

+60-80
Large diffs are not rendered by default.

data/items.js

+17-20
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ let BattleItems = {
4141
fling: {
4242
basePower: 30,
4343
},
44-
onAfterDamage(damage, target, source, move) {
44+
onDamagingHit(damage, target, source, move) {
4545
if (move.type === 'Water') {
4646
target.useItem();
4747
}
@@ -162,18 +162,15 @@ let BattleItems = {
162162
}
163163
},
164164
// airborneness implemented in sim/pokemon.js:Pokemon#isGrounded
165-
onAfterDamage(damage, target, source, effect) {
166-
this.debug('effect: ' + effect.id);
167-
if (effect.effectType === 'Move' && effect.id !== 'confused') {
168-
this.add('-enditem', target, 'Air Balloon');
169-
target.item = '';
170-
target.itemData = {id: '', target};
171-
this.runEvent('AfterUseItem', target, null, null, this.dex.getItem('airballoon'));
172-
}
165+
onDamagingHit(damage, target, source, move) {
166+
this.add('-enditem', target, 'Air Balloon');
167+
target.item = '';
168+
target.itemData = {id: '', target};
169+
this.runEvent('AfterUseItem', target, null, null, this.dex.getItem('airballoon'));
173170
},
174171
onAfterSubDamage(damage, target, source, effect) {
175172
this.debug('effect: ' + effect.id);
176-
if (effect.effectType === 'Move' && effect.id !== 'confused') {
173+
if (effect.effectType === 'Move') {
177174
this.add('-enditem', target, 'Air Balloon');
178175
target.item = '';
179176
target.itemData = {id: '', target};
@@ -736,7 +733,7 @@ let BattleItems = {
736733
fling: {
737734
basePower: 30,
738735
},
739-
onAfterDamage(damage, target, source, move) {
736+
onDamagingHit(damage, target, source, move) {
740737
if (move.type === 'Electric') {
741738
target.useItem();
742739
}
@@ -2900,8 +2897,8 @@ let BattleItems = {
29002897
basePower: 100,
29012898
type: "Dragon",
29022899
},
2903-
onAfterDamage(damage, target, source, move) {
2904-
if (source && source.hp && source !== target && move && move.category === 'Physical') {
2900+
onDamagingHit(damage, target, source, move) {
2901+
if (move.category === 'Physical') {
29052902
if (target.eatItem()) {
29062903
this.damage(source.baseMaxhp / 8, source, target);
29072904
}
@@ -3404,7 +3401,7 @@ let BattleItems = {
34043401
fling: {
34053402
basePower: 30,
34063403
},
3407-
onAfterDamage(damage, target, source, move) {
3404+
onDamagingHit(damage, target, source, move) {
34083405
if (move.type === 'Water') {
34093406
target.useItem();
34103407
}
@@ -5151,9 +5148,9 @@ let BattleItems = {
51515148
fling: {
51525149
basePower: 60,
51535150
},
5154-
onAfterDamageOrder: 2,
5155-
onAfterDamage(damage, target, source, move) {
5156-
if (source && source !== target && move && move.flags['contact']) {
5151+
onDamagingHitOrder: 2,
5152+
onDamagingHit(damage, target, source, move) {
5153+
if (move.flags['contact']) {
51575154
this.damage(source.baseMaxhp / 6, source, target);
51585155
}
51595156
},
@@ -5242,8 +5239,8 @@ let BattleItems = {
52425239
basePower: 100,
52435240
type: "Dark",
52445241
},
5245-
onAfterDamage(damage, target, source, move) {
5246-
if (source && source.hp && source !== target && move && move.category === 'Special') {
5242+
onDamagingHit(damage, target, source, move) {
5243+
if (move.category === 'Special') {
52475244
if (target.eatItem()) {
52485245
this.damage(source.baseMaxhp / 8, source, target);
52495246
}
@@ -5711,7 +5708,7 @@ let BattleItems = {
57115708
fling: {
57125709
basePower: 30,
57135710
},
5714-
onAfterDamage(damage, target, source, move) {
5711+
onDamagingHit(damage, target, source, move) {
57155712
if (move.type === 'Ice') {
57165713
target.useItem();
57175714
}

data/mods/gen2/moves.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ let BattleMovedex = {
956956
onAfterHit() {},
957957
secondary: {
958958
chance: 100,
959-
onAfterHit(target, source) {
959+
onHit(target, source) {
960960
if (source.item || source.volatiles['gem']) {
961961
return;
962962
}

data/mods/gen3/abilities.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ let BattleAbilities = {
66
inherit: true,
77
desc: "There is a 1/3 chance a Pokemon making contact with this Pokemon will become infatuated if it is of the opposite gender.",
88
shortDesc: "1/3 chance of infatuating Pokemon of the opposite gender if they make contact.",
9-
onAfterDamage(damage, target, source, move) {
10-
if (move && move.flags['contact']) {
9+
onDamagingHit(damage, target, source, move) {
10+
if (move.flags['contact']) {
1111
if (this.randomChance(1, 3)) {
1212
source.addVolatile('attract', target);
1313
}
@@ -18,8 +18,8 @@ let BattleAbilities = {
1818
inherit: true,
1919
desc: "10% chance a Pokemon making contact with this Pokemon will be poisoned, paralyzed, or fall asleep.",
2020
shortDesc: "10% chance of poison/paralysis/sleep on others making contact with this Pokemon.",
21-
onAfterDamage(damage, target, source, move) {
22-
if (move && move.flags['contact'] && !source.status) {
21+
onDamagingHit(damage, target, source, move) {
22+
if (move.flags['contact'] && !source.status) {
2323
let r = this.random(300);
2424
if (r < 10) {
2525
source.setStatus('slp', target);
@@ -34,8 +34,8 @@ let BattleAbilities = {
3434
"flamebody": {
3535
inherit: true,
3636
shortDesc: "1/3 chance a Pokemon making contact with this Pokemon will be burned.",
37-
onAfterDamage(damage, target, source, move) {
38-
if (move && move.flags['contact']) {
37+
onDamagingHit(damage, target, source, move) {
38+
if (move.flags['contact']) {
3939
if (this.randomChance(1, 3)) {
4040
source.trySetStatus('brn', target);
4141
}
@@ -129,8 +129,8 @@ let BattleAbilities = {
129129
"poisonpoint": {
130130
inherit: true,
131131
shortDesc: "1/3 chance a Pokemon making contact with this Pokemon will be poisoned.",
132-
onAfterDamage(damage, target, source, move) {
133-
if (move && move.flags['contact']) {
132+
onDamagingHit(damage, target, source, move) {
133+
if (move.flags['contact']) {
134134
if (this.randomChance(1, 3)) {
135135
source.trySetStatus('psn', target);
136136
}
@@ -147,8 +147,8 @@ let BattleAbilities = {
147147
inherit: true,
148148
desc: "Pokemon making contact with this Pokemon lose 1/16 of their maximum HP, rounded down.",
149149
shortDesc: "Pokemon making contact with this Pokemon lose 1/16 of their max HP.",
150-
onAfterDamage(damage, target, source, move) {
151-
if (source && source !== target && move && move.flags['contact']) {
150+
onDamagingHit(damage, target, source, move) {
151+
if (move.flags['contact']) {
152152
this.damage(source.baseMaxhp / 16, source, target);
153153
}
154154
},
@@ -164,8 +164,8 @@ let BattleAbilities = {
164164
"static": {
165165
inherit: true,
166166
shortDesc: "1/3 chance a Pokemon making contact with this Pokemon will be paralyzed.",
167-
onAfterDamage(damage, target, source, effect) {
168-
if (effect && effect.flags['contact']) {
167+
onDamagingHit(damage, target, source, move) {
168+
if (move.flags['contact']) {
169169
if (this.randomChance(1, 3)) {
170170
source.trySetStatus('par', target);
171171
}

data/mods/gen4/abilities.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ let BattleAbilities = {
3333
"colorchange": {
3434
inherit: true,
3535
desc: "This Pokemon's type changes to match the type of the last move that hit it, unless that type is already one of its types. This effect applies after each hit from a multi-hit move.",
36-
onAfterDamage(damage, target, source, move) {
36+
onDamagingHit(damage, target, source, move) {
3737
if (!target.hp) return;
3838
let type = move.type;
39-
if (target.isActive && move.effectType === 'Move' && move.category !== 'Status' && type !== '???' && !target.hasType(type)) {
39+
if (target.isActive && move.category !== 'Status' && type !== '???' && !target.hasType(type)) {
4040
if (!target.setType(type)) return false;
4141
this.add('-start', target, 'typechange', type, '[from] ability: Color Change');
4242
}
@@ -45,8 +45,8 @@ let BattleAbilities = {
4545
},
4646
"effectspore": {
4747
inherit: true,
48-
onAfterDamage(damage, target, source, move) {
49-
if (move && move.flags['contact'] && !source.status) {
48+
onDamagingHit(damage, target, source, move) {
49+
if (move.flags['contact'] && !source.status) {
5050
let r = this.random(100);
5151
if (r < 10) {
5252
source.setStatus('slp', target);

data/mods/gen4/items.js

-22
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,6 @@ let BattleItems = {
125125
onEffectiveness() {},
126126
desc: "Holder's Speed is halved and it becomes grounded.",
127127
},
128-
"jabocaberry": {
129-
inherit: true,
130-
onAfterDamage() {},
131-
onAfterMoveSecondary(target, source, move) {
132-
if (source && source !== target && move && move.category === 'Physical') {
133-
if (target.eatItem()) {
134-
this.damage(source.baseMaxhp / 8, source, target, null, true);
135-
}
136-
}
137-
},
138-
},
139128
"kingsrock": {
140129
inherit: true,
141130
onModifyMove(move) {
@@ -258,17 +247,6 @@ let BattleItems = {
258247
}
259248
},
260249
},
261-
"rowapberry": {
262-
inherit: true,
263-
onAfterDamage() {},
264-
onAfterMoveSecondary(target, source, move) {
265-
if (source && source !== target && move && move.category === 'Special') {
266-
if (target.eatItem()) {
267-
this.damage(source.baseMaxhp / 8, source, target, null, true);
268-
}
269-
}
270-
},
271-
},
272250
"stick": {
273251
inherit: true,
274252
onModifyCritRatio(critRatio, user) {

data/mods/gen6/abilities.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ let BattleAbilities = {
1313
},
1414
"aftermath": {
1515
inherit: true,
16-
onAfterDamage(damage, target, source, move) {
17-
if (source && source !== target && move && move.flags['contact'] && !target.hp) {
16+
onDamagingHit(damage, target, source, move) {
17+
if (move.flags['contact'] && !target.hp) {
1818
this.damage(source.baseMaxhp / 4, source, target, null, true);
1919
}
2020
},
@@ -47,8 +47,8 @@ let BattleAbilities = {
4747
},
4848
"ironbarbs": {
4949
inherit: true,
50-
onAfterDamage(damage, target, source, move) {
51-
if (source && source !== target && move && move.flags['contact']) {
50+
onDamagingHit(damage, target, source, move) {
51+
if (move.flags['contact']) {
5252
this.damage(source.baseMaxhp / 8, source, target, null, true);
5353
}
5454
},
@@ -124,8 +124,8 @@ let BattleAbilities = {
124124
},
125125
"roughskin": {
126126
inherit: true,
127-
onAfterDamage(damage, target, source, move) {
128-
if (source && source !== target && move && move.flags['contact']) {
127+
onDamagingHit(damage, target, source, move) {
128+
if (move.flags['contact']) {
129129
this.damage(source.baseMaxhp / 8, source, target, null, true);
130130
}
131131
},
@@ -142,7 +142,7 @@ let BattleAbilities = {
142142
inherit: true,
143143
desc: "If a physical attack hits this Pokemon, its Defense is lowered by 1 stage and its Speed is raised by 1 stage.",
144144
shortDesc: "If a physical attack hits this Pokemon, Defense is lowered by 1, Speed is raised by 1.",
145-
onAfterDamage(damage, target, source, move) {
145+
onDamagingHit(damage, target, source, move) {
146146
if (move.category === 'Physical') {
147147
this.boost({def: -1, spe: 1}, target, target);
148148
}

data/mods/gen6/items.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ let BattleItems = {
7676
},
7777
jabocaberry: {
7878
inherit: true,
79-
onAfterDamage(damage, target, source, move) {
80-
if (source && source !== target && move && move.category === 'Physical') {
79+
onDamagingHit(damage, target, source, move) {
80+
if (move.category === 'Physical') {
8181
if (target.eatItem()) {
8282
this.damage(source.baseMaxhp / 8, source, target, null, true);
8383
}
@@ -145,16 +145,16 @@ let BattleItems = {
145145
},
146146
rockyhelmet: {
147147
inherit: true,
148-
onAfterDamage(damage, target, source, move) {
149-
if (source && source !== target && move && move.flags['contact']) {
148+
onDamagingHit(damage, target, source, move) {
149+
if (move.flags['contact']) {
150150
this.damage(source.baseMaxhp / 6, source, target, null, true);
151151
}
152152
},
153153
},
154154
rowapberry: {
155155
inherit: true,
156-
onAfterDamage(damage, target, source, move) {
157-
if (source && source !== target && move && move.category === 'Special') {
156+
onDamagingHit(damage, target, source, move) {
157+
if (move.category === 'Special') {
158158
if (target.eatItem()) {
159159
this.damage(source.baseMaxhp / 8, source, target, null, true);
160160
}

data/mods/gen7/abilities.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ let BattleAbilities = {
110110
"rattled": {
111111
desc: "This Pokemon's Speed is raised by 1 stage if hit by a Bug-, Dark-, or Ghost-type attack.",
112112
shortDesc: "This Pokemon's Speed is raised 1 stage if hit by a Bug-, Dark-, or Ghost-type attack.",
113-
onAfterDamage(damage, target, source, effect) {
114-
if (effect && (effect.type === 'Dark' || effect.type === 'Bug' || effect.type === 'Ghost')) {
113+
onDamagingHit(damage, target, source, move) {
114+
if (['Dark', 'Bug', 'Ghost'].includes(move.type)) {
115115
this.boost({spe: 1});
116116
}
117117
},

data/mods/gennext/abilities.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ let BattleAbilities = {
123123
onResidual(target, source, effect) {
124124
this.heal(target.baseMaxhp / 16);
125125
},
126-
onAfterDamage(damage, target, source, move) {
127-
if (move && move.flags['contact'] && this.field.isWeather('hail')) {
126+
onDamagingHit(damage, target, source, move) {
127+
if (move.flags['contact'] && this.field.isWeather('hail')) {
128128
if (this.randomChance(3, 10)) {
129129
source.trySetStatus('frz', target);
130130
}
@@ -141,17 +141,17 @@ let BattleAbilities = {
141141
},
142142
"static": {
143143
inherit: true,
144-
onAfterDamage(damage, target, source, move) {
145-
if (move && move.flags['contact']) {
144+
onDamagingHit(damage, target, source, move) {
145+
if (move.flags['contact']) {
146146
source.trySetStatus('par', target);
147147
}
148148
},
149149
shortDesc: "100% chance a Pokemon making contact with this Pokemon will be paralyzed.",
150150
},
151151
"cutecharm": {
152152
inherit: true,
153-
onAfterDamage(damage, target, source, move) {
154-
if (move && move.flags['contact']) {
153+
onDamagingHit(damage, target, source, move) {
154+
if (move.flags['contact']) {
155155
source.addVolatile('Attract', target);
156156
}
157157
},
@@ -160,8 +160,8 @@ let BattleAbilities = {
160160
},
161161
"poisonpoint": {
162162
inherit: true,
163-
onAfterDamage(damage, target, source, move) {
164-
if (move && move.flags['contact']) {
163+
onDamagingHit(damage, target, source, move) {
164+
if (move.flags['contact']) {
165165
source.trySetStatus('psn', target);
166166
}
167167
},
@@ -416,7 +416,7 @@ let BattleAbilities = {
416416
return damage;
417417
}
418418
},
419-
onAfterDamage() {},
419+
onDamagingHit() {},
420420
desc: "This ability reduces incoming move damage by 1/10 of the user's max HP and increases the user's Speed for the first hit after switch-in (and does not activate again until the next switch-in).",
421421
shortDesc: "Reduces incoming move damage by 1/10 of the user's max HP and increases the user's Spe for the 1st hit after switch-in (doesn't activate until next switch-in).",
422422
},
@@ -482,8 +482,8 @@ let BattleAbilities = {
482482
},
483483
"aftermath": {
484484
inherit: true,
485-
onAfterDamage(damage, target, source, move) {
486-
if (source && source !== target && move && !target.hp) {
485+
onDamagingHit(damage, target, source, move) {
486+
if (!target.hp) {
487487
this.damage(source.baseMaxhp / 3, source, target, null, true);
488488
}
489489
},

0 commit comments

Comments
 (0)