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

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

let battle;

describe('Weather damage calculation', () => {
	afterEach(() => {
		battle.destroy();
	});

	it('should multiply the damage (not the basePower) in favorable weather', () => {
		battle = common.createBattle();
		battle.randomizer = dmg => dmg; // max damage
		battle.setPlayer('p1', { team: [{ species: 'Ninetales', ability: 'drought', moves: ['incinerate'] }] });
		battle.setPlayer('p2', { team: [{ species: 'Cryogonal', ability: 'levitate', moves: ['splash'] }] });
		const attacker = battle.p1.active[0];
		const defender = battle.p2.active[0];
		assert.hurtsBy(defender, 152, () => battle.makeChoices('move incinerate', 'move splash'));
		const move = Dex.moves.get('incinerate');
		const basePower = battle.runEvent('BasePower', attacker, defender, move, move.basePower, true);
		assert.equal(basePower, move.basePower);
	});

	it('should reduce the damage (not the basePower) in unfavorable weather', () => {
		battle = common.createBattle();
		battle.randomizer = dmg => dmg; // max damage
		battle.setPlayer('p1', { team: [{ species: 'Ninetales', ability: 'drizzle', moves: ['incinerate'] }] });
		battle.setPlayer('p2', { team: [{ species: 'Cryogonal', ability: 'levitate', moves: ['splash'] }] });
		const attacker = battle.p1.active[0];
		const defender = battle.p2.active[0];
		assert.hurtsBy(defender, 50, () => battle.makeChoices('move incinerate', 'move splash'));
		const move = Dex.moves.get('incinerate');
		const basePower = battle.runEvent('BasePower', attacker, defender, move, move.basePower, true);
		assert.equal(basePower, move.basePower);
	});

	it('should make Hail/Sandstorm damage some pokemon but not others', () => {
		battle = common.gen(8).createBattle();
		battle.randomizer = dmg => dmg; // max damage
		battle.setPlayer('p1', { team: [{ species: 'Abomasnow', ability: 'snowwarning', moves: ['protect'] }] });
		battle.setPlayer('p2', { team: [{ species: 'Sandslash', ability: 'sandveil', moves: ['protect'] }] });
		battle.makeChoices('move protect', 'move protect');
		const p1active = battle.p1.active[0];
		const p2active = battle.p2.active[0];
		assert.equal(p1active.hp, p1active.maxhp);
		assert.notEqual(p2active.hp, p2active.maxhp);
	});

	it(`should wear off on the final turn before weather effects are applied`, () => {
		battle = common.createBattle([[
			{ species: 'Tyranitar', ability: 'sandstream', moves: ['sleeptalk'] },
		], [
			{ species: 'Wynaut', moves: ['sleeptalk'] },
		]]);

		for (let i = 0; i < 5; i++) battle.makeChoices();
		const wynaut = battle.p2.active[0];
		assert.equal(wynaut.hp, wynaut.maxhp - (Math.floor(wynaut.maxhp / 16) * 4));
	});

	it(`should wear off before future attacks`, () => {
		battle = common.createBattle([[
			{ species: 'Tyranitar', ability: 'sandstream', moves: ['doomdesire', 'soak'] },
		], [
			{ species: 'Roggenrola', moves: ['sleeptalk'] },
		]]);

		battle.makeChoices();
		battle.makeChoices();
		battle.makeChoices('move soak', 'auto');
		const log = battle.getDebugLog();
		const sandDamageIndex = log.indexOf('[from] Sandstorm');
		const futureDamageIndex = log.indexOf('|-end|p2a: Roggenrola|move: Doom Desire');
		assert(sandDamageIndex < futureDamageIndex, `Sandstorm should have dealt damage before Doom Desire`);
	});

	it(`should run residual weather effects in order of Speed`, () => {
		battle = common.createBattle([[
			{ species: 'Sunkern', ability: 'solarpower', moves: ['sunnyday'] },
		], [
			{ species: 'Charizard', ability: 'dryskin', moves: ['sleeptalk'] },
		]]);

		battle.makeChoices();
		const log = battle.getDebugLog();
		const drySkinIndex = log.indexOf('ability: Dry Skin');
		const solarPowerIndex = log.indexOf('ability: Solar Power');
		assert(drySkinIndex < solarPowerIndex, `Charizard should be damaged before Sunkern, because it is faster`);
	});
});