use of mage.filter.FilterCard in project mage by magefree.
the class DesperateResearchEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
Player player = game.getPlayer(source.getControllerId());
if (player == null || cardName == null) {
return false;
}
Cards cardsToExile = new CardsImpl(player.getLibrary().getTopCards(game, 7));
player.revealCards(source, cardsToExile, game);
FilterCard filter = new FilterCard();
filter.add(new NamePredicate(cardName));
Cards cardsToKeep = new CardsImpl(cardsToExile.getCards(filter, game));
cardsToExile.removeAll(cardsToKeep);
player.moveCards(cardsToKeep, Zone.HAND, source, game);
player.moveCards(cardsToExile, Zone.EXILED, source, game);
return true;
}
use of mage.filter.FilterCard in project mage by magefree.
the class DenyingWindEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && player != null) {
TargetCardInLibrary target = new TargetCardInLibrary(0, 7, new FilterCard("cards from player's library to exile"));
if (controller.searchLibrary(target, source, game, player.getId())) {
List<UUID> targets = target.getTargets();
for (UUID targetId : targets) {
Card card = player.getLibrary().remove(targetId, game);
if (card != null) {
controller.moveCardToExileWithInfo(card, null, null, source, game, Zone.LIBRARY, true);
}
}
}
player.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class FinalPartingEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
// Unlike Jarad's Orders, which this mostly copies, you can't fail to find
TargetCardInLibrary target = new TargetCardInLibrary(2, 2, new FilterCard());
if (controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
Cards searched = new CardsImpl();
for (UUID cardId : target.getTargets()) {
Card card = controller.getLibrary().getCard(cardId, game);
searched.add(card);
}
if (target.getTargets().size() == 2) {
TargetCard target2 = new TargetCard(Zone.LIBRARY, filter);
controller.choose(Outcome.Benefit, searched, target2, game);
Card card = searched.get(target2.getFirstTarget(), game);
controller.moveCards(card, Zone.HAND, source, game);
searched.remove(card);
Set<Card> cards = searched.getCards(game);
card = cards.isEmpty() ? null : cards.iterator().next();
controller.moveCards(card, Zone.GRAVEYARD, source, game);
} else if (target.getTargets().size() == 1) {
Set<Card> cards = searched.getCards(game);
Card card = cards.isEmpty() ? null : cards.iterator().next();
controller.moveCards(card, Zone.HAND, source, game);
}
}
controller.shuffleLibrary(source, game);
return true;
}
controller.shuffleLibrary(source, game);
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class JandorsRingWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
JandorsRingWatcher watcher = game.getState().getWatcher(JandorsRingWatcher.class);
if (watcher != null) {
UUID cardId = watcher.getLastDrewCard(source.getControllerId());
Card card = game.getCard(cardId);
if (card != null) {
FilterCard filter = new FilterCard(card.getName());
filter.add(new CardIdPredicate(card.getId()));
DiscardCardYouChooseTargetEffect effect = new DiscardCardYouChooseTargetEffect(filter, TargetController.YOU);
if (effect.apply(game, source)) {
// Conditional was already checked, card should be in hand, but if for some weird reason it fails, the card won't be drawn, although the cost will already be paid
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
controller.drawCards(1, source, game);
}
}
}
return true;
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class LichsMasteryLoseLifeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
FilterPermanent filter = new FilterPermanent();
filter.add(new ControllerIdPredicate(controller.getId()));
for (int i = 0; i < amount; i++) {
int handCount = controller.getHand().size();
int graveCount = controller.getGraveyard().size();
int permCount = game.getBattlefield().getActivePermanents(filter, controller.getId(), game).size();
if (graveCount + handCount == 0 || (permCount > 0 && controller.chooseUse(Outcome.Exile, "Exile permanent you control? (No = from hand or graveyard)", source, game))) {
Target target = new TargetControlledPermanent(1, 1, new FilterControlledPermanent(), true);
controller.choose(outcome, target, source.getSourceId(), game);
Effect effect = new ExileTargetEffect();
effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
effect.apply(game, source);
} else if (graveCount == 0 || (handCount > 0 && controller.chooseUse(Outcome.Exile, "Exile a card from your hand? (No = from graveyard)", source, game))) {
Target target = new TargetCardInHand(1, 1, new FilterCard());
controller.choose(outcome, target, source.getSourceId(), game);
Card card = controller.getHand().get(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.EXILED, source, game);
}
} else if (graveCount > 0) {
Target target = new TargetCardInYourGraveyard(1, 1, new FilterCard(), true);
target.choose(Outcome.Exile, source.getControllerId(), source.getSourceId(), game);
Card card = controller.getGraveyard().get(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.EXILED, source, game);
}
}
}
return true;
}
Aggregations