From dc09f279ed83a2d5d7c2fe5fffa3b27e2bdbd3cc Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Thu, 29 Jul 2021 12:27:23 +0400 Subject: [PATCH] Fixed NPE error in card icons --- .../src/main/java/mage/view/CardView.java | 1 + .../mage/test/serverside/CardIconsTest.java | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/Mage.Common/src/main/java/mage/view/CardView.java b/Mage.Common/src/main/java/mage/view/CardView.java index af34ab296c..6f2f0f1265 100644 --- a/Mage.Common/src/main/java/mage/view/CardView.java +++ b/Mage.Common/src/main/java/mage/view/CardView.java @@ -453,6 +453,7 @@ public class CardView extends SimpleCardView { // x cost Zone cardZone = game.getState().getZone(card.getId()); if (card.getManaCost().containsX() + && card.getSpellAbility() != null && (cardZone.match(Zone.BATTLEFIELD) || cardZone.match(Zone.STACK))) { int costX; if (card instanceof Permanent) { diff --git a/Mage.Tests/src/test/java/org/mage/test/serverside/CardIconsTest.java b/Mage.Tests/src/test/java/org/mage/test/serverside/CardIconsTest.java index dae5855e90..e41a5920fc 100644 --- a/Mage.Tests/src/test/java/org/mage/test/serverside/CardIconsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/serverside/CardIconsTest.java @@ -7,6 +7,7 @@ import mage.view.GameView; import mage.view.PlayerView; import org.junit.Assert; import org.junit.Test; +import org.mage.test.player.TestPlayer; import org.mage.test.serverside.base.CardTestPlayerBase; /** @@ -221,4 +222,63 @@ public class CardIconsTest extends CardTestPlayerBase { execute(); assertAllCommandsUsed(); } + + @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"); + setChoice(playerA, false); // not pay life + 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(); + } }