Search in sources :

Example 31 with TargetCardInGraveyard

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

the class ExtractFromDarknessEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Target target = new TargetCardInGraveyard(StaticFilters.FILTER_CARD_CREATURE);
        target.setNotTarget(true);
        if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && controller.chooseTarget(outcome, target, source, game)) {
            return controller.moveCards(game.getCard(target.getFirstTarget()), Zone.BATTLEFIELD, source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard)

Example 32 with TargetCardInGraveyard

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

the class ReapIntellectEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (targetPlayer != null && sourceObject != null && controller != null) {
        // reveal hand of target player
        targetPlayer.revealCards(sourceObject.getName(), targetPlayer.getHand(), game);
        // Chose cards to exile from hand
        Cards exiledCards = new CardsImpl();
        int xCost = Math.min(source.getManaCostsToPay().getX(), targetPlayer.getHand().size());
        TargetCard target = new TargetCard(0, xCost, Zone.HAND, filterNonLands);
        target.setNotTarget(true);
        controller.chooseTarget(Outcome.Benefit, targetPlayer.getHand(), target, source, game);
        for (UUID cardId : target.getTargets()) {
            Card chosenCard = game.getCard(cardId);
            if (chosenCard != null) {
                controller.moveCardToExileWithInfo(chosenCard, null, "", source, game, Zone.HAND, true);
                exiledCards.add(chosenCard);
            }
        }
        // 4/15/2013  If you don't exile any cards from the player's hand, you don't search that player's library
        if (!exiledCards.isEmpty()) {
            // Building a card filter with all names
            List<NamePredicate> names = new ArrayList<>();
            FilterCard filterNamedCards = new FilterCard();
            for (Card card : exiledCards.getCards(game)) {
                String nameToSearch = CardUtil.getCardNameForSameNameSearch(card);
                if (exiledCards.size() == 1) {
                    filterNamedCards.add(new NamePredicate(nameToSearch));
                } else {
                    names.add(new NamePredicate(nameToSearch));
                }
            }
            if (exiledCards.size() > 1) {
                filterNamedCards.add(Predicates.or(names));
            }
            // search cards in graveyard
            TargetCardInGraveyard targetCardsGraveyard = new TargetCardInGraveyard(0, Integer.MAX_VALUE, filterNamedCards);
            controller.chooseTarget(outcome, targetPlayer.getGraveyard(), targetCardsGraveyard, source, game);
            for (UUID cardId : targetCardsGraveyard.getTargets()) {
                Card card = game.getCard(cardId);
                if (card != null) {
                    controller.moveCardToExileWithInfo(card, null, "", source, game, Zone.GRAVEYARD, true);
                }
            }
            // search cards in hand
            TargetCard targetCardsHand = new TargetCard(0, Integer.MAX_VALUE, Zone.HAND, filterNamedCards);
            controller.chooseTarget(Outcome.Benefit, targetPlayer.getGraveyard(), targetCardsHand, source, game);
            for (UUID cardId : targetCardsHand.getTargets()) {
                Card card = game.getCard(cardId);
                if (card != null) {
                    controller.moveCardToExileWithInfo(card, null, "", source, game, Zone.HAND, true);
                }
            }
            // search cards in Library
            TargetCardInLibrary targetCardsLibrary = new TargetCardInLibrary(0, Integer.MAX_VALUE, filterNamedCards);
            controller.searchLibrary(targetCardsLibrary, source, game, targetPlayer.getId());
            for (UUID cardId : targetCardsLibrary.getTargets()) {
                Card card = game.getCard(cardId);
                if (card != null) {
                    controller.moveCardToExileWithInfo(card, null, "", source, game, Zone.LIBRARY, true);
                }
            }
        }
        targetPlayer.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) MageObject(mage.MageObject) ArrayList(java.util.ArrayList) TargetCard(mage.target.TargetCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) UUID(java.util.UUID)

Example 33 with TargetCardInGraveyard

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

the class ScionOfDarknessTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!event.getSourceId().equals(this.sourceId) || !((DamagedPlayerEvent) event).isCombatDamage()) {
        return false;
    }
    Player damagedPlayer = game.getPlayer(event.getTargetId());
    if (damagedPlayer == null) {
        return false;
    }
    FilterCard filter = new FilterCard("creature in " + damagedPlayer.getName() + "'s graveyard");
    filter.add(CardType.CREATURE.getPredicate());
    filter.add(new OwnerIdPredicate(damagedPlayer.getId()));
    TargetCardInGraveyard target = new TargetCardInGraveyard(filter);
    this.getTargets().clear();
    this.addTarget(target);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent)

Example 34 with TargetCardInGraveyard

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

