mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-05-05 21:17:43 -05:00
Merge pull request #1828 from Slayer95/parse-choice
Hackmons: fix decisions being overriden for first-slot Struggle
This commit is contained in:
commit
25bbdf9be3
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
|
|
|
|||
44
test/simulator/misc/choice-parser.js
Normal file
44
test/simulator/misc/choice-parser.js
Normal 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');
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user