Fix crash in Knock Off + Substitute

(This also fixes a bug where hitting Substitute procced DamagingHit
events.)
This commit is contained in:
Guangcong Luo 2020-02-10 15:37:34 -08:00
parent ec5471872f
commit ee4435716f
2 changed files with 9 additions and 1 deletions

View File

@ -805,7 +805,7 @@ let BattleScripts = {
let damagedTargets = [];
let damagedDamage = [];
for (let i = 0; i < targets.length; i++) {
if (typeof damage[i] === 'number') {
if (typeof damage[i] === 'number' && targets[i]) {
damagedTargets.push(/** @type {Pokemon} */ (targets[i]));
damagedDamage.push(damage[i]);
}

View File

@ -18,6 +18,14 @@ describe('Knock Off', function () {
assert.strictEqual(battle.p2.active[0].item, '');
});
it('should not remove items when hitting Sub', function () {
battle = common.createBattle();
battle.setPlayer('p1', {team: [{species: "Mew", ability: 'noability', moves: ['knockoff']}]});
battle.setPlayer('p2', {team: [{species: "Ninjask", ability: 'noability', item: 'shedshell', moves: ['substitute']}]});
battle.makeChoices();
assert.strictEqual(battle.p2.active[0].item, 'shedshell');
});
it('should not remove plates from Arceus', function () {
battle = common.createBattle();
battle.setPlayer('p1', {team: [{species: "Mew", ability: 'synchronize', moves: ['knockoff']}]});