Search in sources :

Example 36 with TargetCardInYourGraveyard

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

the class ArachnusSpinnerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    FilterCard filter = new FilterCard("card named Arachnus Web");
    filter.add(new NamePredicate("Arachnus Web"));
    Card card = null;
    if (controller.chooseUse(Outcome.Neutral, "Search your graveyard for Arachnus Web?", source, game)) {
        TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filter);
        if (controller.choose(Outcome.PutCardInPlay, controller.getGraveyard(), target, game)) {
            card = game.getCard(target.getFirstTarget());
        }
    }
    if (card == null) {
        TargetCardInLibrary target = new TargetCardInLibrary(filter);
        if (controller.searchLibrary(target, source, game)) {
            card = game.getCard(target.getFirstTarget());
        }
        controller.shuffleLibrary(source, game);
    }
    if (card != null) {
        Permanent permanent = game.getPermanent(source.getFirstTarget());
        if (permanent != null) {
            game.getState().setValue("attachTo:" + card.getId(), permanent.getId());
            if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
                // shouldn't this be done automatically by the logic using the "attachTo:" calue?
                permanent.addAttachment(card.getId(), source, game);
            }
        }
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 37 with TargetCardInYourGraveyard

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

the class ChandraHeartOfFireUltimateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Set<Card> exiledCards = new HashSet<>();
        // from graveyard
        Target target = new TargetCardInYourGraveyard(0, Integer.MAX_VALUE, filter, true).withChooseHint("from graveyard");
        if (target.canChoose(source.getSourceId(), controller.getId(), game) && target.choose(Outcome.AIDontUseIt, controller.getId(), source.getSourceId(), game)) {
            Set<Card> cards = new CardsImpl(target.getTargets()).getCards(game);
            exiledCards.addAll(cards);
        }
        // from library
        target = new TargetCardInLibrary(0, Integer.MAX_VALUE, filter).withChooseHint("from library");
        if (target.canChoose(source.getSourceId(), controller.getId(), game) && target.choose(Outcome.AIDontUseIt, controller.getId(), source.getSourceId(), game)) {
            Set<Card> cards = new CardsImpl(target.getTargets()).getCards(game);
            exiledCards.addAll(cards);
        }
        // exile cards all at once and set the exile name to the source card
        controller.moveCardsToExile(exiledCards, source, game, true, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source));
        controller.shuffleLibrary(source, game);
        exiledCards.removeIf(card -> !Zone.EXILED.equals(game.getState().getZone(card.getId())));
        if (!exiledCards.isEmpty()) {
            ContinuousEffect effect = new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, Duration.EndOfTurn);
            effect.setTargetPointer(new FixedTargets(exiledCards, game));
            game.addEffect(effect, source);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetAnyTarget(mage.target.common.TargetAnyTarget) PlayFromNotOwnHandZoneTargetEffect(mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect) FixedTargets(mage.target.targetpointer.FixedTargets) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) ContinuousEffect(mage.abilities.effects.ContinuousEffect) CardsImpl(mage.cards.CardsImpl) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) HashSet(java.util.HashSet)

Example 38 with TargetCardInYourGraveyard

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

the class CorpseChurnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(StaticFilters.FILTER_CARD_CREATURE_YOUR_GRAVEYARD);
    target.setNotTarget(true);
    if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && controller.chooseUse(outcome, "Return a creature card from your graveyard to hand?", source, game) && controller.choose(Outcome.ReturnToHand, target, source.getSourceId(), game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            controller.moveCards(card, Zone.HAND, source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) Card(mage.cards.Card)

Example 39 with TargetCardInYourGraveyard

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

the class DeathsOasisEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || player.getGraveyard().count(filter, game) == 0) {
        return false;
    }
    TargetCard target = new TargetCardInYourGraveyard(filter);
    target.setNotTarget(true);
    if (!player.choose(outcome, player.getGraveyard(), target, game)) {
        return false;
    }
    return player.moveCards(game.getCard(target.getFirstTarget()), Zone.HAND, source, game);
}
Also used : Player(mage.players.Player) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard)

Example 40 with TargetCardInYourGraveyard

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

the class GraveSifterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Choice typeChoice = new ChoiceCreatureType(game.getObject(source.getSourceId()));
    typeChoice.setMessage("Choose creature type to return cards from your graveyard");
    Player controller = game.getPlayer(source.getControllerId());
    Set<Card> toHand = new HashSet<>();
    if (controller != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                typeChoice.clearChoice();
                if (player.choose(outcome, typeChoice, game)) {
                    game.informPlayers(player.getLogName() + " has chosen: " + typeChoice.getChoice());
                    FilterCard filter = new FilterCreatureCard("creature cards with creature type " + typeChoice.getChoice() + " from your graveyard");
                    filter.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
                    Target target = new TargetCardInYourGraveyard(0, Integer.MAX_VALUE, filter);
                    player.chooseTarget(outcome, target, source, game);
                    toHand.addAll(new CardsImpl(target.getTargets()).getCards(game));
                }
            }
        }
        // must happen simultaneously Rule 101.4
        controller.moveCards(toHand, Zone.HAND, source, game, false, false, true, null);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Target(mage.target.Target) Choice(mage.choices.Choice) ChoiceCreatureType(mage.choices.ChoiceCreatureType) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) HashSet(java.util.HashSet)

Aggregations

TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)88 Player (mage.players.Player)78 Card (mage.cards.Card)47 FilterCard (mage.filter.FilterCard)38 TargetCard (mage.target.TargetCard)29 CardsImpl (mage.cards.CardsImpl)18 UUID (java.util.UUID)16 Target (mage.target.Target)16 Permanent (mage.game.permanent.Permanent)14 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)11 FilterCreatureCard (mage.filter.common.FilterCreatureCard)10 TargetCardInHand (mage.target.common.TargetCardInHand)10 Cards (mage.cards.Cards)9 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)7 MageObject (mage.MageObject)6 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)5 HashSet (java.util.HashSet)4 ExileFromGraveCost (mage.abilities.costs.common.ExileFromGraveCost)4 OneShotEffect (mage.abilities.effects.OneShotEffect)4 FixedTarget (mage.target.targetpointer.FixedTarget)4