use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class PartnersWithSearchEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Player player = game.getPlayer(source.getFirstTarget());
if (player != null) {
FilterCard filter = new FilterCard("card named " + partnerName);
filter.add(new NamePredicate(partnerName));
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (player.chooseUse(Outcome.Benefit, "Search your library for a card named " + partnerName + " and put it into your hand?", source, game)) {
player.searchLibrary(target, source, game);
for (UUID cardId : target.getTargets()) {
Card card = player.getLibrary().getCard(cardId, game);
if (card != null) {
player.revealCards(source, new CardsImpl(card), game);
player.moveCards(card, Zone.HAND, source, game);
}
}
player.shuffleLibrary(source, game);
}
}
// prevent undo
controller.resetStoredBookmark(game);
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class RippleEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (player != null) {
if (!player.chooseUse(Outcome.Neutral, "Reveal " + rippleNumber + " cards from the top of your library?", source, game)) {
// fizzle
return true;
}
// reveal top cards from library
Cards cards = new CardsImpl();
cards.addAll(player.getLibrary().getTopCards(game, rippleNumber));
player.revealCards(sourceObject.getIdName(), cards, game);
// determine which card should be rippled
String cardNameToRipple = sourceObject.getName();
FilterCard sameNameFilter = new FilterCard("card(s) with the name: \"" + cardNameToRipple + "\" to cast without paying their mana cost");
sameNameFilter.add(new NamePredicate(cardNameToRipple));
TargetCard target1 = new TargetCard(Zone.LIBRARY, sameNameFilter);
target1.setRequired(false);
// choose cards to play for free
while (player.canRespond() && cards.count(sameNameFilter, game) > 0 && player.choose(Outcome.PlayForFree, cards, target1, game)) {
Card card = cards.get(target1.getFirstTarget(), game);
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
player.cast(player.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
cards.remove(card);
}
target1.clearChosen();
}
// move cards that weren't cast to the bottom of the library
player.putCardsOnBottomOfLibrary(cards, game, source, true);
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class DeputyOfDetentionExileEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
Permanent targeted = game.getPermanent(source.getFirstTarget());
if (permanent == null || controller == null || targeted == null) {
return false;
}
FilterPermanent filter = new FilterNonlandPermanent();
filter.add(new ControllerIdPredicate(targeted.getControllerId()));
filter.add(new NamePredicate(targeted.getName()));
Set<Card> toExile = new LinkedHashSet<>();
for (Permanent creature : game.getBattlefield().getActivePermanents(filter, controller.getId(), game)) {
toExile.add(creature);
}
if (!toExile.isEmpty()) {
controller.moveCardsToExile(toExile, source, game, true, CardUtil.getCardExileZoneId(game, source), permanent.getIdName());
new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility()).apply(game, source);
}
return true;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class DichotomancyEffect 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 (controller != null && opponent != null) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, opponent.getId(), game)) {
String name = permanent.getName();
FilterCard filterCard = new FilterCard("card named \"" + name + '"');
filterCard.add(new NamePredicate(name));
TargetCardInLibrary target = new TargetCardInLibrary(0, 1, filterCard);
if (controller.searchLibrary(target, source, game, opponent.getId())) {
controller.moveCards(opponent.getLibrary().getCard(target.getFirstTarget(), game), Zone.BATTLEFIELD, source, game);
}
}
opponent.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class ClarionUltimatumTarget method makeFilter.
private static FilterCard makeFilter(Set<String> names) {
FilterCard filter = new FilterCard();
filter.add(Predicates.or(names.stream().map(name -> new NamePredicate(name)).collect(Collectors.toSet())));
return filter;
}
Aggregations