use of mage.filter.FilterCard 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);
}
use of mage.filter.FilterCard in project mage by magefree.
the class BrunaLightOfAlabasterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID bruna = source.getSourceId();
Player controller = game.getPlayer(source.getControllerId());
FilterPermanent filterAura = new FilterPermanent("Aura");
FilterCard filterAuraCard = new FilterCard("Aura card");
filterAura.add(CardType.ENCHANTMENT.getPredicate());
filterAura.add(SubType.AURA.getPredicate());
filterAura.add(new AuraPermanentCanAttachToPermanentId(bruna));
filterAuraCard.add(CardType.ENCHANTMENT.getPredicate());
filterAuraCard.add(SubType.AURA.getPredicate());
filterAuraCard.add(new AuraCardCanAttachToPermanentId(bruna));
if (controller == null) {
return false;
}
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent == null) {
return false;
}
List<Permanent> fromBattlefield = new ArrayList<>();
List<Card> fromHandGraveyard = new ArrayList<>();
int countBattlefield = game.getBattlefield().getAllActivePermanents(filterAura, game).size() - sourcePermanent.getAttachments().size();
while (controller.canRespond() && countBattlefield > 0 && controller.chooseUse(Outcome.Benefit, "Attach an Aura from the battlefield?", source, game)) {
Target targetAura = new TargetPermanent(filterAura);
targetAura.setNotTarget(true);
if (controller.choose(Outcome.Benefit, targetAura, source.getSourceId(), game)) {
Permanent aura = game.getPermanent(targetAura.getFirstTarget());
if (aura != null) {
Target target = aura.getSpellAbility().getTargets().get(0);
if (target != null) {
fromBattlefield.add(aura);
filterAura.add(Predicates.not(new CardIdPredicate(aura.getId())));
}
}
}
countBattlefield = game.getBattlefield().getAllActivePermanents(filterAura, game).size() - sourcePermanent.getAttachments().size();
}
int countHand = controller.getHand().count(filterAuraCard, game);
while (controller.canRespond() && countHand > 0 && controller.chooseUse(Outcome.Benefit, "Attach an Aura from your hand?", source, game)) {
TargetCard targetAura = new TargetCard(Zone.HAND, filterAuraCard);
if (controller.choose(Outcome.Benefit, controller.getHand(), targetAura, game)) {
Card aura = game.getCard(targetAura.getFirstTarget());
if (aura != null) {
Target target = aura.getSpellAbility().getTargets().get(0);
if (target != null) {
fromHandGraveyard.add(aura);
filterAuraCard.add(Predicates.not(new CardIdPredicate(aura.getId())));
}
}
}
countHand = controller.getHand().count(filterAuraCard, game);
}
int countGraveyard = controller.getGraveyard().count(filterAuraCard, game);
while (controller.canRespond() && countGraveyard > 0 && controller.chooseUse(Outcome.Benefit, "Attach an Aura from your graveyard?", source, game)) {
TargetCard targetAura = new TargetCard(Zone.GRAVEYARD, filterAuraCard);
if (controller.choose(Outcome.Benefit, controller.getGraveyard(), targetAura, game)) {
Card aura = game.getCard(targetAura.getFirstTarget());
if (aura != null) {
Target target = aura.getSpellAbility().getTargets().get(0);
if (target != null) {
fromHandGraveyard.add(aura);
filterAuraCard.add(Predicates.not(new CardIdPredicate(aura.getId())));
}
}
}
countGraveyard = controller.getGraveyard().count(filterAuraCard, game);
}
// Move permanents
for (Permanent aura : fromBattlefield) {
Permanent attachedTo = game.getPermanent(aura.getAttachedTo());
if (attachedTo != null) {
attachedTo.removeAttachment(aura.getId(), source, game);
}
sourcePermanent.addAttachment(aura.getId(), source, game);
}
// Move cards
for (Card aura : fromHandGraveyard) {
if (aura != null) {
game.getState().setValue("attachTo:" + aura.getId(), sourcePermanent);
controller.moveCards(aura, Zone.BATTLEFIELD, source, game);
sourcePermanent.addAttachment(aura.getId(), source, game);
}
}
return true;
}
use of mage.filter.FilterCard in project mage by magefree.
the class BrowseEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 5));
if (!cards.isEmpty()) {
controller.lookAtCards(source, null, cards, game);
TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put in your hand"));
if (controller.choose(Outcome.Benefit, cards, target, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.HAND, source, game);
cards.remove(card);
}
}
controller.moveCards(cards, Zone.EXILED, source, game);
}
return true;
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class CryptChampionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Set<Card> toBattlefield = new HashSet<>();
if (controller != null) {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
FilterCard filter = new FilterCreatureCard("creature card with mana value 3 or less from your graveyard");
filter.add(new OwnerIdPredicate(playerId));
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, 4));
Target target = new TargetCardInGraveyard(filter);
if (target.canChoose(source.getSourceId(), playerId, game) && player.chooseTarget(outcome, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
toBattlefield.add(card);
}
}
}
}
// must happen simultaneously Rule 101.4
controller.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game, false, false, true, null);
return true;
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class CrypticGatewayPredicate method apply.
@Override
public boolean apply(Game game, Ability source) {
if (source.getCosts() == null) {
return false;
}
FilterCard filter = new FilterCreatureCard("creature card from your hand that shares a creature type with each creature tapped this way");
for (Cost cost : source.getCosts()) {
if (cost instanceof CrypticGatewayCost) {
Predicate predicate = ((CrypticGatewayCost) cost).getPredicate();
filter.add(predicate);
return new PutCardFromHandOntoBattlefieldEffect(filter).apply(game, source);
}
}
return false;
}
Aggregations