Files
pokemon-showdown/test/sim/moves/allyswitch.js
Guangcong Luo 78439b4a02 Update to ESLint 9 (#10926)
ESLint has a whole new config format, so I figure it's a good time to
make the config system saner.

- First, we no longer have separate eslint-no-types configs. Lint
  performance shouldn't be enough of a problem to justify the
  relevant maintenance complexity.

- Second, our base config should work out-of-the-box now. `npx eslint`
  will work as expected, without any CLI flags. You should still use
  `npm run lint` which adds the `--cached` flag for performance.

- Third, whatever updates I did fixed style linting, which apparently
  has been bugged for quite some time, considering all the obvious
  mixed-tabs-and-spaces issues I found in the upgrade.

Also here are some changes to our style rules. In particular:

- Curly brackets (for objects etc) now have spaces inside them. Sorry
  for the huge change. ESLint doesn't support our old style, and most
  projects use Prettier style, so we might as well match them in this way.
  See https://github.com/eslint-stylistic/eslint-stylistic/issues/415

- String + number concatenation is no longer allowed. We now
  consistently use template strings for this.
2025-02-25 20:03:46 -08:00

148 lines
4.6 KiB
JavaScript

'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')));
});
});