Search in sources :

Example 16 with Deck

use of mage.cards.decks.Deck in project mage by magefree.

the class LoadTest method test_CreateRandomDeck.

@Test
public void test_CreateRandomDeck() {
    Deck deck;
    deck = DeckTestUtils.buildRandomDeck("G", false);
    Assert.assertNotNull(deck);
    for (Card card : deck.getCards()) {
        Assert.assertNotNull(card);
        Assert.assertTrue("card " + card.getName() + " color " + card.getColorIdentity().toString() + " must be in G", card.getColorIdentity().isGreen());
    }
    deck = DeckTestUtils.buildRandomDeck("U", false);
    Assert.assertNotNull(deck);
    for (Card card : deck.getCards()) {
        Assert.assertNotNull(card);
        Assert.assertTrue("card " + card.getName() + " color " + card.getColorIdentity().toString() + " must be in U", card.getColorIdentity().isBlue());
    }
    deck = DeckTestUtils.buildRandomDeck("BR", false);
    Assert.assertNotNull(deck);
    for (Card card : deck.getCards()) {
        Assert.assertNotNull(card);
        Assert.assertTrue("card " + card.getName() + " color " + card.getColorIdentity().toString() + " must be in BR", card.getColorIdentity().isBlack() || card.getColorIdentity().isRed());
    }
    deck = DeckTestUtils.buildRandomDeck("BUG", false);
    Assert.assertNotNull(deck);
    for (Card card : deck.getCards()) {
        Assert.assertNotNull(card);
        Assert.assertTrue("card " + card.getName() + " color " + card.getColorIdentity().toString() + " must be in BUG", card.getColorIdentity().isBlack() || card.getColorIdentity().isBlue() || card.getColorIdentity().isGreen());
    }
    // lands
    deck = DeckTestUtils.buildRandomDeck("UR", true);
    Assert.assertNotNull(deck);
    for (Card card : deck.getCards()) {
        Assert.assertNotNull(card);
        Assert.assertTrue("card " + card.getName() + " color " + card.getColorIdentity().toString() + " must be in UR", card.getColorIdentity().isBlue() || card.getColorIdentity().isRed());
        Assert.assertEquals("card " + card.getName() + " must be basic land ", Rarity.LAND, card.getRarity());
    }
    deck = DeckTestUtils.buildRandomDeck("B", true);
    Assert.assertNotNull(deck);
    for (Card card : deck.getCards()) {
        Assert.assertNotNull(card);
        Assert.assertTrue("card " + card.getName() + " color " + card.getColorIdentity().toString() + " must be in B", card.getColorIdentity().isBlack());
        Assert.assertEquals("card " + card.getName() + " must be basic land ", Rarity.LAND, card.getRarity());
    }
    // allowed sets
    deck = DeckTestUtils.buildRandomDeck("B", true, "GRN");
    Assert.assertNotNull(deck);
    for (Card card : deck.getCards()) {
        Assert.assertNotNull(card);
        Assert.assertTrue("card " + card.getName() + " color " + card.getColorIdentity().toString() + " must be in B", card.getColorIdentity().isBlack());
        Assert.assertEquals("card " + card.getName() + " have wrong set code " + card.getExpansionSetCode(), "GRN", card.getExpansionSetCode());
    }
}
Also used : Deck(mage.cards.decks.Deck) Card(mage.cards.Card) Test(org.junit.Test)

Example 17 with Deck

use of mage.cards.decks.Deck in project mage by magefree.

the class MulliganTestBase method generateDeck.

public static Deck generateDeck(UUID playerId, int count) {
    Deck deck = new Deck();
    Stream.generate(() -> new Forest(playerId, new CardSetInfo("Forest", "TEST", "1", LAND))).limit(count).forEach(deck.getCards()::add);
    return deck;
}
Also used : CardSetInfo(mage.cards.CardSetInfo) Deck(mage.cards.decks.Deck) Forest(mage.cards.basiclands.Forest)

Example 18 with Deck

use of mage.cards.decks.Deck in project mage by magefree.

the class NewTournamentDialog method getTournamentOptions.

