Search in sources :

Example 11 with TargetCardInHand

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

the class AcademyResearchersEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterCard filterCardInHand = new FilterCard();
    filterCardInHand.add(SubType.AURA.getPredicate());
    Player controller = game.getPlayer(source.getControllerId());
    Permanent academyResearchers = game.getPermanent(source.getSourceId());
    if (controller != null && academyResearchers != null) {
        filterCardInHand.add(new AuraCardCanAttachToPermanentId(academyResearchers.getId()));
        TargetCardInHand target = new TargetCardInHand(0, 1, filterCardInHand);
        if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
            Card auraInHand = game.getCard(target.getFirstTarget());
            if (auraInHand != null) {
                game.getState().setValue("attachTo:" + auraInHand.getId(), academyResearchers);
                controller.moveCards(auraInHand, Zone.BATTLEFIELD, source, game);
                if (academyResearchers.addAttachment(auraInHand.getId(), source, game)) {
                    game.informPlayers(controller.getLogName() + " put " + auraInHand.getLogName() + " on the battlefield attached to " + academyResearchers.getLogName() + '.');
                    return true;
                }
            }
        }
    }
    return false;
}
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)

Example 12 with TargetCardInHand

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

the class BalancingActEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int minPermanent = Integer.MAX_VALUE, minCard = Integer.MAX_VALUE;
        // count minimal permanents
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                int count = game.getBattlefield().getActivePermanents(new FilterControlledPermanent(), player.getId(), source.getSourceId(), game).size();
                if (count < minPermanent) {
                    minPermanent = count;
                }
            }
        }
        // sacrifice permanents over the minimum
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                TargetControlledPermanent target = new TargetControlledPermanent(minPermanent, minPermanent, new FilterControlledPermanent(), true);
                if (target.choose(Outcome.Benefit, player.getId(), source.getSourceId(), game)) {
                    for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledPermanent(), player.getId(), source.getSourceId(), game)) {
                        if (permanent != null && !target.getTargets().contains(permanent.getId())) {
                            permanent.sacrifice(source, game);
                        }
                    }
                }
            }
        }
        // count minimal cards in hand
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                int count = player.getHand().size();
                if (count < minCard) {
                    minCard = count;
                }
            }
        }
        // discard cards over the minimum
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                TargetCardInHand target = new TargetCardInHand(minCard, new FilterCard());
                if (target.choose(Outcome.Benefit, player.getId(), source.getSourceId(), game)) {
                    Cards cards = player.getHand().copy();
                    cards.removeIf(target.getTargets()::contains);
                    player.discard(cards, false, source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Cards(mage.cards.Cards)

Example 13 with TargetCardInHand

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

the class BrineSeerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    RevealTargetFromHandCost cost = new RevealTargetFromHandCost(new TargetCardInHand(0, Integer.MAX_VALUE, filter));
    if (!cost.pay(source, game, source, source.getControllerId(), true)) {
        return false;
    }
    int xValue = cost.getNumberRevealedCards();
    return new CounterUnlessPaysEffect(new GenericManaCost(xValue)).apply(game, source);
}
Also used : CounterUnlessPaysEffect(mage.abilities.effects.common.CounterUnlessPaysEffect) RevealTargetFromHandCost(mage.abilities.costs.common.RevealTargetFromHandCost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) TargetCardInHand(mage.target.common.TargetCardInHand)

Example 14 with TargetCardInHand

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

the class DakkonShadowSlayerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    boolean inGrave = player.getGraveyard().count(StaticFilters.FILTER_CARD_ARTIFACT, game) > 0;
    if (!inGrave && player.getHand().count(StaticFilters.FILTER_CARD_ARTIFACT, game) < 1) {
        return false;
    }
    TargetCard target;
    if (!inGrave || player.chooseUse(outcome, "Choose a card in your hand or your graveyard?", null, "Hand", "Graveyard", source, game)) {
        target = new TargetCardInHand(0, 1, StaticFilters.FILTER_CARD_ARTIFACT);
        player.choose(outcome, player.getHand(), target, game);
    } else {
        target = new TargetCardInGraveyard(0, 1, StaticFilters.FILTER_CARD_ARTIFACT);
        player.choose(outcome, player.getGraveyard(), target, game);
    }
    Card card = game.getCard(target.getFirstTarget());
    return card != null && player.moveCards(card, Zone.BATTLEFIELD, source, game);
}
Also used : Player(mage.players.Player) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCard(mage.target.TargetCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 15 with TargetCardInHand

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

the class IwamoriOfTheOpenFistEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Cards cards = new CardsImpl();
        for (UUID playerId : game.getOpponents(controller.getId())) {
            Player opponent = game.getPlayer(playerId);
            Target target = new TargetCardInHand(filter);
            if (opponent != null && target.canChoose(source.getSourceId(), opponent.getId(), game)) {
                if (opponent.chooseUse(Outcome.PutCreatureInPlay, "Put a legendary creature card from your hand onto the battlefield?", source, game)) {
                    if (target.chooseTarget(Outcome.PutCreatureInPlay, opponent.getId(), source, game)) {
                        Card card = game.getCard(target.getFirstTarget());
                        if (card != null) {
                            cards.add(card);
                        }
                    }
                }
            }
        }
        controller.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard)

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