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.
This commit is contained in:
Guangcong Luo
2016-12-21 19:36:23 -08:00
parent 6a1624603e
commit 4fc03700fb
2 changed files with 16 additions and 3 deletions

View File

@@ -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;
}

View File

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