use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class CheeringFanaticEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
new ChooseACardNameEffect(TypeOfName.ALL).apply(game, source);
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (cardName == null) {
return false;
}
FilterCard filter = new FilterCard();
filter.add(new NamePredicate(cardName));
ContinuousEffect effect = new SpellsCostReductionAllEffect(filter, 1);
effect.setDuration(Duration.EndOfTurn);
game.addEffect(effect, source);
return true;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class KotoseTheSilentSpiderWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Card card = game.getCard(getTargetPointer().getFirst(game, source));
if (controller == null || card == null) {
return false;
}
Player opponent = game.getPlayer(card.getOwnerId());
if (opponent == null) {
return false;
}
UUID exileId = CardUtil.getExileZoneId(game, source);
String exileName = CardUtil.getSourceName(game, source);
controller.moveCardsToExile(card, source, game, true, exileId, exileName);
Cards cards = new CardsImpl();
FilterCard filter = new FilterCard("cards named " + card.getName() + " from " + opponent.getName() + "'s graveyard");
filter.add(new NamePredicate(card.getName()));
TargetCardInGraveyard targetCardInGraveyard = new TargetCardInGraveyard(0, Integer.MAX_VALUE, filter);
controller.choose(outcome, opponent.getGraveyard(), targetCardInGraveyard, game);
cards.addAll(targetCardInGraveyard.getTargets());
filter.setMessage("cards named " + card.getName() + " from " + opponent.getName() + "'s hand");
TargetCardInHand targetCardInHand = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
controller.choose(outcome, opponent.getHand(), targetCardInHand, game);
cards.addAll(targetCardInHand.getTargets());
filter.setMessage("cards named " + card.getName() + " from " + opponent.getName() + "'s library");
TargetCardInLibrary target = new TargetCardInLibrary(0, Integer.MAX_VALUE, filter);
controller.searchLibrary(target, source, game, opponent.getId());
target.getTargets().stream().map(cardId -> opponent.getLibrary().getCard(cardId, game)).forEach(cards::add);
Set<Card> cardSet = cards.getCards(game);
controller.moveCardsToExile(cardSet, source, game, true, exileId, exileName);
opponent.shuffleLibrary(source, game);
cardSet.add(card);
if (cardSet.isEmpty() || source.getSourcePermanentIfItStillExists(game) == null) {
return true;
}
KotoseTheSilentSpiderWatcher.addCards(source, cardSet, game);
for (Card exiledCard : cardSet) {
CardUtil.makeCardPlayable(game, source, exiledCard, Duration.WhileControlled, true, null, new KotoseTheSilentSpiderCondition(exiledCard, game));
}
return true;
}
use of mage.filter.predicate.mageobject.NamePredicate 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.predicate.mageobject.NamePredicate 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;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class SecretSalvageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null) {
Card targetCard = game.getCard(getTargetPointer().getFirst(game, source));
if (targetCard != null) {
controller.moveCards(targetCard, Zone.EXILED, source, game);
String nameToSearch = CardUtil.getCardNameForSameNameSearch(targetCard);
FilterCard nameFilter = new FilterCard();
nameFilter.add(new NamePredicate(nameToSearch));
TargetCardInLibrary target = new TargetCardInLibrary(0, Integer.MAX_VALUE, nameFilter);
if (controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
Cards cards = new CardsImpl();
for (UUID cardId : target.getTargets()) {
Card card = controller.getLibrary().remove(cardId, game);
if (card != null) {
cards.add(card);
}
}
controller.revealCards(sourceObject.getIdName(), cards, game);
controller.moveCards(cards, Zone.HAND, source, game);
}
controller.shuffleLibrary(source, game);
return true;
}
}
}
return false;
}
Aggregations