File size: 9,648 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
'use strict';

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

let battle;

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

	it('should cause mega ability to affect the order of the turn in which it happens', () => {
		battle = common.createBattle();
		battle.setPlayer('p1', { team: [{ species: 'Banette', ability: 'frisk', item: 'banettite', moves: ['psychup'] }] });
		battle.setPlayer('p2', { team: [{ species: 'Deoxys-Speed', ability: 'pressure', moves: ['calmmind'] }] });
		const pranksterMega = battle.p1.active[0];
		battle.makeChoices('move psychup mega', 'move calmmind');
		assert.statStage(pranksterMega, 'spa', 0);
	});

	it('should cause an ability copied with Trace by a mega to affect the order of the turn in which it happens', () => {
		battle = common.createBattle([
			[{ species: "Politoed", ability: 'drizzle', item: '', moves: ['scald'] }, { species: "Kingdra", ability: 'swiftswim', item: '', moves: ['dragondance'] }],
			[{ species: "Marowak", ability: 'rockhead', item: '', moves: ['earthquake'] }, { species: "Alakazam", ability: 'magicguard', item: 'alakazite', moves: ['psychup'] }],
		]);
		battle.makeChoices('switch 2', 'switch 2');
		battle.makeChoices('move dragondance', 'move psychup mega');
		assert.statStage(battle.p1.active[0], 'atk', 1);
		assert.statStage(battle.p2.active[0], 'atk', 0);
		assert.species(battle.p2.active[0], 'Alakazam-Mega');
	});

	it('should cause base ability to not affect the order of the turn in which it happens', () => {
		battle = common.createBattle();
		battle.setPlayer('p1', { team: [{ species: 'Sableye', ability: 'prankster', item: 'sablenite', moves: ['psychup'] }] });
		battle.setPlayer('p2', { team: [{ species: 'Deoxys-Speed', ability: 'pressure', moves: ['calmmind'] }] });
		const noPranksterMega = battle.p1.active[0];
		battle.makeChoices('move psychup mega', 'move calmmind');
		assert.statStage(noPranksterMega, 'spa', 1);
	});

	it('should cause mega forme speed to decide turn order', () => {
		battle = common.createBattle();
		battle.setPlayer('p1', { team: [{ species: 'Beedrill', ability: 'swarm', item: 'beedrillite', moves: ['xscissor'] }] });
		battle.setPlayer('p2', { team: [{ species: 'Hoopa-Unbound', ability: 'magician', moves: ['psyshock'] }] });
		const fastBase = battle.p2.active[0];
		battle.makeChoices('move xscissor mega', 'move psyshock');
		assert.fainted(fastBase);
	});

	it('should cause ultra forme speed to decide turn order', () => {
		battle = common.createBattle();
		battle.setPlayer('p1', { team: [{ species: 'Necrozma-Dusk-Mane', ability: 'swarm', item: 'ultranecroziumz', moves: ['xscissor'] }] });
		battle.setPlayer('p2', { team: [{ species: 'Hoopa-Unbound', ability: 'magician', moves: ['darkpulse'] }] });
		const fastBase = battle.p2.active[0];
		battle.makeChoices('move xscissor ultra', 'move darkpulse');
		assert.equal(fastBase.hp, 0);
	});
});

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

	it('should not cause mega ability to affect the order of the turn in which it happens', () => {
		battle = common.gen(6).createBattle();
		battle.setPlayer('p1', { team: [{ species: 'Banette', ability: 'frisk', item: 'banettite', moves: ['psychup'] }] });
		battle.setPlayer('p2', { team: [{ species: 'Deoxys-Speed', ability: 'pressure', moves: ['calmmind'] }] });
		const pranksterMega = battle.p1.active[0];
		battle.makeChoices('move psychup mega', 'move calmmind');
		assert.statStage(pranksterMega, 'spa', 1);
	});

	it('should not cause an ability copied with Trace by a mega to affect the order of the turn in which it happens', () => {
		battle = common.gen(6).createBattle([
			[{ species: "Politoed", ability: 'drizzle', item: '', moves: ['scald'] }, { species: "Kingdra", ability: 'swiftswim', item: '', moves: ['dragondance'] }],
			[{ species: "Marowak", ability: 'rockhead', item: '', moves: ['earthquake'] }, { species: "Alakazam", ability: 'magicguard', item: 'alakazite', moves: ['psychup'] }],
		]);
		battle.makeChoices('switch 2', 'switch 2');
		battle.makeChoices('move dragondance', 'move psychup mega');
		assert.statStage(battle.p1.active[0], 'atk', 1);
		assert.statStage(battle.p2.active[0], 'atk', 1);
		assert.species(battle.p2.active[0], 'Alakazam-Mega');
	});

	it('should cause base ability to affect the order of the turn in which it happens', () => {
		battle = common.gen(6).createBattle();
		battle.setPlayer('p1', { team: [{ species: 'Sableye', ability: 'prankster', item: 'sablenite', moves: ['psychup'] }] });
		battle.setPlayer('p2', { team: [{ species: 'Deoxys-Speed', ability: 'pressure', moves: ['calmmind'] }] });
		const noPranksterMega = battle.p1.active[0];
		battle.makeChoices('move psychup mega', 'move calmmind');
		assert.statStage(noPranksterMega, 'spa', 0);
	});

	it('should cause base forme speed to decide turn order', () => {
		battle = common.gen(6).createBattle();
		battle.setPlayer('p1', { team: [{ species: 'Beedrill', ability: 'swarm', item: 'beedrillite', moves: ['xscissor'] }] });
		battle.setPlayer('p2', { team: [{ species: 'Hoopa-Unbound', ability: 'magician', moves: ['psyshock'] }] });
		const fastMega = battle.p1.active[0];
		battle.makeChoices('move xscissor mega', 'move psyshock');
		assert.fainted(fastMega);
	});
});

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

	it('should update dynamically in Gen 8', () => {
		battle = common.createBattle({ gameType: 'doubles' });
		const p1team = [
			{ species: 'Ludicolo', ability: 'swiftswim', moves: ['scald'], evs: { spe: 100 } }, // 201 Speed
			{ species: 'Appletun', ability: 'ripen', moves: ['sleeptalk'] }, // To be switched out
			{ species: 'Pelipper', ability: 'drizzle', moves: ['sleeptalk'] }, // Will set rain on switch in
		];
		const p2team = [
			{ species: 'Accelgor', ability: 'hydration', moves: ['bugbuzz'], evs: { spe: 156 }, nature: 'Timid' }, // 401 Speed
			{ species: 'Aegislash', ability: 'stancechange', moves: ['sleeptalk'] }, // Does nothing but fill a slot
		];
		battle.setPlayer('p1', { team: p1team });
		battle.setPlayer('p2', { team: p2team });

		// Set ludicolo's and accelgor's HP to 1.
		battle.p1.pokemon[0].sethp(1); // Ludicolo
		battle.p2.pokemon[0].sethp(1); // Accelgor

		battle.makeChoices('move scald 1, switch 3', 'move bugbuzz 1, auto');
		assert.fainted(battle.p2.pokemon[0]); // Accelgor should be fainted
	});

	it('should NOT update dynamically in Gen 7', () => {
		battle = common.gen(7).createBattle({ gameType: 'doubles' });
		const p1team = [
			{ species: 'Ludicolo', ability: 'swiftswim', moves: ['scald'], evs: { spe: 100 } }, // 201 Speed
			{ species: 'Appletun', ability: 'ripen', moves: ['sleeptalk'] }, // To be switched out
			{ species: 'Pelipper', ability: 'drizzle', moves: ['sleeptalk'] }, // Will set rain on switch in
		];
		const p2team = [
			{ species: 'Accelgor', ability: 'hydration', moves: ['bugbuzz'], evs: { spe: 156 }, nature: 'Timid' }, // 401 Speed
			{ species: 'Aegislash', ability: 'stancechange', moves: ['sleeptalk'] }, // Does nothing but fill a slot
		];
		battle.setPlayer('p1', { team: p1team });
		battle.setPlayer('p2', { team: p2team });

		// Set ludicolo's and accelgor's HP to 1.
		battle.p1.pokemon[0].sethp(1); // Ludicolo
		battle.p2.pokemon[0].sethp(1); // Accelgor

		battle.makeChoices('move scald 1, switch 3', 'move bugbuzz 1, auto');
		assert.fainted(battle.p1.pokemon[0]); // Ludicolo should be fainted
	});
});

