Search in sources :

Example 1 with FilterBySubtypeCard

use of mage.filter.common.FilterBySubtypeCard in project mage by magefree.

the class HauntingVoyageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    SubType chosenSubType = ChooseCreatureTypeEffect.getChosenCreatureType(source.getSourceId(), game);
    if (controller != null && chosenSubType != null) {
        Set<Card> cardsToBattlefield = new LinkedHashSet<>();
        if (!ForetoldCondition.instance.apply(game, source)) {
            TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(0, 2, new FilterBySubtypeCard(chosenSubType), true);
            controller.chooseTarget(outcome, target, source, game);
            for (UUID cardId : target.getTargets()) {
                Card card = game.getCard(cardId);
                if (card != null) {
                    cardsToBattlefield.add(card);
                }
            }
        } else {
            for (UUID cardId : controller.getGraveyard()) {
                Card card = game.getCard(cardId);
                if (card != null && card.hasSubtype(chosenSubType, game)) {
                    cardsToBattlefield.add(card);
                }
            }
        }
        if (!cardsToBattlefield.isEmpty()) {
            controller.moveCards(cardsToBattlefield, Zone.BATTLEFIELD, source, game);
            return true;
        }
    }
    return false;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) SubType(mage.constants.SubType) FilterBySubtypeCard(mage.filter.common.FilterBySubtypeCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) UUID(java.util.UUID) FilterBySubtypeCard(mage.filter.common.FilterBySubtypeCard) Card(mage.cards.Card)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)1 UUID (java.util.UUID)1 Card (mage.cards.Card)1 SubType (mage.constants.SubType)1 FilterBySubtypeCard (mage.filter.common.FilterBySubtypeCard)1 Player (mage.players.Player)1 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)1