use of mage.filter.FilterCard in project mage by magefree.
the class MemoryLeakEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(source.getFirstTarget());
if (controller == null || opponent == null) {
return false;
}
opponent.revealCards(source, opponent.getHand(), game);
TargetCard target;
Cards cards;
if (controller.chooseUse(outcome, "Exile a card from hand or graveyard?", null, "Hand", "Graveyard", source, game)) {
FilterCard filter = new FilterNonlandCard("nonland card in " + opponent.getName() + "'s hand");
target = new TargetCard(Zone.HAND, filter);
target.setNotTarget(true);
cards = opponent.getHand();
} else {
FilterCard filter = new FilterNonlandCard("nonland card in " + opponent.getName() + "'s graveyard");
target = new TargetCard(Zone.GRAVEYARD, filter);
target.setNotTarget(true);
cards = opponent.getGraveyard();
}
if (controller.choose(outcome, cards, target, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
controller.moveCards(card, Zone.EXILED, source, game);
}
}
return true;
}
use of mage.filter.FilterCard in project mage by magefree.
the class MurmursFromBeyondEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && controller != null) {
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 3));
if (!cards.isEmpty()) {
controller.revealCards(staticText, cards, game);
Card cardToGraveyard;
if (cards.size() == 1) {
cardToGraveyard = cards.getRandom(game);
} else {
Player opponent;
Set<UUID> opponents = game.getOpponents(controller.getId());
if (opponents.size() == 1) {
opponent = game.getPlayer(opponents.iterator().next());
} else {
Target target = new TargetOpponent(true);
controller.chooseTarget(Outcome.Detriment, target, source, game);
opponent = game.getPlayer(target.getFirstTarget());
}
TargetCard target = new TargetCard(1, Zone.LIBRARY, new FilterCard());
opponent.chooseTarget(outcome, cards, target, source, game);
cardToGraveyard = game.getCard(target.getFirstTarget());
}
if (cardToGraveyard != null) {
controller.moveCards(cardToGraveyard, Zone.GRAVEYARD, source, game);
cards.remove(cardToGraveyard);
}
controller.moveCards(cards, Zone.HAND, source, game);
}
return true;
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class NissasEncouragementTarget method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Card sourceCard = game.getCard(source.getSourceId());
if (player == null || sourceCard == null) {
return false;
}
NissasEncouragementTarget target = new NissasEncouragementTarget(filter);
if (player.searchLibrary(target, source, game)) {
boolean searchGY = false;
if (target.getTargets().size() < 3) {
searchGY = true;
}
Map<String, Integer> foundCards = new HashMap<>();
foundCards.put("Forest", 0);
foundCards.put("Brambleweft Behemoth", 0);
foundCards.put("Nissa, Genesis Mage", 0);
Cards cards = new CardsImpl();
if (!target.getTargets().isEmpty()) {
for (UUID cardId : target.getTargets()) {
Card card = player.getLibrary().remove(cardId, game);
if (card != null) {
cards.add(card);
foundCards.put(card.getName(), 1);
}
}
}
if (searchGY) {
for (String name : foundCards.keySet()) {
if (foundCards.get(name) == 1) {
continue;
}
// Look in graveyard for any with this name
// never change static objects so copy the object here before
FilterCard namedFilterGY = filterGY.copy();
namedFilterGY.add(new NamePredicate(name));
if (player.getGraveyard().count(namedFilterGY, game) > 0) {
TargetCard targetGY = new TargetCard(0, 1, Zone.GRAVEYARD, namedFilterGY);
if (player.choose(Outcome.ReturnToHand, player.getGraveyard(), targetGY, game)) {
for (UUID cardIdGY : targetGY.getTargets()) {
Card cardGY = player.getGraveyard().get(cardIdGY, game);
cards.add(cardGY);
}
}
}
}
}
if (!cards.isEmpty()) {
player.revealCards(sourceCard.getIdName(), cards, game);
player.moveCards(cards, Zone.HAND, source, game);
player.shuffleLibrary(source, game);
return true;
}
}
player.shuffleLibrary(source, game);
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class PsychoticEpisodeEffect 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 FilterCard());
targetCard.setRequired(true);
Cards options = player.getHand().copy();
Card topdeck = player.getLibrary().getFromTop(game);
options.add(topdeck);
controller.lookAtCards("Top of Library (Psychotic Episode)", topdeck, game);
if (controller.choose(Outcome.Discard, options, 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);
}
}
return true;
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class RemembranceTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!((ZoneChangeEvent) event).isDiesEvent()) {
return false;
}
Permanent permanent = game.getPermanentOrLKIBattlefield(event.getTargetId());
if (permanent != null && filter.match(permanent, game)) {
FilterCard filterCard = new FilterCard("card named " + permanent.getName());
filterCard.add(new NamePredicate(permanent.getName()));
this.getEffects().clear();
this.addEffect(new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filterCard), true, true));
return true;
}
return false;
}
Aggregations