Search in sources :

Example 61 with TargetCardInHand

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

the class TheGreatAuroraEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Map<UUID, List<Permanent>> permanentsOwned = new HashMap<>();
        Collection<Permanent> permanents = game.getBattlefield().getActivePermanents(source.getControllerId(), game);
        for (Permanent permanent : permanents) {
            List<Permanent> list = permanentsOwned.computeIfAbsent(permanent.getOwnerId(), k -> new ArrayList<>());
            list.add(permanent);
        }
        // shuffle permanents and hand cards into owner's library
        Map<UUID, Integer> permanentsCount = new HashMap<>();
        for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                int handCards = player.getHand().size();
                player.moveCards(player.getHand(), Zone.LIBRARY, source, game);
                List<Permanent> list = permanentsOwned.remove(player.getId());
                permanentsCount.put(playerId, handCards + (list != null ? list.size() : 0));
                if (list != null) {
                    for (Permanent permanent : list) {
                        player.moveCardToLibraryWithInfo(permanent, source, game, Zone.BATTLEFIELD, true, true);
                    }
                    player.shuffleLibrary(source, game);
                }
            }
        }
        // so effects from creatures that were on the battlefield won't trigger from draw or put into play
        game.getState().processAction(game);
        // Draw cards
        for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                int count = permanentsCount.get(playerId);
                if (count > 0) {
                    player.drawCards(count, source, game);
                }
            }
        }
        // put lands onto the battlefield
        Cards toBattlefield = new CardsImpl();
        for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                TargetCard target = new TargetCardInHand(0, Integer.MAX_VALUE, new FilterLandCard("put any number of land cards from your hand onto the battlefield"));
                player.chooseTarget(Outcome.PutLandInPlay, player.getHand(), target, source, game);
                toBattlefield.addAll(target.getTargets());
            }
        }
        return controller.moveCards(toBattlefield.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) FilterLandCard(mage.filter.common.FilterLandCard) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 62 with TargetCardInHand

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

the class WidespreadPanicEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player shuffler = game.getPlayer(this.getTargetPointer().getFirst(game, source));
    if (shuffler != null) {
        if (!shuffler.getHand().isEmpty()) {
            TargetCardInHand target = new TargetCardInHand();
            target.setNotTarget(true);
            target.setTargetName("a card from your hand to put on top of your library");
            shuffler.choose(Outcome.Detriment, target, source.getSourceId(), game);
            Card card = shuffler.getHand().get(target.getFirstTarget(), game);
            if (card != null) {
                shuffler.moveCardToLibraryWithInfo(card, source, game, Zone.HAND, true, false);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) Card(mage.cards.Card)

Example 63 with TargetCardInHand

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

the class BaneAlleyBrokerLookAtCardEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    controller.drawCards(1, source, game);
    if (controller.getHand().isEmpty()) {
        return false;
    }
    TargetCard target = new TargetCardInHand().withChooseHint("to exile");
    controller.chooseTarget(outcome, controller.getHand(), target, source, game);
    Card card = game.getCard(target.getFirstTarget());
    if (card == null) {
        return false;
    }
    if (!controller.moveCardsToExile(card, source, game, false, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source))) {
        return false;
    }
    card.setFaceDown(true, game);
    return true;
}
Also used : Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCard(mage.target.TargetCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 64 with TargetCardInHand

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

the class DeathrenderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (controller != null && sourcePermanent != null) {
        TargetCardInHand target = new TargetCardInHand(0, 1, StaticFilters.FILTER_CARD_CREATURE);
        if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
            Card creatureInHand = game.getCard(target.getFirstTarget());
            if (creatureInHand != null) {
                if (controller.moveCards(creatureInHand, Zone.BATTLEFIELD, source, game)) {
                    game.getPermanent(creatureInHand.getId()).addAttachment(sourcePermanent.getId(), source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) Card(mage.cards.Card)

Example 65 with TargetCardInHand

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

the class HolyAvengerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = source.getSourcePermanentOrLKI(game);
    if (player == null || sourcePermanent == null) {
        return false;
    }
    Permanent permanent = game.getPermanent(sourcePermanent.getAttachedTo());
    if (permanent == null) {
        return false;
    }
    FilterCard filter = new FilterCard("an Aura than can enchant " + permanent.getName());
    filter.add(SubType.AURA.getPredicate());
    filter.add(new AuraCardCanAttachToPermanentId(permanent.getId()));
    TargetCardInHand target = new TargetCardInHand(0, 1, filter);
    player.choose(Outcome.PutCardInPlay, player.getHand(), target, game);
    Card card = game.getCard(target.getFirstTarget());
    if (card == null) {
        return false;
    }
    game.getState().setValue("attachTo:" + card.getId(), permanent);
    player.moveCards(card, Zone.BATTLEFIELD, source, game);
    if (!permanent.addAttachment(card.getId(), source, game)) {
        return false;
    }
    game.informPlayers(player.getLogName() + " put " + card.getLogName() + " on the battlefield attached to " + permanent.getLogName() + '.');
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) AuraCardCanAttachToPermanentId(mage.filter.predicate.card.AuraCardCanAttachToPermanentId) TargetCardInHand(mage.target.common.TargetCardInHand) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

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