Search in sources :

Example 1 with FilterCard

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

the class BorderlandExplorerEffect 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) {
        // Store for each player the cards to discard, that's important because all discard shall happen at the same time
        Map<UUID, Cards> cardsToDiscard = new HashMap<>();
        // Store for each player the lands to reveal, that's important because all reveals shall happen at the same time
        Map<UUID, Cards> cardsToReveal = new HashMap<>();
        // choose cards to discard
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                Target target = new TargetDiscard(0, 1, new FilterCard(), playerId);
                player.chooseTarget(outcome, target, source, game);
                Cards cards = new CardsImpl(target.getTargets());
                cardsToDiscard.put(playerId, cards);
            }
        }
        // discard all chosen cards
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                Cards cardsPlayer = cardsToDiscard.get(playerId);
                if (cardsPlayer != null) {
                    for (UUID cardId : cardsPlayer) {
                        Card card = game.getCard(cardId);
                        player.discard(card, false, source, game);
                    }
                }
            }
        }
        // search for a land for each player that discarded
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                Cards cardsPlayer = cardsToDiscard.get(playerId);
                if (cardsPlayer != null && !cardsPlayer.isEmpty()) {
                    TargetCardInLibrary target = new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_BASIC_LAND);
                    if (player.searchLibrary(target, source, game)) {
                        if (!target.getTargets().isEmpty()) {
                            Cards cards = new CardsImpl(target.getTargets());
                            cards.addAll(target.getTargets());
                            cardsToReveal.put(playerId, cards);
                        }
                    }
                }
            }
        }
        // reveal the searched lands, put in hands, and shuffle
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                Cards cardsPlayer = cardsToReveal.get(playerId);
                if (cardsPlayer != null) {
                    for (UUID cardId : cardsPlayer) {
                        Card card = game.getCard(cardId);
                        Cards cards = new CardsImpl(game.getCard(cardId));
                        if (card != null && !cards.isEmpty()) {
                            player.revealCards(sourceObject.getIdName() + " (" + player.getName() + ')', cards, game);
                            player.moveCards(card, Zone.HAND, source, game);
                            player.shuffleLibrary(source, game);
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) HashMap(java.util.HashMap) MageObject(mage.MageObject) UUID(java.util.UUID) TargetDiscard(mage.target.common.TargetDiscard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard)

Example 2 with FilterCard

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

the class BoosterTutorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    ChooseExpansionSetEffect effect = new ChooseExpansionSetEffect(Outcome.UnboostCreature);
    effect.apply(game, source);
    Player controller = game.getPlayer(source.getControllerId());
    String setChosen = null;
    if (effect.getValue("setchosen") != null) {
        setChosen = (String) effect.getValue("setchosen");
    } else if (game.getState().getValue(this.getId() + "_set") != null) {
        setChosen = (String) game.getState().getValue(this.getId() + "_set");
    }
    if (setChosen != null && controller != null) {
        // ExpansionInfo set = ExpansionRepository.instance.getSetByName(setChosen);
        ExpansionSet expansionSet = Sets.findSet(setChosen);
        if (expansionSet != null) {
            List<Card> boosterPack = expansionSet.create15CardBooster();
            if (boosterPack != null) {
                StringBuilder message = new StringBuilder(controller.getLogName()).append(" opened: ");
                for (Card card : boosterPack) {
                    message.append(card.getName()).append(" ");
                }
                game.informPlayers(message.toString());
                TargetCard targetCard = new TargetCard(Zone.ALL, new FilterCard());
                Set<Card> cardsToLoad = new HashSet<Card>(boosterPack);
                game.loadCards(cardsToLoad, controller.getId());
                CardsImpl cards = new CardsImpl();
                cards.addAll(boosterPack);
                if (controller.choose(Outcome.Benefit, cards, targetCard, game)) {
                    Card card = game.getCard(targetCard.getFirstTarget());
                    if (card != null) {
                        controller.moveCards(card, Zone.HAND, source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ChooseExpansionSetEffect(mage.abilities.effects.common.ChooseExpansionSetEffect) TargetCard(mage.target.TargetCard) ExpansionSet(mage.cards.ExpansionSet) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 3 with FilterCard

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

the class BoonweaverGiantEffect 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("Aura card");
    filter.add(CardType.ENCHANTMENT.getPredicate());
    filter.add(SubType.AURA.getPredicate());
    Card card = null;
    Zone zone = null;
    if (controller.chooseUse(Outcome.Neutral, "Search your graveyard for an Aura card?", source, game)) {
        TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filter);
        if (controller.choose(Outcome.PutCardInPlay, controller.getGraveyard(), target, game)) {
            card = game.getCard(target.getFirstTarget());
            if (card != null) {
                zone = Zone.GRAVEYARD;
            }
        }
    }
    if (card == null && controller.chooseUse(Outcome.Neutral, "Search your Hand for an Aura card?", source, game)) {
        TargetCardInHand target = new TargetCardInHand(filter);
        if (controller.choose(Outcome.PutCardInPlay, controller.getHand(), target, game)) {
            card = game.getCard(target.getFirstTarget());
            if (card != null) {
                zone = Zone.HAND;
            }
        }
    }
    if (card == null) {
        TargetCardInLibrary target = new TargetCardInLibrary(filter);
        if (controller.searchLibrary(target, source, game)) {
            card = game.getCard(target.getFirstTarget());
            if (card != null) {
                zone = Zone.LIBRARY;
            }
        }
        controller.shuffleLibrary(source, game);
    }
    // aura card found - attach it
    if (card != null) {
        Permanent permanent = game.getPermanent(source.getSourceId());
        if (permanent != null) {
            game.getState().setValue("attachTo:" + card.getId(), permanent);
        }
        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
        if (permanent != null) {
            return permanent.addAttachment(card.getId(), source, game);
        }
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) Zone(mage.constants.Zone) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 4 with FilterCard

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

the class BoneyardParleyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        Cards cards = new CardsImpl();
        for (Target target : source.getTargets()) {
            for (UUID cardId : target.getTargets()) {
                cards.add(cardId);
            }
        }
        if (!cards.isEmpty() && player.moveCards(cards, Zone.EXILED, source, game)) {
            TargetOpponent targetOpponent = new TargetOpponent(true);
            if (player.choose(Outcome.Neutral, targetOpponent, source.getSourceId(), game)) {
                Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
                if (opponent != null) {
                    TargetCard targetCards = new TargetCard(0, cards.size(), Zone.EXILED, new FilterCard("cards to put in the first pile"));
                    List<Card> pile1 = new ArrayList<>();
                    if (opponent.choose(Outcome.Neutral, cards, targetCards, game)) {
                        List<UUID> targets = targetCards.getTargets();
                        for (UUID targetId : targets) {
                            Card card = cards.get(targetId, game);
                            if (card != null) {
                                pile1.add(card);
                                cards.remove(card);
                            }
                        }
                    }
                    List<Card> pile2 = new ArrayList<>();
                    pile2.addAll(cards.getCards(game));
                    boolean choice = player.choosePile(outcome, "Choose a pile to put onto the battlefield.", pile1, pile2, game);
                    Zone pile1Zone = Zone.GRAVEYARD;
                    Zone pile2Zone = Zone.BATTLEFIELD;
                    if (choice) {
                        pile1Zone = Zone.BATTLEFIELD;
                        pile2Zone = Zone.GRAVEYARD;
                    }
                    Set<Card> pile1Set = new HashSet<>();
                    Set<Card> pile2Set = new HashSet<>();
                    pile1Set.addAll(pile1);
                    pile2Set.addAll(pile2);
                    // Cards toBattlefield = new CardsImpl();
                    // Cards toGraveyard = new CardsImpl();
                    // 
                    // if (pile1Zone == Zone.BATTLEFIELD) {
                    // toBattlefield.addAll(pile1);
                    // toGraveyard.addAll(pile2);
                    // } else {
                    // toBattlefield.addAll(pile2);
                    // toGraveyard.addAll(pile1);
                    // }
                    player.moveCards(pile1Set, pile1Zone, source, game, false, false, false, null);
                    player.moveCards(pile2Set, pile2Zone, source, game, false, false, false, null);
                // StringBuilder sb = new StringBuilder("Pile 1, going to ").append(pile1Zone == Zone.BATTLEFIELD ? "Battlefield" : "Graveyard").append(": ");
                // game.informPlayers(sb.toString());
                // sb = new StringBuilder("Pile 2, going to ").append(pile2Zone == Zone.BATTLEFIELD ? "Battlefield" : "Graveyard").append(':');
                // game.informPlayers(sb.toString());
                }
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) Zone(mage.constants.Zone) ArrayList(java.util.ArrayList) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) Target(mage.target.Target) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) HashSet(java.util.HashSet)

Example 5 with FilterCard

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

the class CheeringFanaticEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    new ChooseACardNameEffect(TypeOfName.ALL).apply(game, source);
    String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
    if (cardName == null) {
        return false;
    }
    FilterCard filter = new FilterCard();
    filter.add(new NamePredicate(cardName));
    ContinuousEffect effect = new SpellsCostReductionAllEffect(filter, 1);
    effect.setDuration(Duration.EndOfTurn);
    game.addEffect(effect, source);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) ChooseACardNameEffect(mage.abilities.effects.common.ChooseACardNameEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) SpellsCostReductionAllEffect(mage.abilities.effects.common.cost.SpellsCostReductionAllEffect)

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