Search in sources :

Example 21 with CardType

use of mage.constants.CardType in project mage by magefree.

the class MartyrsBondEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<UUID> perms = new ArrayList<>();
    if (source != null) {
        Permanent saccedPermanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null && saccedPermanent != null) {
            FilterControlledPermanent filter = new FilterControlledPermanent();
            String message = "permanent with type (";
            boolean firstType = true;
            List<CardType.CardTypePredicate> cardTypes = new ArrayList<>();
            for (CardType type : saccedPermanent.getCardType(game)) {
                cardTypes.add(type.getPredicate());
                if (firstType) {
                    message += type;
                    firstType = false;
                } else {
                    message += " or " + type;
                }
            }
            message += ") to sacrifice";
            filter.add(Predicates.or(cardTypes));
            filter.setMessage(message);
            for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
                Player player = game.getPlayer(playerId);
                if (player != null && !playerId.equals(controller.getId())) {
                    TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
                    if (target.canChoose(source.getSourceId(), playerId, game)) {
                        player.chooseTarget(Outcome.Sacrifice, target, source, game);
                        perms.add(target.getFirstTarget());
                    }
                }
            }
            boolean saccedPermaents = false;
            for (UUID permID : perms) {
                Permanent permanent = game.getPermanent(permID);
                if (permanent != null) {
                    permanent.sacrifice(source, game);
                    saccedPermaents = true;
                }
            }
            return saccedPermaents;
        }
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) CardType(mage.constants.CardType) ArrayList(java.util.ArrayList) UUID(java.util.UUID) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 22 with CardType

use of mage.constants.CardType in project mage by magefree.

