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;
}
Aggregations