Search in sources :

Example 21 with NamePredicate

use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.

the class SameNameAsExiledCountValue method calculate.

@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
    int value = 0;
    Permanent permanent = game.getPermanent(sourceAbility.getSourceId());
    if (permanent != null && !permanent.getImprinted().isEmpty()) {
        FilterPermanent filterPermanent = new FilterPermanent();
        filterPermanent.add(new NamePredicate(game.getCard(permanent.getImprinted().get(0)).getName()));
        value = game.getBattlefield().count(filterPermanent, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game);
    }
    return value;
}
Also used : NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent)

Example 22 with NamePredicate

use of mage.filter.predicate.mageobject.NamePredicate 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 23 with NamePredicate

use of mage.filter.predicate.mageobject.NamePredicate 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 24 with NamePredicate

use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.

the class CurseOfMisfortunesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent enchantment = game.getPermanent(source.getSourceId());
    if (controller != null && enchantment != null && enchantment.getAttachedTo() != null) {
        Player targetPlayer = game.getPlayer(enchantment.getAttachedTo());
        Player player = game.getPlayer(source.getControllerId());
        if (player != null && targetPlayer != null) {
            FilterCard filter = new FilterCard("Curse card that doesn't have the same name as a Curse attached to enchanted player");
            filter.add(SubType.CURSE.getPredicate());
            // get the names of attached Curses
            for (UUID attachmentId : targetPlayer.getAttachments()) {
                Permanent attachment = game.getPermanent(attachmentId);
                if (attachment != null && attachment.hasSubtype(SubType.CURSE, game)) {
                    filter.add(Predicates.not(new NamePredicate(attachment.getName())));
                }
            }
            TargetCardInLibrary targetCard = new TargetCardInLibrary(filter);
            if (player.searchLibrary(targetCard, source, game)) {
                Card card = game.getCard(targetCard.getFirstTarget());
                if (card != null) {
                    this.setTargetPointer(new FixedTarget(targetPlayer.getId()));
                    game.getState().setValue("attachTo:" + card.getId(), targetPlayer.getId());
                    if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
                        targetPlayer.addAttachment(card.getId(), source, game);
                    }
                }
            }
            player.shuffleLibrary(source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) FixedTarget(mage.target.targetpointer.FixedTarget) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 25 with NamePredicate

use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.

the class EchoingDecayEffect 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;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) BoostAllEffect(mage.abilities.effects.common.continuous.BoostAllEffect)

Aggregations

NamePredicate (mage.filter.predicate.mageobject.NamePredicate)78 FilterCard (mage.filter.FilterCard)55 Player (mage.players.Player)55 Permanent (mage.game.permanent.Permanent)31 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)30 Card (mage.cards.Card)24 MageObject (mage.MageObject)22 UUID (java.util.UUID)19 FilterPermanent (mage.filter.FilterPermanent)16 TargetCard (mage.target.TargetCard)14 Spell (mage.game.stack.Spell)12 CardsImpl (mage.cards.CardsImpl)10 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)10 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)9 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)8 ContinuousEffect (mage.abilities.effects.ContinuousEffect)7 Cards (mage.cards.Cards)7 TargetPlayer (mage.target.TargetPlayer)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6