Search in sources :

Example 11 with TargetCardInYourGraveyard

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

the class WatchersOfTheDeadEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
    if (controller != null) {
        for (UUID opponentId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player opponent = game.getPlayer(opponentId);
            if (opponent != null && !opponent.equals(controller)) {
                TargetCard target = new TargetCardInYourGraveyard(2, 2, new FilterCard());
                target.setNotTarget(true);
                Cards cardsInGraveyard = opponent.getGraveyard();
                if (cardsInGraveyard.size() > 1) {
                    opponent.choose(outcome, cardsInGraveyard, target, game);
                    for (Card cardInGraveyard : cardsInGraveyard.getCards(game)) {
                        if (!target.getTargets().contains(cardInGraveyard.getId())) {
                            opponent.moveCardToExileWithInfo(cardInGraveyard, CardUtil.getCardExileZoneId(game, source.getId()), sourceObject.getLogName(), source, game, Zone.GRAVEYARD, true);
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 12 with TargetCardInYourGraveyard

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

the class LichsMasteryLoseLifeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    FilterPermanent filter = new FilterPermanent();
    filter.add(new ControllerIdPredicate(controller.getId()));
    for (int i = 0; i < amount; i++) {
        int handCount = controller.getHand().size();
        int graveCount = controller.getGraveyard().size();
        int permCount = game.getBattlefield().getActivePermanents(filter, controller.getId(), game).size();
        if (graveCount + handCount == 0 || (permCount > 0 && controller.chooseUse(Outcome.Exile, "Exile permanent you control? (No = from hand or graveyard)", source, game))) {
            Target target = new TargetControlledPermanent(1, 1, new FilterControlledPermanent(), true);
            controller.choose(outcome, target, source.getSourceId(), game);
            Effect effect = new ExileTargetEffect();
            effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
            effect.apply(game, source);
        } else if (graveCount == 0 || (handCount > 0 && controller.chooseUse(Outcome.Exile, "Exile a card from your hand? (No = from graveyard)", source, game))) {
            Target target = new TargetCardInHand(1, 1, new FilterCard());
            controller.choose(outcome, target, source.getSourceId(), game);
            Card card = controller.getHand().get(target.getFirstTarget(), game);
            if (card != null) {
                controller.moveCards(card, Zone.EXILED, source, game);
            }
        } else if (graveCount > 0) {
            Target target = new TargetCardInYourGraveyard(1, 1, new FilterCard(), true);
            target.choose(Outcome.Exile, source.getControllerId(), source.getSourceId(), game);
            Card card = controller.getGraveyard().get(target.getFirstTarget(), game);
            if (card != null) {
                controller.moveCards(card, Zone.EXILED, source, game);
            }
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) DrawCardSourceControllerEffect(mage.abilities.effects.common.DrawCardSourceControllerEffect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect) LoseGameSourceControllerEffect(mage.abilities.effects.common.LoseGameSourceControllerEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 13 with TargetCardInYourGraveyard

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

the class RootsOfWisdomEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    player.millCards(3, source, game);
    TargetCard targetCard = new TargetCardInYourGraveyard(filter);
    targetCard.setNotTarget(true);
    if (targetCard.canChoose(source.getSourceId(), source.getControllerId(), game) && player.choose(outcome, targetCard, source.getSourceId(), game)) {
        Card card = player.getGraveyard().get(targetCard.getFirstTarget(), game);
        if (card != null && player.moveCards(card, Zone.HAND, source, game)) {
            return true;
        }
    }
    player.drawCards(1, source, game);
    return true;
}
Also used : Player(mage.players.Player) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 14 with TargetCardInYourGraveyard

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

the class SkullwinderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        TargetOpponent targetOpponent = new TargetOpponent(true);
        if (controller.choose(Outcome.Detriment, targetOpponent, source.getSourceId(), game)) {
            Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
            if (opponent != null) {
                game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen " + opponent.getLogName());
                // That player returns a card from their graveyard to their hand
                TargetCardInYourGraveyard targetCard = new TargetCardInYourGraveyard(new FilterCard("a card from your graveyard to return to your hand"));
                targetCard.setNotTarget(true);
                if (opponent.choose(outcome, targetCard, source.getSourceId(), game)) {
                    Card card = game.getCard(targetCard.getFirstTarget());
                    if (card != null) {
                        opponent.moveCards(card, Zone.HAND, source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) MageObject(mage.MageObject) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 15 with TargetCardInYourGraveyard

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

the class TayamLuminousEnigmaReplacementEffect 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.BATTLEFIELD, source, game);
}
Also used : Player(mage.players.Player) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard)

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