From c7b57c27ae5ddbdb63988b513e6fbe10fc736253 Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Thu, 20 Feb 2020 14:20:44 -0800 Subject: [PATCH] Fix Dragon Darts bugs - should not stop after one faint - should not show miss message for first miss --- data/scripts.js | 15 +++++++++------ package.json | 2 +- test/sim/moves/dragondarts.js | 22 +++++++++++++++++++++- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/data/scripts.js b/data/scripts.js index dc6e186eb820..94cf5dd84e7c 100644 --- a/data/scripts.js +++ b/data/scripts.js @@ -481,7 +481,8 @@ let BattleScripts = { } if (accuracy !== true && !this.randomChance(accuracy, 100)) { if (!move.spreadHit) this.attrLastMove('[miss]'); - this.add('-miss', pokemon, target); + const hideFailure = move.smartTarget && (i < targets.length - 1 || hitResults.some(Boolean)); + if (!hideFailure) this.add('-miss', pokemon, target); if (pokemon.hasItem('blunderpolicy') && pokemon.useItem()) this.boost({spe: 2}, pokemon); hitResults[i] = false; continue; @@ -614,11 +615,11 @@ let BattleScripts = { for (hit = 1; hit <= targetHits; hit++) { if (damage.includes(false)) break; if (hit > 1 && pokemon.status === 'slp' && !isSleepUsable) break; - if (targets.some(target => target && !target.hp)) break; + if (targets.every(target => !target || !target.hp)) break; move.hit = hit; - if (move.smartTarget && targets.length > hit - 1) { + if (move.smartTarget && targets.length > 1) { targetsCopy = targets.slice(hit - 1, hit); - if (targetsCopy[0]) this.addMove('-anim', pokemon, move.name, targetsCopy[0]); + if (targetsCopy[0] && hit > 1) this.addMove('-anim', pokemon, move.name, targetsCopy[0]); } else { targetsCopy = targets.slice(0); } @@ -677,7 +678,7 @@ let BattleScripts = { move.mindBlownRecoil = false; } this.eachEvent('Update'); - if (!pokemon.hp) { + if (!pokemon.hp && targets.length === 1) { hit++; // report the correct number of hits for multihit moves break; } @@ -685,7 +686,9 @@ let BattleScripts = { // hit is 1 higher than the actual hit count if (hit === 1) return damage.fill(false); if (nullDamage) damage.fill(false); - if (move.multihit && !move.smartTarget) this.add('-hitcount', targets[0], hit - 1); + if (move.multihit && typeof move.smartTarget === 'boolean') { + this.add('-hitcount', targets[0], hit - 1); + } if (move.recoil && move.totalDamage) { this.damage(this.calcRecoilDamage(move.totalDamage, move), pokemon, pokemon, 'recoil'); diff --git a/package.json b/package.json index 2d85ec0d23e8..b29cc952b85f 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "pretest": "npm run lint && npm run build", "test": "mocha", "posttest": "npm run tsc", - "fulltest": "npm run pretest && npm run tsc && mocha -R spec -g \".*\"" + "fulltest": "npm run pretest && npm run tsc && mocha --forbid-only -R spec -g \".*\"" }, "husky": { "hooks": { diff --git a/test/sim/moves/dragondarts.js b/test/sim/moves/dragondarts.js index d25010966a00..758083ac00dc 100644 --- a/test/sim/moves/dragondarts.js +++ b/test/sim/moves/dragondarts.js @@ -36,14 +36,20 @@ describe('Dragon Darts', function () { it(`should hit the other foe twice if it misses against one`, function () { battle = common.createBattle({gameType: 'doubles'}, [[ - {species: "Ninjask", moves: ['dragondarts']}, + {species: "Ninjask", item: 'blunderpolicy', moves: ['dragondarts']}, {species: "Mew", ability: 'stamina', moves: ['splash']}, ], [ {species: "Mew", ability: 'stamina', moves: ['splash']}, {species: "Shaymin", ability: 'stamina', moves: ['splash']}, ]]); + + // default seed will make Dragon Darts miss at +6 evasion + // remember to manually set the seed if an engine change means it doesn't battle.p2.active[0].boostBy({evasion: 6}); + battle.makeChoices(); + assert(!battle.log.includes('|-miss|p1a: Ninjask|p2a: Mew')); + assert.statStage(battle.p1.active[0], 'spe', 2); assert.statStage(battle.p1.active[1], 'def', 0); assert.statStage(battle.p2.active[0], 'def', 0); assert.statStage(battle.p2.active[1], 'def', 2); @@ -64,6 +70,20 @@ describe('Dragon Darts', function () { assert.statStage(battle.p2.active[1], 'def', 0); }); + it(`should hit both targets even if one faints`, function () { + battle = common.createBattle({gameType: 'doubles'}, [[ + {species: "Ninjask", moves: ['dragondarts']}, + {species: "Mew", moves: ['splash']}, + ], [ + {species: "Shedinja", moves: ['splash']}, + {species: "Shedinja", moves: ['splash']}, + ]]); + battle.makeChoices(); + battle.getDebugLog(); + assert.equal(battle.p2.active[0].hp, 0); + assert.equal(battle.p2.active[1].hp, 0); + }); + it(`should hit the ally twice in doubles`, function () { battle = common.createBattle({gameType: 'doubles'}, [[ {species: "Ninjask", moves: ['dragondarts']},