Search in sources :

Example 11 with FilterPermanentCard

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

the class KamahlsDruidicVowEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int xValue = source.getManaCostsToPay().getX();
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, xValue));
    controller.lookAtCards(source, null, cards, game);
    if (!cards.isEmpty()) {
        FilterCard filter = new FilterPermanentCard("land and/or legendary permanent cards with mana value " + xValue + " or less to put onto the battlefield");
        filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
        filter.add(Predicates.or(CardType.LAND.getPredicate(), SuperType.LEGENDARY.getPredicate()));
        TargetCard target1 = new TargetCard(0, Integer.MAX_VALUE, Zone.LIBRARY, filter);
        target1.setNotTarget(true);
        controller.choose(Outcome.PutCardInPlay, cards, target1, game);
        Cards toBattlefield = new CardsImpl(target1.getTargets());
        cards.removeAll(toBattlefield);
        controller.moveCards(toBattlefield.getCards(game), Zone.BATTLEFIELD, source, game, false, false, false, null);
        controller.moveCards(cards, Zone.GRAVEYARD, source, game);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 12 with FilterPermanentCard

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

the class ZirilanOfTheClawEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        FilterPermanentCard filter = new FilterPermanentCard("a Dragon permanent card");
        filter.add(SubType.DRAGON.getPredicate());
        TargetCardInLibrary target = new TargetCardInLibrary(filter);
        if (controller.searchLibrary(target, source, game)) {
            Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
            if (card != null) {
                controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                Permanent permanent = game.getPermanent(card.getId());
                if (permanent != null) {
                    // gains haste
                    ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
                    effect.setTargetPointer(new FixedTarget(permanent, game));
                    game.addEffect(effect, source);
                    // Exile at begin of next end step
                    ExileTargetEffect exileEffect = new ExileTargetEffect(null, null, Zone.BATTLEFIELD);
                    exileEffect.setTargetPointer(new FixedTarget(permanent, game));
                    DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
                    game.addDelayedTriggeredAbility(delayedAbility, source);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterPermanentCard(mage.filter.common.FilterPermanentCard) Card(mage.cards.Card) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 13 with FilterPermanentCard

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

the class GenesisHydraPutOntoBattlefieldEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Object obj = getValue(CastSourceTriggeredAbility.SOURCE_CAST_SPELL_ABILITY);
    if (controller != null && obj instanceof SpellAbility) {
        int count = ((SpellAbility) obj).getManaCostsToPay().getX();
        if (count > 0) {
            Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, count));
            controller.revealCards(source, cards, game);
            FilterCard filter = new FilterPermanentCard("a nonland permanent card with mana value " + count + " or less to put onto the battlefield");
            filter.add(Predicates.not(CardType.LAND.getPredicate()));
            filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, count + 1));
            TargetCard target1 = new TargetCard(Zone.LIBRARY, filter);
            target1.setRequired(false);
            if (cards.count(filter, controller.getId(), source.getSourceId(), game) > 0) {
                if (controller.choose(Outcome.PutCardInPlay, cards, target1, game)) {
                    Card card = cards.get(target1.getFirstTarget(), game);
                    if (card != null) {
                        cards.remove(card);
                        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                    }
                    target1.clearChosen();
                } else {
                    game.informPlayers(controller.getLogName() + " didn't choose anything");
                }
            } else {
                game.informPlayers("No nonland permanent card with mana value " + count + " or less to choose.");
            }
            if (!cards.isEmpty()) {
                controller.moveCards(cards, Zone.LIBRARY, source, game);
                controller.shuffleLibrary(source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) SpellAbility(mage.abilities.SpellAbility) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard) TargetCard(mage.target.TargetCard)

Example 14 with FilterPermanentCard

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

the class GenesisWaveEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int xValue = source.getManaCostsToPay().getX();
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, xValue));
    if (!cards.isEmpty()) {
        controller.revealCards(source, cards, game);
        FilterCard filter = new FilterPermanentCard("cards with mana value " + xValue + " or less to put onto the battlefield");
        filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
        TargetCard target1 = new TargetCard(0, Integer.MAX_VALUE, Zone.LIBRARY, filter);
        target1.setNotTarget(true);
        controller.choose(Outcome.PutCardInPlay, cards, target1, game);
        Cards toBattlefield = new CardsImpl(target1.getTargets());
        cards.removeAll(toBattlefield);
        controller.moveCards(toBattlefield.getCards(game), Zone.BATTLEFIELD, source, game, false, false, false, null);
        controller.moveCards(cards, Zone.GRAVEYARD, source, game);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCard(mage.target.TargetCard)

Example 15 with FilterPermanentCard

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

the class KodamaOfTheEastTreeWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Object obj = this.getValue("permanentEnteringBattlefield");
    if (!(obj instanceof Permanent)) {
        return false;
    }
    Permanent permanent = (Permanent) obj;
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    FilterCard filter = new FilterPermanentCard("a permanent card with mana value " + permanent.getManaValue() + " or less");
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, permanent.getManaValue() + 1));
    TargetCardInHand target = new TargetCardInHand(filter);
    if (!target.canChoose(source.getSourceId(), source.getControllerId(), game) || !player.chooseUse(outcome, "Put a permanent card onto the battlefield?", source, game)) {
        return false;
    }
    player.choose(outcome, target, source.getSourceId(), game);
    Card card = game.getCard(target.getFirstTarget());
    if (card == null) {
        return false;
    }
    player.moveCards(card, Zone.BATTLEFIELD, source, game);
    Permanent otherPermanent = game.getPermanent(card.getId());
    if (otherPermanent == null) {
        return false;
    }
    KodamaOfTheEastTreeWatcher watcher = game.getState().getWatcher(KodamaOfTheEastTreeWatcher.class);
    if (watcher != null) {
        watcher.addPermanent(otherPermanent, source, game);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard)

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