the class MuldrothaTheGravetideWatcher method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    if (source.isControlledBy(affectedControllerId) && // only from your graveyard
    source.isControlledBy(game.getOwnerId(objectId)) && // only during your turns (e.g. prevent flash creatures)
    affectedControllerId.equals(game.getActivePlayerId()) && Zone.GRAVEYARD.equals(game.getState().getZone(objectId))) {
        MuldrothaTheGravetideWatcher watcher = game.getState().getWatcher(MuldrothaTheGravetideWatcher.class);
        MageObject mageObject = game.getObject(objectId);
        if (mageObject != null && watcher != null) {
            for (CardType cardType : mageObject.getCardType(game)) {
                if (cardType.isPermanentType()) {
                    MageObjectReference mor = new MageObjectReference(source.getSourceObject(game), game);
                    if (!watcher.permanentTypePlayedFromGraveyard(mor, cardType)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : CardType(mage.constants.CardType) MageObject(mage.MageObject) MageObjectReference(mage.MageObjectReference)

Example 23 with CardType

use of mage.constants.CardType in project mage by magefree.

the class SelectionBox method updateCounts.

private void updateCounts() {
    deckNameAndCountLabel.setText(role.getName() + " - " + allCards.size());
    creatureCountLabel.setText(String.valueOf(creatureCounter.get()));
    landCountLabel.setText(String.valueOf(landCounter.get()));
    for (CardType cardType : selectByTypeButtons.keySet()) {
        AbstractButton button = selectByTypeButtons.get(cardType);
        String text = cardType.toString();
        int numCards = getCount(cardType);
        if (cardType == CardType.CONSPIRACY) {
            continue;
        }
        if (numCards > 0) {
            button.setForeground(Color.BLACK);
            text = text + " - " + numCards;
        } else {
            button.setForeground(new Color(100, 100, 100));
        }
        button.setText(text);
    }
}
Also used : CardType(mage.constants.CardType)

Example 24 with CardType

use of mage.constants.CardType in project mage by magefree.

the class SelectionBox method reselectBy.

public void reselectBy() {
    // Deselect everything
    deselectAll();
    boolean useText = false;
    String searchStr = "";
    if (searchByTextField.getText().length() >= 3) {
        useText = true;
        searchStr = searchByTextField.getText().toLowerCase(Locale.ENGLISH);
    }
    for (CardType cardType : selectByTypeButtons.keySet()) {
        AbstractButton button = selectByTypeButtons.get(cardType);
        if (button != null) {
            if (button.isSelected()) {
                // Special case - "Multiples"  (CONSPIRACY type)
                if (cardType == CardType.CONSPIRACY) {
                    Map<String, CardView> cardNames = new HashMap<>();
                    for (List<List<CardView>> gridRow : cardGrid) {
                        for (List<CardView> stack : gridRow) {
                            for (CardView card : stack) {
                                if (cardNames.get(card.getName()) == null) {
                                    cardNames.put(card.getName(), card);
                                } else {
                                    card.setSelected(true);
                                    cardViews.get(card.getId()).update(card);
                                    CardView origCard = cardNames.get(card.getName());
                                    origCard.setSelected(true);
                                    cardViews.get(origCard.getId()).update(origCard);
                                }
                            }
                        }
                    }
                    continue;
                }
                for (List<List<CardView>> gridRow : cardGrid) {
                    for (List<CardView> stack : gridRow) {
                        for (CardView card : stack) {
                            boolean s = card.isSelected() || card.getCardTypes().contains(cardType);
                            card.setSelected(s);
                            cardViews.get(card.getId()).update(card);
                        }
                    }
                }
            }
        }
    }
    if (useText) {
        for (List<List<CardView>> gridRow : cardGrid) {
            for (List<CardView> stack : gridRow) {
                for (CardView card : stack) {
                    boolean s = card.isSelected();
                    // Name
                    if (!s) {
                        s = card.getName().toLowerCase(Locale.ENGLISH).contains(searchStr);
                    }
                    // Sub & Super Types
                    if (!s) {
                        for (SuperType str : card.getSuperTypes()) {
                            s |= str.toString().toLowerCase(Locale.ENGLISH).contains(searchStr);
                        }
                        for (SubType str : card.getSubTypes()) {
                            s |= str.toString().toLowerCase(Locale.ENGLISH).contains(searchStr);
                        }
                    }
                    // Rarity
                    if (!s) {
                        Rarity r = card.getRarity();
                        if (r != null) {
                            s |= r.toString().toLowerCase(Locale.ENGLISH).contains(searchStr);
                        }
                    }
                    // Type line
                    if (!s) {
                        String t = "";
                        for (CardType type : card.getCardTypes()) {
                            t += ' ' + type.toString();
                        }
                        s |= t.toLowerCase(Locale.ENGLISH).contains(searchStr);
                    }
                    // Casting cost
                    if (!s) {
                        s |= card.getManaCostStr().toLowerCase(Locale.ENGLISH).contains(searchStr);
                    }
                    // Rules
                    if (!s) {
                        for (String str : card.getRules()) {
                            s |= str.toLowerCase(Locale.ENGLISH).contains(searchStr);
                        }
                    }
                    card.setSelected(s);
                    cardViews.get(card.getId()).update(card);
                }
            }
        }
    }
    // And finally rerender
    layoutGrid();
    repaintGrid();
}
Also used : SubType(mage.constants.SubType) CardView(mage.view.CardView) SuperType(mage.constants.SuperType) Rarity(mage.constants.Rarity) CardType(mage.constants.CardType) List(java.util.List)

Example 25 with CardType

use of mage.constants.CardType in project mage by magefree.

the class CardInfoWindowDialog method qtyCardTypes.

private int qtyCardTypes(mage.view.CardsView cardsView) {
    Set<String> cardTypesPresent = new LinkedHashSet<String>() {
    };
    for (CardView card : cardsView.values()) {
        Set<CardType> cardTypes = EnumSet.noneOf(CardType.class);
        cardTypes.addAll(card.getCardTypes());
        for (CardType cardType : cardTypes) {
            cardTypesPresent.add(cardType.toString());
        }
    }
    if (cardTypesPresent.isEmpty()) {
        return 0;
    } else {
        return cardTypesPresent.size();
    }
}
Also used : CardType(mage.constants.CardType) CardView(mage.view.CardView)

Aggregations

CardType (mage.constants.CardType)29 Player (mage.players.Player)16 Permanent (mage.game.permanent.Permanent)11 MageObject (mage.MageObject)9 Card (mage.cards.Card)9 TargetPermanent (mage.target.TargetPermanent)8 Choice (mage.choices.Choice)7 ChoiceImpl (mage.choices.ChoiceImpl)7 UUID (java.util.UUID)4 Cards (mage.cards.Cards)4 SuperType (mage.constants.SuperType)4 FilterCard (mage.filter.FilterCard)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)3 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)3 Ability (mage.abilities.Ability)2 Effect (mage.abilities.effects.Effect)2 Rarity (mage.constants.Rarity)2 SubType (mage.constants.SubType)2