the class ShadowKinApplier method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Cards cards = new CardsImpl();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            cards.addAll(player.millCards(3, source, game));
        }
    }
    if (cards.isEmpty()) {
        return false;
    }
    TargetCardInGraveyard target = new TargetCardInGraveyard(0, 1, StaticFilters.FILTER_CARD_CREATURE);
    target.setNotTarget(true);
    controller.choose(outcome, cards, target, game);
    Card card = game.getCard(target.getFirstTarget());
    Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game);
    if (card == null || sourcePermanent == null) {
        return true;
    }
    controller.moveCards(card, Zone.EXILED, source, game);
    Permanent blueprint = new PermanentCard(card, source.getControllerId(), game);
    blueprint.assignNewId();
    CopyApplier applier = new ShadowKinApplier();
    applier.apply(game, blueprint, source, sourcePermanent.getId());
    CopyEffect copyEffect = new CopyEffect(Duration.Custom, blueprint, sourcePermanent.getId());
    copyEffect.newId();
    copyEffect.setApplier(applier);
    Ability newAbility = source.copy();
    copyEffect.init(newAbility, game);
    game.addEffect(copyEffect, newAbility);
    return true;
}
Also used : CopyEffect(mage.abilities.effects.common.CopyEffect) FlashAbility(mage.abilities.keyword.FlashAbility) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) Permanent(mage.game.permanent.Permanent) CopyApplier(mage.util.functions.CopyApplier) UUID(java.util.UUID) PermanentCard(mage.game.permanent.PermanentCard) PermanentCard(mage.game.permanent.PermanentCard)

Example 35 with TargetCardInGraveyard

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

the class SpellweaverVoluteEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent sourcePermanent = game.getPermanent(source.getSourceId());
        if (sourcePermanent != null && sourcePermanent.getAttachedTo() != null) {
            Card enchantedCard = game.getCard(sourcePermanent.getAttachedTo());
            if (enchantedCard != null && game.getState().getZone(enchantedCard.getId()) == Zone.GRAVEYARD) {
                Player ownerEnchanted = game.getPlayer(enchantedCard.getOwnerId());
                if (ownerEnchanted != null && controller.chooseUse(Outcome.Copy, "Create a copy of " + enchantedCard.getName() + '?', source, game)) {
                    Card copiedCard = game.copyCard(enchantedCard, source, source.getControllerId());
                    if (copiedCard != null) {
                        controller.getGraveyard().add(copiedCard);
                        game.getState().setZone(copiedCard.getId(), Zone.GRAVEYARD);
                        if (controller.chooseUse(Outcome.PlayForFree, "Cast the copied card without paying mana cost?", source, game)) {
                            if (copiedCard.getSpellAbility() != null) {
                                game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
                                controller.cast(controller.chooseAbilityForCast(copiedCard, game, true), game, true, new ApprovingObject(source, game));
                                game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
                            }
                            if (controller.moveCards(enchantedCard, Zone.EXILED, source, game)) {
                                FilterCard filter = new FilterCard("instant card in a graveyard");
                                filter.add(CardType.INSTANT.getPredicate());
                                TargetCardInGraveyard auraTarget = new TargetCardInGraveyard(filter);
                                if (auraTarget.canChoose(source.getSourceId(), controller.getId(), game)) {
                                    controller.choose(Outcome.Benefit, auraTarget, source.getSourceId(), game);
                                    Card newAuraTarget = game.getCard(auraTarget.getFirstTarget());
                                    if (newAuraTarget != null) {
                                        if (enchantedCard.getId().equals(newAuraTarget.getId())) {
                                        } else if (newAuraTarget.addAttachment(sourcePermanent.getId(), source, game)) {
                                            game.informPlayers(sourcePermanent.getLogName() + " was attached to " + newAuraTarget.getLogName());
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Aggregations

TargetCardInGraveyard (mage.target.common.TargetCardInGraveyard)59 Player (mage.players.Player)54 Card (mage.cards.Card)32 FilterCard (mage.filter.FilterCard)24 OwnerIdPredicate (mage.filter.predicate.card.OwnerIdPredicate)23 UUID (java.util.UUID)21 FilterCreatureCard (mage.filter.common.FilterCreatureCard)17 Permanent (mage.game.permanent.Permanent)14 Target (mage.target.Target)14 TargetCard (mage.target.TargetCard)12 MageObject (mage.MageObject)8 Ability (mage.abilities.Ability)6 CardsImpl (mage.cards.CardsImpl)6 CardIdPredicate (mage.filter.predicate.mageobject.CardIdPredicate)5 TargetPlayer (mage.target.TargetPlayer)5 HashSet (java.util.HashSet)4 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)4 Cards (mage.cards.Cards)4 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)4 TargetOpponent (mage.target.common.TargetOpponent)4