Search in sources :

Example 21 with Deck

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

the class PennyDreadfulCommander method validate.

@Override
public boolean validate(Deck deck) {
    boolean valid = true;
    errorsList.clear();
    FilterMana colorIdentity = new FilterMana();
    Set<Card> commanders = new HashSet<>();
    Card companion = null;
    if (deck.getSideboard().size() == 1) {
        commanders.add(deck.getSideboard().iterator().next());
    } 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;
            commanders.add(card2);
        } else if (card2.getAbilities().stream().anyMatch(ability -> ability instanceof CompanionAbility)) {
            companion = card2;
            commanders.add(card1);
        } else {
            commanders.add(card1);
            commanders.add(card2);
        }
    } else if (deck.getSideboard().size() == 3) {
        Iterator<Card> iter = deck.getSideboard().iterator();
        Card card1 = iter.next();
        Card card2 = iter.next();
        Card card3 = iter.next();
        if (card1.getAbilities().stream().anyMatch(ability -> ability instanceof CompanionAbility)) {
            companion = card1;
            commanders.add(card2);
            commanders.add(card3);
        } else if (card2.getAbilities().stream().anyMatch(ability -> ability instanceof CompanionAbility)) {
            companion = card2;
            commanders.add(card1);
            commanders.add(card3);
        } else if (card3.getAbilities().stream().anyMatch(ability -> ability instanceof CompanionAbility)) {
            companion = card3;
            commanders.add(card1);
            commanders.add(card2);
        } else {
            addError(DeckValidatorErrorType.PRIMARY, "Commander", "Sideboard must contain only the commander(s) and up to 1 companion");
            valid = false;
        }
    } else {
        addError(DeckValidatorErrorType.PRIMARY, "Commander", "Sideboard must contain only the commander(s) and up to 1 companion");
        valid = false;
    }
    if (companion != null && deck.getCards().size() + deck.getSideboard().size() != 101) {
        addError(DeckValidatorErrorType.DECK_SIZE, "Deck", "Must contain " + 101 + " cards (companion doesn't count for deck size): has " + (deck.getCards().size() + deck.getSideboard().size()) + " cards");
        valid = false;
    } else if (companion == null && deck.getCards().size() + deck.getSideboard().size() != 100) {
        addError(DeckValidatorErrorType.DECK_SIZE, "Deck", "Must contain " + 100 + " 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;
    if (pdAllowed.isEmpty()) {
        pdAllowed.putAll(PennyDreadfulLegalityUtil.getLegalCardList());
    }
    for (String wantedCard : counts.keySet()) {
        if (!(pdAllowed.containsKey(wantedCard))) {
            addError(DeckValidatorErrorType.BANNED, wantedCard, "Banned", true);
            valid = false;
        }
    }
    Set<String> commanderNames = new HashSet<>();
    for (Card commander : commanders) {
        commanderNames.add(commander.getName());
    }
    for (Card commander : commanders) {
        if (bannedCommander.contains(commander.getName())) {
            addError(DeckValidatorErrorType.PRIMARY, commander.getName(), "Commander banned (" + commander.getName() + ')', true);
            valid = false;
        }
        if ((!commander.hasCardTypeForDeckbuilding(CardType.CREATURE) || !commander.isLegendary()) && !commander.getAbilities().contains(CanBeYourCommanderAbility.getInstance())) {
            addError(DeckValidatorErrorType.PRIMARY, commander.getName(), "Commander invalid (" + commander.getName() + ')', true);
            valid = false;
        }
        if (commanders.size() == 2) {
            if (!commander.getAbilities().contains(PartnerAbility.getInstance())) {
                boolean partnersWith = commander.getAbilities().stream().filter(PartnerWithAbility.class::isInstance).map(PartnerWithAbility.class::cast).map(PartnerWithAbility::getPartnerName).anyMatch(commanderNames::contains);
                if (!partnersWith) {
                    addError(DeckValidatorErrorType.PRIMARY, commander.getName(), "Commander without Partner (" + commander.getName() + ')', true);
                    valid = false;
                }
            }
        }
        ManaUtil.collectColorIdentity(colorIdentity, commander.getColorIdentity());
    }
    // no needs in cards check on wrong commanders
    if (!valid) {
        return false;
    }
    for (Card card : deck.getCards()) {
        if (!ManaUtil.isColorIdentityCompatible(colorIdentity, card.getColorIdentity())) {
            addError(DeckValidatorErrorType.OTHER, card.getName(), "Invalid color (" + colorIdentity.toString() + ')', true);
            valid = false;
        }
    }
    for (Card card : deck.getSideboard()) {
        if (!ManaUtil.isColorIdentityCompatible(colorIdentity, card.getColorIdentity())) {
            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.addAll(commanders);
        for (Ability ability : companion.getAbilities()) {
            if (ability instanceof CompanionAbility) {
                CompanionAbility companionAbility = (CompanionAbility) ability;
                if (!companionAbility.isLegal(cards, getDeckMinSize())) {
                    addError(DeckValidatorErrorType.PRIMARY, companion.getName(), "Commander Companion (deck invalid for companion)", true);
                    valid = false;
                }
                break;
            }
        }
    }
    return valid;
}
Also used : PartnerAbility(mage.abilities.keyword.PartnerAbility) PennyDreadfulLegalityUtil(mage.cards.decks.PennyDreadfulLegalityUtil) java.util(java.util) DeckValidatorErrorType(mage.cards.decks.DeckValidatorErrorType) PartnerWithAbility(mage.abilities.keyword.PartnerWithAbility) Deck(mage.cards.decks.Deck) CanBeYourCommanderAbility(mage.abilities.common.CanBeYourCommanderAbility) Sets(mage.cards.Sets) Constructed(mage.cards.decks.Constructed) ManaUtil(mage.util.ManaUtil) ExpansionSet(mage.cards.ExpansionSet) CardType(mage.constants.CardType) CompanionAbility(mage.abilities.keyword.CompanionAbility) Card(mage.cards.Card) Ability(mage.abilities.Ability) FilterMana(mage.filter.FilterMana) PartnerAbility(mage.abilities.keyword.PartnerAbility) PartnerWithAbility(mage.abilities.keyword.PartnerWithAbility) CanBeYourCommanderAbility(mage.abilities.common.CanBeYourCommanderAbility) CompanionAbility(mage.abilities.keyword.CompanionAbility) Ability(mage.abilities.Ability) FilterMana(mage.filter.FilterMana) CompanionAbility(mage.abilities.keyword.CompanionAbility) Card(mage.cards.Card) PartnerWithAbility(mage.abilities.keyword.PartnerWithAbility)

Example 22 with Deck

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

the class FreeformCommander method validate.

@Override
public boolean validate(Deck deck) {
    boolean valid = true;
    errorsList.clear();
    FilterMana colorIdentity = new FilterMana();
    Set<Card> commanders = new HashSet<>();
    Card companion = null;
    if (deck.getSideboard().size() == 1) {
        commanders.add(deck.getSideboard().iterator().next());
    } 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;
            commanders.add(card2);
        } else if (card2.getAbilities().stream().anyMatch(ability -> ability instanceof CompanionAbility)) {
            companion = card2;
            commanders.add(card1);
        } else {
            commanders.add(card1);
            commanders.add(card2);
        }
    } else if (deck.getSideboard().size() == 3) {
        Iterator<Card> iter = deck.getSideboard().iterator();
        Card card1 = iter.next();
        Card card2 = iter.next();
        Card card3 = iter.next();
        if (card1.getAbilities().stream().anyMatch(ability -> ability instanceof CompanionAbility)) {
            companion = card1;
            commanders.add(card2);
            commanders.add(card3);
        } else if (card2.getAbilities().stream().anyMatch(ability -> ability instanceof CompanionAbility)) {
            companion = card2;
            commanders.add(card1);
            commanders.add(card3);
        } else if (card3.getAbilities().stream().anyMatch(ability -> ability instanceof CompanionAbility)) {
            companion = card3;
            commanders.add(card1);
            commanders.add(card2);
        } else {
            addError(DeckValidatorErrorType.PRIMARY, "Commander", "Sideboard must contain only the commander(s) and up to 1 companion");
            valid = false;
        }
    } else {
        addError(DeckValidatorErrorType.PRIMARY, "Commander", "Sideboard must contain only the commander(s) and up to 1 companion");
        valid = false;
    }
    if (companion != null && deck.getCards().size() + deck.getSideboard().size() != 101) {
        addError(DeckValidatorErrorType.DECK_SIZE, "Deck", "Must contain " + 101 + " cards (companion doesn't count for deck size): has " + (deck.getCards().size() + deck.getSideboard().size()) + " cards");
        valid = false;
    } else if (companion == null && deck.getCards().size() + deck.getSideboard().size() != 100) {
        addError(DeckValidatorErrorType.DECK_SIZE, "Deck", "Must contain " + 100 + " 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;
    Set<String> commanderNames = new HashSet<>();
    for (Card commander : commanders) {
        commanderNames.add(commander.getName());
    }
    for (Card commander : commanders) {
        if (!commander.hasCardTypeForDeckbuilding(CardType.CREATURE) && !commander.isLegendary()) {
            addError(DeckValidatorErrorType.PRIMARY, commander.getName(), "For Freeform Commander, the commander must be a creature or be legendary. Yours was: " + commander.getName(), true);
            valid = false;
        }
        if (commanders.size() == 2) {
            if (!commander.getAbilities().contains(PartnerAbility.getInstance())) {
                boolean partnersWith = commander.getAbilities().stream().filter(PartnerWithAbility.class::isInstance).map(PartnerWithAbility.class::cast).map(PartnerWithAbility::getPartnerName).anyMatch(commanderNames::contains);
                if (!partnersWith) {
                    addError(DeckValidatorErrorType.PRIMARY, commander.getName(), "Commander without Partner (" + commander.getName() + ')', true);
                    valid = false;
                }
            }
        }
        ManaUtil.collectColorIdentity(colorIdentity, commander.getColorIdentity());
    }
    // no needs in cards check on wrong commanders
    if (!valid) {
        return false;
    }
    for (Card card : deck.getCards()) {
        if (!ManaUtil.isColorIdentityCompatible(colorIdentity, card.getColorIdentity())) {
            addError(DeckValidatorErrorType.OTHER, card.getName(), "Invalid color (" + colorIdentity.toString() + ')', true);
            valid = false;
        }
    }
    for (Card card : deck.getSideboard()) {
        if (!ManaUtil.isColorIdentityCompatible(colorIdentity, card.getColorIdentity())) {
            addError(DeckValidatorErrorType.OTHER, card.getName(), "Invalid color (" + colorIdentity.toString() + ')', true);
            valid = false;
        }
    }
    // Check for companion legality
    if (companion != null) {
        Set<Card> cards = new HashSet<>(deck.getCards());
        cards.addAll(commanders);
        for (Ability ability : companion.getAbilities()) {
            if (ability instanceof CompanionAbility) {
                CompanionAbility companionAbility = (CompanionAbility) ability;
                if (!companionAbility.isLegal(cards, getDeckMinSize())) {
                    addError(DeckValidatorErrorType.PRIMARY, companion.getName(), "Commander Companion (deck invalid for companion)", true);
                    valid = false;
                }
                break;
            }
        }
    }
    return valid;
}
Also used : PartnerAbility(mage.abilities.keyword.PartnerAbility) java.util(java.util) DeckValidatorErrorType(mage.cards.decks.DeckValidatorErrorType) PartnerWithAbility(mage.abilities.keyword.PartnerWithAbility) Deck(mage.cards.decks.Deck) Sets(mage.cards.Sets) Constructed(mage.cards.decks.Constructed) ManaUtil(mage.util.ManaUtil) ExpansionSet(mage.cards.ExpansionSet) CardType(mage.constants.CardType) CompanionAbility(mage.abilities.keyword.CompanionAbility) Card(mage.cards.Card) Ability(mage.abilities.Ability) FilterMana(mage.filter.FilterMana) PartnerAbility(mage.abilities.keyword.PartnerAbility) PartnerWithAbility(mage.abilities.keyword.PartnerWithAbility) CompanionAbility(mage.abilities.keyword.CompanionAbility) Ability(mage.abilities.Ability) FilterMana(mage.filter.FilterMana) CompanionAbility(mage.abilities.keyword.CompanionAbility) Card(mage.cards.Card) PartnerWithAbility(mage.abilities.keyword.PartnerWithAbility)

Example 23 with Deck

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

the class TableController method submitDeck.

public synchronized boolean submitDeck(UUID userId, DeckCardLists deckList) throws MageException {
    UUID playerId = userPlayerMap.get(userId);
    if (table.isTournament()) {
        TournamentPlayer player = tournament.getPlayer(playerId);
        if (player == null || player.hasQuit()) {
            // so the construct panel closes after submit
            return true;
        }
    } else if (table.getMatch() != null) {
        MatchPlayer mPlayer = table.getMatch().getPlayer(playerId);
        if (mPlayer == null || mPlayer.hasQuit()) {
            // so the construct panel closes after submit
            return true;
        }
        if (table.isTournamentSubTable()) {
            TournamentPlayer tournamentPlayer = table.getTournament().getPlayer(mPlayer.getPlayer().getId());
            if (tournamentPlayer != null) {
                // reset sideboarding state
                tournamentPlayer.setStateInfo("");
            }
        }
    }
    if (table.getState() != TableState.SIDEBOARDING && table.getState() != TableState.CONSTRUCTING) {
        return false;
    }
    Deck deck = Deck.load(deckList, false, false);
    if (table.getState() == TableState.SIDEBOARDING && table.getMatch() != null) {
        MatchPlayer mPlayer = table.getMatch().getPlayer(playerId);
        if (mPlayer != null) {
            deck.setName(mPlayer.getDeck().getName());
        }
    }
    if (!Main.isTestMode() && !table.getValidator().validate(deck)) {
        Optional<User> _user = managerFactory.userManager().getUser(userId);
        if (!_user.isPresent()) {
            return false;
        }
        StringBuilder sb = new StringBuilder("Invalid deck for the selected ").append(table.getValidator().getName()).append(" format. \n\n");
        List<DeckValidatorError> errorsList = table.getValidator().getErrorsListSorted();
        errorsList.stream().forEach(error -> {
            sb.append(error.getGroup()).append(": ").append(error.getMessage()).append("\n");
        });
        sb.append("\n\nAdd enough cards and try again!");
        _user.get().showUserMessage("Submit deck", sb.toString());
        return false;
    }
    submitDeck(userId, playerId, deck);
    return true;
}
Also used : DeckValidatorError(mage.cards.decks.DeckValidatorError) TournamentPlayer(mage.game.tournament.TournamentPlayer) MatchPlayer(mage.game.match.MatchPlayer) Deck(mage.cards.decks.Deck)

Example 24 with Deck

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

the class TableController method joinTable.

public synchronized boolean joinTable(UUID userId, String name, PlayerType playerType, int skill, DeckCardLists deckList, String password) throws MageException {
    Optional<User> _user = managerFactory.userManager().getUser(userId);
    if (!_user.isPresent()) {
        logger.error("Join Table: can't find user to join " + name + " Id = " + userId);
        return false;
    }
    User user = _user.get();
    if (userPlayerMap.containsKey(userId) && playerType == PlayerType.HUMAN) {
        user.showUserMessage("Join Table", new StringBuilder("You can join a table only one time.").toString());
        return false;
    }
    if (table.getState() != TableState.WAITING) {
        user.showUserMessage("Join Table", "No available seats.");
        return false;
    }
    // check password
    if (!table.getMatch().getOptions().getPassword().isEmpty() && playerType == PlayerType.HUMAN) {
        if (!table.getMatch().getOptions().getPassword().equals(password)) {
            user.showUserMessage("Join Table", "Wrong password.");
            return false;
        }
    }
    Seat seat = table.getNextAvailableSeat(playerType);
    if (seat == null) {
        user.showUserMessage("Join Table", "No available seats.");
        return false;
    }
    Deck deck = Deck.load(deckList, false, false);
    if (!Main.isTestMode() && !table.getValidator().validate(deck)) {
        StringBuilder sb = new StringBuilder("You (").append(name).append(") have an invalid deck for the selected ").append(table.getValidator().getName()).append(" Format. \n\n");
        List<DeckValidatorError> errorsList = table.getValidator().getErrorsListSorted();
        errorsList.stream().forEach(error -> {
            sb.append(error.getGroup()).append(": ").append(error.getMessage()).append("\n");
        });
        sb.append("\n\nSelect a deck that is appropriate for the selected format and try again!");
        user.showUserMessage("Join Table", sb.toString());
        if (isOwner(userId)) {
            logger.debug("New table removed because owner submitted invalid deck tableId " + table.getId());
            managerFactory.tableManager().removeTable(table.getId());
        }
        return false;
    }
    // Check quit ratio.
    int quitRatio = table.getMatch().getOptions().getQuitRatio();
    if (quitRatio < user.getMatchQuitRatio()) {
        String message = new StringBuilder("Your quit ratio ").append(user.getMatchQuitRatio()).append("% is higher than the table requirement ").append(quitRatio).append('%').toString();
        user.showUserMessage("Join Table", message);
        return false;
    }
    // Check minimum rating.
    int minimumRating = table.getMatch().getOptions().getMinimumRating();
    int userRating;
    if (table.getMatch().getOptions().isLimited()) {
        userRating = user.getUserData().getLimitedRating();
    } else {
        userRating = user.getUserData().getConstructedRating();
    }
    if (userRating < minimumRating) {
        String message = new StringBuilder("Your rating ").append(userRating).append(" is lower than the table requirement ").append(minimumRating).toString();
        user.showUserMessage("Join Table", message);
        return false;
    }
    // Check power level for table (currently only used for EDH/Commander table)
    int edhPowerLevel = table.getMatch().getOptions().getEdhPowerLevel();
    if (edhPowerLevel > 0 && table.getValidator().getName().toLowerCase(Locale.ENGLISH).equals("commander")) {
        int deckEdhPowerLevel = table.getValidator().getEdhPowerLevel(deck);
        if (deckEdhPowerLevel % 100 > edhPowerLevel) {
            String message = new StringBuilder("Your deck appears to be too powerful for this table.\n\nReduce the number of extra turn cards, infect, counters, fogs, reconsider your commander. ").append("\nThe table requirement has a maximum power level of ").append(edhPowerLevel).append(" whilst your deck has a calculated power level of ").append(deckEdhPowerLevel % 100).toString();
            user.showUserMessage("Join Table", message);
            return false;
        }
        boolean restrictedColor = false;
        String badColor = "";
        int colorVal = edhPowerLevel % 10;
        if (colorVal == 6 && deckEdhPowerLevel >= 10000000) {
            restrictedColor = true;
            badColor = "white";
        }
        if (colorVal == 4 && deckEdhPowerLevel % 10000000 >= 1000000) {
            restrictedColor = true;
            badColor = "blue";
        }
        if (colorVal == 3 && deckEdhPowerLevel % 1000000 >= 100000) {
            restrictedColor = true;
            badColor = "black";
        }
        if (colorVal == 2 && deckEdhPowerLevel % 100000 >= 10000) {
            restrictedColor = true;
            badColor = "red";
        }
        if (colorVal == 1 && deckEdhPowerLevel % 10000 >= 1000) {
            restrictedColor = true;
            badColor = "green";
        }
        if (restrictedColor) {
            String message = new StringBuilder("Your deck contains ").append(badColor).append(".  The creator of the table has requested no ").append(badColor).append(" cards to be on the table!").toString();
            user.showUserMessage("Join Table", message);
            return false;
        }
    }
    Optional<Player> playerOpt = createPlayer(name, seat.getPlayerType(), skill);
    if (!playerOpt.isPresent()) {
        String message = "Could not create player " + name + " of type " + seat.getPlayerType();
        logger.warn("User: " + user.getName() + " => " + message);
        user.showUserMessage("Join Table", message);
        return false;
    }
    Player player = playerOpt.get();
    if (!player.canJoinTable(table)) {
        user.showUserMessage("Join Table", "A " + seat.getPlayerType() + " player can't join this table.");
        return false;
    }
    match.addPlayer(player, deck);
    table.joinTable(player, seat);
    logger.trace(player.getName() + " joined tableId: " + table.getId());
    // only inform human players and add them to sessionPlayerMap
    if (seat.getPlayer().isHuman()) {
        seat.getPlayer().setUserData(user.getUserData());
        if (!table.isTournamentSubTable()) {
            user.addTable(player.getId(), table);
        }
        user.ccJoinedTable(table.getRoomId(), table.getId(), false);
        userPlayerMap.put(userId, player.getId());
    }
    return true;
}
Also used : DeckValidatorError(mage.cards.decks.DeckValidatorError) MatchPlayer(mage.game.match.MatchPlayer) Player(mage.players.Player) DraftPlayer(mage.game.draft.DraftPlayer) TournamentPlayer(mage.game.tournament.TournamentPlayer) Deck(mage.cards.decks.Deck)

Example 25 with Deck

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

the class TestGameType method reloadCards.

private void reloadCards() {
    // apply selected theme (warning, it will be applied for all app, so can be bugged in other dialogs - but it's ok for debug)
    PreferencesDialog.setCurrentTheme((ThemeType) comboTheme.getSelectedItem());
    cardsPanel.cleanUp();
    cardsPanel.setCustomRenderMode(comboRenderMode.getSelectedIndex());
    // enable full battlefield render mode (it was bugged in test dialog so was disabled in old days, not it works fine)
    cardsPanel.setCustomNeedFullPermanentRender(true);
    cardsPanel.setCustomCardSize(new Dimension(getCardWidth(), getCardHeight()));
    cardsPanel.setCustomXOffsetBetweenCardsOrColumns(10);
    cardsPanel.setCustomCardIconsPanelPosition(CardIconPosition.fromString((String) comboCardIconsPosition.getSelectedItem()));
    cardsPanel.setCustomCardIconsPanelOrder(CardIconOrder.fromString((String) comboCardIconsOrder.getSelectedItem()));
    cardsPanel.setCustomCardIconsPanelColor((CardIconColor) comboCardColor.getSelectedItem());
    cardsPanel.setCustomCardIconsMaxVisibleCount((Integer) spinnerCardIconsMaxVisible.getValue());
    int needAdditionalIcons = Math.min(99, Math.max(0, (Integer) spinnerCardIconsAdditionalAmount.getValue()));
    // reload new settings
    cardsPanel.changeGUISize();
    // sample popup menus
    JMenuItem item;
    JPopupMenu popupCardMenu = new JPopupMenu();
    item = new JMenuItem("Card menu 1");
    popupCardMenu.add(item);
    item = new JMenuItem("Card menu 2");
    popupCardMenu.add(item);
    item = new JMenuItem("Card menu 3");
    popupCardMenu.add(item);
    // 
    JPopupMenu popupPanelMenu = new JPopupMenu();
    item = new JMenuItem("Panel menu 1");
    popupPanelMenu.add(item);
    item = new JMenuItem("Panel menu 2");
    popupPanelMenu.add(item);
    item = new JMenuItem("Panel menu 3");
    popupPanelMenu.add(item);
    // init card listener for clicks, menu and other events
    if (this.cardListener == null) {
        this.cardListener = event -> {
            switch(event.getEventType()) {
                case CARD_CLICK:
                case CARD_DOUBLE_CLICK:
                    handleCardClick(event);
                    break;
                case CARD_POPUP_MENU:
                    if (event.getSource() != null) {
                        // card
                        handlePopupMenu(event, popupCardMenu);
                    } else {
                        // panel
                        handlePopupMenu(event, popupPanelMenu);
                    }
                    break;
            }
        };
        cardsPanel.addCardEventListener(this.cardListener);
    }
    game = new TestGame(MultiplayerAttackOption.MULTIPLE, RangeOfInfluence.ALL, MulliganType.GAME_DEFAULT.getMulligan(0), 20);
    Deck deck = new Deck();
    Player playerYou = new StubPlayer("player1", RangeOfInfluence.ALL);
    game.addPlayer(playerYou, deck);
    Player playerOpponent = new StubPlayer("player2", RangeOfInfluence.ALL);
    game.addPlayer(playerOpponent, deck);
    List<Ability> additionalIcons = Collections.singletonList(new SimpleStaticAbility(Zone.ALL, null));
    for (int i = 0; i < needAdditionalIcons; i++) {
        String text = "";
        if (RandomUtil.nextBoolean()) {
            if (RandomUtil.nextBoolean()) {
                text = "75";
            } else {
                text = "8";
            }
        }
        additionalIcons.get(0).addIcon(new CardIconImpl(CardIconType.PLAYABLE_COUNT, "test icon " + i + 1, text));
    }
    List<CardView> cardViews = new ArrayList<>();
    /* // test morphed
        cardViews.add(createPermanentCard(game, playerYou.getId(), "RNA", "263", 0, 0, 0, false, null)); // mountain
        cardViews.add(createPermanentCard(game, playerYou.getId(), "RNA", "185", 0, 0, 0, true, null)); // Judith, the Scourge Diva
        cardViews.add(createHandCard(game, playerYou.getId(), "DIS", "153")); // Odds // Ends (split card)
        cardViews.add(createHandCard(game, playerYou.getId(), "ELD", "38")); // Animating Faerie (adventure card)
        cardViews.add(createFaceDownCard(game, playerOpponent.getId(), "ELD", "38", false, false, false)); // face down
        cardViews.add(createFaceDownCard(game, playerOpponent.getId(), "ELD", "38", true, false, true)); // morphed
        cardViews.add(createFaceDownCard(game, playerOpponent.getId(), "ELD", "38", false, true, false)); // manifested
        //*/
    /* //test emblems
        cardViews.add(createPermanentCard(game, playerYou.getId(), "RNA", "78", 125, 89, 0, false, false, null)); // Noxious Groodion
        cardViews.add(createPermanentCard(game, playerYou.getId(), "RNA", "14", 3, 5, 2, false, false, null)); // Knight of Sorrows
        cardViews.add(createPermanentCard(game, playerYou.getId(), "DKA", "140", 5, 2, 2, false, false, null)); // Huntmaster of the Fells, transforms
        cardViews.add(createPermanentCard(game, playerYou.getId(), "RNA", "221", 0, 0, 0, false, false, null)); // Bedeck // Bedazzle
        cardViews.add(createPermanentCard(game, playerYou.getId(), "XLN", "234", 0, 0, 0, false, false, null)); // Conqueror's Galleon
        cardViews.add(createEmblem(new AjaniAdversaryOfTyrantsEmblem())); // Emblem Ajani
        cardViews.add(createPlane(new AkoumPlane())); // Plane - Akoum
        //*/
    // test split, transform and mdf in hands
    // Accursed Witch
    cardViews.add(createHandCard(game, playerYou.getId(), "SOI", "97"));
    // Fire // Ice
    cardViews.add(createHandCard(game, playerYou.getId(), "UMA", "225"));
    // Giant Killer
    cardViews.add(createHandCard(game, playerYou.getId(), "ELD", "14"));
    // Akoum Warrior
    cardViews.add(createHandCard(game, playerYou.getId(), "ZNR", "134"));
    // */
    // * //test card icons
    // Grizzly Bears
    cardViews.add(createHandCard(game, playerYou.getId(), "POR", "169"));
    // Huntmaster of the Fells, transforms
    cardViews.add(createHandCard(game, playerYou.getId(), "DKA", "140"));
    // Huntmaster of the Fells, transforms
    cardViews.add(createPermanentCard(game, playerYou.getId(), "DKA", "140", 3, 3, 1, false, true, additionalIcons));
    // Hinterland Drake
    cardViews.add(createPermanentCard(game, playerYou.getId(), "MB1", "401", 1, 1, 0, false, false, additionalIcons));
    // duplicate cards
    if (checkBoxGenerateManyCards.isSelected()) {
        while (cardViews.size() < 30) {
            int addingCount = cardViews.size();
            for (int i = 0; i < addingCount; i++) {
                CardView view = cardViews.get(i);
                CardView newView = new CardView(view);
                cardViews.add(newView);
            }
        }
    }
    BigCard big = new BigCard();
    CardsView view = new CardsView(cardViews);
    cardsPanel.loadCards(view, big, game.getId());
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) TransformAbility(mage.abilities.keyword.TransformAbility) Ability(mage.abilities.Ability) StubPlayer(mage.players.StubPlayer) Player(mage.players.Player) BigCard(mage.client.cards.BigCard) CardIconImpl(mage.abilities.icon.CardIconImpl) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Deck(mage.cards.decks.Deck) StubPlayer(mage.players.StubPlayer)

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