Card card;
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
ExileZone exile = game.getExile().createZone(source.getSourceId(), player.getName() + " Cascade");
Card stackCard = game.getCard(targetPointer.getFirst(game, source));
if (stackCard == null) {
return false;
}
int sourceCost = stackCard.getManaCost().convertedManaCost();
do {
card = player.getLibrary().removeFromTop(game);
if (card == null) {
break;
}
player.moveCardToExileWithInfo(card, source.getSourceId(), exile.getName(), source.getSourceId(), game, Zone.LIBRARY);
} while (card.getCardType().contains(CardType.LAND) || card.getManaCost().convertedManaCost() >= sourceCost);
if (card != null) {
if (player.chooseUse(outcome, "Use cascade effect on " + card.getName() + "?", game)) {
player.cast(card.getSpellAbility(), game, true);
exile.remove(card.getId());
}
}
while (exile.size() > 0) {
card = exile.getRandom(game);
exile.remove(card.getId());
player.moveCardToLibraryWithInfo(card, source.getSourceId(), game, Zone.EXILED, false, false);
}
return true;
}