Search in sources :

Example 11 with Rarity

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

the class FateReforgedCollator method addSpecialCards.

@Override
protected void addSpecialCards(List<Card> booster, int number) {
    // number is here always 1
    Rarity rarity;
    if (RandomUtil.nextInt(24) < 23) {
        rarity = Rarity.COMMON;
    } else {
        rarity = Rarity.RARE;
    }
    addToBooster(booster, getSpecialCardsByRarity(rarity));
}
Also used : Rarity(mage.constants.Rarity)

Example 12 with Rarity

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

the class CardCriteria method buildQuery.

public void buildQuery(QueryBuilder qb) throws SQLException {
    optimize();
    Where where = qb.where();
    where.eq("nightCard", false);
    where.eq("splitCardHalf", false);
    int clausesCount = 2;
    if (name != null) {
        where.like("name", new SelectArg('%' + name + '%'));
        clausesCount++;
    }
    if (nameExact != null) {
        where.like("name", new SelectArg(nameExact));
        clausesCount++;
    }
    if (rules != null) {
        where.like("rules", new SelectArg('%' + rules + '%'));
        clausesCount++;
    }
    if (doubleFaced != null) {
        where.eq("doubleFaced", doubleFaced);
        clausesCount++;
    }
    if (modalDoubleFaced != null) {
        where.eq("modalDoubleFacesCard", modalDoubleFaced);
        clausesCount++;
    }
    for (Rarity rarity : rarities) {
        where.eq("rarity", rarity);
    }
    if (!rarities.isEmpty()) {
        where.or(rarities.size());
        clausesCount++;
    }
    for (String setCode : setCodes) {
        where.eq("setCode", setCode);
    }
    if (!setCodes.isEmpty()) {
        where.or(setCodes.size());
        clausesCount++;
    }
    for (String ignoreSetCode : ignoreSetCodes) {
        where.ne("setCode", ignoreSetCode);
    }
    if (!ignoreSetCodes.isEmpty()) {
        where.or(ignoreSetCodes.size());
        clausesCount++;
    }
    if (types.size() != 7) {
        // if all types selected - no selection needed (Tribal and Conspiracy not selectable yet)
        for (CardType type : types) {
            where.like("types", new SelectArg('%' + type.name() + '%'));
        }
        if (!types.isEmpty()) {
            where.or(types.size());
            clausesCount++;
        }
    }
    for (CardType type : notTypes) {
        where.not().like("types", new SelectArg('%' + type.name() + '%'));
        clausesCount++;
    }
    for (SuperType superType : supertypes) {
        where.like("supertypes", new SelectArg('%' + superType.name() + '%'));
        clausesCount++;
    }
    for (SuperType superType : notSupertypes) {
        where.not().like("supertypes", new SelectArg('%' + superType.name() + '%'));
        clausesCount++;
    }
    for (SubType subType : subtypes) {
        where.like("subtypes", new SelectArg('%' + subType.toString() + '%'));
        clausesCount++;
    }
    if (manaValue != null) {
        where.eq("manaValue", manaValue);
        clausesCount++;
    }
    int colorClauses = 0;
    if (black) {
        where.eq("black", true);
        colorClauses++;
    }
    if (blue) {
        where.eq("blue", true);
        colorClauses++;
    }
    if (green) {
        where.eq("green", true);
        colorClauses++;
    }
    if (red) {
        where.eq("red", true);
        colorClauses++;
    }
    if (white) {
        where.eq("white", true);
        colorClauses++;
    }
    if (colorless) {
        where.eq("black", false).eq("blue", false).eq("green", false).eq("red", false).eq("white", false);
        where.and(5);
        colorClauses++;
    }
    if (colorClauses > 0) {
        where.or(colorClauses);
        clausesCount++;
    }
    if (minCardNumber != Integer.MIN_VALUE) {
        where.ge("cardNumberAsInt", minCardNumber);
        clausesCount++;
    }
    if (maxCardNumber != Integer.MAX_VALUE) {
        where.le("cardNumberAsInt", maxCardNumber);
        clausesCount++;
    }
    if (clausesCount > 0) {
        where.and(clausesCount);
    } else {
        where.eq("cardNumber", new SelectArg(0));
    }
    if (start != null) {
        qb.offset(start);
    }
    if (count != null) {
        qb.limit(count);
    }
    if (sortBy != null) {
        qb.orderBy(sortBy, true);
    }
}
Also used : Rarity(mage.constants.Rarity) SelectArg(com.j256.ormlite.stmt.SelectArg) SubType(mage.constants.SubType) CardType(mage.constants.CardType) Where(com.j256.ormlite.stmt.Where) SuperType(mage.constants.SuperType)

