Search in sources :

Example 6 with ExpansionSet

use of mage.cards.ExpansionSet in project mage by magefree.

the class MomirEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int value = source.getManaCostsToPay().getX();
    if (game.isSimulation()) {
        // Create dummy token to prevent multiple DB find cards what causes H2 java.lang.IllegalStateException if AI cancels calculation because of time out
        Token token = new CreatureToken(value, value + 1);
        token.putOntoBattlefield(1, game, source, source.getControllerId(), false, false);
        return true;
    }
    // should this be random across card names
    CardCriteria criteria = new CardCriteria().types(CardType.CREATURE).manaValue(value);
    List<CardInfo> options = CardRepository.instance.findCards(criteria);
    if (options == null || options.isEmpty()) {
        game.informPlayers("No random creature card with mana value of " + value + " was found.");
        return false;
    }
    // search for a random non custom set creature
    EmptyToken token = null;
    while (!options.isEmpty()) {
        int index = RandomUtil.nextInt(options.size());
        ExpansionSet expansionSet = Sets.findSet(options.get(index).getSetCode());
        if (expansionSet == null || !expansionSet.getSetType().isEternalLegal()) {
            options.remove(index);
        } else {
            Card card = options.get(index).getCard();
            if (card != null) {
                token = new EmptyToken();
                CardUtil.copyTo(token).from(card, game);
                break;
            } else {
                options.remove(index);
            }
        }
    }
    if (token != null) {
        token.putOntoBattlefield(1, game, source, source.getControllerId(), false, false);
        return true;
    }
    return false;
}
Also used : CardCriteria(mage.cards.repository.CardCriteria) CardInfo(mage.cards.repository.CardInfo) EmptyToken(mage.game.permanent.token.EmptyToken) CreatureToken(mage.game.permanent.token.custom.CreatureToken) Token(mage.game.permanent.token.Token) ExpansionSet(mage.cards.ExpansionSet) CreatureToken(mage.game.permanent.token.custom.CreatureToken) EmptyToken(mage.game.permanent.token.EmptyToken) Card(mage.cards.Card)

Example 7 with ExpansionSet

use of mage.cards.ExpansionSet in project mage by magefree.

the class BoosterGenerationTest method test_CollectBoosterStats.

// debug only: collect info about cards in boosters, see https://github.com/magefree/mage/issues/8081
@Ignore
@Test
public void test_CollectBoosterStats() {
    ExpansionSet setToAnalyse = Innistrad.getInstance();
    int openBoosters = 1000;
    Map<String, Integer> resRatio = new HashMap<>();
    int totalCards = 0;
    for (int i = 1; i <= openBoosters; i++) {
        List<Card> booster = setToAnalyse.createBooster();
        totalCards += booster.size();
        booster.forEach(card -> {
            String code = String.format("%s %s", card.getRarity().getCode(), card.getName());
            resRatio.putIfAbsent(code, 0);
            resRatio.computeIfPresent(code, (u, count) -> count + 1);
        });
    }
    final Integer totalCardsFinal = totalCards;
    List<String> info = resRatio.entrySet().stream().sorted(new Comparator<Map.Entry<String, Integer>>() {

        @Override
        public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
            return Integer.compare(o2.getValue(), o1.getValue());
        }
    }).map(e -> String.format("%s: %d", e.getKey(), e.getValue())).collect(Collectors.toList());
    System.out.println(setToAnalyse.getName() + " - boosters opened: " + openBoosters + ". Found cards: " + totalCardsFinal + "\n" + info.stream().collect(Collectors.joining("\n")));
}
Also used : MageTestBase(org.mage.test.serverside.base.MageTestBase) java.util(java.util) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) mage.sets(mage.sets) CardScanner(mage.cards.repository.CardScanner) PartnerWithAbility(mage.abilities.keyword.PartnerWithAbility) Test(org.junit.Test) SubType(mage.constants.SubType) Collectors(java.util.stream.Collectors) ExpansionSet(mage.cards.ExpansionSet) Ignore(org.junit.Ignore) CardInfo(mage.cards.repository.CardInfo) CardType(mage.constants.CardType) MageObject(mage.MageObject) Rarity(mage.constants.Rarity) Card(mage.cards.Card) Assert(org.junit.Assert) Ability(mage.abilities.Ability) Before(org.junit.Before) ExpansionSet(mage.cards.ExpansionSet) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) Card(mage.cards.Card) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with ExpansionSet

use of mage.cards.ExpansionSet in project mage by magefree.

the class SummonThePackEffect 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();
            List<Card> creatureCards = new ArrayList<>();
            if (boosterPack != null) {
                StringBuilder message = new StringBuilder(controller.getLogName()).append(" opened: ");
                for (Card c : boosterPack) {
                    if (c != null && c.isCreature(game)) {
                        message.append(c.getName()).append(" ");
                        message.append(" (creature card) ");
                        ContinuousEffect effect2 = new BecomesBlackZombieAdditionEffect(false);
                        effect2.setTargetPointer(new FixedTarget(c.getId()));
                        game.addEffect(effect2, source);
                        creatureCards.add(c);
                        c.setZone(Zone.OUTSIDE, game);
                    }
                }
                if (creatureCards.size() > 0) {
                    Set<Card> ccs = new HashSet<>(creatureCards);
                    game.loadCards(ccs, controller.getId());
                    controller.moveCards(ccs, Zone.BATTLEFIELD, source, game);
                }
                game.informPlayers(message.toString());
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) ArrayList(java.util.ArrayList) BecomesBlackZombieAdditionEffect(mage.abilities.effects.common.continuous.BecomesBlackZombieAdditionEffect) ExpansionSet(mage.cards.ExpansionSet) Card(mage.cards.Card) ChooseExpansionSetEffect(mage.abilities.effects.common.ChooseExpansionSetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) HashSet(java.util.HashSet)

