Search in sources :

Example 6 with TargetCard

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

the class DimensionalBreachReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(game.getActivePlayerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(morSet.stream().map(mor -> mor.getCard(game)).filter(Objects::nonNull).filter(c -> c.isOwnedBy(game.getActivePlayerId())).collect(Collectors.toSet()));
    if (cards.isEmpty()) {
        return false;
    }
    if (cards.size() > 1) {
        TargetCard target = new TargetCardInExile(StaticFilters.FILTER_CARD);
        target.setNotTarget(true);
        player.choose(outcome, cards, target, game);
        cards.clear();
        cards.add(target.getFirstTarget());
    }
    return player.moveCards(cards, Zone.BATTLEFIELD, source, game);
}
Also used : Player(mage.players.Player) TargetCardInExile(mage.target.common.TargetCardInExile) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 7 with TargetCard

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

the class DiscordantDirgeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent discordantDirge = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (discordantDirge == null) {
        return false;
    }
    int verseCounters = discordantDirge.getCounters(game).getCount(CounterType.VERSE);
    Player targetOpponent = game.getPlayer(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (targetOpponent == null || controller == null) {
        return false;
    }
    controller.lookAtCards(targetOpponent.getName() + " hand", targetOpponent.getHand(), game);
    TargetCard target = new TargetCard(0, verseCounters, Zone.HAND, new FilterCard());
    target.setNotTarget(true);
    if (!controller.choose(Outcome.Benefit, targetOpponent.getHand(), target, game)) {
        return false;
    }
    targetOpponent.discard(new CardsImpl(target.getTargets()), false, source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) CardsImpl(mage.cards.CardsImpl)

Example 8 with TargetCard

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

the class HatcherySpiderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int xValue = new CardsInControllerGraveyardCount(StaticFilters.FILTER_CARD_CREATURE).calculate(game, source, this);
    FilterCard filter = new FilterPermanentCard("green permanent card with mana value " + xValue + " or less");
    filter.add(new ColorPredicate(ObjectColor.GREEN));
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
    TargetCard target = new TargetCardInLibrary(filter);
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, xValue));
    if (player.chooseUse(outcome, "Put a card onto the battlefield?", source, game) && player.choose(outcome, cards, target, game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null && player.moveCards(card, Zone.BATTLEFIELD, source, game)) {
            cards.remove(card);
        }
    }
    while (!cards.isEmpty()) {
        Card card = cards.getRandom(game);
        player.getLibrary().putOnBottom(card, game);
        cards.remove(card);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCard(mage.target.TargetCard) CardsInControllerGraveyardCount(mage.abilities.dynamicvalue.common.CardsInControllerGraveyardCount) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard)

Example 9 with TargetCard

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

the class HauntedFengrafEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || player.getGraveyard().count(StaticFilters.FILTER_CARD_CREATURE, game) < 1) {
        return false;
    }
    TargetCard target = new TargetCardInYourGraveyard(StaticFilters.FILTER_CARD_CREATURE);
    target.setNotTarget(true);
    target.setRandom(true);
    target.chooseTarget(outcome, player.getId(), source, game);
    return player.moveCards(game.getCard(target.getFirstTarget()), Zone.HAND, source, game);
}
Also used : Player(mage.players.Player) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard)

Example 10 with TargetCard

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

the class HazoretsUndyingFuryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        controller.shuffleLibrary(source, game);
        // move cards from library to exile
        controller.moveCardsToExile(controller.getLibrary().getTopCards(game, 4), source, game, true, source.getSourceId(), sourceObject.getIdName());
        // cast the possible cards without paying the mana
        ExileZone hazoretsUndyingFuryExileZone = game.getExile().getExileZone(source.getSourceId());
        Cards cardsToCast = new CardsImpl();
        if (hazoretsUndyingFuryExileZone == null) {
            return true;
        }
        cardsToCast.addAll(hazoretsUndyingFuryExileZone.getCards(filter, source.getSourceId(), source.getControllerId(), game));
        while (controller.canRespond() && !cardsToCast.isEmpty()) {
            if (!controller.chooseUse(Outcome.PlayForFree, "Cast (another) a card exiled with " + sourceObject.getLogName() + " without paying its mana cost?", source, game)) {
                break;
            }
            TargetCard targetCard = new TargetCard(1, Zone.EXILED, new FilterCard("nonland card to cast for free"));
            if (controller.choose(Outcome.PlayForFree, cardsToCast, targetCard, game)) {
                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 : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) ExileZone(mage.game.ExileZone) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

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