Search in sources :

Example 56 with NamePredicate

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

the class MindblazeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    Player playerControls = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (player == null || playerControls == null || sourceObject == null) {
        return false;
    }
    Choice numberChoice = new ChoiceImpl();
    numberChoice.setMessage("Choose a number greater than 0");
    Set<String> numbers = new HashSet<>();
    for (int i = 1; i <= 4; i++) {
        numbers.add(Integer.toString(i));
    }
    numberChoice.setChoices(numbers);
    String cardName = ChooseACardNameEffect.TypeOfName.NON_LAND_NAME.getChoice(playerControls, game, source, false);
    playerControls.choose(Outcome.Neutral, numberChoice, game);
    game.informPlayers(sourceObject.getIdName() + " - Chosen number: [" + numberChoice.getChoice() + ']');
    Cards cards = new CardsImpl();
    cards.addAll(player.getLibrary().getCards(game));
    playerControls.revealCards("Library", cards, game);
    FilterCard filter = new FilterCard();
    filter.add(new NamePredicate(cardName));
    int count = Integer.parseInt(numberChoice.getChoice());
    if (player.getLibrary().count(filter, game) == count) {
        player.damage(8, source.getSourceId(), source, game);
    }
    player.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Choice(mage.choices.Choice) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) HashSet(java.util.HashSet)

Example 57 with NamePredicate

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

the class PackHuntEffect 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 SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 3, filter), true).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) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 58 with NamePredicate

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

the class TibaltsTrickeryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
    if (spell != null) {
        String spellName = spell.getName();
        Player controller = game.getPlayer(spell.getControllerId());
        game.getStack().counter(spell.getId(), source, game);
        if (controller != null) {
            int random = RandomUtil.nextInt(3) + 1;
            game.informPlayers(random + " was chosen at random");
            controller.millCards(random, source, game);
            Card cardToCast = null;
            Set<Card> cardsToExile = new HashSet<>();
            FilterCard filter = new FilterCard();
            filter.add(Predicates.not(CardType.LAND.getPredicate()));
            filter.add(Predicates.not(new NamePredicate(spellName)));
            for (Card card : controller.getLibrary().getCards(game)) {
                cardsToExile.add(card);
                if (filter.match(card, game)) {
                    cardToCast = card;
                    break;
                }
            }
            controller.moveCardsToExile(cardsToExile, source, game, true, source.getSourceId(), CardUtil.createObjectRealtedWindowTitle(source, game, null));
            if (cardToCast != null) {
                if (controller.chooseUse(Outcome.PlayForFree, "Cast " + cardToCast.getLogName() + " for free?", source, game)) {
                    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);
                }
            }
            ExileZone exile = game.getExile().getExileZone(source.getSourceId());
            if (exile != null) {
                controller.putCardsOnBottomOfLibrary(exile, game, source, false);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) ApprovingObject(mage.ApprovingObject) ExileZone(mage.game.ExileZone) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 59 with NamePredicate

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

the class WoodSageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller == null || sourceObject == null) {
        return false;
    }
    String cardName = ChooseACardNameEffect.TypeOfName.CREATURE_NAME.getChoice(controller, game, source, false);
    FilterCreatureCard filter = new FilterCreatureCard("all of them with that name");
    filter.add(new NamePredicate(cardName));
    new RevealLibraryPutIntoHandEffect(4, filter, Zone.GRAVEYARD).apply(game, source);
    return true;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) RevealLibraryPutIntoHandEffect(mage.abilities.effects.common.RevealLibraryPutIntoHandEffect) MageObject(mage.MageObject)

Example 60 with NamePredicate

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

the class CloneTest method testCopyNightmare.

// copy Nightmare test, check that the P/T setting effect ends
// if the clone leaves battlefield
@Test
public void testCopyNightmare() {
    addCard(Zone.BATTLEFIELD, playerA, "Island", 5);
    addCard(Zone.BATTLEFIELD, playerA, "Swamp", 1);
    addCard(Zone.BATTLEFIELD, playerB, "Swamp", 6);
    addCard(Zone.BATTLEFIELD, playerB, "Forest", 1);
    // Target creature you control gets +1/+1 and gains hexproof until end of turn. (It can't be the target of spells or abilities your opponents control.)
    addCard(Zone.HAND, playerB, "Ranger's Guile");
    addCard(Zone.HAND, playerA, "Clone");
    // Return target nonland permanent to its owner's hand.
    addCard(Zone.HAND, playerA, "Disperse");
    addCard(Zone.BATTLEFIELD, playerB, "Nightmare", 1);
    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Clone");
    setChoice(playerA, "Nightmare");
    castSpell(1, PhaseStep.BEGIN_COMBAT, playerB, "Ranger's Guile", "Nightmare");
    castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Disperse", "Nightmare");
    setStopAt(2, PhaseStep.UPKEEP);
    execute();
    assertPermanentCount(playerB, "Nightmare", 1);
    assertPowerToughness(playerB, "Nightmare", 6, 6);
    assertPermanentCount(playerA, "Nightmare", 0);
    assertHandCount(playerA, "Disperse", 0);
    FilterCard filter = new FilterCard();
    filter.add(new NamePredicate("Clone"));
    Card card = playerA.getHand().getCards(filter, currentGame).iterator().next();
    if (card != null) {
        Assert.assertEquals("Power has to be 0 because copy from nightmare P/T ability may no longer be applied", 0, card.getPower().getValue());
    }
    Logger.getLogger(CloneTest.class).debug("EXISTING CONTINUOUS EFFECTS:");
    for (ContinuousEffectsList effectsList : currentGame.getContinuousEffects().allEffectsLists) {
        for (Object anEffectsList : effectsList) {
            ContinuousEffect effect = (ContinuousEffect) anEffectsList;
            Logger.getLogger(CloneTest.class).debug("- " + effect.toString());
        }
    }
}
Also used : FilterCard(mage.filter.FilterCard) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) ContinuousEffectsList(mage.abilities.effects.ContinuousEffectsList) ContinuousEffect(mage.abilities.effects.ContinuousEffect) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card) Test(org.junit.Test)

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