Search in sources :

Example 91 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class CardTestPlayerAPIImpl method assertHandCount.

/**
 * Assert card count in player's hand.
 *
 * @param player   {@link Player} who's hand should be counted.
 * @param cardName Name of the cards that should be counted.
 * @param count    Expected count.
 */
public void assertHandCount(Player player, String cardName, int count) throws AssertionError {
    // Assert.assertNotEquals("", cardName);
    int actual;
    if (cardName.contains("//")) {
        // special logic for cheched split cards, because in game logic of card name filtering is different than for test
        actual = 0;
        for (Card card : currentGame.getPlayer(player.getId()).getHand().getCards(currentGame)) {
            if (CardUtil.haveSameNames(card.getName(), cardName, true)) {
                actual++;
            }
        }
    } else {
        FilterCard filter = new FilterCard();
        // must find any cards even without names
        filter.add(new NamePredicate(cardName, true));
        actual = currentGame.getPlayer(player.getId()).getHand().count(filter, player.getId(), currentGame);
    }
    Assert.assertEquals("(Hand) Card counts for card " + cardName + " for " + player.getName() + " are not equal ", count, actual);
}
Also used : FilterCard(mage.filter.FilterCard) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) PermanentCard(mage.game.permanent.PermanentCard)

Example 92 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class SearchLibraryWithLessCMCPutInPlayEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        // never change static objects so copy the object here before
        FilterCard advancedFilter = filter.copy();
        advancedFilter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));
        TargetCardInLibrary target = new TargetCardInLibrary(advancedFilter);
        if (controller.searchLibrary(target, source, game)) {
            if (!target.getTargets().isEmpty()) {
                Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
                if (card != null) {
                    controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                }
            }
            controller.shuffleLibrary(source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 93 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class AladdinsLampEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, source.getManaCostsToPay().getX()));
    controller.lookAtCards(source, null, cards, game);
    TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to stay at the top of library"));
    if (controller.choose(outcome, cards, target, game)) {
        cards.remove(target.getFirstTarget());
    }
    controller.putCardsOnBottomOfLibrary(cards, game, source, false);
    game.getState().processAction(game);
    controller.drawCards(1, source, game, event);
    discard();
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetCard(mage.target.TargetCard)

Example 94 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class AssemblyHallEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller == null || controller.getHand().isEmpty() || sourceObject == null) {
        return false;
    }
    Card cardToReveal = null;
    Target target = new TargetCardInHand(StaticFilters.FILTER_CARD_CREATURE);
    target.setNotTarget(true);
    if (controller.chooseTarget(outcome, target, source, game)) {
        cardToReveal = game.getCard(target.getFirstTarget());
    }
    if (cardToReveal == null) {
        return false;
    }
    controller.revealCards("from hand :" + sourceObject.getName(), new CardsImpl(cardToReveal), game);
    String nameToSearch = CardUtil.getCardNameForSameNameSearch(cardToReveal);
    FilterCard filterCard = new FilterCard("card named " + nameToSearch);
    filterCard.add(new NamePredicate(nameToSearch));
    return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filterCard), true, true).apply(game, source);
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) TargetCardInHand(mage.target.common.TargetCardInHand) MageObject(mage.MageObject) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) CardsImpl(mage.cards.CardsImpl) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 95 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class AshnodsCylixEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 3));
    player.lookAtCards(source, null, cards, game);
    TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put on top of your library"));
    if (player.choose(Outcome.Benefit, cards, target, game)) {
        Card card = cards.get(target.getFirstTarget(), game);
        if (card != null) {
            cards.remove(card);
            game.informPlayers(source.getSourceObject(game).getIdName() + ": " + player.getLogName() + " puts a card back on top of their library");
        }
    }
    player.moveCards(cards, Zone.EXILED, source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Aggregations

FilterCard (mage.filter.FilterCard)337 Player (mage.players.Player)287 Card (mage.cards.Card)148 TargetCard (mage.target.TargetCard)127 UUID (java.util.UUID)97 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)87 Permanent (mage.game.permanent.Permanent)79 MageObject (mage.MageObject)75 CardsImpl (mage.cards.CardsImpl)75 Cards (mage.cards.Cards)60 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)56 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)54 Target (mage.target.Target)41 TargetCardInHand (mage.target.common.TargetCardInHand)41 TargetPlayer (mage.target.TargetPlayer)35 ApprovingObject (mage.ApprovingObject)29 FilterCreatureCard (mage.filter.common.FilterCreatureCard)25 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)24 TargetCardInGraveyard (mage.target.common.TargetCardInGraveyard)22 ArrayList (java.util.ArrayList)21