Search in sources :

Example 81 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary in project mage by magefree.

the class PyreOfHeroesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sacrificedPermanent = null;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost) {
            SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
            if (!sacrificeCost.getPermanents().isEmpty()) {
                sacrificedPermanent = sacrificeCost.getPermanents().get(0);
            }
            break;
        }
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (sacrificedPermanent == null || controller == null) {
        return false;
    }
    int newConvertedCost = sacrificedPermanent.getManaValue() + 1;
    FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost);
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, newConvertedCost));
    filter.add(CardType.CREATURE.getPredicate());
    filter.add(new SharesCreatureTypePredicate(sacrificedPermanent));
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    if (controller.searchLibrary(target, source, game)) {
        Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    }
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) SharesCreatureTypePredicate(mage.filter.predicate.mageobject.SharesCreatureTypePredicate) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 82 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary in project mage by magefree.

the class WuSpyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(this.getTargetPointer().getFirst(game, source));
    if (controller != null && opponent != null) {
        Cards cards = new CardsImpl(opponent.getLibrary().getTopCards(game, 2));
        if (!cards.isEmpty()) {
            TargetCard target = new TargetCardInLibrary(new FilterCard("card to put into graveyard"));
            controller.choose(Outcome.Benefit, cards, target, game);
            Card card = cards.get(target.getFirstTarget(), game);
            if (card != null) {
                cards.remove(card);
                controller.moveCards(card, Zone.GRAVEYARD, source, game);
            }
        }
        return true;
    }
    return false;
}
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) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 83 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary in project mage by magefree.

the class ArmoredSkyhunterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 6));
    TargetCardInLibrary targetCard = new TargetCardInLibrary(0, 1, filter);
    player.choose(outcome, cards, targetCard, game);
    Card card = game.getCard(targetCard.getFirstTarget());
    if (card == null) {
        return player.putCardsOnBottomOfLibrary(cards, game, source, false);
    }
    player.moveCards(card, Zone.BATTLEFIELD, source, game);
    cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.LIBRARY);
    Permanent equipment = game.getPermanent(card.getId());
    if (equipment == null || !equipment.hasSubtype(SubType.EQUIPMENT, game)) {
        return player.putCardsOnBottomOfLibrary(cards, game, source, false);
    }
    TargetPermanent targetPermanent = new TargetControlledCreaturePermanent(0, 1);
    targetCard.setNotTarget(true);
    player.choose(outcome, targetPermanent, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(targetPermanent.getFirstTarget());
    if (permanent != null) {
        permanent.addAttachment(equipment.getId(), source, game);
    }
    return player.putCardsOnBottomOfLibrary(cards, game, source, false);
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard)

Example 84 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary in project mage by magefree.

the class BlossomPrancerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 5));
    TargetCard target = new TargetCardInLibrary(0, 1, filter);
    player.choose(outcome, cards, target, game);
    Card card = game.getCard(target.getFirstTarget());
    if (card != null) {
        player.revealCards(source, new CardsImpl(card), game);
        player.moveCards(card, Zone.HAND, source, game);
        cards.remove(card);
        player.putCardsOnBottomOfLibrary(card, game, source, false);
    } else {
        player.putCardsOnBottomOfLibrary(card, game, source, false);
        player.gainLife(4, game, source);
    }
    return true;
}
Also used : Player(mage.players.Player) TargetCard(mage.target.TargetCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 85 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary in project mage by magefree.

the class CongregationAtDawnEffect 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 && sourceObject != null) {
        TargetCardInLibrary target = new TargetCardInLibrary(0, 3, new FilterCreatureCard("creature cards"));
        if (controller.searchLibrary(target, source, game)) {
            if (!target.getTargets().isEmpty()) {
                Cards revealed = new CardsImpl();
                for (UUID cardId : target.getTargets()) {
                    Card card = controller.getLibrary().remove(cardId, game);
                    revealed.add(card);
                }
                controller.revealCards(sourceObject.getName(), revealed, game);
                controller.shuffleLibrary(source, game);
                TargetCard targetToLib = new TargetCard(Zone.LIBRARY, new FilterCard(textTop));
                while (revealed.size() > 1 && controller.canRespond()) {
                    controller.choose(Outcome.Neutral, revealed, targetToLib, game);
                    Card card = revealed.get(targetToLib.getFirstTarget(), game);
                    if (card != null) {
                        revealed.remove(card);
                        controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, true, false);
                    }
                    targetToLib.clearChosen();
                }
                if (revealed.size() == 1) {
                    Card card = revealed.get(revealed.iterator().next(), game);
                    controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, true, false);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard)

Aggregations

TargetCardInLibrary (mage.target.common.TargetCardInLibrary)225 Player (mage.players.Player)207 FilterCard (mage.filter.FilterCard)120 Card (mage.cards.Card)110 Permanent (mage.game.permanent.Permanent)68 UUID (java.util.UUID)65 CardsImpl (mage.cards.CardsImpl)53 TargetCard (mage.target.TargetCard)53 MageObject (mage.MageObject)37 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)31 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)28 Cards (mage.cards.Cards)26 TargetPlayer (mage.target.TargetPlayer)19 FilterCreatureCard (mage.filter.common.FilterCreatureCard)18 FilterPermanent (mage.filter.FilterPermanent)14 TargetPermanent (mage.target.TargetPermanent)14 FixedTarget (mage.target.targetpointer.FixedTarget)14 Cost (mage.abilities.costs.Cost)13 SearchLibraryPutInHandEffect (mage.abilities.effects.common.search.SearchLibraryPutInHandEffect)13 SearchLibraryPutInPlayEffect (mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)12