Skip to content

Commit

Permalink
Fix Leppa Berry (#5025)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander B authored and Zarel committed Dec 14, 2018
1 parent 664975a commit eecde00
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
21 changes: 4 additions & 17 deletions data/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -2901,27 +2901,14 @@ let BattleItems = {
},
onUpdate: function (pokemon) {
if (!pokemon.hp) return;
let moveSlot = pokemon.lastMove && pokemon.getMoveData(pokemon.lastMove.id);
if (moveSlot && moveSlot.pp === 0) {
pokemon.addVolatile('leppaberry');
pokemon.volatiles['leppaberry'].moveSlot = moveSlot;
if (pokemon.moveSlots.some(move => move.pp === 0)) {
pokemon.eatItem();
}
},
onEat: function (pokemon) {
let moveSlot;
if (pokemon.volatiles['leppaberry']) {
moveSlot = pokemon.volatiles['leppaberry'].moveSlot;
pokemon.removeVolatile('leppaberry');
} else {
let pp = 99;
for (const possibleMoveSlot of pokemon.moveSlots) {
if (possibleMoveSlot.pp < pp) {
moveSlot = possibleMoveSlot;
pp = moveSlot.pp;
}
}
}
let moveSlot = pokemon.moveSlots.find(move => move.pp === 0) ||
pokemon.moveSlots.find(move => move.pp < move.maxpp);
if (!moveSlot) return;
moveSlot.pp += 10;
if (moveSlot.pp > moveSlot.maxpp) moveSlot.pp = moveSlot.maxpp;
this.add('-activate', pokemon, 'item: Leppa Berry', moveSlot.move, '[consumed]');
Expand Down
27 changes: 27 additions & 0 deletions test/simulator/items/leppaberry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const assert = require('./../../assert');
const common = require('./../../common');

let battle;

describe('Leppa Berry', function () {
afterEach(function () {
battle.destroy();
});

it('should restore PP to the first move with any PP missing when eaten forcibly', function () {
battle = common.createBattle([
[{species: 'Gyarados', ability: 'moxie', item: '', moves: ['sleeptalk', 'splash']}],
[{species: 'Geodude', ability: 'sturdy', item: 'leppaberry', moves: ['sleeptalk', 'fling']}],
]);

const pokemon = battle.p1.active[0];

battle.makeChoices('move sleeptalk', 'move sleeptalk');
battle.makeChoices('move splash', 'move fling');

assert.strictEqual(pokemon.getMoveData('sleeptalk').pp, 16);
assert.false.strictEqual(pokemon.getMoveData('splash').pp, 64);
});
});

0 comments on commit eecde00

Please sign in to comment.