Search in sources :

Example 1 with FilterEnchantmentCard

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;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) FilterEnchantmentCard(mage.filter.common.FilterEnchantmentCard) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterEnchantmentCard(mage.filter.common.FilterEnchantmentCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Aggregations

UUID (java.util.UUID)1 MageObject (mage.MageObject)1 Card (mage.cards.Card)1 Cards (mage.cards.Cards)1 CardsImpl (mage.cards.CardsImpl)1 FilterCreatureCard (mage.filter.common.FilterCreatureCard)1 FilterEnchantmentCard (mage.filter.common.FilterEnchantmentCard)1 Player (mage.players.Player)1 TargetCard (mage.target.TargetCard)1