From 4fc03700fba19d837ef9cb3eb6bb428cbef02f2f Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Wed, 21 Dec 2016 19:36:23 -0800 Subject: [PATCH] Fix Mega Pursuit Previously, if a pokemon mega evolved and used Pursuit, and the foe switched on the next turn, it would use Pursuit again on the next turn, in addition to its usual decision. This is a hack to fix it; a full fix is pending a rewrite of the decision structure. --- battle-engine.js | 6 +++--- test/simulator/moves/pursuit.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/battle-engine.js b/battle-engine.js index e34c4d860a..7352d04657 100644 --- a/battle-engine.js +++ b/battle-engine.js @@ -4208,7 +4208,7 @@ class Battle extends Tools.BattleDex { sortQueue() { this.queue.sort(Battle.comparePriority); } - insertQueue(decision) { + insertQueue(decision, noResolve) { if (Array.isArray(decision)) { for (let i = 0; i < decision.length; i++) { this.insertQueue(decision[i]); @@ -4217,7 +4217,7 @@ class Battle extends Tools.BattleDex { } if (decision.pokemon) decision.pokemon.updateSpeed(); - this.resolvePriority(decision); + if (!noResolve) this.resolvePriority(decision); for (let i = 0; i < this.queue.length; i++) { if (Battle.comparePriority(decision, this.queue[i]) < 0) { this.queue.splice(i, 0, decision); @@ -4505,7 +4505,7 @@ class Battle extends Tools.BattleDex { const moveIndex = this.queue.findIndex(queuedDecision => queuedDecision.pokemon === decision.pokemon && queuedDecision.choice === 'move'); if (moveIndex >= 0) { const moveDecision = this.queue.splice(moveIndex, 1)[0]; - this.insertQueue(moveDecision); + this.insertQueue(moveDecision, true); } return false; } diff --git a/test/simulator/moves/pursuit.js b/test/simulator/moves/pursuit.js index 10bd24f45c..aaf3ef0509 100644 --- a/test/simulator/moves/pursuit.js +++ b/test/simulator/moves/pursuit.js @@ -17,4 +17,17 @@ describe(`Pursuit`, function () { assert.species(battle.p1.active[0], "Beedrill-Mega"); assert.fainted(battle.p2.active[0]); }); + + it(`should not repeat`, function () { + battle = common.createBattle(); + battle.join('p1', 'Guest 1', 1, [{species: "Beedrill", ability: 'swarm', item: 'beedrillite', moves: ['pursuit']}, {species: "Clefable", ability: 'unaware', moves: ['calmmind']}]); + battle.join('p2', 'Guest 2', 1, [{species: "Clefable", ability: 'magicguard', moves: ['calmmind']}, {species: "Alakazam", ability: 'unaware', moves: ['calmmind']}]); + battle.p1.chooseMove('pursuit', null, true); + battle.p2.chooseMove('calmmind'); + let clefable = battle.p2.pokemon[0]; + let hpBeforeSwitch = clefable.hp; + battle.p1.chooseSwitch(2); + battle.p2.chooseSwitch(2); + assert.strictEqual(hpBeforeSwitch, clefable.hp); + }); });