Search in sources :

Example 1 with FilterPermanentCard

use of mage.filter.common.FilterPermanentCard in project mage by magefree.

the class HatcherySpiderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int xValue = new CardsInControllerGraveyardCount(StaticFilters.FILTER_CARD_CREATURE).calculate(game, source, this);
    FilterCard filter = new FilterPermanentCard("green permanent card with mana value " + xValue + " or less");
    filter.add(new ColorPredicate(ObjectColor.GREEN));
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
    TargetCard target = new TargetCardInLibrary(filter);
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, xValue));
    if (player.chooseUse(outcome, "Put a card onto the battlefield?", source, game) && player.choose(outcome, cards, target, game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null && player.moveCards(card, Zone.BATTLEFIELD, source, game)) {
            cards.remove(card);
        }
    }
    while (!cards.isEmpty()) {
        Card card = cards.getRandom(game);
        player.getLibrary().putOnBottom(card, game);
        cards.remove(card);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCard(mage.target.TargetCard) CardsInControllerGraveyardCount(mage.abilities.dynamicvalue.common.CardsInControllerGraveyardCount) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard)

Example 2 with FilterPermanentCard

use of mage.filter.common.FilterPermanentCard in project mage by magefree.

the class NissaStewardOfElementsToken method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int count = 1 + new CountersSourceCount(CounterType.LOYALTY).calculate(game, source, this);
    FilterPermanentCard filter = new FilterPermanentCard();
    filter.add(Predicates.or(CardType.CREATURE.getPredicate(), CardType.LAND.getPredicate()));
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, count));
    Card card = controller.getLibrary().getFromTop(game);
    if (card != null) {
        controller.lookAtCards(source, null, new CardsImpl(card), game);
        if (filter.match(card, game)) {
            if (controller.chooseUse(outcome, "Put " + card.getName() + " onto the battlefield?", source, game)) {
                controller.moveCards(card, Zone.BATTLEFIELD, source, game);
            }
        }
    }
    return true;
}
Also used : CountersSourceCount(mage.abilities.dynamicvalue.common.CountersSourceCount) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card) FilterPermanentCard(mage.filter.common.FilterPermanentCard)

Example 3 with FilterPermanentCard

use of mage.filter.common.FilterPermanentCard in project mage by magefree.

the class ZarethSanTheTricksterTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Player opponent = game.getPlayer(event.getPlayerId());
    if (opponent == null || !event.getSourceId().equals(this.sourceId) || !((DamagedEvent) event).isCombatDamage()) {
        return false;
    }
    FilterCard filter = new FilterPermanentCard("permanent card in " + opponent.getLogName() + "'s graveyard");
    filter.add(new OwnerIdPredicate(opponent.getId()));
    this.getTargets().clear();
    this.addTarget(new TargetCardInGraveyard(filter));
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) DamagedEvent(mage.game.events.DamagedEvent)

Example 4 with FilterPermanentCard

use of mage.filter.common.FilterPermanentCard 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);
}
Also used : FilterCard(mage.filter.FilterCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) SearchLibraryPutInPlayEffect(mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)

Example 5 with FilterPermanentCard

use of mage.filter.common.FilterPermanentCard in project mage by magefree.

the class EurekaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        PlayerList playerList = game.getState().getPlayerList().copy();
        while (!playerList.get().equals(source.getControllerId()) && controller.canRespond()) {
            playerList.getNext();
        }
        Player currentPlayer = game.getPlayer(playerList.get());
        UUID firstInactivePlayer = null;
        Target target = new TargetCardInHand(new FilterPermanentCard());
        while (controller.canRespond()) {
            if (firstInactivePlayer == null) {
                firstInactivePlayer = currentPlayer.getId();
            }
            if (currentPlayer != null && currentPlayer.canRespond() && game.getState().getPlayersInRange(controller.getId(), game).contains(currentPlayer.getId())) {
                target.clearChosen();
                if (target.canChoose(source.getSourceId(), currentPlayer.getId(), game) && currentPlayer.chooseUse(outcome, "Put permanent from your hand to play?", source, game)) {
                    if (target.chooseTarget(outcome, currentPlayer.getId(), source, game)) {
                        Card card = game.getCard(target.getFirstTarget());
                        if (card != null) {
                            currentPlayer.moveCards(card, Zone.BATTLEFIELD, source, game);
                            firstInactivePlayer = null;
                        }
                    }
                }
            }
            // get next player
            playerList.getNext();
            currentPlayer = game.getPlayer(playerList.get());
            // if all player since this player didn't put permanent in play finish the process
            if (currentPlayer != null && currentPlayer.getId().equals(firstInactivePlayer)) {
                break;
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterPermanentCard(mage.filter.common.FilterPermanentCard) PlayerList(mage.players.PlayerList) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterPermanentCard(mage.filter.common.FilterPermanentCard) Card(mage.cards.Card)

Aggregations

FilterPermanentCard (mage.filter.common.FilterPermanentCard)19 Player (mage.players.Player)16 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)12 FilterCard (mage.filter.FilterCard)11 Card (mage.cards.Card)9 Permanent (mage.game.permanent.Permanent)8 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)6 TargetCard (mage.target.TargetCard)5 CardsImpl (mage.cards.CardsImpl)4 TargetCardInHand (mage.target.common.TargetCardInHand)4 UUID (java.util.UUID)2 MageObject (mage.MageObject)2 SearchLibraryPutInPlayEffect (mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)2 Cards (mage.cards.Cards)2 FilterPermanent (mage.filter.FilterPermanent)2 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)2 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)2 ApprovingObject (mage.ApprovingObject)1 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)1 SpellAbility (mage.abilities.SpellAbility)1