Search in sources :

Example 36 with FilterCard

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

the class CardSelector method filterCards.

private void filterCards() {
    FilterCard filter = buildFilter();
    MageFrame.getDesktop().setCursor(new Cursor(Cursor.WAIT_CURSOR));
    try {
        // debug
        // debugObjectMemorySize("Old cards size", this.currentView.getCardsStore());
        this.currentView.clearCardsStoreBeforeUpdate();
        java.util.List<Card> filteredCards = new ArrayList<>();
        if (chkPennyDreadful.isSelected() && pdAllowed.isEmpty()) {
            pdAllowed.putAll(PennyDreadfulLegalityUtil.getLegalCardList());
        }
        if (limited) {
            for (Card card : cards) {
                if (filter.match(card, null)) {
                    filteredCards.add(card);
                }
            }
        } else {
            java.util.List<CardInfo> foundCards = CardRepository.instance.findCards(buildCriteria());
            for (CardInfo cardInfo : foundCards) {
                // filter by penny
                if (chkPennyDreadful.isSelected()) {
                    if (!pdAllowed.containsKey(cardInfo.getName())) {
                        continue;
                    }
                }
                // filter by settings
                Card card = cardInfo.getMockCard();
                if (!filter.match(card, null)) {
                    continue;
                }
                // found
                filteredCards.add(card);
            }
        }
        // force to list mode on too much cards
        if (currentView instanceof CardGrid && filteredCards.size() > CardGrid.MAX_IMAGES) {
            this.toggleViewMode();
        }
        // debug
        // debugObjectMemorySize("New cards size", filteredCards);
        this.currentView.loadCards(new CardsView(filteredCards), sortSetting, bigCard, null, false);
        this.cardCount.setText(String.valueOf(filteredCards.size()));
    } finally {
        MageFrame.getDesktop().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }
}
Also used : FilterCard(mage.filter.FilterCard) java.util(java.util) CardsView(mage.view.CardsView) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 37 with FilterCard

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

the class AchHansRunEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    String cardName = ChooseACardNameEffect.TypeOfName.CREATURE_NAME.getChoice(controller, game, source, false);
    game.informPlayers(controller.getLogName() + ": \"Ach! Hans, run! It's the " + cardName + "!\"");
    FilterCard nameFilter = new FilterCard();
    nameFilter.add(new NamePredicate(cardName));
    TargetCardInLibrary target = new TargetCardInLibrary(1, 1, nameFilter);
    if (!controller.searchLibrary(target, source, game)) {
        return false;
    }
    Card card = controller.getLibrary().remove(target.getFirstTarget(), game);
    if (card == null || !controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
        return false;
    }
    Permanent creature = game.getPermanent(card.getId());
    if (creature == null) {
        return false;
    }
    // gains haste
    ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
    effect.setTargetPointer(new FixedTarget(creature, game));
    game.addEffect(effect, source);
    // Exile at begin of next end step
    ExileTargetEffect exileEffect = new ExileTargetEffect(null, null, Zone.BATTLEFIELD);
    exileEffect.setTargetPointer(new FixedTarget(creature, game));
    DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
    game.addDelayedTriggeredAbility(delayedAbility, source);
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Permanent(mage.game.permanent.Permanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 38 with FilterCard

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

the class AcademyResearchersEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterCard filterCardInHand = new FilterCard();
    filterCardInHand.add(SubType.AURA.getPredicate());
    Player controller = game.getPlayer(source.getControllerId());
    Permanent academyResearchers = game.getPermanent(source.getSourceId());
    if (controller != null && academyResearchers != null) {
        filterCardInHand.add(new AuraCardCanAttachToPermanentId(academyResearchers.getId()));
        TargetCardInHand target = new TargetCardInHand(0, 1, filterCardInHand);
        if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
            Card auraInHand = game.getCard(target.getFirstTarget());
            if (auraInHand != null) {
                game.getState().setValue("attachTo:" + auraInHand.getId(), academyResearchers);
                controller.moveCards(auraInHand, Zone.BATTLEFIELD, source, game);
                if (academyResearchers.addAttachment(auraInHand.getId(), source, game)) {
                    game.informPlayers(controller.getLogName() + " put " + auraInHand.getLogName() + " on the battlefield attached to " + academyResearchers.getLogName() + '.');
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) AuraCardCanAttachToPermanentId(mage.filter.predicate.card.AuraCardCanAttachToPermanentId) TargetCardInHand(mage.target.common.TargetCardInHand) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 39 with FilterCard

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

the class AmassTheComponentsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    player.drawCards(3, source, game);
    if (!player.getHand().isEmpty()) {
        FilterCard filter = new FilterCard("card from your hand to put on the bottom of your library");
        TargetCard target = new TargetCard(Zone.HAND, filter);
        if (player.choose(Outcome.Detriment, player.getHand(), target, game)) {
            Card card = player.getHand().get(target.getFirstTarget(), game);
            if (card != null) {
                return player.putCardsOnBottomOfLibrary(card, game, source, true);
            }
        }
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 40 with FilterCard

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

the class BalancingActEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int minPermanent = Integer.MAX_VALUE, minCard = Integer.MAX_VALUE;
        // count minimal permanents
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                int count = game.getBattlefield().getActivePermanents(new FilterControlledPermanent(), player.getId(), source.getSourceId(), game).size();
                if (count < minPermanent) {
                    minPermanent = count;
                }
            }
        }
        // sacrifice permanents over the minimum
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                TargetControlledPermanent target = new TargetControlledPermanent(minPermanent, minPermanent, new FilterControlledPermanent(), true);
                if (target.choose(Outcome.Benefit, player.getId(), source.getSourceId(), game)) {
                    for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledPermanent(), player.getId(), source.getSourceId(), game)) {
                        if (permanent != null && !target.getTargets().contains(permanent.getId())) {
                            permanent.sacrifice(source, game);
                        }
                    }
                }
            }
        }
        // count minimal cards in hand
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                int count = player.getHand().size();
                if (count < minCard) {
                    minCard = count;
                }
            }
        }
        // discard cards over the minimum
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                TargetCardInHand target = new TargetCardInHand(minCard, new FilterCard());
                if (target.choose(Outcome.Benefit, player.getId(), source.getSourceId(), game)) {
                    Cards cards = player.getHand().copy();
                    cards.removeIf(target.getTargets()::contains);
                    player.discard(cards, false, source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Cards(mage.cards.Cards)

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