Example 13 with Rarity

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

the class StrixhavenSchoolOfMagesCollator method addSpecialCards.

@Override
protected void addSpecialCards(List<Card> booster, int number) {
    // number is here always 2
    // Boosters have one card from STA, odds are 2/3 for uncommon, 4/15 for rare, 1/15 for mythic
    Rarity rarity;
    int rarityKey = RandomUtil.nextInt(15);
    if (rarityKey == 14) {
        rarity = Rarity.MYTHIC;
    } else if (rarityKey >= 10) {
        rarity = Rarity.RARE;
    } else {
        rarity = Rarity.UNCOMMON;
    }
    addToBooster(booster, StrixhavenMysticalArchive.getInstance().getCardsByRarity(rarity));
    // Boosters have one Lesson card
    rarityKey = RandomUtil.nextInt(148);
    if (rarityKey == 0) {
        rarity = Rarity.MYTHIC;
    } else if (rarityKey < 11) {
        rarity = Rarity.RARE;
    } else {
        rarity = Rarity.COMMON;
    }
    addToBooster(booster, getSpecialCardsByRarity(rarity));
}
Also used : Rarity(mage.constants.Rarity)

Example 14 with Rarity

use of mage.constants.Rarity 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 15 with Rarity

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

the class ManaSymbols method loadImages.

