use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class GateToTheAfterlifeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
FilterCard filter = new FilterCard("card named " + cardName);
filter.add(new NamePredicate(cardName));
Card card = null;
// Graveyard check
if (controller.chooseUse(Outcome.Benefit, "Search your graveyard for " + cardName + "?", source, game)) {
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(1, 1, filter, true);
if (controller.choose(outcome, controller.getGraveyard(), target, game)) {
card = game.getCard(target.getFirstTarget());
}
}
// Hand check
if (card == null && controller.chooseUse(Outcome.Benefit, "Search your hand for " + cardName + "?", source, game)) {
TargetCardInHand target = new TargetCardInHand(0, 1, filter);
if (controller.choose(Outcome.PutCardInPlay, controller.getHand(), target, game)) {
card = game.getCard(target.getFirstTarget());
}
}
// Library check
boolean librarySearched = false;
if (card == null && controller.chooseUse(Outcome.Benefit, "Search your library for " + cardName + "?", source, game)) {
librarySearched = true;
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
card = game.getCard(target.getFirstTarget());
}
controller.shuffleLibrary(source, game);
}
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
if (librarySearched) {
controller.shuffleLibrary(source, game);
}
return true;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class GuardianProjectEffect method checkCondition.
// This is needed as checkInterveningIfClause can't access trigger event information
static boolean checkCondition(Permanent permanent, UUID controllerId, Game game) {
Player player = game.getPlayer(controllerId);
if (player == null) {
return false;
}
if (!permanent.getName().isEmpty()) {
FilterCard filterCard = new FilterCard();
filterCard.add(new NamePredicate(permanent.getName()));
filterCard.add(new OwnerIdPredicate(controllerId));
if (player.getGraveyard().count(filterCard, game) > 0) {
return false;
}
}
FilterPermanent filterPermanent = new FilterCreaturePermanent();
filterPermanent.add(new NamePredicate(permanent.getName()));
filterPermanent.add(Predicates.not(new CardIdPredicate(permanent.getId())));
filterPermanent.add(new ControllerIdPredicate(controllerId));
if (!game.getBattlefield().getActivePermanents(filterPermanent, controllerId, game).isEmpty()) {
return false;
}
return true;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class HomingLightningEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent targetPermanent = game.getPermanent(source.getFirstTarget());
if (targetPermanent == null) {
return false;
}
FilterCreaturePermanent filter = new FilterCreaturePermanent();
if (CardUtil.haveEmptyName(targetPermanent)) {
// if no name (face down creature) only the creature itself is selected
filter.add(new PermanentIdPredicate(targetPermanent.getId()));
} else {
filter.add(new NamePredicate(targetPermanent.getName()));
}
for (Permanent creature : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
if (creature != null) {
creature.damage(4, source.getSourceId(), source, game, false, true);
}
}
return true;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class NantukoShrineEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(getTargetPointer().getFirst(game, source));
if (spell != null) {
Player controller = game.getPlayer(spell.getControllerId());
if (controller != null) {
int count = 0;
String name = spell.getName();
FilterCard filterCardName = new FilterCard();
filterCardName.add(new NamePredicate(name));
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
count += player.getGraveyard().count(filterCardName, game);
}
}
if (count > 0) {
new SquirrelToken().putOntoBattlefield(count, game, source, spell.getControllerId());
}
return true;
}
}
return false;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class RegularExpression method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
List<NamePredicate> predicates = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_ANOTHER_CREATURE, source.getControllerId(), source.getSourceId(), game).stream().map(Permanent::getName).filter(Objects::nonNull).filter(s -> !s.isEmpty()).map(NamePredicate::new).collect(Collectors.toList());
FilterCard filter = new FilterCard("a creature card with the same name as another creature you control");
filter.add(Predicates.or(predicates));
return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true, true).apply(game, source);
}
Aggregations