Search in sources :

Example 61 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class MonomaniaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getFirstTarget());
    if (player == null || player.getHand().isEmpty()) {
        return false;
    }
    TargetCard target = new TargetDiscard(player.getId());
    player.choose(Outcome.Benefit, player.getHand(), target, game);
    Cards cards = player.getHand().copy();
    cards.removeIf(target.getTargets()::contains);
    return !player.discard(cards, false, source, game).isEmpty();
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) TargetCard(mage.target.TargetCard) TargetDiscard(mage.target.common.TargetDiscard) Cards(mage.cards.Cards)

Example 62 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class NecromentiaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
    Player controller = game.getPlayer(source.getControllerId());
    if (cardName != null && controller != null) {
        FilterCard filter = new FilterCard("card named " + cardName);
        filter.add(new NamePredicate(cardName));
        Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
        // cards in Graveyard
        int cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getGraveyard().count(filter, game));
        if (cardsCount > 0) {
            filter.setMessage("card named " + cardName + " in the graveyard of " + targetPlayer.getName());
            TargetCard target = new TargetCard(0, cardsCount, Zone.GRAVEYARD, filter);
            if (controller.choose(Outcome.Exile, targetPlayer.getGraveyard(), target, game)) {
                controller.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
            }
        }
        // cards in Hand
        int numberOfCardsExiledFromHand = 0;
        cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getHand().count(filter, game));
        if (cardsCount > 0) {
            filter.setMessage("card named " + cardName + " in the hand of " + targetPlayer.getName());
            TargetCard target = new TargetCard(0, cardsCount, Zone.HAND, filter);
            if (controller.choose(Outcome.Exile, targetPlayer.getHand(), target, game)) {
                numberOfCardsExiledFromHand = target.getTargets().size();
                controller.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
            }
        } else {
            targetPlayer.revealCards(targetPlayer.getName() + "'s Hand", targetPlayer.getHand(), game);
        }
        // cards in Library
        Cards cardsInLibrary = new CardsImpl();
        cardsInLibrary.addAll(targetPlayer.getLibrary().getCards(game));
        cardsCount = (cardName.isEmpty() ? 0 : cardsInLibrary.count(filter, game));
        if (cardsCount > 0) {
            filter.setMessage("card named " + cardName + " in the library of " + targetPlayer.getLogName());
            TargetCardInLibrary targetLib = new TargetCardInLibrary(0, cardsCount, filter);
            if (controller.choose(Outcome.Exile, cardsInLibrary, targetLib, game)) {
                controller.moveCards(new CardsImpl(targetLib.getTargets()), Zone.EXILED, source, game);
            }
        } else {
            targetPlayer.revealCards(targetPlayer.getName() + "'s Library", new CardsImpl(new HashSet<>(targetPlayer.getLibrary().getCards(game))), game);
        }
        targetPlayer.shuffleLibrary(source, game);
        if (numberOfCardsExiledFromHand > 0) {
            game.getState().applyEffects(game);
            Token zombieToken = new ZombieToken();
            zombieToken.putOntoBattlefield(numberOfCardsExiledFromHand, game, source, targetPlayer.getId());
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) ZombieToken(mage.game.permanent.token.ZombieToken) TargetCard(mage.target.TargetCard) Token(mage.game.permanent.token.Token) ZombieToken(mage.game.permanent.token.ZombieToken) CardsImpl(mage.cards.CardsImpl) Cards(mage.cards.Cards) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) HashSet(java.util.HashSet)

Example 63 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class RansackEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getFirstTarget());
    FilterCard filter = new FilterCard("cards to put on the bottom of your library");
    if (player != null) {
        int number = min(player.getLibrary().size(), 5);
        Set<Card> cards = player.getLibrary().getTopCards(game, number);
        Cards cardsRemaining = new CardsImpl();
        cardsRemaining.addAll(cards);
        TargetCard target = new TargetCard(0, number, Zone.LIBRARY, filter);
        if (player.choose(Outcome.DrawCard, cardsRemaining, target, game)) {
            Cards pickedCards = new CardsImpl(target.getTargets());
            cardsRemaining.removeAll(pickedCards);
            player.putCardsOnBottomOfLibrary(pickedCards, game, source, true);
            player.putCardsOnTopOfLibrary(cardsRemaining, game, source, true);
            return true;
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 64 with TargetCard

use of mage.target.TargetCard 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 65 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class SkyclavePlunderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int xValue = 3 + PartyCount.instance.calculate(game, source, this);
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, xValue));
    int toTake = Math.min(cards.size(), 3);
    TargetCard target = new TargetCardInLibrary(toTake, toTake, StaticFilters.FILTER_CARD);
    player.choose(outcome, cards, target, game);
    Cards toHand = new CardsImpl(target.getTargets());
    cards.removeIf(target.getTargets()::contains);
    player.moveCards(toHand, Zone.HAND, source, game);
    player.putCardsOnBottomOfLibrary(cards, game, source, false);
    return true;
}
Also used : Player(mage.players.Player) TargetCard(mage.target.TargetCard) PartyCountHint(mage.abilities.hint.common.PartyCountHint) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Aggregations

TargetCard (mage.target.TargetCard)309 Player (mage.players.Player)297 FilterCard (mage.filter.FilterCard)177 Card (mage.cards.Card)130 CardsImpl (mage.cards.CardsImpl)96 UUID (java.util.UUID)83 Cards (mage.cards.Cards)81 MageObject (mage.MageObject)80 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)52 Permanent (mage.game.permanent.Permanent)49 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)30 ApprovingObject (mage.ApprovingObject)26 TargetPlayer (mage.target.TargetPlayer)25 FilterCreatureCard (mage.filter.common.FilterCreatureCard)22 TargetOpponent (mage.target.common.TargetOpponent)22 TargetCardInHand (mage.target.common.TargetCardInHand)21 Target (mage.target.Target)19 FilterNonlandCard (mage.filter.common.FilterNonlandCard)18 FixedTarget (mage.target.targetpointer.FixedTarget)18 ArrayList (java.util.ArrayList)16