/*
* Get moves learned by levelling up
*/
for (int i = 1; i <= level; i++) {
if (ps.getLevelMoves().containsKey(i)) {
MoveListEntry m = moveList.getMove(ps.getLevelMoves().get(i));
boolean exists = false;
/* Check if this move is already in the list of possible moves */
for (int j = 0; j < possibleMoves.size(); j++) {
if (possibleMoves.get(j) != null
&& possibleMoves.get(j).getName() != null && m != null
&& m.getName() != null
&& possibleMoves.get(j).getName().equalsIgnoreCase(m.getName())) {
exists = true;
break;
}
}
/* If the move is not already in the list, add it to the list */
if (!exists) possibleMoves.add(m);
}
}
/*
* possibleMoves sometimes has null moves stored in it, get rid of them
*/
for (int i = 0; i < possibleMoves.size(); i++) {
if (possibleMoves.get(i) == null) possibleMoves.remove(i);
}
possibleMoves.trimToSize();
/*
* Now the store the final set of moves for the Pokemon
*/
if (possibleMoves.size() <= 4) {
for (int i = 0; i < possibleMoves.size(); i++) {
moves[i] = possibleMoves.get(i);
}
} else {
MoveListEntry m = null;
for (int i = 0; i < 4; i++) {
if (possibleMoves.size() == 0) {
moves[i] = null;
} else {
m = possibleMoves.get(random.nextInt(possibleMoves.size()));