describe('Switching out', () => {
	it('should happen in order of switch-out\'s Speed stat', () => {
		battle = common.createBattle();
		const p1team = [
			{ species: 'Accelgor', ability: 'runaway', moves: ['sleeptalk'] },
			{ species: 'Shuckle', ability: 'intimidate', moves: ['sleeptalk'] },
		];
		const p2team = [
			{ species: 'Durant', ability: 'runaway', moves: ['sleeptalk'] },
			{ species: 'Barraskewda', ability: 'runaway', moves: ['sleeptalk'] },
		];
		battle.setPlayer('p1', { team: p1team });
		battle.setPlayer('p2', { team: p2team });

		battle.makeChoices('switch 2', 'switch 2');
		assert.equal(battle.p2.pokemon[0].boosts.atk, 0);
	});
});

describe('Switching in', () => {
	it(`should trigger events in an order determined by what each Pokemon's speed was when they switched in`, () => {
		battle = common.gen(7).createBattle([[
			{ species: "ribombee", moves: ['stickyweb'] },
			{ species: "groudon", item: 'redorb', moves: ['sleeptalk'], evs: { spe: 0 } },
		], [
			{ species: "golemalola", ability: 'galvanize', moves: ['explosion'] },
			{ species: "kyogre", item: 'blueorb', moves: ['sleeptalk'], evs: { spe: 252 } },
		]]);
		battle.makeChoices();
		battle.makeChoices('switch 2', 'switch 2');
		const kyogre = battle.p2.active[0];
		assert.statStage(kyogre, 'spe', -1);
		assert.equal(battle.field.weather, 'desolateland', 'Groudon should have reverted after Kyogre in spite of Sticky Web because it was slower before the SwitchIn event started');
	});
});

describe('Speed ties', () => {
	it('(slow) Perish Song faint order should be random', () => {
		const wins = { p1: 0, p2: 0 };
		for (let i = 0; i < 20; i++) {
			battle = common.createBattle({
				seed: [i, 2, 3, 4],
			}, [[
				{ species: "Politoed", moves: ['perishsong'] },
			], [
				{ species: "Politoed", moves: ['perishsong'] },
			]]);
			battle.makeChoices('auto', 'auto');
			battle.makeChoices('auto', 'auto');
			battle.makeChoices('auto', 'auto');
			battle.makeChoices('auto', 'auto');
			wins[battle.winner === 'Player 1' ? 'p1' : 'p2']++;
			if (wins.p1 && wins.p2) break;
		}
		assert(wins.p1);
		assert(wins.p2);
	});
});