Search in sources :

Example 96 with TargetCardInHand

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

the class PendantOfProsperityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    effect1.apply(game, source);
    effect2.apply(game, source);
    Player player = game.getPlayer(game.getOwnerId(game.getPermanent(source.getSourceId())));
    if (player == null) {
        return false;
    }
    player.drawCards(1, source, game);
    if (!player.chooseUse(outcome, "Put a land into play from your hand?", source, game)) {
        return true;
    }
    TargetCardInHand target = new TargetCardInHand(0, 1, StaticFilters.FILTER_CARD_LAND_A);
    if (!player.choose(outcome, player.getHand(), target, game)) {
        return true;
    }
    player.moveCards(new CardsImpl(target.getTargets()), Zone.BATTLEFIELD, source, game);
    return true;
}
Also used : Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) CardsImpl(mage.cards.CardsImpl)

Example 97 with TargetCardInHand

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

the class RetracedImageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        TargetCardInHand target = new TargetCardInHand();
        if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.choose(outcome, target, source.getSourceId(), game)) {
            Card chosenCard = game.getCard(target.getFirstTarget());
            if (chosenCard != null) {
                Cards cards = new CardsImpl();
                cards.add(chosenCard);
                controller.revealCards(source, cards, game);
                for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
                    if (permanent.getName().equals(chosenCard.getName())) {
                        return controller.moveCards(chosenCard, Zone.BATTLEFIELD, source, game);
                    }
                }
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 98 with TargetCardInHand

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

the class RofellossGiftEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    TargetCardInHand targetCardInHand = new TargetCardInHand(0, Integer.MAX_VALUE, filter1);
    if (!player.choose(outcome, player.getHand(), targetCardInHand, game)) {
        return false;
    }
    Cards cards = new CardsImpl();
    for (UUID cardId : targetCardInHand.getTargets()) {
        Card card = game.getCard(cardId);
        if (card != null) {
            cards.add(card);
        }
    }
    player.revealCards(source, cards, game);
    int enchantmentsToReturn = Math.min(player.getGraveyard().count(filter2, game), targetCardInHand.getTargets().size());
    TargetCardInYourGraveyard targetCardInYourGraveyard = new TargetCardInYourGraveyard(enchantmentsToReturn, filter2);
    targetCardInYourGraveyard.setNotTarget(true);
    if (!player.choose(outcome, targetCardInYourGraveyard, source.getSourceId(), game)) {
        return false;
    }
    cards = new CardsImpl();
    for (UUID cardId : targetCardInYourGraveyard.getTargets()) {
        Card card = game.getCard(cardId);
        if (card != null) {
            cards.add(card);
        }
    }
    return player.moveCards(cards, Zone.HAND, source, game);
}
Also used : Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard)

Example 99 with TargetCardInHand

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

the class SneakAttackEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || !controller.chooseUse(Outcome.PutCreatureInPlay, choiceText, source, game)) {
        return true;
    }
    TargetCardInHand target = new TargetCardInHand(StaticFilters.FILTER_CARD_CREATURE);
    if (!controller.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
        return true;
    }
    Card card = game.getCard(target.getFirstTarget());
    if (card == null || !controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
        return false;
    }
    Permanent permanent = game.getPermanent(CardUtil.getDefaultCardSideForBattlefield(game, card).getId());
    if (permanent == null) {
        return true;
    }
    ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
    effect.setTargetPointer(new FixedTarget(permanent, game));
    game.addEffect(effect, source);
    game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new SacrificeTargetEffect("sacrifice " + card.getName(), source.getControllerId()).setTargetPointer(new FixedTarget(permanent, game))), source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) SacrificeTargetEffect(mage.abilities.effects.common.SacrificeTargetEffect) Card(mage.cards.Card)

Example 100 with TargetCardInHand

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

the class StrongholdGambitEffect 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, UUID> choosenCard = new LinkedHashMap<>();
        for (UUID playerId : game.getState().getPlayerList(controller.getId())) {
            Player player = game.getPlayer(playerId);
            if (player != null && !player.getHand().isEmpty()) {
                TargetCardInHand target = new TargetCardInHand();
                if (player.choose(Outcome.Benefit, target, source.getSourceId(), game)) {
                    choosenCard.put(playerId, target.getFirstTarget());
                }
            }
        }
        int lowestCMC = Integer.MAX_VALUE;
        for (UUID playerId : game.getState().getPlayerList(controller.getId())) {
            Player player = game.getPlayer(playerId);
            if (player != null && choosenCard.containsKey(playerId)) {
                Card card = game.getCard(choosenCard.get(playerId));
                if (card != null) {
                    Cards cardsToReveal = new CardsImpl(card);
                    player.revealCards(sourceObject.getIdName() + " (" + player.getName() + ')', cardsToReveal, game);
                    if (card.isCreature(game) && lowestCMC > card.getManaValue()) {
                        lowestCMC = card.getManaValue();
                    }
                }
            }
        }
        if (lowestCMC < Integer.MAX_VALUE) {
            Cards creaturesToBattlefield = new CardsImpl();
            for (UUID playerId : game.getState().getPlayerList(controller.getId())) {
                Player player = game.getPlayer(playerId);
                if (player != null && choosenCard.containsKey(playerId)) {
                    Card card = game.getCard(choosenCard.get(playerId));
                    if (card != null) {
                        if (card.isCreature(game) && lowestCMC == card.getManaValue()) {
                            creaturesToBattlefield.add(card);
                        }
                    }
                }
            }
            controller.moveCards(creaturesToBattlefield.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) MageObject(mage.MageObject) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) LinkedHashMap(java.util.LinkedHashMap) 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