use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class CephalidShrineEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int count = 0;
MageObject mageObject = game.getObject(source.getSourceId());
if (mageObject != null) {
Spell spell = (Spell) game.getState().getValue("cephalidShrine" + mageObject);
if (spell != null) {
Player controller = game.getPlayer(spell.getControllerId());
if (controller != null) {
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);
}
}
// even if the cost is 0, we still offer
Cost cost = ManaUtil.createManaCost(count, true);
if (game.getStack().contains(spell) && cost.canPay(source, source, controller.getId(), game) && controller.chooseUse(outcome, "Pay " + cost.getText() + " to prevent countering " + spell.getName() + "?", source, game) && cost.pay(source, game, source, controller.getId(), false) && cost.isPaid()) {
return false;
} else {
game.getStack().counter(spell.getId(), source, game);
game.informPlayers(spell.getName() + " has been countered due to " + controller.getName() + " not paying " + cost.getText());
return true;
}
}
}
}
return false;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class DoublingChantTarget method makeFilter.
private static FilterCard makeFilter(Set<String> names) {
FilterCard filter = new FilterCreatureCard();
filter.add(Predicates.or(names.stream().map(name -> new NamePredicate(name)).collect(Collectors.toSet())));
return filter;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class MoratoriumStoneEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getFirstTarget());
if (card == null) {
return false;
}
String cardName = card.getName();
FilterCard filter1 = new FilterCard();
filter1.add(new NamePredicate(cardName));
FilterPermanent filter2 = new FilterPermanent();
filter2.add(new NamePredicate(cardName));
return new ExileGraveyardAllPlayersEffect(filter1).apply(game, source) && new ExileAllEffect(filter2).apply(game, source);
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class ThoughtHemorrhageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (sourceObject != null && controller != null && cardName != null && !cardName.isEmpty()) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (targetPlayer != null) {
targetPlayer.revealCards("hand of " + targetPlayer.getName(), targetPlayer.getHand(), game);
int cardsFound = 0;
for (Card card : targetPlayer.getHand().getCards(game)) {
if (CardUtil.haveSameNames(card, cardName, game)) {
cardsFound++;
}
}
if (cardsFound > 0) {
targetPlayer.damage(3 * cardsFound, source.getSourceId(), source, game);
}
// Exile all cards with the same name
// Building a card filter with the name
FilterCard filterNamedCards = new FilterCard();
filterNamedCards.add(new NamePredicate(cardName));
Set<Card> toExile = new LinkedHashSet<>();
// search cards in graveyard
for (Card checkCard : targetPlayer.getGraveyard().getCards(game)) {
if (checkCard.getName().equals(cardName)) {
toExile.add(checkCard);
}
}
// search cards in Hand
TargetCard targetCardInHand = new TargetCard(0, Integer.MAX_VALUE, Zone.HAND, filterNamedCards);
if (controller.chooseTarget(Outcome.Exile, targetPlayer.getHand(), targetCardInHand, source, game)) {
List<UUID> targets = targetCardInHand.getTargets();
for (UUID targetId : targets) {
Card targetCard = targetPlayer.getHand().get(targetId, game);
if (targetCard != null) {
toExile.add(targetCard);
}
}
}
// search cards in Library
// If the player has no nonland cards in their hand, you can still search
// that player's library and have that player shuffle it.
TargetCardInLibrary targetCardsLibrary = new TargetCardInLibrary(0, Integer.MAX_VALUE, filterNamedCards);
controller.searchLibrary(targetCardsLibrary, source, game, targetPlayer.getId());
for (UUID cardId : targetCardsLibrary.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
toExile.add(card);
}
}
controller.moveCards(toExile, Zone.EXILED, source, game);
targetPlayer.shuffleLibrary(source, game);
return true;
}
}
return false;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class BifurcateEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
FilterCard filter = new FilterPermanentCard();
filter.add(new NamePredicate(permanent.getName()));
return new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filter)).apply(game, source);
}
Aggregations