Search in sources :

Example 76 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class CauldronsGiftEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    if (AdamantCondition.BLACK.apply(game, source)) {
        player.millCards(4, source, game);
    }
    if (player.getGraveyard().count(StaticFilters.FILTER_CARD_CREATURE, game) == 0 || !player.chooseUse(outcome, "Choose a creature card in your graveyard to return to the battlefield?", source, game)) {
        return true;
    }
    TargetCard target = new TargetCardInYourGraveyard(StaticFilters.FILTER_CARD_CREATURE_YOUR_GRAVEYARD);
    target.setNotTarget(true);
    if (!player.choose(outcome, player.getGraveyard(), target, game)) {
        return false;
    }
    Card card = game.getCard(target.getFirstTarget());
    if (card == null || !player.moveCards(card, Zone.BATTLEFIELD, source, game)) {
        return false;
    }
    Permanent permanent = game.getPermanent(card.getId());
    if (permanent != null) {
        permanent.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 77 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class CartographersSurveyEffect method actionWithSelectedCards.

@Override
protected void actionWithSelectedCards(Cards cards, Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        TargetCard target = new TargetCard(0, 2, Zone.LIBRARY, StaticFilters.FILTER_CARD_LANDS);
        controller.choose(outcome, cards, target, game);
        Cards pickedCards = new CardsImpl(target.getTargets());
        if (!pickedCards.isEmpty()) {
            cards.removeAll(pickedCards);
            controller.moveCards(pickedCards.getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null);
        }
    }
}
Also used : Player(mage.players.Player) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 78 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class CloneShellDiesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 4));
    if (!cards.isEmpty()) {
        TargetCard target1 = new TargetCard(Zone.LIBRARY, filter1);
        if (controller.choose(Outcome.Benefit, cards, target1, game)) {
            Card card = cards.get(target1.getFirstTarget(), game);
            if (card != null) {
                cards.remove(card);
                controller.moveCardsToExile(card, source, game, false, CardUtil.getCardExileZoneId(game, source), CardUtil.createObjectRealtedWindowTitle(source, game, "(Imprint)"));
                card.setFaceDown(true, game);
                Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
                if (permanent != null) {
                    permanent.imprint(card.getId(), game);
                }
            }
            target1.clearChosen();
        }
        controller.putCardsOnBottomOfLibrary(cards, game, source, true);
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 79 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class CruelFateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(source.getFirstTarget());
    if (controller == null || opponent == null) {
        return false;
    }
    Cards cards = new CardsImpl(opponent.getLibrary().getTopCards(game, 5));
    if (cards.isEmpty()) {
        return false;
    }
    if (cards.size() == 1) {
        return controller.moveCards(cards, Zone.GRAVEYARD, source, game);
    }
    TargetCard targetCard = new TargetCardInLibrary();
    controller.choose(outcome, cards, targetCard, game);
    Card card = game.getCard(targetCard.getFirstTarget());
    if (card != null) {
        controller.moveCards(card, Zone.GRAVEYARD, source, game);
        cards.remove(card);
    }
    return controller.putCardsOnTopOfLibrary(card, game, source, true);
}
Also used : Player(mage.players.Player) TargetCard(mage.target.TargetCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) TargetCard(mage.target.TargetCard)

Example 80 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class EcologicalAppreciationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int xValue = source.getManaCostsToPay().getX();
    FilterCard filter = new FilterCreatureCard();
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
    TargetCard targetCardsInLibrary = new TargetCardInLibrary(0, 4, filter) {

        @Override
        public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) {
            if (!super.canTarget(playerId, id, source, game)) {
                return false;
            }
            Card card = game.getCard(id);
            Set<Card> disallowedCards = this.getTargets().stream().map(game::getCard).collect(Collectors.toSet());
            return isValidTarget(card, disallowedCards);
        }
    };
    targetCardsInLibrary.setNotTarget(true);
    targetCardsInLibrary.withChooseHint("Step 1 of 2: Search library");
    player.choose(Outcome.PutCreatureInPlay, new CardsImpl(player.getLibrary().getCards(game)), targetCardsInLibrary, game);
    Cards cards = new CardsImpl(targetCardsInLibrary.getTargets());
    boolean status = !cards.isEmpty();
    if (status) {
        int remainingCards = 4 - cards.size();
        if (remainingCards > 0) {
            TargetCard targetCardsInGY = new TargetCardInYourGraveyard(0, remainingCards, filter) {

                @Override
                public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) {
                    if (!super.canTarget(playerId, id, source, game)) {
                        return false;
                    }
                    Card card = game.getCard(id);
                    Set<Card> disallowedCards = this.getTargets().stream().map(game::getCard).collect(Collectors.toSet());
                    Set<Card> checkList = new HashSet<>();
                    checkList.addAll(disallowedCards);
                    checkList.addAll(cards.getCards(game));
                    return isValidTarget(card, checkList);
                }
            };
            targetCardsInGY.setNotTarget(true);
            targetCardsInGY.withChooseHint("Step 2 of 2: Search graveyard");
            player.choose(Outcome.PutCreatureInPlay, new CardsImpl(player.getGraveyard().getCards(game)), targetCardsInGY, game);
            cards.addAll(targetCardsInGY.getTargets());
        }
        TargetOpponent targetOpponent = new TargetOpponent();
        targetOpponent.setNotTarget(true);
        player.choose(outcome, targetOpponent, source.getSourceId(), game);
        Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
        if (opponent == null) {
            status = false;
        }
        if (status) {
            TargetCard chosenCards = new TargetCard(2, Zone.ALL, StaticFilters.FILTER_CARD);
            chosenCards.setNotTarget(true);
            opponent.choose(outcome, cards, chosenCards, game);
            Cards toShuffle = new CardsImpl(chosenCards.getTargets().stream().map(game::getCard).collect(Collectors.toList()));
            player.putCardsOnTopOfLibrary(toShuffle, game, source, false);
            cards.removeAll(toShuffle);
            player.moveCards(cards, Zone.BATTLEFIELD, source, game);
        }
    }
    player.shuffleLibrary(source, game);
    return status;
}
Also used : Ability(mage.abilities.Ability) Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Game(mage.game.Game) UUID(java.util.UUID) HashSet(java.util.HashSet)

Aggregations

TargetCard (mage.target.TargetCard)309 Player (mage.players.Player)297 FilterCard (mage.filter.FilterCard)177 Card (mage.cards.Card)130 CardsImpl (mage.cards.CardsImpl)96 UUID (java.util.UUID)83 Cards (mage.cards.Cards)81 MageObject (mage.MageObject)80 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)52 Permanent (mage.game.permanent.Permanent)49 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)30 ApprovingObject (mage.ApprovingObject)26 TargetPlayer (mage.target.TargetPlayer)25 FilterCreatureCard (mage.filter.common.FilterCreatureCard)22 TargetOpponent (mage.target.common.TargetOpponent)22 TargetCardInHand (mage.target.common.TargetCardInHand)21 Target (mage.target.Target)19 FilterNonlandCard (mage.filter.common.FilterNonlandCard)18 FixedTarget (mage.target.targetpointer.FixedTarget)18 ArrayList (java.util.ArrayList)16