Skip to content

Commit

Permalink
Fix Dragon Darts bugs
Browse files Browse the repository at this point in the history
- should not stop after one faint
- should not show miss message for first miss
  • Loading branch information
Zarel committed Feb 20, 2020
1 parent 5cb8c6e commit c7b57c2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
15 changes: 9 additions & 6 deletions data/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -677,15 +678,17 @@ 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;
}
}
// 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');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
22 changes: 21 additions & 1 deletion test/sim/moves/dragondarts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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']},
Expand Down

0 comments on commit c7b57c2

Please sign in to comment.