use of mage.filter.common.FilterNonlandCard in project mage by magefree.
the class TidehollowScullerLeaveEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(source.getFirstTarget());
// Then its first ability will resolve and exile the chosen card forever.
if (controller != null && opponent != null) {
opponent.revealCards("Tidehollow Sculler", opponent.getHand(), game);
TargetCard target = new TargetCard(Zone.HAND, new FilterNonlandCard("nonland card to exile"));
if (controller.choose(Outcome.Exile, opponent.getHand(), target, game)) {
Card card = opponent.getHand().get(target.getFirstTarget(), game);
if (card != null) {
controller.moveCardsToExile(card, source, game, true, CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()), "Tidehollow Sculler");
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterNonlandCard in project mage by magefree.
the class VenarianGlimmerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player != null) {
FilterCard filter = new FilterNonlandCard();
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));
Effect effect = new DiscardCardYouChooseTargetEffect(filter, TargetController.ANY);
effect.setTargetPointer(targetPointer);
effect.apply(game, source);
return true;
}
return false;
}
use of mage.filter.common.FilterNonlandCard in project mage by magefree.
the class VendilionCliqueEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (player != null && controller != null && sourceObject != null) {
TargetCard targetCard = new TargetCard(Zone.ALL, new FilterNonlandCard());
targetCard.setRequired(false);
if (controller.choose(Outcome.Discard, player.getHand(), targetCard, game)) {
Card card = game.getCard(targetCard.getFirstTarget());
if (card != null) {
CardsImpl cards = new CardsImpl();
cards.add(card);
player.revealCards(sourceObject.getIdName(), cards, game);
player.putCardsOnBottomOfLibrary(cards, game, source, true);
player.drawCards(1, source, game);
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterNonlandCard in project mage by magefree.
the class ShimianSpecterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (targetPlayer != null && sourceObject != null && controller != null) {
// reveal hand of target player
targetPlayer.revealCards(sourceObject.getName(), targetPlayer.getHand(), game);
// You choose a nonland card from it
TargetCard target = new TargetCard(Zone.HAND, new FilterNonlandCard());
target.setNotTarget(true);
Card chosenCard = null;
if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(Outcome.Benefit, targetPlayer.getHand(), target, source, game)) {
chosenCard = game.getCard(target.getFirstTarget());
}
// Exile all cards with the same name
// Building a card filter with the name
FilterCard filterNamedCards = new FilterCard();
// so no card matches
String nameToSearch = "---";
if (chosenCard != null) {
nameToSearch = CardUtil.getCardNameForSameNameSearch(chosenCard);
}
filterNamedCards.add(new NamePredicate(nameToSearch));
// search cards in graveyard
if (chosenCard != null) {
for (Card checkCard : targetPlayer.getGraveyard().getCards(game)) {
if (checkCard.getName().equals(chosenCard.getName())) {
controller.moveCardToExileWithInfo(checkCard, null, "", source, game, Zone.GRAVEYARD, true);
}
}
// search cards in hand
TargetCard targetHandCards = new TargetCard(0, Integer.MAX_VALUE, Zone.HAND, filterNamedCards);
controller.chooseTarget(Outcome.Benefit, targetPlayer.getHand(), targetHandCards, source, game);
for (UUID cardId : targetHandCards.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
controller.moveCardToExileWithInfo(card, null, "", source, game, Zone.HAND, true);
}
}
}
// that player's library and have that player shuffle it.
if (chosenCard != null || controller.chooseUse(outcome, "Search library anyway?", source, game)) {
TargetCardInLibrary targetCardsLibrary = new TargetCardInLibrary(0, Integer.MAX_VALUE, filterNamedCards);
controller.searchLibrary(targetCardsLibrary, source, game, targetPlayer.getId());
for (UUID cardId : targetCardsLibrary.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
controller.moveCardToExileWithInfo(card, null, "", source, game, Zone.LIBRARY, true);
}
}
targetPlayer.shuffleLibrary(source, game);
}
return true;
}
return false;
}
use of mage.filter.common.FilterNonlandCard in project mage by magefree.
the class TwinningGlassEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<Spell> spells = new ArrayList<>();
Permanent twinningGlass = game.getPermanent(source.getSourceId());
Player controller = game.getPlayer(source.getControllerId());
SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
if (twinningGlass == null) {
twinningGlass = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
}
if (twinningGlass != null && controller != null && watcher != null) {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
if (watcher.getSpellsCastThisTurn(playerId) != null) {
for (Spell spell : watcher.getSpellsCastThisTurn(playerId)) {
spells.add(spell);
}
}
}
if (spells.isEmpty()) {
return false;
}
List<NamePredicate> predicates = spells.stream().map(Spell::getName).filter(Objects::nonNull).filter(s -> !s.isEmpty()).map(NamePredicate::new).collect(Collectors.toList());
FilterNonlandCard filterCard = new FilterNonlandCard("nonland card that was cast this turn");
filterCard.add(Predicates.or(predicates));
TargetCard target = new TargetCard(0, 1, Zone.HAND, filterCard);
target.withChooseHint("free cast");
if (controller.choose(Outcome.PlayForFree, controller.getHand(), target, game)) {
Card chosenCard = game.getCard(target.getFirstTarget());
if (chosenCard != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + chosenCard.getId(), Boolean.TRUE);
Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(chosenCard, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + chosenCard.getId(), null);
return cardWasCast;
}
}
}
return false;
}
Aggregations