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

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

let battle;

describe(`Ally Switch`, () => {
	afterEach(() => {
		battle.destroy();
	});

	it(`should cause the Pokemon to switch sides in a double battle`, () => {
		battle = common.createBattle({ gameType: 'doubles' }, [[
			{ species: 'Primeape', moves: ['sleeptalk'] },
			{ species: 'Wynaut', moves: ['allyswitch'] },
		], [
			{ species: 'Dreepy', moves: ['sleeptalk'] },
			{ species: 'Pichu', moves: ['sleeptalk'] },
		]]);

		let wynaut = battle.p1.active[1];
		assert.species(wynaut, 'Wynaut');
		battle.makeChoices();

		wynaut = battle.p1.active[0];
		assert.species(wynaut, 'Wynaut');
	});

	it(`should not work if the user is in the center of a Triple Battle`, () => {
		battle = common.gen(6).createBattle({ gameType: 'triples' }, [[
			{ species: 'Primeape', moves: ['sleeptalk'] },
			{ species: 'Wynaut', moves: ['allyswitch'] },
			{ species: 'Shaymin', moves: ['sleeptalk'] },
		], [
			{ species: 'Murkrow', moves: ['sleeptalk'] },
			{ species: 'Pichu', moves: ['sleeptalk'] },
			{ species: 'Skrelp', moves: ['sleeptalk'] },
		]]);

		battle.makeChoices();
		const wynaut = battle.p1.active[1];
		assert.species(wynaut, 'Wynaut');
	});

	it(`should swap Pokemon on the edges of a Triple Battle`, () => {
		battle = common.gen(6).createBattle({ gameType: 'triples' }, [[
			{ species: 'Wynaut', moves: ['allyswitch'] },
			{ species: 'Primeape', moves: ['sleeptalk'] },
			{ species: 'Shaymin', moves: ['sleeptalk'] },
		], [
			{ species: 'Murkrow', moves: ['sleeptalk'] },
			{ species: 'Pichu', moves: ['sleeptalk'] },
			{ species: 'Skrelp', moves: ['sleeptalk'] },
		]]);

		battle.makeChoices();
		const wynaut = battle.p1.active[2];
		assert.species(wynaut, 'Wynaut');
	});

	it(`should not work in formats where you do not control allies`, () => {
		battle = common.createBattle([[
			{ species: 'Wynaut', moves: ['allyswitch'] },
		], [
			{ species: 'Pichu', moves: ['swordsdance'] },
		]]);

		battle.makeChoices();
		assert(battle.log.some(line => line.includes('|-fail|')), `It should fail in singles`);

		battle = common.createBattle({ gameType: 'multi' }, [[
			{ species: 'Wynaut', moves: ['allyswitch'] },
		], [
			{ species: 'Cubone', moves: ['swordsdance'] },
		], [
			{ species: 'Marowak', moves: ['swordsdance'] },
		], [
			{ species: 'Shaymin', moves: ['swordsdance'] },
		]]);

		battle.makeChoices();
		assert(battle.log.some(line => line.includes('|-fail|')), `It should fail in multis`);

		battle = common.createBattle({ gameType: 'freeforall' }, [[
			{ species: 'wynaut', moves: ['allyswitch'] },
		], [
			{ species: 'scyther', moves: ['swordsdance'] },
		], [
			{ species: 'scizor', moves: ['swordsdance'] },
		], [
			{ species: 'shaymin', moves: ['swordsdance'] },
		]]);

		battle.makeChoices();
		assert(battle.log.some(line => line.includes('|-fail|')), `It should fail in FFAs`);
	});

	it(`should have a chance to fail when used successively`, () => {
		battle = common.createBattle({ gameType: 'doubles', forceRandomChance: false }, [[
			{ species: 'Primeape', moves: ['sleeptalk'] },
			{ species: 'Wynaut', moves: ['allyswitch'] },
		], [
			{ species: 'Dreepy', moves: ['sleeptalk'] },
			{ species: 'Pichu', moves: ['sleeptalk'] },
		]]);

		battle.makeChoices();
		battle.makeChoices();

		const wynaut = battle.p1.active[0];
		assert.species(wynaut, 'Wynaut');
	});

	it(`[Gen 8] should not have a chance to fail when used successively`, () => {
		battle = common.gen(8).createBattle({ gameType: 'doubles', forceRandomChance: false }, [[
			{ species: 'Primeape', moves: ['sleeptalk'] },
			{ species: 'Wynaut', moves: ['allyswitch'] },
		], [
			{ species: 'Dreepy', moves: ['sleeptalk'] },
			{ species: 'Pichu', moves: ['sleeptalk'] },
		]]);

		battle.makeChoices();
		battle.makeChoices();

		const wynaut = battle.p1.active[1];
		assert.species(wynaut, 'Wynaut');
	});

	it(`should not use the protection counter when determining if the move should fail`, () => {
		battle = common.createBattle({ gameType: 'doubles', forceRandomChance: false }, [[
			{ species: 'Primeape', moves: ['calmmind'] },
			{ species: 'Wynaut', moves: ['allyswitch', 'protect'] },
		], [
			{ species: 'Dreepy', moves: ['calmmind'] },
			{ species: 'Pichu', moves: ['calmmind'] },
		]]);

		battle.makeChoices('move calmmind, move allyswitch', 'auto');
		battle.makeChoices('move protect, move calmmind', 'auto');
		battle.makeChoices('move allyswitch, move calmmind', 'auto');
		battle.makeChoices('move calmmind, move protect', 'auto');

		assert(battle.log.every(line => !line.startsWith('|-fail')));
	});
});