private TournamentOptions getTournamentOptions() {
    TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
    int numSeats = (Integer) this.spnNumSeats.getValue();
    TournamentOptions tOptions = new TournamentOptions(this.txtName.getText(), "", numSeats);
    tOptions.setTournamentType(tournamentType.getName());
    tOptions.setPassword(txtPassword.getText());
    tOptions.getPlayerTypes().add(PlayerType.HUMAN);
    tOptions.setWatchingAllowed(cbAllowSpectators.isSelected());
    tOptions.setPlaneChase(cbPlaneChase.isSelected());
    tOptions.setQuitRatio((Integer) spnQuitRatio.getValue());
    tOptions.setMinimumRating((Integer) spnMinimumRating.getValue());
    for (TournamentPlayerPanel player : players) {
        tOptions.getPlayerTypes().add((PlayerType) player.getPlayerType().getSelectedItem());
    }
    if (!tournamentType.isElimination()) {
        tOptions.setNumberRounds((Integer) spnNumRounds.getValue());
    }
    if (tournamentType.isDraft()) {
        DraftOptions options = new DraftOptions();
        options.setTiming((TimingOption) this.cbDraftTiming.getSelectedItem());
        tOptions.setLimitedOptions(options);
    }
    if (tOptions.getLimitedOptions() == null) {
        tOptions.setLimitedOptions(new LimitedOptions());
    }
    if (tournamentType.isLimited()) {
        tOptions.getLimitedOptions().setConstructionTime((Integer) this.spnConstructTime.getValue() * 60);
        tOptions.getLimitedOptions().setIsRandom(tournamentType.isRandom());
        tOptions.getLimitedOptions().setIsRichMan(tournamentType.isRichMan());
        tOptions.getLimitedOptions().setIsJumpstart(tournamentType.isJumpstart());
        if (tournamentType.isJumpstart()) {
            if (!(jumpstartPacksFilename.isEmpty())) {
                String jumpstartPacksData = "";
                try {
                    jumpstartPacksData = new String(Files.readAllBytes(Paths.get(jumpstartPacksFilename)));
                    if (jumpstartPacksData.length() > 300000) {
                        JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Chosen file too big", "Jumpstart Packs data is too long.  Please trim or choose another file.", JOptionPane.ERROR_MESSAGE);
                        jumpstartPacksData = "";
                    }
                } catch (IOException e2) {
                    JOptionPane.showMessageDialog(MageFrame.getDesktop(), e2.getMessage(), "Error loading Jumpstart Packs data", JOptionPane.ERROR_MESSAGE);
                }
                tOptions.getLimitedOptions().setJumpstartPacks(jumpstartPacksData);
            }
        }
        if (tournamentType.isCubeBooster()) {
            tOptions.getLimitedOptions().setDraftCubeName(this.cbDraftCube.getSelectedItem().toString());
            if (!(cubeFromDeckFilename.isEmpty())) {
                Deck cubeFromDeck = new Deck();
                try {
                    cubeFromDeck = Deck.load(DeckImporter.importDeckFromFile(cubeFromDeckFilename, true), true, true);
                } catch (GameException e1) {
                    JOptionPane.showMessageDialog(MageFrame.getDesktop(), e1.getMessage(), "Error loading deck", JOptionPane.ERROR_MESSAGE);
                }
                if (cubeFromDeck != null) {
                    cubeFromDeck.clearLayouts();
                    tOptions.getLimitedOptions().setCubeFromDeck(cubeFromDeck);
                }
            }
        } else if (tournamentType.isRandom() || tournamentType.isRichMan()) {
            this.isRandom = tournamentType.isRandom();
            this.isRichMan = tournamentType.isRichMan();
            tOptions.getLimitedOptions().getSetCodes().clear();
            java.util.List<String> selected = randomPackSelector.getSelectedPacks();
            Collections.shuffle(selected);
            int maxPacks = 3 * (players.size() + 1);
            if (tournamentType.isRichMan()) {
                maxPacks = 36;
            }
            if (selected.size() > maxPacks) {
                StringBuilder infoString = new StringBuilder("More sets were selected than needed. ");
                infoString.append(maxPacks);
                infoString.append(" sets will be randomly chosen.");
                JOptionPane.showMessageDialog(MageFrame.getDesktop(), infoString, "Information", JOptionPane.INFORMATION_MESSAGE);
                tOptions.getLimitedOptions().getSetCodes().addAll(selected.subList(0, maxPacks));
            } else {
                tOptions.getLimitedOptions().getSetCodes().addAll(selected);
            }
        } else {
            for (JPanel panel : packPanels) {
                JComboBox combo = findComboInComponent(panel);
                if (combo != null) {
                    tOptions.getLimitedOptions().getSetCodes().add(((ExpansionInfo) combo.getSelectedItem()).getCode());
                } else {
                    logger.error("Can't find combo component in " + panel.toString());
                }
            }
        }
        tOptions.getMatchOptions().setDeckType("Limited");
        tOptions.getMatchOptions().setGameType("Two Player Duel");
        tOptions.getMatchOptions().setLimited(true);
    } else {
        tOptions.getLimitedOptions().setConstructionTime(0);
        tOptions.getLimitedOptions().setNumberBoosters(0);
        tOptions.getLimitedOptions().setDraftCube(null);
        tOptions.getLimitedOptions().setDraftCubeName("");
        tOptions.getMatchOptions().setDeckType((String) this.cbDeckType.getSelectedItem());
        tOptions.getMatchOptions().setGameType(((GameTypeView) this.cbGameType.getSelectedItem()).getName());
        tOptions.getMatchOptions().setLimited(false);
    }
    String serverAddress = SessionHandler.getSession().getServerHostname().orElse("");
    tOptions.getMatchOptions().setBannedUsers(IgnoreList.getIgnoredUsers(serverAddress));
    tOptions.getMatchOptions().setMatchTimeLimit((MatchTimeLimit) this.cbTimeLimit.getSelectedItem());
    tOptions.getMatchOptions().setSkillLevel((SkillLevel) this.cbSkillLevel.getSelectedItem());
    tOptions.getMatchOptions().setWinsNeeded((Integer) this.spnNumWins.getValue());
    tOptions.getMatchOptions().setFreeMulligans((Integer) this.spnFreeMulligans.getValue());
    tOptions.getMatchOptions().setMullgianType((MulliganType) this.cbMulligan.getSelectedItem());
    tOptions.getMatchOptions().setAttackOption(MultiplayerAttackOption.LEFT);
    tOptions.getMatchOptions().setRange(RangeOfInfluence.ALL);
    tOptions.getMatchOptions().setRollbackTurnsAllowed(this.chkRollbackTurnsAllowed.isSelected());
    tOptions.getMatchOptions().setRated(this.chkRated.isSelected());
    return tOptions;
}
Also used : LimitedOptions(mage.game.tournament.LimitedOptions) Deck(mage.cards.decks.Deck) IOException(java.io.IOException) TournamentPlayerPanel(mage.client.table.TournamentPlayerPanel) TournamentTypeView(mage.view.TournamentTypeView) TournamentOptions(mage.game.tournament.TournamentOptions) DraftOptions(mage.game.draft.DraftOptions) IgnoreList(mage.client.util.IgnoreList) ExpansionInfo(mage.cards.repository.ExpansionInfo) GameException(mage.game.GameException)

