Search in sources :

Example 36 with TargetCard

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

the class GiftsUngivenTarget method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Card sourceCard = game.getCard(source.getSourceId());
    if (player == null || sourceCard == null) {
        return false;
    }
    Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (opponent == null) {
        return false;
    }
    GiftsUngivenTarget target = new GiftsUngivenTarget();
    if (player.searchLibrary(target, source, game)) {
        if (!target.getTargets().isEmpty()) {
            Cards cards = new CardsImpl();
            for (UUID cardId : target.getTargets()) {
                Card card = player.getLibrary().remove(cardId, game);
                if (card != null) {
                    cards.add(card);
                }
            }
            player.revealCards(sourceCard.getIdName(), cards, game);
            CardsImpl cardsToKeep = new CardsImpl();
            if (cards.size() > 2) {
                cardsToKeep.addAll(cards);
                TargetCard targetDiscard = new TargetCard(2, Zone.LIBRARY, new FilterCard("cards to put in graveyard"));
                if (opponent.choose(Outcome.Discard, cards, targetDiscard, game)) {
                    cardsToKeep.removeAll(targetDiscard.getTargets());
                    cards.removeAll(cardsToKeep);
                }
            }
            player.moveCards(cards, Zone.GRAVEYARD, source, game);
            player.moveCards(cardsToKeep, Zone.HAND, source, game);
        }
        player.shuffleLibrary(source, game);
        return true;
    }
    player.shuffleLibrary(source, game);
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 37 with TargetCard

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

the class GrislySalvageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 5));
        boolean properCardFound = cards.count(filterPutInHand, game) > 0;
        if (!cards.isEmpty()) {
            controller.revealCards(source, cards, game);
            TargetCard target = new TargetCard(Zone.LIBRARY, filterPutInHand);
            if (properCardFound && controller.chooseUse(outcome, "Put a creature or land card from the revealed cards into your hand?", source, game) && controller.choose(Outcome.DrawCard, cards, target, game)) {
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    controller.moveCards(card, Zone.HAND, source, game);
                    cards.remove(card);
                }
            }
            controller.moveCards(cards, Zone.GRAVEYARD, source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 38 with TargetCard

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

the class HellcarverDemonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && sourceObject != null) {
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(source.getControllerId())) {
            if (!Objects.equals(permanent, sourceObject)) {
                permanent.sacrifice(source, game);
            }
        }
        if (!controller.getHand().isEmpty()) {
            int cardsInHand = controller.getHand().size();
            controller.discard(cardsInHand, false, false, source, game);
        }
        // move cards from library to exile
        Set<Card> currentExiledCards = new HashSet<>();
        currentExiledCards.addAll(controller.getLibrary().getTopCards(game, 6));
        controller.moveCardsToExile(currentExiledCards, source, game, true, source.getSourceId(), sourceObject.getIdName());
        // cast the possible cards without paying the mana
        Cards cardsToCast = new CardsImpl();
        cardsToCast.addAll(currentExiledCards);
        boolean alreadyCast = false;
        while (controller.canRespond() && !cardsToCast.isEmpty()) {
            if (!controller.chooseUse(outcome, "Cast a" + (alreadyCast ? "another" : "") + " card exiled with " + sourceObject.getLogName() + " without paying its mana cost?", source, game)) {
                break;
            }
            TargetCard targetCard = new TargetCard(1, Zone.EXILED, new FilterNonlandCard("nonland card to cast for free"));
            if (controller.choose(Outcome.PlayForFree, cardsToCast, targetCard, game)) {
                alreadyCast = true;
                Card card = game.getCard(targetCard.getFirstTarget());
                if (card != null) {
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                    Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                    cardsToCast.remove(card);
                    if (!cardWasCast) {
                        game.informPlayer(controller, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) HashSet(java.util.HashSet)

Example 39 with TargetCard

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

the class MundaAmbushLeaderEffect 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) {
        Cards allCards = new CardsImpl();
        allCards.addAll(controller.getLibrary().getTopCards(game, 4));
        controller.lookAtCards(sourceObject.getIdName(), allCards, game);
        if (!allCards.isEmpty()) {
            Cards cardsToReveal = new CardsImpl();
            TargetCard target = new TargetCard(0, Integer.MAX_VALUE, Zone.LIBRARY, filter);
            controller.chooseTarget(outcome, allCards, target, source, game);
            cardsToReveal.addAll(target.getTargets());
            if (!cardsToReveal.isEmpty()) {
                controller.revealCards(sourceObject.getIdName(), cardsToReveal, game, true);
                allCards.removeAll(cardsToReveal);
            }
            controller.putCardsOnTopOfLibrary(cardsToReveal, game, source, true);
        }
        if (!allCards.isEmpty()) {
            controller.putCardsOnBottomOfLibrary(allCards, game, source, true);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 40 with TargetCard

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

the class OKagachiMadeManifestEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (controller == null || player == null) {
        return false;
    }
    Card card;
    switch(controller.getGraveyard().count(StaticFilters.FILTER_CARD_A_NON_LAND, game)) {
        case 0:
            return false;
        case 1:
            card = controller.getGraveyard().getCards(StaticFilters.FILTER_CARD_A_NON_LAND, game).stream().findFirst().orElse(null);
            break;
        default:
            TargetCard target = new TargetCardInGraveyard(StaticFilters.FILTER_CARD_A_NON_LAND);
            target.setNotTarget(true);
            player.choose(Outcome.ReturnToHand, controller.getGraveyard(), target, game);
            card = game.getCard(target.getFirstTarget());
    }
    if (card == null) {
        return false;
    }
    int manaValue = card.getManaValue();
    player.moveCards(card, Zone.HAND, source, game);
    if (manaValue > 0) {
        game.addEffect(new BoostSourceEffect(manaValue, 0, Duration.EndOfTurn), source);
    }
    return true;
}
Also used : BoostSourceEffect(mage.abilities.effects.common.continuous.BoostSourceEffect) Player(mage.players.Player) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) TargetCard(mage.target.TargetCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

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