use of mage.filter.common.FilterNonlandCard in project mage by magefree.
the class MindleechMassEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
if (opponent != null && controller != null) {
Cards cardsInHand = new CardsImpl();
cardsInHand.addAll(opponent.getHand());
opponent.revealCards("Opponents hand", cardsInHand, game);
if (!cardsInHand.isEmpty() && !cardsInHand.getCards(new FilterNonlandCard(), game).isEmpty()) {
TargetCard target = new TargetCard(1, Zone.HAND, new FilterNonlandCard());
if (controller.chooseTarget(Outcome.PlayForFree, cardsInHand, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterNonlandCard in project mage by magefree.
the class SvellaIceShaperEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Set<Card> cardsSet = controller.getLibrary().getTopCards(game, 4);
Cards cards = new CardsImpl(cardsSet);
TargetCard target = new TargetCardInLibrary(0, 1, new FilterNonlandCard("card to cast without paying its mana cost"));
controller.choose(Outcome.PlayForFree, cards, target, game);
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card == null) {
controller.putCardsOnBottomOfLibrary(cards, game, source, false);
return true;
}
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
if (cardWasCast) {
cards.remove(card);
}
controller.putCardsOnBottomOfLibrary(cards, game, source, false);
return true;
}
use of mage.filter.common.FilterNonlandCard in project mage by magefree.
the class VillainousWealthEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
if (controller != null && mageObject != null) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
FilterCard filter = new FilterNonlandCard();
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));
UUID exileId = CardUtil.getCardExileZoneId(game, source);
if (player != null) {
Cards cardsToExile = new CardsImpl();
cardsToExile.addAll(player.getLibrary().getTopCards(game, source.getManaCostsToPay().getX()));
controller.moveCards(cardsToExile, Zone.EXILED, source, game);
if (controller.chooseUse(Outcome.PlayForFree, "Cast cards exiled with " + mageObject.getLogName() + " without paying its mana cost?", source, game)) {
OuterLoop: while (cardsToExile.count(filter, game) > 0) {
if (!controller.canRespond()) {
return false;
}
TargetCardInExile target = new TargetCardInExile(0, 1, filter, exileId, false);
target.setNotTarget(true);
while (controller.canRespond() && cardsToExile.count(filter, game) > 0 && controller.choose(Outcome.PlayForFree, cardsToExile, target, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
if (cardWasCast) {
cardsToExile.remove(card);
}
} else {
break OuterLoop;
}
target.clearChosen();
}
}
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterNonlandCard in project mage by magefree.
the class NightsnareDiscardEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
if (player == null || controller == null) {
return false;
}
if (player.getHand().isEmpty()) {
return true;
}
Cards revealedCards = new CardsImpl();
revealedCards.addAll(player.getHand());
Card sourceCard = game.getCard(source.getSourceId());
player.revealCards(sourceCard != null ? sourceCard.getIdName() : "Discard", revealedCards, game);
// You may choose a nonland card from it.
if (!controller.chooseUse(outcome, "Choose a card to discard? (Otherwise " + player.getLogName() + " has to discard 2 cards).", source, game)) {
player.discard(2, false, false, source, game);
return true;
}
TargetCard target = new TargetCard(1, Zone.HAND, new FilterNonlandCard());
if (controller.choose(Outcome.Benefit, revealedCards, target, game)) {
Card card = revealedCards.get(target.getFirstTarget(), game);
player.discard(card, false, source, game);
}
return true;
}
use of mage.filter.common.FilterNonlandCard in project mage by magefree.
the class SpectersShriekEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player player = game.getPlayer(source.getFirstTarget());
if (controller == null || player == null) {
return false;
}
player.revealCards(source, player.getHand(), game);
if (player.getHand().count(StaticFilters.FILTER_CARD_NON_LAND, game) == 0 || !controller.chooseUse(Outcome.Benefit, "Exile a card from " + player.getName() + "'s hand?", source, game)) {
return false;
}
TargetCard target = new TargetCard(Zone.HAND, new FilterNonlandCard());
target.setNotTarget(true);
target.setRequired(false);
if (!controller.chooseTarget(Outcome.Benefit, player.getHand(), target, source, game)) {
return false;
}
Card card = game.getCard(target.getFirstTarget());
if (card == null) {
return false;
}
boolean isBlack = card.getColor(game).isBlack();
player.moveCards(card, Zone.EXILED, source, game);
if (isBlack || controller.getHand().isEmpty()) {
return true;
}
target = new TargetCardInHand(filter);
target.setNotTarget(true);
return controller.choose(Outcome.Detriment, controller.getHand(), target, game) && controller.moveCards(game.getCard(target.getFirstTarget()), Zone.EXILED, source, game);
}
Aggregations