Search in sources :

Example 21 with SubType

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

the class ChooseCreatureTypeEffect method getChosenCreatureType.

/**
 * @param objectId    sourceId the effect was exeuted under
 * @param game
 * @param typePostfix special postfix if you want to store multiple choices from different effects
 * @return
 */
public static SubType getChosenCreatureType(UUID objectId, Game game, String typePostfix) {
    SubType creatureType = null;
    Object savedCreatureType = game.getState().getValue(objectId + typePostfix);
    if (savedCreatureType != null) {
        creatureType = SubType.byDescription(savedCreatureType.toString());
    }
    return creatureType;
}
Also used : SubType(mage.constants.SubType) MageObject(mage.MageObject)

Example 22 with SubType

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

the class ChooseLandTypeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getPermanentEntering(source.getSourceId());
    if (mageObject == null) {
        mageObject = game.getObject(source.getSourceId());
    }
    if (controller != null && mageObject != null) {
        Choice typeChoice = new ChoiceImpl(true);
        typeChoice.setMessage("Choose land type");
        typeChoice.setChoices(SubType.getLandTypes().stream().map(SubType::toString).collect(Collectors.toSet()));
        if (controller.choose(outcome, typeChoice, game)) {
            if (!game.isSimulation()) {
                game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + typeChoice.getChoice());
            }
            game.getState().setValue(mageObject.getId() + "_type", SubType.byDescription(typeChoice.getChoice()));
            if (mageObject instanceof Permanent) {
                ((Permanent) mageObject).addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice()), game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) SubType(mage.constants.SubType) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl)

Example 23 with SubType

use of mage.constants.SubType 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 24 with SubType

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

the class DefensiveManeuversEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (player == null || sourceObject == null) {
        return false;
    }
    Choice choice = new ChoiceCreatureType(sourceObject);
    SubType subType = null;
    if (player.choose(outcome, choice, game)) {
        subType = SubType.byDescription(choice.getChoice());
    }
    if (subType == null) {
        return false;
    }
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(subType.getPredicate());
    game.addEffect(new BoostAllEffect(0, 4, Duration.EndOfTurn, filter, false), source);
    return true;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) SubType(mage.constants.SubType) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) MageObject(mage.MageObject) ChoiceCreatureType(mage.choices.ChoiceCreatureType) BoostAllEffect(mage.abilities.effects.common.continuous.BoostAllEffect)

Aggregations

SubType (mage.constants.SubType)24 Player (mage.players.Player)11 MageObject (mage.MageObject)8 CardType (mage.constants.CardType)6 Permanent (mage.game.permanent.Permanent)6 UUID (java.util.UUID)5 SuperType (mage.constants.SuperType)5 Collectors (java.util.stream.Collectors)4 Ability (mage.abilities.Ability)4 Card (mage.cards.Card)4 ObjectColor (mage.ObjectColor)3 Effect (mage.abilities.effects.Effect)3 OneShotEffect (mage.abilities.effects.OneShotEffect)3 FilterCreatureCard (mage.filter.common.FilterCreatureCard)3 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 CardImpl (mage.cards.CardImpl)2 CardSetInfo (mage.cards.CardSetInfo)2 Choice (mage.choices.Choice)2 Rarity (mage.constants.Rarity)2