File size: 14,269 Bytes
5c2ed06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
'use strict';

const assert = require('./../../assert');
const common = require('./../../common');

let battle;

describe('Burn', () => {
	afterEach(() => {
		battle.destroy();
	});

	it('should inflict 1/16 of max HP at the end of the turn, rounded down', () => {
		battle = common.createBattle([
			[{ species: 'Machamp', ability: 'noguard', moves: ['bulkup'] }],
			[{ species: 'Sableye', ability: 'prankster', moves: ['willowisp'] }],
		]);
		const target = battle.p1.active[0];
		assert.hurtsBy(target, Math.floor(target.maxhp / 16), () => battle.makeChoices('move bulkup', 'move willowisp'));
	});

	it(`should halve damage from most Physical attacks`, () => {
		battle = common.createBattle([[
			{ species: 'Machamp', ability: 'noguard', moves: ['boneclub'] },
		], [
			{ species: 'Sableye', ability: 'prankster', moves: ['willowisp'] },
		]]);
		battle.makeChoices();
		const sableye = battle.p2.active[0];
		const damage = sableye.maxhp - sableye.hp;
		assert.bounded(damage, [37, 44]);
	});

	it('should reduce atk to 50% of its original value in Stadium', () => {
		// I know WoW doesn't exist in Stadium, but the engine supports future gen moves
		// and this is easier than digging for a seed that makes Flamethrower burn
		battle = common.createBattle({ formatid: 'gen1stadiumou@@@!teampreview' }, [
			[{ species: 'Vaporeon', moves: ['growl'] }],
			[{ species: 'Jolteon', moves: ['willowisp'] }],
		]);
		const attack = battle.p1.active[0].getStat('atk');
		battle.makeChoices('move growl', 'move willowisp');
		assert.equal(battle.p1.active[0].getStat('atk'), Math.floor(attack * 0.5));
	});

	it('should not halve damage from moves with set damage', () => {
		battle = common.createBattle([
			[{ species: 'Machamp', ability: 'noguard', moves: ['seismictoss'] }],
			[{ species: 'Talonflame', ability: 'galewings', moves: ['willowisp'] }],
		]);
		assert.hurtsBy(battle.p2.active[0], 100, () => battle.makeChoices('move seismictoss', 'move willowisp'));
	});
});

