File size: 16,822 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
368
369
370
371
372
373
374
375
376
377
378
379
'use strict';

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

let battle;

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

	describe(`Targetted Pokémon fainted in-turn`, () => {
		it(`should redirect 'any' from a fainted foe to a targettable foe`, () => {
			battle = common.createBattle({ gameType: 'doubles' }, [[
				{ species: 'Wailord', item: 'laggingtail', ability: 'pressure', moves: ['watergun'] },
				{ species: 'Metapod', ability: 'shedskin', moves: ['harden'] },
			], [
				{ species: 'Chansey', ability: 'naturalcure', moves: ['curse'] },
				{ species: 'Latias', ability: 'levitate', moves: ['healingwish'] },
				{ species: 'Magikarp', ability: 'rattled', moves: ['splash'] },
			]]);
			const defender = battle.p2.active[0];
			assert.hurts(defender, () => battle.makeChoices('move watergun 2, auto', 'auto'));
		});

		it(`should not redirect 'any' from a fainted ally to another Pokémon by default`, () => {
			battle = common.createBattle({ gameType: 'doubles' }, [[
				{ species: 'Wailord', item: 'laggingtail', ability: 'pressure', moves: ['watergun'] },
				{ species: 'Latias', ability: 'levitate', moves: ['healingwish'] },
				{ species: 'Magikarp', ability: 'rattled', moves: ['splash'] },
			], [
				{ species: 'Chansey', ability: 'naturalcure', moves: ['curse'] },
				{ species: 'Metapod', ability: 'shedskin', moves: ['harden'] },
			]]);
			const activePokemonList = [battle.p1.active[0], ...battle.p2.active];
			const prevHps = activePokemonList.map(pokemon => pokemon.hp);
			battle.makeChoices('move watergun -2, auto', 'auto');
			const newHps = activePokemonList.map(pokemon => pokemon.hp);

			assert.deepEqual(prevHps, newHps);
			assert(battle.log.includes('|move|p1a: Wailord|Water Gun|p1: Latias|[notarget]'));
			assert(battle.log.includes('|-fail|p1a: Wailord'));
		});

		it(`should support RedirectTarget event for a fainted foe and type 'any' `, () => {
			battle = common.gen(5).createBattle({ gameType: 'triples' }, [[
				{ species: 'Wailord', item: 'laggingtail', ability: 'pressure', moves: ['waterpulse'] }, // Water Pulse over Water Gun due to targeting in triples
				{ species: 'Magikarp', ability: 'rattled', moves: ['splash'] },
				{ species: 'Magikarp', ability: 'rattled', moves: ['splash'] },
			], [
				{ species: 'Gastrodon', ability: 'stormdrain', moves: ['curse'] },
				{ species: 'Latias', ability: 'levitate', moves: ['healingwish'] },
				{ species: 'Magikarp', ability: 'rattled', moves: ['splash'] },
				{ species: 'Magikarp', ability: 'rattled', moves: ['splash'] },
			]]);
			let redirector = battle.p2.active[0];
			battle.makeChoices('move waterpulse 2, auto', 'auto');
			assert.statStage(redirector, 'spa', 1);

			// Do it again with swapped positions
			battle.destroy();
			battle = common.gen(5).createBattle({ gameType: 'triples' }, [[
				{ species: 'Wailord', item: 'laggingtail', ability: 'pressure', moves: ['watergun'] },
				{ species: 'Magikarp', ability: 'rattled', moves: ['splash'] },
				{ species: 'Magikarp', ability: 'rattled', moves: ['splash'] },
			], [
				{ species: 'Magikarp', ability: 'rattled', moves: ['splash'] },
				{ species: 'Latias', ability: 'levitate', moves: ['healingwish'] },
				{ species: 'Gastrodon', ability: 'stormdrain', moves: ['curse'] },
				{ species: 'Magikarp', ability: 'rattled', moves: ['splash'] },
			]]);
			redirector = battle.p2.active[2];
			battle.makeChoices('move watergun 2, auto', 'auto');
			assert.statStage(redirector, 'spa', 1);

			// Test Storm Drain on the user's side
			battle.destroy();
			battle = common.gen(5).createBattle({ gameType: 'triples' }, [[
				{ species: 'Shuckle', moves: ['watergun'] },
				{ species: 'Gastrodon', ability: 'stormdrain', moves: ['swordsdance'] },
				{ species: 'Magikarp', moves: ['swordsdance'] },
			], [
				{ species: 'Beartic', moves: ['swordsdance'] },
				{ species: 'Magikarp', moves: ['swordsdance'] },
				{ species: 'Victini', moves: ['finalgambit'] },
			]]);
			redirector = battle.p1.active[1];
			battle.makeChoices('move watergun 3, auto', 'move swordsdance, move swordsdance, move finalgambit -2');
			assert.statStage(redirector, 'spa', 1);
		});

		it(`should not redirect non-pulse/flying moves in Triples if the Pokemon is out of range`, () => {
			battle = common.gen(6).createBattle({ gameType: 'triples' }, [[
				{ species: 'Shuckle', moves: ['watergun'] },
				{ species: 'Magikarp', moves: ['swordsdance'] },
				{ species: 'Magikarp', moves: ['swordsdance'] },
			], [
				{ species: 'Beartic', moves: ['swordsdance'] },
				{ species: 'Magikarp', moves: ['swordsdance'] },
				{ species: 'Victini', moves: ['finalgambit'] },
			]]);
			battle.makeChoices('move watergun 3, auto', 'move swordsdance, move swordsdance, move finalgambit -2');
			assert.fullHP(battle.p2.active[0], `Beartic should not be damaged by a Water Gun because it is out of range`);
		});

		it(`should support RedirectTarget event for a fainted ally and type 'any'`, () => {
			battle = common.createBattle({ gameType: 'doubles' }, [[
				{ species: 'Wailord', item: 'laggingtail', ability: 'pressure', moves: ['watergun'] },
				{ species: 'Latias', ability: 'levitate', moves: ['healingwish'] },
				{ species: 'Magikarp', ability: 'rattled', moves: ['splash'] },
			], [
				{ species: 'Gastrodon', ability: 'stormdrain', moves: ['curse'] },
				{ species: 'Metapod', ability: 'shedskin', moves: ['harden'] },
			]]);
			const redirector = battle.p2.active[0];
			battle.makeChoices('move watergun -2, auto', 'auto');
			assert.statStage(redirector, 'spa', 1);
		});

		it(`should not redirect to another random target if the intended one is fainted in FFA`, () => {
			battle = common.createBattle({ gameType: 'freeforall' }, [[
				{ species: 'Calyrex', moves: ['sleeptalk'] },
			], [
				{ species: 'Victini', ability: 'Victory Star', moves: ['vcreate'] },
			], [
				{ species: 'Chansey', moves: ['sleeptalk'] },
			], [
				{ species: 'Tyrunt', moves: ['crunch'] },
			]]);
			battle.makeChoices('auto', 'move vcreate 1', 'auto', 'move crunch 1');
			assert.fainted(battle.sides[0].active[0]);
			assert.fullHP(battle.sides[1].active[0]);
			assert.fullHP(battle.sides[2].active[0]);
		});
	});

	describe(`Targetted slot is empty`, () => {
		it(`should redirect 'any' from a fainted foe to a targettable foe`, () => {
			battle = common.createBattle({ gameType: 'doubles' }, [[
				{ species: 'Wailord', ability: 'pressure', moves: ['watergun'] },
				{ species: 'Shedinja', item: 'flameorb', ability: 'wonderguard', moves: ['agility'] },
			], [
				{ species: 'Wailord', ability: 'pressure', moves: ['watergun'] },
				{ species: 'Shedinja', item: 'flameorb', ability: 'wonderguard', moves: ['agility'] },
			]]);
			const attackers = battle.sides.map(side => side.active[0]);

			battle.makeChoices('auto', 'auto'); // Shedinjas burned
			battle.makeChoices('auto', 'auto'); // Shedinjas faint

			const prevHps = attackers.map(pokemon => pokemon.hp);
			battle.makeChoices('move watergun 2, pass', 'move watergun 2, pass');
			const newHps = attackers.map(pokemon => pokemon.hp);

			assert(
				newHps[0] < prevHps[0] && newHps[1] < prevHps[1],
				`It should redirect the attacks from their original fainted targets to valid targets`
			);
		});

		it(`should not redirect 'any' from a fainted ally to another Pokémon by default`, () => {
			battle = common.createBattle({ gameType: 'doubles' }, [[
				{ species: 'Wailord', ability: 'pressure', moves: ['watergun'] },
				{ species: 'Shedinja', item: 'flameorb', ability: 'wonderguard', moves: ['agility'] },
			], [
				{ species: 'Wailord', ability: 'pressure', moves: ['watergun'] },
				{ species: 'Shedinja', item: 'flameorb', ability: 'wonderguard', moves: ['agility'] },
			]]);

			const attackers = battle.sides.map(side => side.active[0]);
			const faintTargets = battle.sides.map(side => side.active[1]);

			battle.makeChoices('auto', 'auto'); // Shedinjas burned
			battle.makeChoices('auto', 'auto'); // Shedinjas faint
			assert.fainted(faintTargets[0]);
			assert.fainted(faintTargets[1]);

			const prevHps = attackers.map(pokemon => pokemon.hp);
			battle.makeChoices('move watergun -2, pass', 'move watergun -2, pass');
			const newHps = attackers.map(pokemon => pokemon.hp);

			assert.deepEqual(prevHps, newHps);
			assert(battle.log.includes('|move|p1a: Wailord|Water Gun|p1: Shedinja|[notarget]'));
			assert(battle.log.includes('|-fail|p1a: Wailord'));
			assert(battle.log.includes('|move|p2a: Wailord|Water Gun|p2: Shedinja|[notarget]'));
			assert(battle.log.includes('|-fail|p2a: Wailord'));
		});

		it(`should support RedirectTarget event for a fainted foe and type 'any'`, () => {
			battle = common.createBattle({ gameType: 'doubles' }, [[
				{ species: 'Hippowdon', ability: 'sandstream', moves: ['waterpulse'] },
				{ species: 'Shedinja', ability: 'wonderguard', moves: ['agility'] },
			], [
				{ species: 'Gastrodon', ability: 'stormdrain', moves: ['curse'] },
				{ species: 'Shedinja', ability: 'wonderguard', moves: ['agility'] },
			]]);
			const redirector = battle.p2.active[0];

			battle.makeChoices('auto', 'auto'); // Shedinjas faint
			battle.makeChoices('move waterpulse 2, pass', 'auto');
			assert.statStage(redirector, 'spa', 2);
		});

		it(`should support RedirectTarget event for a fainted ally and type 'any'`, () => {
			battle = common.createBattle({ gameType: 'doubles' }, [[
				{ species: 'Hippowdon', ability: 'sandstream', moves: ['waterpulse'] },
				{ species: 'Shedinja', ability: 'wonderguard', moves: ['agility'] },
			], [
				{ species: 'Gastrodon', ability: 'stormdrain', moves: ['curse'] },
				{ species: 'Shedinja', ability: 'wonderguard', moves: ['agility'] },
			]]);
			const redirector = battle.p2.active[0];

			battle.makeChoices('auto', 'auto'); // Shedinjas faint
			battle.makeChoices('move waterpulse -2, pass', 'auto');
			assert.statStage(redirector, 'spa', 2);
		});
	});

	describe(`Smart-tracking targeting effects`, () => {
		it(`should allow Stalwart to follow its target after an opposing Ally Switch`, () => {
			battle = common.createBattle({ gameType: 'doubles' }, [[
				{ species: 'Duraludon', ability: 'stalwart', moves: ['watergun'] },
				{ species: 'Wynaut', moves: ['sleeptalk'] },
			], [
				{ species: 'Gastrodon', moves: ['sleeptalk'] },
				{ species: 'Ninjask', moves: ['allyswitch'] },
			]]);

			const ninjask = battle.p2.active[1];
			battle.makeChoices('move watergun 2, move sleeptalk', 'auto');
			assert.false.fullHP(ninjask, `Duraludon should have followed Ninjask's Ally Switch.`);
		});

		it(`should allow Stalwart to bypass Storm Drain redirection`, () => {
			battle = common.createBattle({ gameType: 'doubles' }, [[
				{ species: 'Duraludon', ability: 'stalwart', moves: ['watergun'] },
				{ species: 'Wynaut', moves: ['sleeptalk'] },
			], [
				{ species: 'Gastrodon', ability: 'stormdrain', moves: ['sleeptalk'] },
				{ species: 'Ninjask', moves: ['sleeptalk'] },
			]]);

			const ninjask = battle.p2.active[1];
			battle.makeChoices('move watergun 2, move sleeptalk', 'auto');
			assert.false.fullHP(ninjask, `Duraludon should have ignored Gastrodon's Storm Drain.`);
		});

		it(`should allow Stalwart to bypass Follow Me redirection`, () => {
			battle = common.createBattle({ gameType: 'doubles' }, [[
				{ species: 'Duraludon', ability: 'stalwart', moves: ['watergun'] },
				{ species: 'Wynaut', moves: ['sleeptalk'] },
			], [
				{ species: 'Clefable', moves: ['followme'] },
				{ species: 'Ninjask', moves: ['sleeptalk'] },
			]]);

			const ninjask = battle.p2.active[1];
			battle.makeChoices('move watergun 2, move sleeptalk', 'auto');
			assert.false.fullHP(ninjask, `Duraludon should have ignored Clefable's Follow Me.`);
		});

		it(`should allow Stalwart to correctly target a Pokemon which switched out and back in another slot`, () => {
			battle = common.createBattle({ gameType: 'doubles' }, [[
				{ species: 'Duraludon', ability: 'stalwart', moves: ['watergun'] },
				{ species: 'Wynaut', moves: ['sleeptalk'] },
			], [
				{ species: 'Ninjask', moves: ['uturn'] },
				{ species: 'Regieleki', moves: ['uturn'] },
				{ species: 'Octillery', moves: ['sleeptalk'] },
			]]);

			const regieleki = battle.p2.active[1];
			battle.makeChoices('move watergun 2, move sleeptalk', 'move uturn -2, move uturn -1');
			battle.choose('p2', 'switch 3');
			battle.choose('p2', 'switch 3');
			assert.false.fullHP(regieleki, `Duraludon should have followed Regieleki through its switch-out.`);
		});

		it(`should allow Snipe Shot to follow its target after an opposing Ally Switch`, () => {
			battle = common.createBattle({ gameType: 'doubles' }, [[
				{ species: 'Inteleon', moves: ['snipeshot'] },
				{ species: 'Ninjask', moves: ['sleeptalk'] },
			], [
				{ species: 'Gastrodon', moves: ['sleeptalk'] },
				{ species: 'Ninjask', moves: ['allyswitch'] },
			]]);

			const ninjask = battle.p2.active[1];
			battle.makeChoices('move snipeshot 2, move sleeptalk', 'auto');
			assert.false.fullHP(ninjask, `Inteleon should have followed Ninjask's Ally Switch.`);
		});
	});

	it('should not force charge moves called by another move to target an ally after Ally Switch', () => {
		battle = common.createBattle({ gameType: 'doubles' }, [[
			{ species: 'purrloin', ability: 'no guard', moves: ['copycat', 'sleeptalk'] },
			{ species: 'wynaut', moves: ['allyswitch', 'fly', 'skullbash'] },
		], [
			{ species: 'aron', moves: ['sleeptalk'] },
			{ species: 'lairon', moves: ['sleeptalk'] },
		]]);

		battle.makeChoices('move sleeptalk, move fly 1', 'auto');
		battle.makeChoices();
		battle.makeChoices();
		battle.makeChoices('move skullbash 1, move sleeptalk', 'auto');
		battle.makeChoices();
		battle.makeChoices();
		// ally switch was used twice, so wynaut will be back where it started
		assert.fullHP(battle.p1.active[1]);
	});

	it(`Ally Switch should cause single-target moves to fail if targeting an ally`, () => {
		battle = common.gen(8).createBattle({ gameType: 'doubles' }, [[
			{ species: 'purrloin', moves: ['thunder', 'ironhead'] },
			{ species: 'wynaut', moves: ['allyswitch'] },
		], [
			{ species: 'swablu', moves: ['sleeptalk'] },
			{ species: 'swablu', moves: ['sleeptalk'] },
		]]);

		battle.makeChoices('move ironhead -2, move allyswitch', 'auto');
		battle.makeChoices('move allyswitch, move thunder -1', 'auto');
		assert.fullHP(battle.p1.active[0]);
	});

	it(`charge moves like Phantom Force should target slots turn 1 and Pokemon turn 2`, () => {
		battle = common.createBattle({ gameType: 'doubles' }, [[
			{ species: 'houndour', level: 1, moves: ['sleeptalk'] },
			{ species: 'altaria', moves: ['sleeptalk'] },
			{ species: 'aggron', moves: ['sleeptalk'] },
		], [
			{ species: 'dragapult', moves: ['phantomforce'] },
			{ species: 'regieleki', moves: ['sleeptalk', 'sheercold'] },
		]]);

		// Phantom Force should still target slot 1, despite Houndour fainting
		battle.makeChoices('auto', 'move phantomforce 1, move sheercold 1');
		battle.makeChoices('switch 3');
		battle.makeChoices();
		assert.fullHP(battle.p1.active[1], 'Altaria should be at full HP, because it was not targeted.');
		assert.false.fullHP(battle.p1.active[0], 'Aggron should not be at full HP, because it was targeted.');

		battle = common.createBattle({ gameType: 'doubles' }, [[
			{ species: 'houndour', level: 1, moves: ['sleeptalk'] },
			{ species: 'altaria', moves: ['sleeptalk'] },
			{ species: 'aggron', moves: ['sleeptalk'] },
		], [
			{ species: 'dragapult', moves: ['phantomforce'] },
			{ species: 'regieleki', moves: ['sleeptalk', 'sheercold'] },
		]]);

		battle.makeChoices('auto', 'move phantomforce 1, move sleeptalk');
		battle.makeChoices('auto', 'move phantomforce 1, move sheercold 1');
		assert.false.fullHP(battle.p1.active[1], 'Altaria should not be at full HP, because Phantom Force was redirected and targeted it.');
	});

	it(`should cause Rollout to target the same slot after being called as a submove`, () => {
		// hardcoded RNG seed to show the erroneous targeting behavior
		battle = common.createBattle({ gameType: 'doubles', seed: [1, 2, 3, 4] }, [[
			{ species: 'shuckle', ability: 'compoundeyes', moves: ['copycat'] },
			{ species: 'foongus', item: 'laggingtail', moves: ['spore'] },
		], [
			{ species: 'aggron', moves: ['splash'] },
			{ species: 'slowbro', moves: ['splash', 'rollout'] },
		]]);

		battle.makeChoices('move copycat, move spore 2', 'move splash, move rollout 1');
		// Determine which slot was damaged on first turn of Rollout
		const aggron = battle.p2.active[0];
		const notTargetedPokemon = aggron.hp === aggron.maxhp ? aggron : battle.p2.active[1];

		for (let i = 0; i < 5; i++) battle.makeChoices();
		assert.fullHP(notTargetedPokemon);
	});
});