diff --git a/Mage.Tests/src/test/java/org/mage/test/utils/CardRepositoryTest.java b/Mage.Tests/src/test/java/org/mage/test/utils/CardRepositoryTest.java index fdedafc73b..c047431553 100644 --- a/Mage.Tests/src/test/java/org/mage/test/utils/CardRepositoryTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/utils/CardRepositoryTest.java @@ -128,9 +128,35 @@ public class CardRepositoryTest { assertFindCard("dizzYIng sWOop"); } + /** + * Reported bug: https://github.com/magefree/mage/issues/9533 + * + * Each half of a split card displays the combined information of both halves in the deck editor. + * + * `findCards`'s `returnSplitCardHalf` parameter should handle this issue + */ + @Test + public void splitCardInfoIsntDoubled() { + // Consecrate // Consume + // {1}{W/B} // {2}{W}{B} + List fullCard1 = CardRepository.instance.findCards("Consecrate", 1, false); + Assert.assertTrue(fullCard1.get(0).isSplitCard()); + Assert.assertEquals("Consecrate // Consume", fullCard1.get(0).getName()); + List fullCard2 = CardRepository.instance.findCards("Consume", 1, false); + Assert.assertTrue(fullCard2.get(0).isSplitCard()); + Assert.assertEquals("Consecrate // Consume", fullCard2.get(0).getName()); + + List splitHalfCardLeft = CardRepository.instance.findCards("Consecrate", 1, true); + Assert.assertTrue(splitHalfCardLeft.get(0).isSplitCardHalf()); + Assert.assertEquals("Consecrate", splitHalfCardLeft.get(0).getName()); + List splitHalfCardRight = CardRepository.instance.findCards("Consume", 1, true); + Assert.assertTrue(splitHalfCardRight.get(0).isSplitCardHalf()); + Assert.assertEquals("Consume", splitHalfCardRight.get(0).getName()); + } + /** * Checks if the card with name cardName can be found when searched for - * using the case sensitive approach. + * using the case-sensitive approach. * * @param cardName The name of the card to search by. */ diff --git a/Mage/src/main/java/mage/cards/mock/MockSplitCard.java b/Mage/src/main/java/mage/cards/mock/MockSplitCard.java index 86ca616ed6..8c2512d236 100644 --- a/Mage/src/main/java/mage/cards/mock/MockSplitCard.java +++ b/Mage/src/main/java/mage/cards/mock/MockSplitCard.java @@ -49,13 +49,13 @@ public class MockSplitCard extends SplitCard { this.addAbility(textAbilityFromString(ruleText)); } - CardInfo leftHalf = CardRepository.instance.findCardWPreferredSet(getLeftHalfName(card), card.getSetCode()); + CardInfo leftHalf = CardRepository.instance.findCardWPreferredSet(getLeftHalfName(card), card.getSetCode(), true); if (leftHalf != null) { this.leftHalfCard = new MockSplitCardHalf(leftHalf); ((SplitCardHalf) this.leftHalfCard).setParentCard(this); } - CardInfo rightHalf = CardRepository.instance.findCardWPreferredSet(getRightHalfName(card), card.getSetCode()); + CardInfo rightHalf = CardRepository.instance.findCardWPreferredSet(getRightHalfName(card), card.getSetCode(), true); if (rightHalf != null) { this.rightHalfCard = new MockSplitCardHalf(rightHalf); ((SplitCardHalf) this.rightHalfCard).setParentCard(this); diff --git a/Mage/src/main/java/mage/cards/repository/CardRepository.java b/Mage/src/main/java/mage/cards/repository/CardRepository.java index 66f04c2844..b912ed8c59 100644 --- a/Mage/src/main/java/mage/cards/repository/CardRepository.java +++ b/Mage/src/main/java/mage/cards/repository/CardRepository.java @@ -389,14 +389,17 @@ public enum CardRepository { * Function to find a card by name from a specific set. * Used for building cubes, packs, and for ensuring that dual faces and split cards have sides/halves from the same set. * - * @param name name of the card, or side of the card, to find - * @param expansion the set name from which to find the card + * @param name name of the card, or side of the card, to find + * @param expansion the set name from which to find the card + * @param returnSplitCardHalf whether to return a half of a split card or the corresponding full card. + * Want this `false` when user is searching by either names in a split card so that + * the full card can be found by either name. * @return */ - public CardInfo findCardWPreferredSet(String name, String expansion) { + public CardInfo findCardWPreferredSet(String name, String expansion, boolean returnSplitCardHalf) { List cards; - cards = findCards(name); + cards = findCards(name, 0, returnSplitCardHalf); if (!cards.isEmpty()) { for (CardInfo cardinfo : cards) { @@ -408,6 +411,10 @@ public enum CardRepository { return findPreferredCoreExpansionCard(name); } + public CardInfo findCardWPreferredSet(String name, String expansion) { + return findCardWPreferredSet(name, expansion, false); + } + public List findCards(String name) { return findCards(name, 0); } @@ -424,12 +431,16 @@ public enum CardRepository { * ALL the others MUST be queried for by the first half of their full name (i.e. "A" from "A // B") * when querying by "name". * - * @param name the name of the card to search for - * @param limitByMaxAmount return max amount of different cards (if 0 then return card from all sets) - * @return A list of the reprints of the card if it was found (up to limitByMaxAmount number), or - * an empty list if the card was not found. + * @param name the name of the card to search for + * @param limitByMaxAmount return max amount of different cards (if 0 then return card from all sets) + * @param returnSplitCardHalf whether to return a half of a split card or the corresponding full card. + * Want this `false` when user is searching by either names in a split card so that + * the full card can be found by either name. + * Want this `true` when the client is searching for info on both halves to display it. + * @return a list of the reprints of the card if it was found (up to limitByMaxAmount number), + * or an empty list if the card was not found. */ - public List findCards(String name, long limitByMaxAmount) { + public List findCards(String name, long limitByMaxAmount, boolean returnSplitCardHalf) { List results; QueryBuilder queryBuilder = cardDao.queryBuilder(); if (limitByMaxAmount > 0) { @@ -467,8 +478,8 @@ public enum CardRepository { // Check that a full card was found and not a SplitCardHalf // Can be caused by searching for "Fire" instead of "Fire // Ice" CardInfo firstCardInfo = results.get(0); - if (firstCardInfo.isSplitCardHalf()) { - // Find the main card by it's setCode and CardNumber + if (firstCardInfo.isSplitCardHalf() && !returnSplitCardHalf) { + // Find the main card by its setCode and CardNumber queryBuilder.where() .eq("setCode", new SelectArg(firstCardInfo.setCode)).and() .eq("cardNumber", new SelectArg(firstCardInfo.cardNumber)); @@ -498,6 +509,10 @@ public enum CardRepository { return Collections.emptyList(); } + public List findCards(String name, long limitByMaxAmount) { + return findCards(name, limitByMaxAmount, false); + } + public List findCardsByClass(String canonicalClassName) { try { QueryBuilder queryBuilder = cardDao.queryBuilder();