Search in sources :

Example 16 with CardView

use of mage.view.CardView in project mage by magefree.

the class CardIconsTest method test_CostX_Spells.

@Test
public void test_CostX_Spells() {
    // Chalice of the Void enters the battlefield with X charge counters on it.
    // Whenever a player casts a spell with converted mana cost equal to the number of charge counters on Chalice of the Void, counter that spell.
    // {X}{X}
    addCard(Zone.HAND, playerA, "Chalice of the Void", 1);
    addCard(Zone.BATTLEFIELD, playerA, "Forest", 4);
    // hand (not visible)
    runCode("card icons in hand", 1, PhaseStep.PRECOMBAT_MAIN, playerA, (info, player, game) -> {
        GameView gameView = getGameView(player);
        Assert.assertEquals("must have 1 card in hand", 1, gameView.getHand().values().size());
        CardView cardView = gameView.getHand().values().stream().findFirst().get();
        Assert.assertEquals("must have non x cost card icons in hand", 0, cardView.getCardIcons().size());
    });
    // cast and put on stack
    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Chalice of the Void");
    setChoice(playerA, "X=2");
    // stack (visible)
    runCode("card icons on stack (spell)", 1, PhaseStep.PRECOMBAT_MAIN, playerA, (info, player, game) -> {
        GameView gameView = getGameView(player);
        Assert.assertEquals("must have 1 card in stack", 1, gameView.getStack().values().size());
        CardView cardView = gameView.getStack().values().stream().findFirst().get();
        Assert.assertEquals("must have x cost card icons in stack", 1, cardView.getCardIcons().size());
        Assert.assertEquals("x cost text", "x=2", cardView.getCardIcons().get(0).getText());
    });
    waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
    checkPermanentCount("after cast", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Chalice of the Void", 1);
    // battlefield (card, not visible)
    runCode("card icons in battlefield (card)", 1, PhaseStep.PRECOMBAT_MAIN, playerA, (info, player, game) -> {
        GameView gameView = getGameView(player);
        PlayerView playerView = gameView.getPlayers().get(0);
        Assert.assertEquals("player", player.getName(), playerView.getName());
        CardView cardView = playerView.getBattlefield().values().stream().filter(p -> p.getName().equals("Chalice of the Void")).findFirst().orElse(null);
        Assert.assertNotNull("must have 1 chalice in battlefield", cardView);
        Assert.assertEquals("must have x cost card icons in battlefield (card)", 1, cardView.getCardIcons().size());
        Assert.assertEquals("x cost text", "x=2", cardView.getCardIcons().get(0).getText());
    });
    setStrictChooseMode(true);
    setStopAt(1, PhaseStep.END_TURN);
    execute();
    assertAllCommandsUsed();
}
Also used : CardView(mage.view.CardView) PlayerView(mage.view.PlayerView) GameView(mage.view.GameView) Test(org.junit.Test)

Example 17 with CardView

use of mage.view.CardView in project mage by magefree.

the class CardIconsTest method test_CostX_Copies.

@Test
public void test_CostX_Copies() {
    // Grenzo, Dungeon Warden enters the battlefield with X +1/+1 counters on it.
    // {X}{B}{R}
    addCard(Zone.HAND, playerA, "Grenzo, Dungeon Warden", 1);
    addCard(Zone.BATTLEFIELD, playerA, "Forest", 2);
    addCard(Zone.BATTLEFIELD, playerA, "Swamp", 1);
    addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
    // 
    // Copy target creature spell you control, except it isn't legendary if the spell is legendary.
    // {G}{U}
    addCard(Zone.HAND, playerA, "Double Major", 1);
    addCard(Zone.BATTLEFIELD, playerA, "Forest", 1);
    addCard(Zone.BATTLEFIELD, playerA, "Island", 1);
    // cast and put on stack
    activateManaAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add {G}", 2);
    activateManaAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add {B}", 1);
    activateManaAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add {R}", 1);
    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Grenzo, Dungeon Warden");
    setChoice(playerA, "X=2");
    // prepare copy of spell
    activateManaAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add {G}", 1);
    activateManaAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add {U}", 1);
    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Double Major", "Grenzo, Dungeon Warden", "Grenzo, Dungeon Warden");
    checkStackSize("before copy spell", 1, PhaseStep.PRECOMBAT_MAIN, playerA, 2);
    waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN, playerA, true);
    checkStackSize("after copy spell", 1, PhaseStep.PRECOMBAT_MAIN, playerA, 2);
    // stack (copied spell)
    runCode("card icons on stack (copied spell)", 1, PhaseStep.PRECOMBAT_MAIN, playerA, (info, player, game) -> {
        GameView gameView = getGameView(player);
        Assert.assertEquals("must have 2 cards in stack", 2, gameView.getStack().values().size());
        CardView originalCardView = gameView.getStack().values().stream().filter(c -> !c.getOriginalCard().isCopy()).findFirst().get();
        CardView copiedCardView = gameView.getStack().values().stream().filter(c -> c.getOriginalCard().isCopy()).findFirst().get();
        Assert.assertNotNull("stack must have original spell", originalCardView);
        Assert.assertNotNull("stack must have copied spell", copiedCardView);
        Assert.assertNotEquals("must find two spells on stack", originalCardView.getId(), copiedCardView.getId());
        Assert.assertEquals("original spell must have x cost card icons", 1, originalCardView.getCardIcons().size());
        Assert.assertEquals("copied spell must have x cost card icons", 1, copiedCardView.getCardIcons().size());
        Assert.assertEquals("original x cost text", "x=2", originalCardView.getCardIcons().get(0).getText());
        Assert.assertEquals("copied x cost text", "x=2", copiedCardView.getCardIcons().get(0).getText());
    });
    // must resolve copied creature spell as a token
    waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
    checkPermanentCount("after cast", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Grenzo, Dungeon Warden", 2);
    // battlefield (card and copied card as token)
    runCode("card icons in battlefield (copied)", 1, PhaseStep.PRECOMBAT_MAIN, playerA, (info, player, game) -> {
        GameView gameView = getGameView(player);
        PlayerView playerView = gameView.getPlayers().get(0);
        Assert.assertEquals("player", player.getName(), playerView.getName());
        // copied spell goes as token to battlefield, not copied card - so must check isToken
        // original
        CardView originalCardView = playerView.getBattlefield().values().stream().filter(p -> p.getName().equals("Grenzo, Dungeon Warden")).filter(p -> !p.isToken()).findFirst().orElse(null);
        Assert.assertNotNull("original card must be in battlefield", originalCardView);
        Assert.assertEquals("original must have x cost card icons", 1, originalCardView.getCardIcons().size());
        Assert.assertEquals("original x cost text", "x=2", originalCardView.getCardIcons().get(0).getText());
        // 
        CardView copiedCardView = playerView.getBattlefield().values().stream().filter(p -> p.getName().equals("Grenzo, Dungeon Warden")).filter(p -> p.isToken()).findFirst().orElse(null);
        Assert.assertNotNull("copied card must be in battlefield", copiedCardView);
        Assert.assertEquals("copied must have x cost card icons", 1, copiedCardView.getCardIcons().size());
        Assert.assertEquals("copied x cost text", "x=0", copiedCardView.getCardIcons().get(0).getText());
    });
    setStrictChooseMode(true);
    setStopAt(1, PhaseStep.END_TURN);
    execute();
    assertAllCommandsUsed();
}
Also used : TestPlayer(org.mage.test.player.TestPlayer) CardTestPlayerBase(org.mage.test.serverside.base.CardTestPlayerBase) Zone(mage.constants.Zone) PlayerView(mage.view.PlayerView) PhaseStep(mage.constants.PhaseStep) Test(org.junit.Test) Assert(org.junit.Assert) CardView(mage.view.CardView) GameView(mage.view.GameView) CardView(mage.view.CardView) PlayerView(mage.view.PlayerView) GameView(mage.view.GameView) Test(org.junit.Test)

Example 18 with CardView

use of mage.view.CardView in project mage by magefree.

the class CardIconsTest method test_CostX_MDFC.

@Test
public void test_CostX_MDFC() {
    // Agadeem's Awakening
    // Sorcery {X}{B}{B}{B}
    // Return from your graveyard to the battlefield any number of target creature cards that each have a different converted mana cost X or less.
    // 
    // Agadeem, the Undercrypt
    // Land
    // As Agadeem, the Undercrypt enters the battlefield, you may pay 3 life. If you don't, it enters the battlefield tapped.
    addCard(Zone.HAND, playerA, "Agadeem's Awakening", 2);
    addCard(Zone.BATTLEFIELD, playerA, "Swamp", 5);
    // hand (not visible)
    runCode("card icons in hand", 1, PhaseStep.PRECOMBAT_MAIN, playerA, (info, player, game) -> {
        GameView gameView = getGameView(player);
        CardView cardView = gameView.getHand().values().stream().filter(c -> c.getName().equals("Agadeem's Awakening")).findFirst().orElse(null);
        Assert.assertEquals("main must have non x cost card icons in hand", 0, cardView.getCardIcons().size());
        Assert.assertEquals("right must have non x cost card icons in hand", 0, cardView.getSecondCardFace().getCardIcons().size());
    });
    // play spell and check X
    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Agadeem's Awakening");
    setChoice(playerA, "X=2");
    addTarget(playerA, TestPlayer.TARGET_SKIP);
    // stack (spell - visible)
    runCode("card icons on stack (visible)", 1, PhaseStep.PRECOMBAT_MAIN, playerA, (info, player, game) -> {
        GameView gameView = getGameView(player);
        Assert.assertEquals("must have 1 card in stack", 1, gameView.getStack().values().size());
        CardView cardView = gameView.getStack().values().stream().filter(c -> c.getName().equals("Agadeem's Awakening")).findFirst().orElse(null);
        Assert.assertEquals("main must have x cost card icons in stack", 1, cardView.getCardIcons().size());
        Assert.assertNull("right must be null in stack", cardView.getSecondCardFace());
    });
    waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
    // play land and check X
    playLand(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Agadeem, the Undercrypt");
    // not pay life
    setChoice(playerA, false);
    runCode("card icons in battlefield", 1, PhaseStep.PRECOMBAT_MAIN, playerA, (info, player, game) -> {
        GameView gameView = getGameView(player);
        PlayerView playerView = gameView.getPlayers().get(0);
        Assert.assertEquals("player", player.getName(), playerView.getName());
        CardView cardView = playerView.getBattlefield().values().stream().filter(p -> p.getName().equals("Agadeem, the Undercrypt")).findFirst().orElse(null);
        Assert.assertNotNull("must have Agadeem, the Undercrypt in battlefield", cardView);
        Assert.assertEquals("main must have not x cost card icons in battlefield", 0, cardView.getCardIcons().size());
        Assert.assertNull("second side must be null", cardView.getSecondCardFace());
    });
    setStrictChooseMode(true);
    setStopAt(1, PhaseStep.END_TURN);
    execute();
    assertAllCommandsUsed();
}
Also used : CardView(mage.view.CardView) PlayerView(mage.view.PlayerView) GameView(mage.view.GameView) Test(org.junit.Test)

Example 19 with CardView

use of mage.view.CardView in project mage by magefree.

the class SelectionBox method dragCardDrop.

@Override
public void dragCardDrop(MouseEvent e, DragCardSource source, Collection<CardView> cards) {
    e = SwingUtilities.convertMouseEvent(this, e, cardContent);
    int x = e.getX();
    int y = e.getY();
    // Clamp to region
    if (x < 0) {
        x = 0;
    }
    if (y < 0) {
        y = 0;
    }
    // compact the grid removing the null gaps / empty rows & cols later)
    if (source == this) {
        for (List<List<CardView>> gridRow : cardGrid) {
            for (List<CardView> stack : gridRow) {
                for (int i = 0; i < stack.size(); ++i) {
                    if (cards.contains(stack.get(i))) {
                        stack.set(i, null);
                    }
                }
            }
        }
    }
    // Determine column
    int cardWidth = getCardWidth();
    int cardHeight = getCardHeight();
    int cardTopHeight = CardRenderer.getCardTopHeight(cardWidth);
    int dx = x % (cardWidth + GRID_PADDING);
    int col = x / (cardWidth + GRID_PADDING);
    int gridWidth = cardGrid.isEmpty() ? 0 : cardGrid.get(0).size();
    if (dx < GRID_PADDING && col < gridWidth) {
        // Which row to add to?
        int curY = COUNT_LABEL_HEIGHT;
        int rowIndex = 0;
        for (int i = 0; i < cardGrid.size(); ++i) {
            int maxStack = maxStackSize.get(i);
            int rowHeight = cardTopHeight * (maxStack - 1) + cardHeight;
            int rowBottom = curY + rowHeight + COUNT_LABEL_HEIGHT;
            // Break out if we're in that row
            if (y < rowBottom) {
                // Set the row
                rowIndex = i;
                break;
            } else {
                rowIndex = i + 1;
                curY = rowBottom;
            }
        }
        // Add a new row if needed
        if (rowIndex >= cardGrid.size()) {
            List<List<CardView>> newRow = new ArrayList<>();
            if (!cardGrid.isEmpty()) {
                for (int colIndex = 0; colIndex < cardGrid.get(0).size(); ++colIndex) {
                    newRow.add(new ArrayList<>());
                }
            }
            cardGrid.add(newRow);
            maxStackSize.add(0);
        }
        // Insert the new column to add to
        for (int i = 0; i < cardGrid.size(); ++i) {
            cardGrid.get(i).add(col, new ArrayList<>());
        }
        // Add the cards
        cardGrid.get(rowIndex).get(col).addAll(cards);
    } else {
        // Clamp to a new col one after the current last one
        col = Math.min(col, gridWidth);
        // Determine place in the col
        int curY = COUNT_LABEL_HEIGHT;
        int rowIndex = 0;
        int offsetIntoStack = 0;
        for (int i = 0; i < cardGrid.size(); ++i) {
            int maxStack = maxStackSize.get(i);
            int rowHeight = cardTopHeight * (maxStack - 1) + cardHeight;
            int rowBottom = curY + rowHeight + COUNT_LABEL_HEIGHT;
            // Break out if we're in that row
            if (y < rowBottom) {
                // Set the row
                rowIndex = i;
                offsetIntoStack = y - curY;
                break;
            } else {
                rowIndex = i + 1;
                offsetIntoStack = y - rowBottom;
                curY = rowBottom;
            }
        }
        // Add a new row if needed
        if (rowIndex >= cardGrid.size()) {
            List<List<CardView>> newRow = new ArrayList<>();
            if (!cardGrid.isEmpty()) {
                for (int colIndex = 0; colIndex < cardGrid.get(0).size(); ++colIndex) {
                    newRow.add(new ArrayList<>());
                }
            }
            cardGrid.add(newRow);
            maxStackSize.add(0);
        }
        // Add a new col if needed
        if (col >= cardGrid.get(0).size()) {
            for (int i = 0; i < cardGrid.size(); ++i) {
                cardGrid.get(i).add(new ArrayList<>());
            }
        }
        // Get the appropirate stack
        List<CardView> stack = cardGrid.get(rowIndex).get(col);
        // Figure out position in the stack based on the offsetIntoRow
        int stackInsertIndex = (offsetIntoStack + cardTopHeight / 2) / cardTopHeight;
        stackInsertIndex = Math.max(0, Math.min(stackInsertIndex, stack.size()));
        // Insert the cards
        stack.addAll(stackInsertIndex, cards);
    }
    if (source == this) {
        // Remove empty rows / cols / spaces in stacks
        trimGrid();
        layoutGrid();
        repaintGrid();
    } else {
        // Add new cards to grid
        for (CardView card : cards) {
            card.setSelected(true);
            addCardView(card, false);
            eventSource.fireEvent(card, ClientEventType.DECK_ADD_SPECIFIC_CARD);
        }
        layoutGrid();
        repaintGrid();
    }
}
Also used : CardView(mage.view.CardView) List(java.util.List)

Example 20 with CardView

use of mage.view.CardView in project mage by magefree.

the class SelectionBox method oldVersionDeck.

private void oldVersionDeck() {
    if (this.mode != Constants.DeckEditorMode.FREE_BUILDING) {
        return;
    }
    if (JOptionPane.showConfirmDialog(null, "Are you sure you want to switch your card versions to the oldest ones?", "WARNING", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
        return;
    }
    List<List<List<CardView>>> newCardGrid = new ArrayList<>();
    for (List<List<CardView>> gridRow : cardGrid) {
        List<List<CardView>> newGridRow = new ArrayList<>();
        for (List<CardView> stack : gridRow) {
            List<CardView> newStack = new ArrayList<>();
            for (CardView card : stack) {
                CardInfo oldestCardInfo = CardRepository.instance.findOldestNonPromoVersionCard(card.getName());
                if (oldestCardInfo != null) {
                    CardView oldestCardView = new CardView(oldestCardInfo.getMockCard());
                    this.removeCardView(card);
                    eventSource.fireEvent(card, ClientEventType.DECK_REMOVE_SPECIFIC_CARD);
                    this.addCardView(oldestCardView, false);
                    eventSource.fireEvent(oldestCardView, ClientEventType.DECK_ADD_SPECIFIC_CARD);
                    newStack.add(oldestCardView);
                } else {
                    newStack.add(card);
                }
            }
            newGridRow.add(newStack);
        }
        newCardGrid.add(newGridRow);
    }
    cardGrid = newCardGrid;
    layoutGrid();
    repaintGrid();
}
Also used : CardView(mage.view.CardView) DeckCardInfo(mage.cards.decks.DeckCardInfo) CardInfo(mage.cards.repository.CardInfo) List(java.util.List)

Aggregations

CardView (mage.view.CardView)41 List (java.util.List)15 MageCard (mage.cards.MageCard)10 CardInfo (mage.cards.repository.CardInfo)9 Card (mage.cards.Card)6 DeckCardInfo (mage.cards.decks.DeckCardInfo)5 java.util (java.util)4 BigCard (mage.client.cards.BigCard)4 CardIconRenderSettings (mage.abilities.icon.CardIconRenderSettings)3 GameView (mage.view.GameView)3 PlayerView (mage.view.PlayerView)3 SimpleCardView (mage.view.SimpleCardView)3 Test (org.junit.Test)3 java.awt (java.awt)2 java.awt.event (java.awt.event)2 ArrayList (java.util.ArrayList)2 Entry (java.util.Map.Entry)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 javax.swing (javax.swing)2