describe('Paralysis', () => {
	afterEach(() => {
		battle.destroy();
	});

	it(`should reduce speed to 50% of its original value`, () => {
		battle = common.createBattle([[
			{ species: 'Vaporeon', moves: ['sleeptalk'] },
		], [
			{ species: 'Jolteon', moves: ['glare'] },
		]]);

		const vaporeon = battle.p1.active[0];
		const speed = vaporeon.getStat('spe');
		battle.makeChoices('move sleeptalk', 'move glare');
		assert.equal(vaporeon.getStat('spe'), battle.modify(speed, 0.5));
	});

	it(`should apply its Speed reduction after all other Speed modifiers`, () => {
		battle = common.createBattle([[
			{ species: 'goldeen', item: 'choicescarf', evs: { spe: 252 }, moves: ['sleeptalk'] }, // 225 Speed
		], [
			{ species: 'wynaut', moves: ['glare'] },
		]]);

		battle.makeChoices();
		assert.equal(battle.p1.active[0].getStat('spe'), 168); // would be 169 if both Choice Scarf and paralysis were chained

		battle = common.createBattle([[
			{ species: 'hawlucha', item: 'whiteherb', ability: 'unburden', evs: { spe: 4 }, moves: ['closecombat'] }, // 273 Speed
		], [
			{ species: 'wynaut', moves: ['glare'] },
		]]);

		battle.makeChoices();
		assert.equal(battle.p1.active[0].getStat('spe'), 273); // would be 272 if paralysis was applied first
	});

	it('should reduce speed to 25% of its original value in Gen 6', () => {
		battle = common.gen(6).createBattle();
		battle.setPlayer('p1', { team: [{ species: 'Vaporeon', ability: 'waterabsorb', moves: ['aquaring'] }] });
		battle.setPlayer('p2', { team: [{ species: 'Jolteon', ability: 'voltabsorb', moves: ['thunderwave'] }] });
		const speed = battle.p1.active[0].getStat('spe');
		battle.makeChoices('move aquaring', 'move thunderwave');
		assert.equal(battle.p1.active[0].getStat('spe'), battle.modify(speed, 0.25));
	});

	it('should reduce speed to 25% of its original value in Gen 2', () => {
		battle = common.gen(2).createBattle();
		battle.setPlayer('p1', { team: [{ species: 'Vaporeon', ability: 'waterabsorb', moves: ['aquaring'] }] });
		battle.setPlayer('p2', { team: [{ species: 'Jolteon', ability: 'voltabsorb', moves: ['thunderwave'] }] });
		const speed = battle.p1.active[0].getStat('spe');
		battle.makeChoices('move aquaring', 'move thunderwave');
		assert.equal(battle.p1.active[0].getStat('spe'), battle.modify(speed, 0.25));
	});

	it('should reduce speed to 25% of its original value in Stadium', () => {
		battle = common.createBattle({ formatid: 'gen1stadiumou@@@!teampreview' }, [
			[{ species: 'Vaporeon', moves: ['growl'] }],
			[{ species: 'Jolteon', moves: ['thunderwave'] }],
		]);
		const speed = battle.p1.active[0].getStat('spe');
		battle.makeChoices('move growl', 'move thunderwave');
		assert.equal(battle.p1.active[0].getStat('spe'), Math.floor(speed * 0.25));
	});

	it('should reapply its speed drop when an opponent uses a stat-altering move in Gen 1', () => {
		battle = common.gen(1).createBattle([
			[{ species: 'Electrode', moves: ['rest'] }],
			[{ species: 'Slowpoke', moves: ['amnesia', 'thunderwave'] }],
		]);
		battle.makeChoices('move rest', 'move thunderwave');
		const speed = battle.p1.active[0].getStat('spe');
		battle.makeChoices('move rest', 'move amnesia');
		assert.equal(battle.p1.active[0].getStat('spe'), battle.modify(speed, 0.25));
	});

	it('should not reapply its speed drop when an opponent uses a failed stat-altering move in Gen 1', () => {
		battle = common.gen(1).createBattle([
			[{ species: 'Electrode', moves: ['rest'] }],
			[{ species: 'Slowpoke', moves: ['amnesia', 'thunderwave'] }],
		]);
		battle.makeChoices('move rest', 'move amnesia');
		battle.makeChoices('move rest', 'move amnesia');
		battle.makeChoices('move rest', 'move amnesia');
		battle.makeChoices('move rest', 'move thunderwave');
		const speed = battle.p1.active[0].getStat('spe');
		battle.makeChoices('move rest', 'move amnesia');
		assert.equal(battle.p1.active[0].getStat('spe'), speed);
	});
});

describe('Toxic Poison', () => {
	afterEach(() => {
		battle.destroy();
	});

	it('should inflict 1/16 of max HP rounded down, times the number of active turns with the status, at the end of the turn', () => {
		battle = common.createBattle([
			[{ species: 'Chansey', ability: 'naturalcure', moves: ['softboiled'] }],
			[{ species: 'Gengar', ability: 'levitate', moves: ['toxic'] }],
		]);
		const target = battle.p1.active[0];
		for (let i = 1; i <= 8; i++) {
			battle.makeChoices('move softboiled', 'move toxic');
			assert.equal(target.maxhp - target.hp, Math.floor(target.maxhp / 16) * i);
		}
	});

	it('should reset the damage counter when the Pokemon switches out', () => {
		battle = common.createBattle([
			[{ species: 'Chansey', ability: 'serenegrace', moves: ['counter'] }, { species: 'Snorlax', ability: 'immunity', moves: ['curse'] }],
			[{ species: 'Crobat', ability: 'infiltrator', moves: ['toxic', 'whirlwind'] }],
		]);
		for (let i = 0; i < 4; i++) {
			battle.makeChoices('move counter', 'move toxic');
		}
		const pokemon = battle.p1.active[0];
		pokemon.hp = pokemon.maxhp;
		battle.makeChoices('switch 2', 'move whirlwind');
		assert.equal(pokemon.maxhp - pokemon.hp, Math.floor(pokemon.maxhp / 16));
	});
});

