Merge pull request #1828 from Slayer95/parse-choice

Hackmons: fix decisions being overriden for first-slot Struggle
This commit is contained in:
Guangcong Luo 2015-04-27 06:27:42 +00:00
commit 25bbdf9be3
3 changed files with 51 additions and 23 deletions

View File

@ -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) {
@ -873,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;
@ -4061,13 +4048,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;

View File

@ -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'];

View File

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