use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class CastSplitCardsWithCostModificationTest method prepareReduceEffect.
private void prepareReduceEffect(String cardNameToReduce, int reduceAmount) {
FilterCard filter = new FilterCard();
filter.add(new NamePredicate(cardNameToReduce));
addCustomCardWithAbility("reduce", playerA, new SimpleStaticAbility(new SpellsCostReductionAllEffect(filter, reduceAmount)));
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class SearchTargetGraveyardHandLibraryForCardNameAndExileEffect method applySearchAndExile.
/**
* @param game
* @param source
* @param cardName name of the card to exile
* @param targetPlayerId id of the target player to exile card name from his
* or her zones
* @return
*/
public boolean applySearchAndExile(Game game, Ability source, String cardName, UUID targetPlayerId) {
Player controller = game.getPlayer(source.getControllerId());
if (cardName != null && controller != null) {
Player targetPlayer = game.getPlayer(targetPlayerId);
if (targetPlayer != null) {
FilterCard filter = new FilterCard("card named " + cardName);
filter.add(new NamePredicate(cardName));
// cards in Graveyard
int cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getGraveyard().count(filter, game));
if (cardsCount > 0) {
filter.setMessage("card named " + cardName + " in the graveyard of " + targetPlayer.getName());
TargetCard target = new TargetCard((graveyardExileOptional ? 0 : cardsCount), cardsCount, Zone.GRAVEYARD, filter);
if (controller.choose(Outcome.Exile, targetPlayer.getGraveyard(), target, game)) {
controller.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
}
}
// cards in Hand
cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getHand().count(filter, game));
filter.setMessage("card named " + cardName + " in the hand of " + targetPlayer.getName());
TargetCard target = new TargetCard(0, cardsCount, Zone.HAND, filter);
if (controller.choose(Outcome.Exile, targetPlayer.getHand(), target, game)) {
controller.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
}
// cards in Library
Cards cardsInLibrary = new CardsImpl();
cardsInLibrary.addAll(targetPlayer.getLibrary().getCards(game));
cardsCount = (cardName.isEmpty() ? 0 : cardsInLibrary.count(filter, game));
filter.setMessage("card named " + cardName + " in the library of " + targetPlayer.getLogName());
TargetCardInLibrary targetLib = new TargetCardInLibrary(0, cardsCount, filter);
if (controller.choose(Outcome.Exile, cardsInLibrary, targetLib, game)) {
controller.moveCards(new CardsImpl(targetLib.getTargets()), 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 EchoingCourageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source));
if (targetPermanent != null) {
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()));
}
ContinuousEffect effect = new BoostAllEffect(2, 2, Duration.EndOfTurn, filter, false);
game.addEffect(effect, source);
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class ReturnToHandAllNamedPermanentsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (controller != null && permanent != null) {
FilterPermanent filter = new FilterPermanent();
if (CardUtil.haveEmptyName(permanent)) {
// if no name (face down creature) only the creature itself is selected
filter.add(new PermanentIdPredicate(permanent.getId()));
} else {
filter.add(new NamePredicate(permanent.getName()));
}
Cards cardsToHand = new CardsImpl();
for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
cardsToHand.add(perm);
}
controller.moveCards(cardsToHand, Zone.HAND, source, game);
return true;
}
return true;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class LobotomyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (targetPlayer != null && sourceObject != null && controller != null) {
// reveal hand of target player
targetPlayer.revealCards(sourceObject.getIdName(), targetPlayer.getHand(), game);
// You choose card other than a basic land card
TargetCard target = new TargetCard(Zone.HAND, filter);
target.setNotTarget(true);
Card chosenCard = null;
if (controller.chooseTarget(Outcome.Benefit, targetPlayer.getHand(), target, source, game)) {
chosenCard = game.getCard(target.getFirstTarget());
}
// Exile all cards with the same name
// Building a card filter with the name
FilterCard filterNamedCards = new FilterCard();
// so no card matches
String nameToSearch = "---";
if (chosenCard != null) {
nameToSearch = CardUtil.getCardNameForSameNameSearch(chosenCard);
filterNamedCards.setMessage("cards named " + nameToSearch);
}
filterNamedCards.add(new NamePredicate(nameToSearch));
Cards cardsToExile = new CardsImpl();
// search cards in graveyard
if (chosenCard != null) {
for (Card checkCard : targetPlayer.getGraveyard().getCards(game)) {
if (checkCard.getName().equals(chosenCard.getName())) {
cardsToExile.add(checkCard);
}
}
// search cards in hand
TargetCard targetCardsHand = new TargetCard(0, Integer.MAX_VALUE, Zone.HAND, filterNamedCards);
controller.chooseTarget(outcome, targetPlayer.getHand(), targetCardsHand, source, game);
for (UUID cardId : targetCardsHand.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
cardsToExile.add(card);
}
}
}
// If the player has no nonland cards in their hand, you can still search that player's library and have that player shuffle it.
if (chosenCard != null || controller.chooseUse(outcome, "Search library anyway?", source, game)) {
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) {
cardsToExile.add(card);
}
}
}
if (!cardsToExile.isEmpty()) {
controller.moveCards(cardsToExile, Zone.EXILED, source, game);
}
targetPlayer.shuffleLibrary(source, game);
return true;
}
return false;
}
Aggregations