@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Cards cards = new CardsImpl(Zone.PICK);
int count = Math.min(player.getLibrary().size(), 7);
for (int i = 0; i < count; i++) {
Card card = player.getLibrary().removeFromTop(game);
if (card != null) {
cards.add(card);
}
}
if (!cards.isEmpty()) {
TargetCard target = new TargetCard(Zone.PICK,
new FilterCreatureCard(
"creature card to put on the battlefield"));
if (player.choose(Outcome.PutCreatureInPlay, cards, target, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
card.putOntoBattlefield(game, Zone.PICK,
source.getSourceId(), source.getControllerId());
}
}
if (cards.size() > 0) {
TargetCard target2 = new TargetCard(Zone.PICK,
new FilterCard(
"card to put on the bottom of your library"));
while (player.isInGame() && cards.size() > 1) {
player.choose(Outcome.Benefit, cards, target2,
game);
Card card = cards.get(target2.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
player.getLibrary().putOnBottom(card, game);
}
target2.clearChosen();
}
Card card = cards.get(cards.iterator().next(), game);
cards.remove(card);
player.getLibrary().putOnBottom(card, game);
}
}
return false;