Search in sources :

Example 91 with TargetCardInHand

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

the class GateToTheAfterlifeEffect 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("card named " + cardName);
    filter.add(new NamePredicate(cardName));
    Card card = null;
    // Graveyard check
    if (controller.chooseUse(Outcome.Benefit, "Search your graveyard for " + cardName + "?", source, game)) {
        TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(1, 1, filter, true);
        if (controller.choose(outcome, controller.getGraveyard(), target, game)) {
            card = game.getCard(target.getFirstTarget());
        }
    }
    // Hand check
    if (card == null && controller.chooseUse(Outcome.Benefit, "Search your hand for " + cardName + "?", source, game)) {
        TargetCardInHand target = new TargetCardInHand(0, 1, filter);
        if (controller.choose(Outcome.PutCardInPlay, controller.getHand(), target, game)) {
            card = game.getCard(target.getFirstTarget());
        }
    }
    // Library check
    boolean librarySearched = false;
    if (card == null && controller.chooseUse(Outcome.Benefit, "Search your library for " + cardName + "?", source, game)) {
        librarySearched = true;
        TargetCardInLibrary target = new TargetCardInLibrary(filter);
        if (controller.searchLibrary(target, source, game)) {
            card = game.getCard(target.getFirstTarget());
        }
        controller.shuffleLibrary(source, game);
    }
    if (card != null) {
        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    }
    if (librarySearched) {
        controller.shuffleLibrary(source, game);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 92 with TargetCardInHand

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

the class KamahlsSummonsEffect 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) {
        Map<UUID, Integer> revealedCards = new HashMap<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                if (player.getHand().count(StaticFilters.FILTER_CARD_CREATURE, game) > 0) {
                    TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, StaticFilters.FILTER_CARD_CREATURE);
                    if (player.choose(outcome, target, source.getSourceId(), game)) {
                        Cards cards = new CardsImpl(target.getTargets());
                        controller.revealCards(sourceObject.getIdName(), cards, game);
                        revealedCards.put(playerId, target.getTargets().size());
                    }
                }
            }
        }
        Token token = new BearToken();
        for (Map.Entry<UUID, Integer> revealedCardsByPlayer : revealedCards.entrySet()) {
            int value = revealedCardsByPlayer.getValue();
            if (value > 0) {
                token.putOntoBattlefield(value, game, source, revealedCardsByPlayer.getKey());
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) HashMap(java.util.HashMap) TargetCardInHand(mage.target.common.TargetCardInHand) MageObject(mage.MageObject) BearToken(mage.game.permanent.token.BearToken) Token(mage.game.permanent.token.Token) BearToken(mage.game.permanent.token.BearToken) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 93 with TargetCardInHand

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

the class KroxaTitanOfDeathsHungerDiscardEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Cards cards = new CardsImpl();
    game.getOpponents(source.getControllerId()).stream().map(game::getPlayer).filter(Objects::nonNull).forEachOrdered(player -> {
        if (player.getHand().size() == 0) {
            return;
        }
        TargetCard target = new TargetCardInHand(1, StaticFilters.FILTER_CARD);
        player.choose(Outcome.Discard, player.getHand(), target, game);
        cards.add(target.getFirstTarget());
    });
    Set<UUID> playerSet = new HashSet();
    cards.getCards(game).stream().forEachOrdered(card -> {
        Player player = game.getPlayer(card.getOwnerId());
        if (player == null || !player.discard(card, false, source, game) || card.isLand(game)) {
            return;
        }
        playerSet.add(player.getId());
    });
    game.getOpponents(source.getControllerId()).stream().filter(uuid -> !playerSet.contains(uuid)).map(game::getPlayer).filter(Objects::nonNull).forEachOrdered(player -> player.loseLife(3, game, source, false));
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) TargetCardInHand(mage.target.common.TargetCardInHand) EntersBattlefieldOrAttacksSourceTriggeredAbility(mage.abilities.common.EntersBattlefieldOrAttacksSourceTriggeredAbility) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) Set(java.util.Set) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) CardsImpl(mage.cards.CardsImpl) SubType(mage.constants.SubType) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) HashSet(java.util.HashSet) Objects(java.util.Objects) Game(mage.game.Game) EscapeAbility(mage.abilities.keyword.EscapeAbility) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) CardType(mage.constants.CardType) SuperType(mage.constants.SuperType) Ability(mage.abilities.Ability) Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) HashSet(java.util.HashSet)

Example 94 with TargetCardInHand

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

the class MindleechGhoulEffect 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();
    for (UUID playerId : game.getOpponents(source.getControllerId())) {
        Player opponent = game.getPlayer(playerId);
        if (opponent == null || opponent.getHand().isEmpty()) {
            continue;
        }
        TargetCard target = new TargetCardInHand();
        opponent.choose(Outcome.Discard, opponent.getHand(), target, game);
        cards.add(game.getCard(target.getFirstTarget()));
    }
    return controller.moveCards(cards, Zone.EXILED, source, game);
}
Also used : Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 95 with TargetCardInHand

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

the class NantukoCultivatorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || player.getHand().count(StaticFilters.FILTER_CARD_LAND, game) < 1) {
        return false;
    }
    TargetCardInHand toDiscard = new TargetCardInHand(0, Integer.MAX_VALUE, StaticFilters.FILTER_CARD_LAND);
    player.chooseTarget(Outcome.AIDontUseIt, toDiscard, source, game);
    int count = player.discard(new CardsImpl(toDiscard.getTargets()), false, source, game).size();
    if (count < 1) {
        return false;
    }
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent != null) {
        permanent.addCounters(CounterType.P1P1.createInstance(count), source.getControllerId(), source, game);
    }
    player.drawCards(count, source, game);
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) CardsImpl(mage.cards.CardsImpl)

Aggregations

TargetCardInHand (mage.target.common.TargetCardInHand)148 Player (mage.players.Player)133 Card (mage.cards.Card)96 FilterCard (mage.filter.FilterCard)61 Permanent (mage.game.permanent.Permanent)45 CardsImpl (mage.cards.CardsImpl)41 UUID (java.util.UUID)39 Cards (mage.cards.Cards)24 Target (mage.target.Target)21 TargetCard (mage.target.TargetCard)21 MageObject (mage.MageObject)17 FixedTarget (mage.target.targetpointer.FixedTarget)14 ApprovingObject (mage.ApprovingObject)13 FilterCreatureCard (mage.filter.common.FilterCreatureCard)12 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)10 RevealTargetFromHandCost (mage.abilities.costs.common.RevealTargetFromHandCost)10 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)10 ContinuousEffect (mage.abilities.effects.ContinuousEffect)9 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)9 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)9