Search in sources :

Example 46 with TargetCardInHand

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

the class StrefanMaurerProgenitorPlayVampireEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    TargetCard target = new TargetCardInHand(0, 1, vampireCardFilter);
    if (!player.choose(outcome, player.getHand(), target, game)) {
        return false;
    }
    Card card = game.getCard(target.getFirstTarget());
    if (card == null) {
        return false;
    }
    player.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, true, null);
    Permanent permanent = game.getPermanent(card.getId());
    if (permanent == null) {
        return false;
    }
    game.getCombat().addAttackingCreature(permanent.getId(), game);
    // Gains indestructable until end of turn
    ContinuousEffect effect = new GainAbilityTargetEffect(IndestructibleAbility.getInstance(), Duration.EndOfTurn);
    effect.setTargetPointer(new FixedTarget(permanent.getId(), game));
    game.addEffect(effect, source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetCardInHand(mage.target.common.TargetCardInHand) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) TargetCard(mage.target.TargetCard) ContinuousEffect(mage.abilities.effects.ContinuousEffect) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 47 with TargetCardInHand

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

the class TemptingWurmEffect 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);
            if (opponent != null) {
                Target target = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
                if (target.canChoose(source.getSourceId(), opponent.getId(), game)) {
                    if (opponent.chooseUse(Outcome.PutCardInPlay, "Put any artifact, creature, enchantment, and/or land cards cards from your hand onto the battlefield?", source, game)) {
                        if (target.chooseTarget(Outcome.PutCardInPlay, opponent.getId(), source, game)) {
                            for (UUID cardId : target.getTargets()) {
                                Card card = game.getCard(cardId);
                                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) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 48 with TargetCardInHand

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

the class ExileFromZoneTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player == null) {
        return false;
    }
    Target target = null;
    switch(zone) {
        case HAND:
            target = new TargetCardInHand(Math.min(player.getHand().count(filter, game), amount), filter);
            break;
        case GRAVEYARD:
            target = new TargetCardInYourGraveyard(Math.min(player.getGraveyard().count(filter, game), amount), filter);
            break;
        default:
    }
    if (target == null || !target.canChoose(source.getSourceId(), player.getId(), game)) {
        return true;
    }
    target.chooseTarget(Outcome.Exile, player.getId(), source, game);
    Cards cards = new CardsImpl(target.getTargets());
    if (withSource) {
        return player.moveCardsToExile(cards.getCards(game), source, game, true, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source));
    }
    return player.moveCards(cards, Zone.EXILED, source, game);
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 49 with TargetCardInHand

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

the class AuraSwapEffect method apply.

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

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

the class ArsenalThresherEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Permanent arsenalThresher = game.getPermanentEntering(source.getSourceId());
    FilterArtifactCard filter = new FilterArtifactCard();
    filter.add(new AnotherCardPredicate());
    if (controller.chooseUse(Outcome.Benefit, "Reveal other artifacts in your hand?", source, game)) {
        Cards cards = new CardsImpl();
        if (controller.getHand().count(filter, source.getSourceId(), source.getControllerId(), game) > 0) {
            TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
            if (controller.choose(Outcome.Benefit, target, source.getSourceId(), game)) {
                for (UUID uuid : target.getTargets()) {
                    cards.add(controller.getHand().get(uuid, game));
                }
                if (arsenalThresher != null) {
                    controller.revealCards(arsenalThresher.getIdName(), cards, game);
                    // the basic event is the EntersBattlefieldEvent, so use already applied replacement effects from that event
                    List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
                    arsenalThresher.addCounters(CounterType.P1P1.createInstance(cards.size()), source.getControllerId(), source, game, appliedEffects);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) ArrayList(java.util.ArrayList) FilterArtifactCard(mage.filter.common.FilterArtifactCard) AnotherCardPredicate(mage.filter.predicate.mageobject.AnotherCardPredicate) UUID(java.util.UUID) Cards(mage.cards.Cards) 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