Search in sources :

Example 56 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class PatriarchsBiddingEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller != null && sourceObject != null) {
        Set<String> chosenTypes = new HashSet<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            Choice typeChoice = new ChoiceCreatureType(sourceObject);
            if (!player.choose(Outcome.PutCreatureInPlay, typeChoice, game)) {
                continue;
            }
            String chosenType = typeChoice.getChoice();
            game.informPlayers(sourceObject.getLogName() + ": " + player.getLogName() + " has chosen " + chosenType);
            chosenTypes.add(chosenType);
        }
        List<SubType.SubTypePredicate> predicates = new ArrayList<>();
        for (String type : chosenTypes) {
            predicates.add(SubType.byDescription(type).getPredicate());
        }
        FilterCard filter = new FilterCreatureCard();
        filter.add(Predicates.or(predicates));
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                player.moveCards(player.getGraveyard().getCards(filter, game), Zone.BATTLEFIELD, source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) MageObject(mage.MageObject) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ChoiceCreatureType(mage.choices.ChoiceCreatureType)

Example 57 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class PrimeSpeakerVannifarEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sacrificedPermanent = null;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost) {
            SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
            if (!sacrificeCost.getPermanents().isEmpty()) {
                sacrificedPermanent = sacrificeCost.getPermanents().get(0);
            }
            break;
        }
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (sacrificedPermanent == null || controller == null) {
        return false;
    }
    int newConvertedCost = sacrificedPermanent.getManaValue() + 1;
    FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost);
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, newConvertedCost));
    filter.add(CardType.CREATURE.getPredicate());
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    if (controller.searchLibrary(target, source, game)) {
        Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    }
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 58 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class RakdosAugermageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    if (player != null && controller != null) {
        Cards revealedCards = new CardsImpl();
        revealedCards.addAll(controller.getHand());
        Card sourceCard = game.getCard(source.getSourceId());
        player.revealCards((sourceCard != null ? sourceCard.getIdName() + " (" + sourceCard.getZoneChangeCounter(game) + ") (" : "Discard (") + controller.getName() + ")", revealedCards, game);
        TargetCard target = new TargetCard(Zone.HAND, new FilterCard());
        if (player.choose(Outcome.Benefit, revealedCards, target, game)) {
            Card card = revealedCards.get(target.getFirstTarget(), game);
            return player.discard(card, false, source, game);
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 59 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class SawtoothLoonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        controller.drawCards(2, source, game);
        TargetCardInHand target = new TargetCardInHand(2, 2, new FilterCard());
        controller.chooseTarget(Outcome.Detriment, target, source, game);
        Cards cardsToLibrary = new CardsImpl(target.getTargets());
        if (!cardsToLibrary.isEmpty()) {
            controller.putCardsOnBottomOfLibrary(cardsToLibrary, game, source, false);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 60 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class ShrineOfPiercingVisionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
    if (player == null || permanent == null) {
        return false;
    }
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, permanent.getCounters(game).getCount(CounterType.CHARGE)));
    if (!cards.isEmpty()) {
        player.lookAtCards(source, null, cards, game);
        TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put into your hand"));
        if (player.choose(Outcome.DrawCard, cards, target, game)) {
            Card card = cards.get(target.getFirstTarget(), game);
            if (card != null) {
                cards.remove(card);
                player.moveCards(card, Zone.HAND, source, game);
            }
        }
        player.putCardsOnBottomOfLibrary(cards, game, source, true);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Aggregations

FilterCard (mage.filter.FilterCard)337 Player (mage.players.Player)287 Card (mage.cards.Card)148 TargetCard (mage.target.TargetCard)127 UUID (java.util.UUID)97 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)87 Permanent (mage.game.permanent.Permanent)79 MageObject (mage.MageObject)75 CardsImpl (mage.cards.CardsImpl)75 Cards (mage.cards.Cards)60 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)56 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)54 Target (mage.target.Target)41 TargetCardInHand (mage.target.common.TargetCardInHand)41 TargetPlayer (mage.target.TargetPlayer)35 ApprovingObject (mage.ApprovingObject)29 FilterCreatureCard (mage.filter.common.FilterCreatureCard)25 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)24 TargetCardInGraveyard (mage.target.common.TargetCardInGraveyard)22 ArrayList (java.util.ArrayList)21