Search in sources :

Example 6 with TargetCardInHand

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

the class IncandescentSoulstokeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        if (controller.chooseUse(Outcome.PutCreatureInPlay, choiceText, source, game)) {
            FilterCard filter = new FilterCreatureCard();
            filter.add(SubType.ELEMENTAL.getPredicate());
            TargetCardInHand target = new TargetCardInHand(filter);
            if (controller.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
                        Permanent permanent = game.getPermanent(card.getId());
                        if (permanent != null) {
                            ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
                            effect.setTargetPointer(new FixedTarget(permanent, game));
                            game.addEffect(effect, source);
                            SacrificeTargetEffect sacrificeEffect = new SacrificeTargetEffect("sacrifice " + card.getName(), source.getControllerId());
                            sacrificeEffect.setTargetPointer(new FixedTarget(permanent, game));
                            game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(sacrificeEffect), source);
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) 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) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 7 with TargetCardInHand

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

the class KaaliaOfTheVastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || !controller.chooseUse(Outcome.PutCreatureInPlay, "Put an Angel, Demon, or Dragon creature card from your hand onto the battlefield tapped and attacking?", source, game)) {
        return false;
    }
    TargetCardInHand target = new TargetCardInHand(filter);
    if (target.canChoose(source.getSourceId(), controller.getId(), game) && target.choose(outcome, controller.getId(), source.getSourceId(), game)) {
        if (!target.getTargets().isEmpty()) {
            UUID cardId = target.getFirstTarget();
            Card card = game.getCard(cardId);
            if (card != null && game.getCombat() != null) {
                UUID defenderId = game.getCombat().getDefendingPlayerId(source.getSourceId(), game);
                if (defenderId != null) {
                    controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
                    Permanent creature = game.getPermanent(cardId);
                    if (creature != null) {
                        game.getCombat().addAttackerToCombat(card.getId(), defenderId, game);
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Example 8 with TargetCardInHand

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

the class KotoseTheSilentSpiderWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Card card = game.getCard(getTargetPointer().getFirst(game, source));
    if (controller == null || card == null) {
        return false;
    }
    Player opponent = game.getPlayer(card.getOwnerId());
    if (opponent == null) {
        return false;
    }
    UUID exileId = CardUtil.getExileZoneId(game, source);
    String exileName = CardUtil.getSourceName(game, source);
    controller.moveCardsToExile(card, source, game, true, exileId, exileName);
    Cards cards = new CardsImpl();
    FilterCard filter = new FilterCard("cards named " + card.getName() + " from " + opponent.getName() + "'s graveyard");
    filter.add(new NamePredicate(card.getName()));
    TargetCardInGraveyard targetCardInGraveyard = new TargetCardInGraveyard(0, Integer.MAX_VALUE, filter);
    controller.choose(outcome, opponent.getGraveyard(), targetCardInGraveyard, game);
    cards.addAll(targetCardInGraveyard.getTargets());
    filter.setMessage("cards named " + card.getName() + " from " + opponent.getName() + "'s hand");
    TargetCardInHand targetCardInHand = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
    controller.choose(outcome, opponent.getHand(), targetCardInHand, game);
    cards.addAll(targetCardInHand.getTargets());
    filter.setMessage("cards named " + card.getName() + " from " + opponent.getName() + "'s library");
    TargetCardInLibrary target = new TargetCardInLibrary(0, Integer.MAX_VALUE, filter);
    controller.searchLibrary(target, source, game, opponent.getId());
    target.getTargets().stream().map(cardId -> opponent.getLibrary().getCard(cardId, game)).forEach(cards::add);
    Set<Card> cardSet = cards.getCards(game);
    controller.moveCardsToExile(cardSet, source, game, true, exileId, exileName);
    opponent.shuffleLibrary(source, game);
    cardSet.add(card);
    if (cardSet.isEmpty() || source.getSourcePermanentIfItStillExists(game) == null) {
        return true;
    }
    KotoseTheSilentSpiderWatcher.addCards(source, cardSet, game);
    for (Card exiledCard : cardSet) {
        CardUtil.makeCardPlayable(game, source, exiledCard, Duration.WhileControlled, true, null, new KotoseTheSilentSpiderCondition(exiledCard, game));
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) java.util(java.util) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) mage.cards(mage.cards) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Condition(mage.abilities.condition.Condition) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) CardUtil(mage.util.CardUtil) MageInt(mage.MageInt) Collectors(java.util.stream.Collectors) Player(mage.players.Player) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) Spell(mage.game.stack.Spell) mage.constants(mage.constants) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) TargetCardInOpponentsGraveyard(mage.target.common.TargetCardInOpponentsGraveyard) Ability(mage.abilities.Ability) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) mage.cards(mage.cards) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard)

Example 9 with TargetCardInHand

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

the class KozilekDiscardCost method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    Spell targetSpell = game.getStack().getSpell(ability.getFirstTarget());
    if (targetSpell == null) {
        return false;
    }
    Player player = game.getPlayer(controllerId);
    if (player == null) {
        return false;
    }
    FilterCard filter = new FilterCard("card with mana value of " + targetSpell.getManaValue());
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, targetSpell.getManaValue()));
    TargetCardInHand target = new TargetCardInHand(filter);
    this.getTargets().clear();
    this.getTargets().add(target);
    if (targets.choose(Outcome.Discard, controllerId, source.getSourceId(), game)) {
        for (UUID targetId : targets.get(0).getTargets()) {
            Card card = player.getHand().get(targetId, game);
            if (card == null) {
                return false;
            }
            player.discard(card, true, source, game);
            paid = true;
        }
    }
    return paid;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) FilterSpell(mage.filter.FilterSpell) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 10 with TargetCardInHand

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

the class PryingQuestionsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetOpponent = game.getPlayer(this.getTargetPointer().getFirst(game, source));
    if (targetOpponent != null) {
        if (!targetOpponent.getHand().isEmpty()) {
            TargetCardInHand target = new TargetCardInHand();
            target.setNotTarget(true);
            target.setTargetName("a card from your hand to put on top of your library");
            targetOpponent.choose(Outcome.Detriment, target, source.getSourceId(), game);
            Card card = targetOpponent.getHand().get(target.getFirstTarget(), game);
            if (card != null) {
                targetOpponent.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)

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