Example 9 with ExpansionSet

use of mage.cards.ExpansionSet in project mage by magefree.

the class RandomBoosterDraft method getNextBooster.

private ExpansionSet getNextBooster() {
    if (useBoosters.isEmpty()) {
        resetBoosters();
    }
    ExpansionSet theBooster = useBoosters.get(0);
    useBoosters.remove(theBooster);
    return theBooster;
}
Also used : ExpansionSet(mage.cards.ExpansionSet)

Example 10 with ExpansionSet

use of mage.cards.ExpansionSet in project mage by magefree.

the class MageBook method updateCardStats.

private void updateCardStats(String setCode, boolean isCardsShow) {
    // sets do not have total cards number, it's a workaround
    ExpansionSet set = Sets.findSet(setCode);
    if (set != null) {
        setCaption.setText(set.getCode() + " - " + set.getName());
    } else {
        setCaption.setText("ERROR");
        setInfo.setText("ERROR");
        return;
    }
    if (!isCardsShow) {
        // tokens or emblems, stats not need
        setInfo.setText("");
        return;
    }
    // cards stats
    List<Integer> haveNumbers = set.getSetCardInfo().stream().map(ExpansionSet.SetCardInfo::getCardNumberAsInt).collect(Collectors.toList());
    int startNumber = haveNumbers.stream().min(Integer::compareTo).orElse(9999);
    int endNumber = haveNumbers.stream().max(Integer::compareTo).orElse(0);
    // second run for empty numbers
    int countHave = haveNumbers.size();
    int countNotHave = IntStream.range(startNumber, endNumber + 1).map(x -> haveNumbers.contains(x) ? 0 : 1).sum();
    // result
    setInfo.setText(String.format("%d cards of %d are available", countHave, countHave + countNotHave));
    if (countNotHave > 0) {
        setInfo.setForeground(new Color(150, 0, 0));
    } else {
        setInfo.setForeground(jLayeredPane.getForeground());
    }
}
Also used : IntStream(java.util.stream.IntStream) ManaSymbols(org.mage.card.arcane.ManaSymbols) DownloadPicturesService.getTokenCardUrls(org.mage.plugins.card.images.DownloadPicturesService.getTokenCardUrls) MageFrame(mage.client.MageFrame) CardCriteria(mage.cards.repository.CardCriteria) ImagePanel(mage.components.ImagePanel) Sets(mage.cards.Sets) AudioManager(mage.client.util.audio.AudioManager) CardIconRenderSettings(mage.abilities.icon.CardIconRenderSettings) Constructor(java.lang.reflect.Constructor) ClientDefaultSettings(mage.client.util.ClientDefaultSettings) ArrayList(java.util.ArrayList) RateCard(mage.game.draft.RateCard) mage.view(mage.view) Logger(org.apache.log4j.Logger) ExpansionSet(mage.cards.ExpansionSet) NaturalOrderCardNumberComparator(mage.client.util.NaturalOrderCardNumberComparator) ImagePanelStyle(mage.components.ImagePanelStyle) PermanentToken(mage.game.permanent.PermanentToken) Locale(java.util.Locale) ImageIO(javax.imageio.ImageIO) MageCard(mage.cards.MageCard) ConstructedFormats(mage.client.util.sets.ConstructedFormats) Emblem(mage.game.command.Emblem) ImageHelper(mage.client.util.ImageHelper) BufferedImage(java.awt.image.BufferedImage) CardDimensions(mage.cards.CardDimensions) Plane(mage.game.command.Plane) CardDownloadData(org.mage.plugins.card.images.CardDownloadData) UUID(java.util.UUID) Math.min(java.lang.Math.min) CardRepository(mage.cards.repository.CardRepository) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HoverButton(mage.client.components.HoverButton) java.awt(java.awt) PreferencesDialog(mage.client.dialog.PreferencesDialog) Plugins(mage.client.plugins.impl.Plugins) Dungeon(mage.game.command.Dungeon) List(java.util.List) Token(mage.game.permanent.token.Token) BigCard(mage.client.cards.BigCard) CardInfo(mage.cards.repository.CardInfo) ExpansionRepository(mage.cards.repository.ExpansionRepository) javax.swing(javax.swing) InputStream(java.io.InputStream) ExpansionSet(mage.cards.ExpansionSet)

Aggregations

ExpansionSet (mage.cards.ExpansionSet)15 Card (mage.cards.Card)5 CardInfo (mage.cards.repository.CardInfo)4 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3 java.util (java.util)2 HashSet (java.util.HashSet)2 List (java.util.List)2 ChooseExpansionSetEffect (mage.abilities.effects.common.ChooseExpansionSetEffect)2 Sets (mage.cards.Sets)2 DeckValidatorError (mage.cards.decks.DeckValidatorError)2 CardCriteria (mage.cards.repository.CardCriteria)2 java.awt (java.awt)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Math.min (java.lang.Math.min)1 Constructor (java.lang.reflect.Constructor)1