describe('Freeze', () => {
	afterEach(() => {
		battle.destroy();
	});

	it('should cause an afflicted Shaymin-Sky to revert to its base forme', () => {
		battle = common.createBattle([
			[{ species: 'Chansey', ability: 'serenegrace', moves: ['icebeam'] }],
			[{ species: 'Shaymin-Sky', ability: 'sturdy', moves: ['sleeptalk'] }],
		]);
		// I didn't feel like manually testing seed after seed. Sue me.
		battle.onEvent('ModifyMove', battle.format, function (move) {
			if (move.secondaries) {
				this.debug('Freeze test: Guaranteeing secondary');
				for (const secondary of move.secondaries) {
					secondary.chance = 100;
				}
			}
		});
		battle.makeChoices('move icebeam', 'move sleeptalk');
		assert.equal(battle.p2.active[0].status, 'frz');
		assert.equal(battle.p2.active[0].species.name, 'Shaymin');
	});

	it('should not cause an afflicted Pokemon transformed into Shaymin-Sky to change to Shaymin', () => {
		battle = common.createBattle([
			[{ species: 'Ditto', ability: 'imposter', moves: ['transform'] }],
			[{ species: 'Shaymin-Sky', ability: 'sturdy', moves: ['icebeam', 'sleeptalk'] }],
		]);
		battle.onEvent('ModifyMove', battle.format, function (move) {
			if (move.secondaries) {
				this.debug('Freeze test: Guaranteeing secondary');
				for (const secondary of move.secondaries) {
					secondary.chance = 100;
				}
			}
		});
		battle.makeChoices('move sleeptalk', 'move icebeam');
		assert.equal(battle.p1.active[0].status, 'frz');
		assert.equal(battle.p1.active[0].species.name, 'Shaymin-Sky');
	});

	it(`should not be possible to burn a frozen target when using a move that thaws that target`, () => {
		battle = common.createBattle([[
			{ species: 'wynaut', ability: 'serenegrace', item: 'widelens', moves: ['sleeptalk', 'sacredfire'] },
		], [
			{ species: 'shuckle', moves: ['meteorassault'] },
		]]);
		battle.makeChoices(); // Use Meteor Assault to force recharge next turn and skip potential thaw
		const frozenMon = battle.p2.active[0];
		frozenMon.setStatus('frz');
		battle.makeChoices('move sacredfire', 'auto');
		assert.equal(frozenMon.status, '');
	});
});

describe('Burn [Gen 6]', () => {
	afterEach(() => {
		battle.destroy();
	});

	it('should inflict 1/8 of max HP at the end of the turn, rounded down', () => {
		battle = common.gen(6).createBattle([
			[{ species: 'Machamp', ability: 'noguard', moves: ['bulkup'] }],
			[{ species: 'Sableye', ability: 'prankster', moves: ['willowisp'] }],
		]);
		const target = battle.p1.active[0];
		assert.hurtsBy(target, Math.floor(target.maxhp / 8), () => battle.makeChoices('move bulkup', 'move willowisp'));
	});
});

describe('Toxic Poison [Gen 1]', () => {
	afterEach(() => {
		battle.destroy();
	});

	it(`should affect Leech Seed damage counter`, () => {
		battle = common.gen(1).createBattle([[
			{ species: 'Venusaur', moves: ['toxic', 'leechseed'] },
		], [
			{ species: 'Chansey', moves: ['splash'] },
		]]);

		// Modding accuracy so the status moves always hit
		battle.onEvent('Accuracy', battle.format, true);

		battle.makeChoices('move toxic', 'move splash');
		const chansey = battle.p2.active[0];
		assert.equal(chansey.maxhp - chansey.hp, Math.floor(chansey.maxhp / 16));
		battle.makeChoices('move leechseed', 'move splash');
		// (1/16) + (2/16) + (3/16) = (6/16)
		assert.equal(chansey.maxhp - chansey.hp, Math.floor(chansey.maxhp / 16) * 6);
	});
});