public static void loadImages() {
    logger.info("Loading symbols...");
    // TODO: delete files rename jpg->gif (it was for backward compatibility for one of the old version?)
    renameSymbols(getResourceSymbolsPath(ResourceSymbolSize.SMALL));
    renameSymbols(getResourceSymbolsPath(ResourceSymbolSize.MEDIUM));
    renameSymbols(getResourceSymbolsPath(ResourceSymbolSize.LARGE));
    // renameSymbols(getSymbolsPath(ResourceSymbolSize.SVG)); // not need
    // TODO: remove medium sets files to "medium" folder like symbols above?
    // prepare svg's css settings
    SvgUtils.prepareCss(CSS_FILE_NAME, CSS_ADDITIONAL_SETTINGS, true);
    // preload symbol images
    loadSymbolImages(15);
    loadSymbolImages(25);
    loadSymbolImages(50);
    // save symbol images in png for html replacement in texts
    // you can add bigger size for better quality
    Map<String, BufferedImage> pngImages = manaImages.get(50);
    if (pngImages != null) {
        File pngPath = new File(getResourceSymbolsPath(ResourceSymbolSize.PNG));
        if (!pngPath.exists()) {
            pngPath.mkdirs();
        }
        for (String symbol : symbols) {
            try {
                BufferedImage image = pngImages.get(symbol);
                if (image != null) {
                    File newFile = new File(pngPath.getPath() + File.separator + symbol + ".png");
                    ImageIO.write(image, "png", newFile);
                }
            } catch (Exception e) {
                logger.warn("Can't generate png image for symbol:" + symbol);
            }
        }
    }
    // preload set images
    java.util.List<String> setCodes = ExpansionRepository.instance.getSetCodes();
    if (setCodes == null) {
        // the cards db file is probaly not included in the client. It will be created after the first connect to a server.
        logger.warn("No db information for sets found. Connect to a server to create database file on client side. Then try to restart the client.");
        return;
    }
    for (String set : setCodes) {
        if (withoutSymbols.contains(set)) {
            continue;
        }
        Set<Rarity> codes;
        if (onlyMythics.contains(set)) {
            codes = EnumSet.of(Rarity.MYTHIC);
        } else {
            codes = EnumSet.of(Rarity.COMMON, Rarity.UNCOMMON, Rarity.RARE, Rarity.MYTHIC);
        }
        Map<Rarity, Image> rarityImages = new EnumMap<>(Rarity.class);
        setImages.put(set, rarityImages);
        // load medium size
        for (Rarity rarityCode : codes) {
            File file = new File(getResourceSetsPath(ResourceSetSize.MEDIUM) + set + '-' + rarityCode.getCode() + ".jpg");
            try {
                Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
                int width = image.getWidth(null);
                if (width > 21) {
                    int h = image.getHeight(null);
                    if (h > 0) {
                        Rectangle r = new Rectangle(21, (int) (h * 21.0f / width));
                        BufferedImage resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
                        rarityImages.put(rarityCode, resized);
                    }
                } else {
                    rarityImages.put(rarityCode, image);
                }
            } catch (Exception e) {
            }
        }
        // generate small size
        try {
            File file = new File(getResourceSetsPath(ResourceSetSize.MEDIUM));
            if (!file.exists()) {
                file.mkdirs();
            }
            String pathRoot = getResourceSetsPath(ResourceSetSize.SMALL) + set;
            for (Rarity code : codes) {
                File newFile = new File(pathRoot + '-' + code + ".png");
                if (!(MageFrame.isSkipSmallSymbolGenerationForExisting() && newFile.exists())) {
                    // skip if option enabled and file already exists
                    file = new File(getResourceSetsPath(ResourceSetSize.MEDIUM) + set + '-' + code + ".png");
                    if (file.exists()) {
                        continue;
                    }
                    file = new File(getResourceSetsPath(ResourceSetSize.MEDIUM) + set + '-' + code + ".jpg");
                    Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
                    try {
                        int width = image.getWidth(null);
                        int height = image.getHeight(null);
                        if (height > 0) {
                            int dx = 0;
                            if (set.equals("M10") || set.equals("M11") || set.equals("M12")) {
                                dx = 6;
                            }
                            Rectangle r = new Rectangle(15 + dx, (int) (height * (15.0f + dx) / width));
                            BufferedImage resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
                            ImageIO.write(resized, "png", newFile);
                        }
                    } catch (Exception e) {
                        if (file.exists()) {
                            file.delete();
                        }
                    }
                }
            }
        } catch (Exception e) {
        }
    }
    // mark loaded images
    // TODO: delete that code, images draw-show must dynamicly
    File file;
    for (String set : ExpansionRepository.instance.getSetCodes()) {
        file = new File(getResourceSetsPath(ResourceSetSize.SMALL));
        if (!file.exists()) {
            break;
        }
        file = new File(getResourceSetsPath(ResourceSetSize.SMALL) + set + "-C.png");
        try {
            Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
            int width = image.getWidth(null);
            int height = image.getHeight(null);
            setImagesExist.put(set, new Dimension(width, height));
        } catch (Exception e) {
        }
    }
}
Also used : BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage) Rarity(mage.constants.Rarity) java.util(java.util)

Aggregations

Rarity (mage.constants.Rarity)16 CardInfo (mage.cards.repository.CardInfo)4 CardType (mage.constants.CardType)3 SubType (mage.constants.SubType)3 java.util (java.util)2 SuperType (mage.constants.SuperType)2 SelectArg (com.j256.ormlite.stmt.SelectArg)1 Where (com.j256.ormlite.stmt.Where)1 BufferedImage (java.awt.image.BufferedImage)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 MageObject (mage.MageObject)1 Ability (mage.abilities.Ability)1 PartnerWithAbility (mage.abilities.keyword.PartnerWithAbility)1 Card (mage.cards.Card)1 ExpansionSet (mage.cards.ExpansionSet)1 ModalDoubleFacesCard (mage.cards.ModalDoubleFacesCard)1 CardScanner (mage.cards.repository.CardScanner)1 mage.sets (mage.sets)1 CardView (mage.view.CardView)1