From 16e8c4bc33a8b5a7dc02587a9c3da606ee0ef2fd Mon Sep 17 00:00:00 2001 From: Ivo Julca Date: Sun, 26 Apr 2015 02:50:14 -0500 Subject: [PATCH 1/4] BattlePokemon#getMoves now returns an empty array for no moves It's a needed distinction to fix Struggle when hacked into a moveset --- battle-engine.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/battle-engine.js b/battle-engine.js index fcb52257cf..c47ef392c7 100644 --- a/battle-engine.js +++ b/battle-engine.js @@ -598,17 +598,15 @@ BattlePokemon = (function () { } if (hasValidMove) return moves; - return [{ - move: 'Struggle', - id: 'struggle' - }]; + return []; }; BattlePokemon.prototype.getRequestData = function () { var lockedMove = this.getLockedMove(); // Information should be restricted for the last active Pokémon var isLastActive = this.isLastActive(); - var data = {moves: this.getMoves(lockedMove, isLastActive)}; + var moves = this.getMoves(lockedMove, isLastActive); + var data = {moves: moves.length ? moves : [{move: 'Struggle', id: 'struggle'}]}; if (isLastActive) { if (this.maybeDisabled) { From 245f9bd8ac6610d8c5b6926b5c5335ebb2500aed Mon Sep 17 00:00:00 2001 From: Ivo Julca Date: Sun, 26 Apr 2015 17:36:06 -0500 Subject: [PATCH 2/4] =?UTF-8?q?Hackmons:=20add=20failing=20test=20for=20ch?= =?UTF-8?q?oice=20parsing=20when=20a=20pok=C3=A9mon=20knows=20Struggle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/simulator/misc/choice-parser.js | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/simulator/misc/choice-parser.js diff --git a/test/simulator/misc/choice-parser.js b/test/simulator/misc/choice-parser.js new file mode 100644 index 0000000000..06709742e1 --- /dev/null +++ b/test/simulator/misc/choice-parser.js @@ -0,0 +1,44 @@ +var assert = require('assert'); +var battle; + +describe('Choice parser', function () { + afterEach(function () { + battle.destroy(); + }); + + it('should force Struggle usage on move attempt for no valid moves', function () { + battle = BattleEngine.Battle.construct(); + battle.join('p1', 'Guest 1', 1, [{species: "Mew", ability: 'synchronize', moves: ['recover']}]); + battle.join('p2', 'Guest 2', 1, [{species: "Rhydon", ability: 'prankster', moves: ['sketch']}]); + + // First turn + battle.choose('p1', 'move 1'); + battle.choose('p2', 'move 1'); + + // Second turn + battle.choose('p1', 'move recover'); + battle.choose('p2', 'move sketch'); + + // Implementation-dependent paths + if (battle.turn === 3) { + assert.strictEqual(battle.p2.active[0].lastMove, 'struggle'); + } else { + battle.choose('p2', 'move 1'); + assert.strictEqual(battle.turn, 3); + assert.strictEqual(battle.p2.active[0].lastMove, 'struggle'); + } + }); + + it('should not force Struggle usage on move attempt for valid moves', function () { + battle = BattleEngine.Battle.construct(); + battle.join('p1', 'Guest 1', 1, [{species: "Mew", ability: 'synchronize', moves: ['recover']}]); + battle.join('p2', 'Guest 2', 1, [{species: "Rhydon", ability: 'prankster', moves: ['struggle', 'surf']}]); + + // First turn + battle.choose('p1', 'move 1'); + battle.choose('p2', 'move 2'); + + assert.strictEqual(battle.turn, 2); + assert.notStrictEqual(battle.p2.active[0].lastMove, 'struggle'); + }); +}); From 54c8c8a0addf9aa13e513a986e6a8bac2c3410dc Mon Sep 17 00:00:00 2001 From: Ivo Julca Date: Sun, 26 Apr 2015 17:36:36 -0500 Subject: [PATCH 3/4] Hackmons: fix decisions being overriden when Struggle is in the first slot --- battle-engine.js | 8 ++++---- data/scripts.js | 3 --- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/battle-engine.js b/battle-engine.js index c47ef392c7..414f8f892e 100644 --- a/battle-engine.js +++ b/battle-engine.js @@ -4059,13 +4059,13 @@ Battle = (function () { */ var moves = pokemon.getMoves(); - if (!moves.length || moves[0].id === 'struggle') { - // override decision and use Struggle if there are no other valid moves + if (!moves.length) { + // Override decision and use Struggle if there are no enabled moves with PP if (this.gen <= 4) side.send('-activate', pokemon, 'move: Struggle'); moveid = 'struggle'; } else { - // at least a move is valid (other than Struggle) - // check if the chosen one is + // At least a move is valid. Check if the chosen one is. + // This may include Struggle in Hackmons. var isEnabled = false; for (var j = 0; j < moves.length; j++) { if (moves[j].id !== moveid) continue; diff --git a/data/scripts.js b/data/scripts.js index a8b7d8c565..c59a258a4b 100644 --- a/data/scripts.js +++ b/data/scripts.js @@ -836,9 +836,6 @@ exports.BattleScripts = { } } - // PS overrides your move if you have Struggle in the first slot - if (m[0] === 'struggle') m.push(m.shift()); - // Random EVs var evs = {hp: 0, atk: 0, def: 0, spa: 0, spd: 0, spe: 0}; var s = ['hp', 'atk', 'def', 'spa', 'spd', 'spe']; From b46cbb46ad0bf8462dfa46953e8cca8a69aeda2c Mon Sep 17 00:00:00 2001 From: Ivo Julca Date: Sun, 26 Apr 2015 17:36:51 -0500 Subject: [PATCH 4/4] Remove BattlePokemon#getValidMoves As of f33909e9, this method is no longer called anywhere. --- battle-engine.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/battle-engine.js b/battle-engine.js index 414f8f892e..2eb4649ba8 100644 --- a/battle-engine.js +++ b/battle-engine.js @@ -871,17 +871,6 @@ BattlePokemon = (function () { } return false; }; - BattlePokemon.prototype.getValidMoves = function (lockedMove) { - var pMoves = this.getMoves(lockedMove); - var moves = []; - for (var i = 0; i < pMoves.length; i++) { - if (!pMoves[i].disabled) { - moves.push(pMoves[i].id); - } - } - if (!moves.length) return ['struggle']; - return moves; - }; BattlePokemon.prototype.disableMove = function (moveid, isHidden, sourceEffect) { if (!sourceEffect && this.battle.event) { sourceEffect = this.battle.effect;