use of mage.filter.FilterCard in project mage by magefree.
the class ThoughtpickerWitchEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (controller != null && opponent != null) {
Cards cards = new CardsImpl(opponent.getLibrary().getTopCards(game, 2));
if (!cards.isEmpty()) {
TargetCard target = new TargetCardInLibrary(new FilterCard("card to exile"));
if (controller.choose(Outcome.Exile, cards, target, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
opponent.moveCards(card, Zone.EXILED, source, game);
}
}
}
return true;
}
return false;
}
use of mage.filter.FilterCard 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.FilterCard in project mage by magefree.
the class WatchersOfTheDeadEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (controller != null) {
for (UUID opponentId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player opponent = game.getPlayer(opponentId);
if (opponent != null && !opponent.equals(controller)) {
TargetCard target = new TargetCardInYourGraveyard(2, 2, new FilterCard());
target.setNotTarget(true);
Cards cardsInGraveyard = opponent.getGraveyard();
if (cardsInGraveyard.size() > 1) {
opponent.choose(outcome, cardsInGraveyard, target, game);
for (Card cardInGraveyard : cardsInGraveyard.getCards(game)) {
if (!target.getTargets().contains(cardInGraveyard.getId())) {
opponent.moveCardToExileWithInfo(cardInGraveyard, CardUtil.getCardExileZoneId(game, source.getId()), sourceObject.getLogName(), source, game, Zone.GRAVEYARD, true);
}
}
}
}
}
return true;
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class GainProtectionFromColorTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent creature = game.getPermanent(getTargetPointer().getFirst(game, source));
if (creature != null) {
FilterCard protectionFilter = (FilterCard) ((ProtectionAbility) ability).getFilter();
protectionFilter.add(new ColorPredicate(choice.getColor()));
protectionFilter.setMessage(choice.getChoice());
((ProtectionAbility) ability).setFilter(protectionFilter);
creature.addAbility(ability, source.getSourceId(), game);
return true;
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class CastWithoutPayingManaCostEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int cmc = manaCost.calculate(game, source, this);
FilterCard filter = this.filter.copy();
filter.setMessage(filter.getMessage().replace("%mv", "" + cmc));
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, cmc + 1));
Target target = new TargetCardInHand(filter);
if (!target.canChoose(source.getSourceId(), controller.getId(), game) || !controller.chooseUse(Outcome.PlayForFree, "Cast " + CardUtil.addArticle(filter.getMessage()) + " without paying its mana cost?", source, game)) {
return true;
}
Card cardToCast = null;
boolean cancel = false;
while (controller.canRespond() && !cancel) {
if (controller.chooseTarget(Outcome.PlayForFree, target, source, game)) {
cardToCast = game.getCard(target.getFirstTarget());
if (cardToCast != null) {
if (cardToCast.getSpellAbility() == null) {
Logger.getLogger(CastWithoutPayingManaCostEffect.class).fatal("Card: " + cardToCast.getName() + " is no land and has no spell ability!");
cancel = true;
}
if (cardToCast.getSpellAbility().canChooseTarget(game, controller.getId())) {
cancel = true;
}
}
} else {
cancel = true;
}
}
if (cardToCast != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
}
return true;
}
Aggregations