Search in sources :

Example 56 with TargetCardInLibrary

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

the class SkyclavePlunderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int xValue = 3 + PartyCount.instance.calculate(game, source, this);
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, xValue));
    int toTake = Math.min(cards.size(), 3);
    TargetCard target = new TargetCardInLibrary(toTake, toTake, StaticFilters.FILTER_CARD);
    player.choose(outcome, cards, target, game);
    Cards toHand = new CardsImpl(target.getTargets());
    cards.removeIf(target.getTargets()::contains);
    player.moveCards(toHand, Zone.HAND, source, game);
    player.putCardsOnBottomOfLibrary(cards, game, source, false);
    return true;
}
Also used : Player(mage.players.Player) TargetCard(mage.target.TargetCard) PartyCountHint(mage.abilities.hint.common.PartyCountHint) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 57 with TargetCardInLibrary

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

the class StonehewerGiantEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    FilterCard filter = new FilterCard("Equipment");
    filter.add(SubType.EQUIPMENT.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 equipment = game.getPermanent(card.getId());
            Target targetCreature = new TargetControlledCreaturePermanent();
            targetCreature.setNotTarget(true);
            if (equipment != null && controller.choose(Outcome.BoostCreature, targetCreature, source.getSourceId(), game)) {
                Permanent permanent = game.getPermanent(targetCreature.getFirstTarget());
                permanent.addAttachment(equipment.getId(), source, game);
            }
        }
    }
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 58 with TargetCardInLibrary

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

the class SameNameAsExiledCountValue method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    TargetCardInLibrary target = new TargetCardInLibrary(new FilterLandCard());
    if (player.searchLibrary(target, source, game)) {
        if (!target.getTargets().isEmpty()) {
            UUID cardId = target.getTargets().get(0);
            Card card = player.getLibrary().remove(cardId, game);
            if (card != null) {
                card.moveToExile(source.getSourceId(), "Strata Scythe", source, game);
                Permanent permanent = game.getPermanent(source.getSourceId());
                if (permanent != null) {
                    permanent.imprint(card.getId(), game);
                }
            }
        }
    }
    player.shuffleLibrary(source, game);
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterLandCard(mage.filter.common.FilterLandCard) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterLandCard(mage.filter.common.FilterLandCard) Card(mage.cards.Card)

Example 59 with TargetCardInLibrary

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

the class WinotaJoinerOfForcesEffect 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 targetCardInLibrary = new TargetCardInLibrary(0, 1, filter);
    player.choose(outcome, cards, targetCardInLibrary, game);
    Card card = game.getCard(targetCardInLibrary.getFirstTarget());
    if (card == null || !player.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, true, null)) {
        return player.putCardsOnBottomOfLibrary(cards, game, source, false);
    }
    Permanent permanent = game.getPermanent(card.getId());
    if (permanent == null) {
        return player.putCardsOnBottomOfLibrary(cards, game, source, false);
    }
    game.getCombat().addAttackingCreature(permanent.getId(), game);
    cards.remove(card);
    game.addEffect(new GainAbilityTargetEffect(IndestructibleAbility.getInstance(), Duration.EndOfTurn).setTargetPointer(new FixedTarget(permanent, game)), source);
    return player.putCardsOnBottomOfLibrary(cards, game, source, false);
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard)

Example 60 with TargetCardInLibrary

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

the class SearchLibraryGraveyardPutInHandEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    Card cardFound = null;
    boolean needShuffle = false;
    if (controller != null && sourceObject != null) {
        if (forceToSearchBoth || controller.chooseUse(outcome, "Search your library for a card named " + filter.getMessage() + '?', source, game)) {
            TargetCardInLibrary target = new TargetCardInLibrary(0, 1, filter);
            target.clearChosen();
            if (controller.searchLibrary(target, source, game)) {
                if (!target.getTargets().isEmpty()) {
                    cardFound = game.getCard(target.getFirstTarget());
                }
            }
            needShuffle = true;
        }
        if (cardFound == null && controller.chooseUse(outcome, "Search your graveyard for a card named " + filter.getMessage() + '?', source, game)) {
            TargetCard target = new TargetCardInYourGraveyard(0, 1, filter, true);
            target.clearChosen();
            if (controller.choose(outcome, controller.getGraveyard(), target, game)) {
                if (!target.getTargets().isEmpty()) {
                    cardFound = game.getCard(target.getFirstTarget());
                }
            }
        }
        if (cardFound != null) {
            controller.revealCards(sourceObject.getIdName(), new CardsImpl(cardFound), game);
            controller.moveCards(cardFound, Zone.HAND, source, game);
        }
        if (needShuffle) {
            controller.shuffleLibrary(source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

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