Example 19 with Deck

use of mage.cards.decks.Deck in project mage by magefree.

the class DeckLegalityPanel method validateDeck.

public void validateDeck(Deck deck) {
    // Non game GUI like Deck Editor works with Mock cards (fake cards with texts only), but validate must use
    // real cards all the time. So convert it here before check.
    final Deck deckToValidate;
    if (deck.getCards().stream().noneMatch(this::isMockCard) && deck.getSideboard().stream().noneMatch(this::isMockCard)) {
        // contains real cards, e.g. it's a game
        deckToValidate = deck;
    } else {
        // contains mock cards, e.g. it's a Deck Editor
        try {
            deckToValidate = Deck.load(deck.getDeckCardLists(), true, false);
        } catch (Exception ex) {
            logger.error("Can't load real deck cards for validate: " + ex.getMessage(), ex);
            return;
        }
    }
    Arrays.stream(getComponents()).filter(LegalityLabel.class::isInstance).map(LegalityLabel.class::cast).forEach(label -> label.validateDeck(deckToValidate));
}
Also used : LegalityLabel(mage.client.components.LegalityLabel) Deck(mage.cards.decks.Deck)

Example 20 with Deck

use of mage.cards.decks.Deck in project mage by magefree.

the class Brawl method validate.

@Override
public boolean validate(Deck deck) {
    boolean valid = true;
    errorsList.clear();
    Card brawler = null;
    Card companion = null;
    FilterMana colorIdentity = new FilterMana();
    if (deck.getSideboard().size() == 1) {
        for (Card card : deck.getSideboard()) {
            brawler = card;
        }
    } else if (deck.getSideboard().size() == 2) {
        Iterator<Card> iter = deck.getSideboard().iterator();
        Card card1 = iter.next();
        Card card2 = iter.next();
        if (card1.getAbilities().stream().anyMatch(ability -> ability instanceof CompanionAbility)) {
            companion = card1;
            brawler = card2;
        } else if (card2.getAbilities().stream().anyMatch(ability -> ability instanceof CompanionAbility)) {
            companion = card2;
            brawler = card1;
        } else {
            addError(DeckValidatorErrorType.PRIMARY, "Brawl", "Sideboard must contain only the brawler and up to 1 companion");
            valid = false;
        }
    } else {
        addError(DeckValidatorErrorType.PRIMARY, "Brawl", "Sideboard must contain only the brawler and up to 1 companion");
        valid = false;
    }
    if (brawler != null) {
        ManaUtil.collectColorIdentity(colorIdentity, brawler.getColorIdentity());
        if (bannedCommander.contains(brawler.getName())) {
            addError(DeckValidatorErrorType.PRIMARY, brawler.getName(), "Brawler banned (" + brawler.getName() + ')', true);
            valid = false;
        }
        if (!((brawler.hasCardTypeForDeckbuilding(CardType.CREATURE) && brawler.isLegendary()) || brawler.hasCardTypeForDeckbuilding(CardType.PLANESWALKER) || brawler.getAbilities().contains(CanBeYourCommanderAbility.getInstance()))) {
            addError(DeckValidatorErrorType.PRIMARY, brawler.getName(), "Brawler Invalid (" + brawler.getName() + ')', true);
            valid = false;
        }
    }
    if (companion != null && deck.getCards().size() + deck.getSideboard().size() != getDeckMinSize() + 1) {
        addError(DeckValidatorErrorType.DECK_SIZE, "Deck", "Must contain " + (getDeckMinSize() + 1) + " cards (companion doesn't count in deck size requirement): has " + (deck.getCards().size() + deck.getSideboard().size()) + " cards");
        valid = false;
    } else if (companion == null && deck.getCards().size() + deck.getSideboard().size() != getDeckMinSize()) {
        addError(DeckValidatorErrorType.DECK_SIZE, "Deck", "Must contain " + getDeckMinSize() + " cards: has " + (deck.getCards().size() + deck.getSideboard().size()) + " cards");
        valid = false;
    }
    Map<String, Integer> counts = new HashMap<>();
    countCards(counts, deck.getCards());
    countCards(counts, deck.getSideboard());
    valid = checkCounts(1, counts) && valid;
    for (String bannedCard : banned) {
        if (counts.containsKey(bannedCard)) {
            addError(DeckValidatorErrorType.BANNED, bannedCard, "Banned", true);
            valid = false;
        }
    }
    Set<String> basicsInDeck = new HashSet<>();
    if (colorIdentity.isColorless()) {
        for (Card card : deck.getCards()) {
            if (basicLandNames.contains(card.getName())) {
                basicsInDeck.add(card.getName());
            }
        }
    }
    for (Card card : deck.getCards()) {
        if (!ManaUtil.isColorIdentityCompatible(colorIdentity, card.getColorIdentity()) && !(colorIdentity.isColorless() && basicsInDeck.size() == 1 && basicsInDeck.contains(card.getName()))) {
            addError(DeckValidatorErrorType.OTHER, card.getName(), "Invalid color (" + colorIdentity.toString() + ')', true);
            valid = false;
        }
    }
    for (Card card : deck.getSideboard()) {
        if (!ManaUtil.isColorIdentityCompatible(colorIdentity, card.getColorIdentity()) && !(colorIdentity.isColorless() && basicsInDeck.size() == 1 && basicsInDeck.contains(card.getName()))) {
            addError(DeckValidatorErrorType.OTHER, card.getName(), "Invalid color (" + colorIdentity.toString() + ')', true);
            valid = false;
        }
    }
    for (Card card : deck.getCards()) {
        if (!isSetAllowed(card.getExpansionSetCode())) {
            if (!legalSets(card)) {
                addError(DeckValidatorErrorType.WRONG_SET, card.getName(), "Not allowed Set: " + card.getExpansionSetCode(), true);
                valid = false;
            }
        }
    }
    for (Card card : deck.getSideboard()) {
        if (!isSetAllowed(card.getExpansionSetCode())) {
            if (!legalSets(card)) {
                addError(DeckValidatorErrorType.WRONG_SET, card.getName(), "Not allowed Set: " + card.getExpansionSetCode(), true);
                valid = false;
            }
        }
    }
    // Check for companion legality
    if (companion != null) {
        Set<Card> cards = new HashSet<>(deck.getCards());
        cards.add(brawler);
        for (Ability ability : companion.getAbilities()) {
            if (ability instanceof CompanionAbility) {
                CompanionAbility companionAbility = (CompanionAbility) ability;
                if (!companionAbility.isLegal(cards, getDeckMinSize())) {
                    addError(DeckValidatorErrorType.PRIMARY, companion.getName(), "Brawl Companion Invalid", true);
                    valid = false;
                }
                break;
            }
        }
    }
    return valid;
}
Also used : java.util(java.util) DeckValidatorErrorType(mage.cards.decks.DeckValidatorErrorType) CardType(mage.constants.CardType) CompanionAbility(mage.abilities.keyword.CompanionAbility) Deck(mage.cards.decks.Deck) CanBeYourCommanderAbility(mage.abilities.common.CanBeYourCommanderAbility) Card(mage.cards.Card) Constructed(mage.cards.decks.Constructed) ManaUtil(mage.util.ManaUtil) Ability(mage.abilities.Ability) FilterMana(mage.filter.FilterMana) CompanionAbility(mage.abilities.keyword.CompanionAbility) CanBeYourCommanderAbility(mage.abilities.common.CanBeYourCommanderAbility) Ability(mage.abilities.Ability) FilterMana(mage.filter.FilterMana) CompanionAbility(mage.abilities.keyword.CompanionAbility) Card(mage.cards.Card)

Aggregations

Deck (mage.cards.decks.Deck)27 Card (mage.cards.Card)11 Player (mage.players.Player)7 Ability (mage.abilities.Ability)5 Test (org.junit.Test)5 java.util (java.util)4 CompanionAbility (mage.abilities.keyword.CompanionAbility)4 Constructed (mage.cards.decks.Constructed)4 DeckValidatorErrorType (mage.cards.decks.DeckValidatorErrorType)4 CardType (mage.constants.CardType)4 FilterMana (mage.filter.FilterMana)4 Game (mage.game.Game)4 TwoPlayerDuel (mage.game.TwoPlayerDuel)4 UUID (java.util.UUID)3 CanBeYourCommanderAbility (mage.abilities.common.CanBeYourCommanderAbility)3 PartnerAbility (mage.abilities.keyword.PartnerAbility)3 PartnerWithAbility (mage.abilities.keyword.PartnerWithAbility)3 ExpansionSet (mage.cards.ExpansionSet)3 Sets (mage.cards.Sets)3 DeckCardLists (mage.cards.decks.DeckCardLists)3