describe('Toxic Poison [Gen 2]', () => {
	afterEach(() => {
		battle.destroy();
	});

	it(`should not affect Leech Seed damage counter`, () => {
		battle = common.gen(2).createBattle({ forceRandomChance: true }, [[
			{ species: 'Venusaur', moves: ['toxic', 'leechseed'] },
		], [
			{ species: 'Chansey', moves: ['splash'] },
		]]);
		battle.makeChoices('move toxic', 'move splash');
		const pokemon = battle.p2.active[0];
		assert.equal(pokemon.maxhp - pokemon.hp, Math.floor(pokemon.maxhp / 16));
		battle.makeChoices('move leechseed', 'move splash');
		// (1/16) + (2/16) + (1/8) = (5/16)
		assert.equal(pokemon.maxhp - pokemon.hp, Math.floor(pokemon.maxhp / 16) * 5);
	});

	it(`should pass the damage counter to Pokemon with Baton Pass`, () => {
		battle = common.gen(2).createBattle([[
			{ species: 'Smeargle', moves: ['toxic', 'willowisp', 'splash'] },
		], [
			{ species: 'Chansey', moves: ['splash'] },
			{ species: 'Celebi', moves: ['batonpass', 'splash'] },
		]]);

		// Modding accuracy so the status moves always hit
		battle.onEvent('Accuracy', battle.format, true);

		battle.makeChoices('move willowisp', 'move splash');
		const chansey = battle.p2.active[0];
		battle.makeChoices('move toxic', 'switch 2');
		battle.makeChoices('move splash', 'move splash');
		battle.makeChoices('move splash', 'move splash');
		battle.makeChoices('move splash', 'move batonpass');
		battle.makeChoices('', 'switch 2');
		let hp = chansey.hp;
		battle.makeChoices('move splash', 'move splash');
		assert.equal(hp - chansey.hp, Math.floor(chansey.maxhp / 16) * 4, `Chansey should have taken a lot more damage from burn`);

		// Only hint about this once per battle, not every turn.
		assert.equal(battle.log.filter(m => m.startsWith('|-hint')).length, 1);

		// Damage counter should be removed on regular switch out
		battle.makeChoices('move splash', 'switch 2');
		hp = chansey.hp;
		battle.makeChoices('move splash', 'switch 2');
		assert.equal(hp - chansey.hp, Math.floor(chansey.maxhp / 8), `Chansey should have taken normal damage from burn`);
	});

	it('should revert to regular poison on switch in, even for Poison types', () => {
		battle = common.gen(2).createBattle([
			[{ species: 'Smeargle', moves: ['toxic', 'splash'] }],
			[
				{ species: 'Qwilfish', moves: ['transform', 'splash'] },
				{ species: 'Gengar', moves: ['nightshade'] },
			],
		]);
		battle.makeChoices('move toxic', 'move transform');
		battle.makeChoices('move splash', 'switch 2');
		battle.makeChoices('move splash', 'switch 2');
		// We could check 'psn' at this point, but the following line caused crashes
		// before #5463 was fixed so its useful to execute for regression testing purposes.
		battle.makeChoices('move splash', 'move splash');
		assert.equal(battle.p2.active[0].status, 'psn');
	});

	it('should not have its damage counter affected by Heal Bell', () => {
		battle = common.gen(2).createBattle([[
			{ species: 'Smeargle', moves: ['toxic', 'willowisp', 'splash'] },
		], [
			{ species: 'Chansey', moves: ['splash', 'healbell'] },
		]]);

		// Modding accuracy so the status moves always hit
		battle.onEvent('Accuracy', battle.format, true);

		battle.makeChoices('move toxic', 'move splash');
		const chansey = battle.p2.active[0];
		battle.makeChoices('move splash', 'move healbell');
		battle.makeChoices('move willowisp', 'move splash');
		let hp = chansey.hp;
		battle.makeChoices('move splash', 'move splash');
		assert.equal(hp - chansey.hp, Math.floor(chansey.maxhp / 16) * 3);
		hp = chansey.hp;

		battle.makeChoices('move splash', 'move healbell');
		battle.makeChoices('move toxic', 'move splash');
		// Toxic counter should be reset by a successful Toxic
		assert.equal(hp - chansey.hp, Math.floor(chansey.maxhp / 16));
	});
});