use of mage.filter.common.FilterEnchantmentCard in project mage by magefree.
the class BenefactionOfRhonasEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && controller != null) {
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 5));
boolean creatureCardFound = false;
boolean enchantmentCardFound = false;
for (UUID cardId : cards) {
Card card = game.getCard(cardId);
if (card != null) {
cards.add(card);
if (card.isCreature(game)) {
creatureCardFound = true;
}
if (card.isEnchantment(game)) {
enchantmentCardFound = true;
}
}
}
if (!cards.isEmpty()) {
controller.revealCards(sourceObject.getName(), cards, game);
if ((creatureCardFound || enchantmentCardFound) && controller.chooseUse(Outcome.DrawCard, "Put a creature card and/or enchantment card into your hand?", source, game)) {
TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCreatureCard("creature card to put into your hand"));
if (creatureCardFound && controller.chooseTarget(Outcome.DrawCard, cards, target, source, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
controller.moveCards(card, Zone.HAND, source, game);
}
}
target = new TargetCard(Zone.LIBRARY, new FilterEnchantmentCard("enchantment card to put into your hand"));
if (enchantmentCardFound && controller.chooseTarget(Outcome.DrawCard, cards, target, source, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
controller.moveCards(card, Zone.HAND, source, game);
}
}
}
}
controller.moveCards(cards, Zone.GRAVEYARD, source, game);
return true;
}
return false;
}
Aggregations