diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPicturesService.java b/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPicturesService.java
index 18f6c63d02..33f6a1e509 100644
--- a/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPicturesService.java
+++ b/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPicturesService.java
@@ -455,7 +455,7 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
throw new IllegalStateException("Second side card can't have empty name.");
}
- CardInfo secondSideCard = CardRepository.instance.findCardWPreferredSet(card.getSecondSideName(), card.getSetCode(), false);
+ CardInfo secondSideCard = CardRepository.instance.findCardWPreferredSet(card.getSecondSideName(), card.getSetCode());
if (secondSideCard == null) {
throw new IllegalStateException("Can''t find second side card in database: " + card.getSecondSideName());
}
diff --git a/Mage.Server/src/main/java/mage/server/ChatManagerImpl.java b/Mage.Server/src/main/java/mage/server/ChatManagerImpl.java
index dbdbb00dd5..4642ef9993 100644
--- a/Mage.Server/src/main/java/mage/server/ChatManagerImpl.java
+++ b/Mage.Server/src/main/java/mage/server/ChatManagerImpl.java
@@ -128,7 +128,7 @@ public class ChatManagerImpl implements ChatManager {
Matcher matchPattern = cardNamePattern.matcher(message);
while (matchPattern.find()) {
String cardName = matchPattern.group(1);
- CardInfo cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(cardName, true);
+ CardInfo cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(cardName);
if (cardInfo != null) {
String colour = "silver";
if (cardInfo.getCard().getColor(null).isMulticolored()) {
@@ -270,7 +270,7 @@ public class ChatManagerImpl implements ChatManager {
Matcher matchPattern = getCardTextPattern.matcher(message.toLowerCase(Locale.ENGLISH));
if (matchPattern.find()) {
String cardName = matchPattern.group(1);
- CardInfo cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(cardName, true);
+ CardInfo cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(cardName);
if (cardInfo != null) {
cardInfo.getRules();
message = "" + cardInfo.getName() + ": Cost:" + cardInfo.getManaCosts(CardInfo.ManaCostSide.ALL).toString() + ", Types:" + cardInfo.getTypes().toString() + ", ";
diff --git a/Mage.Sets/src/mage/sets/Battlebond.java b/Mage.Sets/src/mage/sets/Battlebond.java
index 3cecbae6fd..24fc08ad38 100644
--- a/Mage.Sets/src/mage/sets/Battlebond.java
+++ b/Mage.Sets/src/mage/sets/Battlebond.java
@@ -358,7 +358,7 @@ public final class Battlebond extends ExpansionSet {
//Check if the pack already contains a partner pair
if (partnerAllowed) {
//Added card always replaces an uncommon card
- Card card = CardRepository.instance.findCardWPreferredSet(partnerName, sourceCard.getExpansionSetCode(), false).getCard();
+ Card card = CardRepository.instance.findCardWPreferredSet(partnerName, sourceCard.getExpansionSetCode()).getCard();
if (i < max) {
booster.add(card);
} else {
diff --git a/Mage.Sets/src/mage/sets/MysteryBooster.java b/Mage.Sets/src/mage/sets/MysteryBooster.java
index 089538bfce..86f213208d 100644
--- a/Mage.Sets/src/mage/sets/MysteryBooster.java
+++ b/Mage.Sets/src/mage/sets/MysteryBooster.java
@@ -3482,7 +3482,7 @@ public class MysteryBooster extends ExpansionSet {
private void populateSlot(int slotNumber, List cardNames) {
final List cardInfoList = this.possibleCardsPerBoosterSlot.get(slotNumber);
for (String name : cardNames) {
- final CardInfo cardWithGivenName = CardRepository.instance.findCardWPreferredSet(name, this.code, false);
+ final CardInfo cardWithGivenName = CardRepository.instance.findCardWPreferredSet(name, this.code);
cardInfoList.add(cardWithGivenName);
}
}
diff --git a/Mage.Tests/src/test/java/org/mage/test/decks/importer/TxtDeckImporterTest.java b/Mage.Tests/src/test/java/org/mage/test/decks/importer/TxtDeckImporterTest.java
index 4043e013be..1c4fd8fe31 100644
--- a/Mage.Tests/src/test/java/org/mage/test/decks/importer/TxtDeckImporterTest.java
+++ b/Mage.Tests/src/test/java/org/mage/test/decks/importer/TxtDeckImporterTest.java
@@ -21,13 +21,13 @@ public class TxtDeckImporterTest {
String[] sideboard = {"Swamp", "Mountain"};
for (String c : cards) {
- card = CardRepository.instance.findPreferredCoreExpansionCard(c, true);
+ card = CardRepository.instance.findPreferredCoreExpansionCard(c);
assert card != null;
deck.getCards().add(new DeckCardInfo(card.getName(), card.getCardNumber(), card.getSetCode()));
}
for (String s : sideboard) {
- card = CardRepository.instance.findPreferredCoreExpansionCard(s, true);
+ card = CardRepository.instance.findPreferredCoreExpansionCard(s);
assert card != null;
deck.getSideboard().add(new DeckCardInfo(card.getName(), card.getCardNumber(), card.getSetCode()));
}
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
new file mode 100644
index 0000000000..fdedafc73b
--- /dev/null
+++ b/Mage.Tests/src/test/java/org/mage/test/utils/CardRepositoryTest.java
@@ -0,0 +1,144 @@
+package org.mage.test.utils;
+
+import mage.cards.repository.CardInfo;
+import mage.cards.repository.CardRepository;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.List;
+
+/**
+ * Testing of CardRepository functionality.
+ *
+ * @author Alex-Vasile
+ */
+public class CardRepositoryTest {
+
+ /**
+ * Test CardRepository.findCards for the difficult cases when provided with the full card name.
+ *
+ * CardRepository.findCards is used only for testing purposes.
+ */
+ @Test
+ public void testFindSplitCardsByFullName() {
+ // Modal double-faced
+ assertFindCard("Malakir Rebirth // Malakir Mire");
+ // Transform double-faced
+ assertFindCard("Brutal Cathar // Moonrage Brute");
+ // Split
+ assertFindCard("Alive // Well");
+ // Flip
+ assertFindCard("Rune-Tail, Kitsune Ascendant // Rune-Tail's Essence");
+ // Adventure
+ assertFindCard("Ardenvale Tactician // Dizzying Swoop");
+ }
+
+ /**
+ * Test CardRepository.findCards for the difficult cases.
+ *
+ * CardRepository.findCards is used only for testing purposes.
+ */
+ @Test
+ public void testFindSplitCardsByMainName() {
+ // Modal double-faced
+ assertFindCard("Malakir Rebirth");
+ // Transform double-faced
+ assertFindCard("Brutal Cathar");
+ // Split
+ assertFindCard("Alive");
+ // Flip
+ assertFindCard("Rune-Tail, Kitsune Ascendant");
+ // Adventure
+ assertFindCard("Ardenvale Tactician");
+ }
+
+ /**
+ * Test CardRepository.findCards for the difficult cases.
+ *
+ * CardRepository.findCards is used only for testing purposes.
+ */
+ @Test
+ public void testFindSplitCardsBySecondName() {
+ // Modal double-faced
+ assertFindCard("Malakir Mire");
+ // Transform double-faced
+ assertFindCard("Moonrage Brute");
+ // Split
+ assertFindCard("Well");
+ // Flip
+ assertFindCard("Rune-Tail's Essence");
+ // Adventure
+ assertFindCard("Dizzying Swoop");
+ }
+
+ /**
+ * Test CardRepository.findCardsCaseInsensitive for the difficult cases.
+ *
+ * CardRepository.findCardsCaseInsensitive is used for actual game
+ */
+ @Test
+ public void testFindSplitCardsByFullNameCaseInsensitive() {
+ // Modal double-faced
+ assertFindCard("malakIR rebirTH // maLAkir mIRe");
+ // Transform double-faced
+ assertFindCard("brutAL cathAR // moonRAge BRUte");
+ // Split
+ assertFindCard("aliVE // wELl");
+ // Flip
+ assertFindCard("ruNE-taIL, kitsuNE ascendaNT // rUNe-tAIl's essENce");
+ // Adventure
+ assertFindCard("ardenvaLE tacticiAN // dizzYIng sWOop");
+ }
+
+ /**
+ * Test CardRepository.findCards for the difficult cases.
+ *
+ * CardRepository.findCards is used only for testing purposes.
+ */
+ @Test
+ public void testFindSplitCardsByMainNameCaseInsensitive() {
+ // Modal double-faced
+ assertFindCard("malakIR rebirTH");
+ // Transform double-faced
+ assertFindCard("brutAL cathAR");
+ // Split
+ assertFindCard("aliVE");
+ // Flip
+ assertFindCard("ruNE-taIL, kitsuNE ascendaNT");
+ // Adventure
+ assertFindCard("ardenvaLE tacticiAN");
+ }
+
+ /**
+ * Test CardRepository.findCards for the difficult cases.
+ *
+ * CardRepository.findCards is used only for testing purposes.
+ */
+ @Test
+ public void testFindSplitCardsBySecondNameCaseInsensitive() {
+ // Modal double-faced
+ assertFindCard("maLAkir mIRe");
+ // Transform double-faced
+ assertFindCard("moonRAge BRUte");
+ // Split
+ assertFindCard("wELl");
+ // Flip
+ assertFindCard("rUNe-tAIl's essENce");
+ // Adventure
+ assertFindCard("dizzYIng sWOop");
+ }
+
+ /**
+ * Checks if the card with name cardName can be found when searched for
+ * using the case sensitive approach.
+ *
+ * @param cardName The name of the card to search by.
+ */
+ private void assertFindCard(String cardName) {
+ List foundCards = CardRepository.instance.findCards(cardName);
+ Assert.assertFalse(
+ "Could not find " + "\"" + cardName + "\".",
+ foundCards.isEmpty()
+ );
+ }
+}
diff --git a/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java b/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java
index d8df408131..2c92d2af45 100644
--- a/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java
+++ b/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java
@@ -1923,9 +1923,9 @@ public class VerifyCardDataTest {
// same find code as original cube
CardInfo cardInfo;
if (!cardId.getExtension().isEmpty()) {
- cardInfo = CardRepository.instance.findCardWPreferredSet(cardId.getName(), cardId.getExtension(), false);
+ cardInfo = CardRepository.instance.findCardWPreferredSet(cardId.getName(), cardId.getExtension());
} else {
- cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(cardId.getName(), false);
+ cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(cardId.getName());
}
if (cardInfo == null) {
errorsList.add("Error: broken cube, can't find card: " + cube.getClass().getCanonicalName() + " - " + cardId.getName());
diff --git a/Mage/src/main/java/mage/cards/decks/importer/CardLookup.java b/Mage/src/main/java/mage/cards/decks/importer/CardLookup.java
index 2998803e36..05e24ac08a 100644
--- a/Mage/src/main/java/mage/cards/decks/importer/CardLookup.java
+++ b/Mage/src/main/java/mage/cards/decks/importer/CardLookup.java
@@ -12,7 +12,7 @@ public class CardLookup {
public static final CardLookup instance = new CardLookup();
public Optional lookupCardInfo(String name) {
- return Optional.ofNullable(CardRepository.instance.findPreferredCoreExpansionCard(name, true));
+ return Optional.ofNullable(CardRepository.instance.findPreferredCoreExpansionCard(name));
}
public List lookupCardInfo(CardCriteria criteria) {
diff --git a/Mage/src/main/java/mage/cards/decks/importer/DckDeckImporter.java b/Mage/src/main/java/mage/cards/decks/importer/DckDeckImporter.java
index 0b9119d566..005ec361ad 100644
--- a/Mage/src/main/java/mage/cards/decks/importer/DckDeckImporter.java
+++ b/Mage/src/main/java/mage/cards/decks/importer/DckDeckImporter.java
@@ -92,7 +92,7 @@ public class DckDeckImporter extends PlainTextDeckImporter {
}
if (!cardName.equals("")) {
- foundedCard = CardRepository.instance.findPreferredCoreExpansionCard(cardName, false, setCode);
+ foundedCard = CardRepository.instance.findPreferredCoreExpansionCard(cardName, setCode);
}
if (foundedCard != null) {
diff --git a/Mage/src/main/java/mage/cards/decks/importer/DekDeckImporter.java b/Mage/src/main/java/mage/cards/decks/importer/DekDeckImporter.java
index af3c484156..95a689fdf8 100644
--- a/Mage/src/main/java/mage/cards/decks/importer/DekDeckImporter.java
+++ b/Mage/src/main/java/mage/cards/decks/importer/DekDeckImporter.java
@@ -21,7 +21,7 @@ public class DekDeckImporter extends PlainTextDeckImporter {
Integer cardCount = Integer.parseInt(extractAttribute(line, "Quantity"));
String cardName = extractAttribute(line, "Name");
boolean isSideboard = "true".equals(extractAttribute(line, "Sideboard"));
- CardInfo cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(cardName, true);
+ CardInfo cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(cardName);
if (cardInfo == null) {
sbMessage.append("Could not find card: '").append(cardName).append("' at line ").append(lineCount).append('\n');
} else {
diff --git a/Mage/src/main/java/mage/cards/decks/importer/TxtDeckImporter.java b/Mage/src/main/java/mage/cards/decks/importer/TxtDeckImporter.java
index 8b940b39ed..6a499e086f 100644
--- a/Mage/src/main/java/mage/cards/decks/importer/TxtDeckImporter.java
+++ b/Mage/src/main/java/mage/cards/decks/importer/TxtDeckImporter.java
@@ -126,7 +126,7 @@ public class TxtDeckImporter extends PlainTextDeckImporter {
wasCardLines = true;
- CardInfo cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(lineName, true);
+ CardInfo cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(lineName);
if (cardInfo == null) {
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append('\n');
} else {
diff --git a/Mage/src/main/java/mage/cards/mock/MockCard.java b/Mage/src/main/java/mage/cards/mock/MockCard.java
index 6136be28e9..f4b8239487 100644
--- a/Mage/src/main/java/mage/cards/mock/MockCard.java
+++ b/Mage/src/main/java/mage/cards/mock/MockCard.java
@@ -63,8 +63,9 @@ public class MockCard extends CardImpl {
this.flipCard = card.isFlipCard();
this.nightCard = card.isNightCard();
+
if (card.getSecondSideName() != null && !card.getSecondSideName().isEmpty()) {
- this.secondSideCard = new MockCard(CardRepository.instance.findCardWPreferredSet(card.getSecondSideName(), card.getSetCode(), false));
+ this.secondSideCard = new MockCard(CardRepository.instance.findCardWPreferredSet(card.getSecondSideName(), card.getSetCode()));
}
if (card.isAdventureCard()) {
diff --git a/Mage/src/main/java/mage/cards/mock/MockSplitCard.java b/Mage/src/main/java/mage/cards/mock/MockSplitCard.java
index de5e116b60..86ca616ed6 100644
--- a/Mage/src/main/java/mage/cards/mock/MockSplitCard.java
+++ b/Mage/src/main/java/mage/cards/mock/MockSplitCard.java
@@ -38,8 +38,9 @@ public class MockSplitCard extends SplitCard {
this.flipCard = card.isFlipCard();
this.nightCard = card.isNightCard();
+
if (card.getSecondSideName() != null && !card.getSecondSideName().isEmpty()) {
- this.secondSideCard = new MockCard(CardRepository.instance.findCardWPreferredSet(card.getSecondSideName(), card.getSetCode(), false));
+ this.secondSideCard = new MockCard(CardRepository.instance.findCardWPreferredSet(card.getSecondSideName(), card.getSetCode()));
}
this.flipCardName = card.getFlipCardName();
@@ -48,13 +49,13 @@ public class MockSplitCard extends SplitCard {
this.addAbility(textAbilityFromString(ruleText));
}
- CardInfo leftHalf = CardRepository.instance.findCardWPreferredSet(getLeftHalfName(card), card.getSetCode(), false);
+ CardInfo leftHalf = CardRepository.instance.findCardWPreferredSet(getLeftHalfName(card), card.getSetCode());
if (leftHalf != null) {
this.leftHalfCard = new MockSplitCardHalf(leftHalf);
((SplitCardHalf) this.leftHalfCard).setParentCard(this);
}
- CardInfo rightHalf = CardRepository.instance.findCardWPreferredSet(getRightHalfName(card), card.getSetCode(), false);
+ CardInfo rightHalf = CardRepository.instance.findCardWPreferredSet(getRightHalfName(card), card.getSetCode());
if (rightHalf != null) {
this.rightHalfCard = new MockSplitCardHalf(rightHalf);
((SplitCardHalf) this.rightHalfCard).setParentCard(this);
diff --git a/Mage/src/main/java/mage/cards/repository/CardInfo.java b/Mage/src/main/java/mage/cards/repository/CardInfo.java
index 135358e268..4c21b18d57 100644
--- a/Mage/src/main/java/mage/cards/repository/CardInfo.java
+++ b/Mage/src/main/java/mage/cards/repository/CardInfo.java
@@ -34,12 +34,6 @@ public class CardInfo {
@DatabaseField(indexName = "name_index")
protected String name;
- /**
- * lower_name exists to speed up importing decks, specifically to provide an indexed column.
- * H2 does not support expressions in indices, so we need a physical column.
- */
- @DatabaseField(indexName = "lower_name_index")
- protected String lower_name;
@DatabaseField(indexName = "setCode_cardNumber_index")
protected String setCode;
@DatabaseField(indexName = "setCode_cardNumber_index")
@@ -125,7 +119,6 @@ public class CardInfo {
public CardInfo(Card card) {
this.name = card.getName();
- this.lower_name = name.toLowerCase(Locale.ENGLISH);
this.cardNumber = card.getCardNumber();
this.cardNumberAsInt = CardUtil.parseCardNumberAsInt(card.getCardNumber());
this.setCode = card.getExpansionSetCode();
diff --git a/Mage/src/main/java/mage/cards/repository/CardRepository.java b/Mage/src/main/java/mage/cards/repository/CardRepository.java
index de7b6decba..1a5448be25 100644
--- a/Mage/src/main/java/mage/cards/repository/CardRepository.java
+++ b/Mage/src/main/java/mage/cards/repository/CardRepository.java
@@ -2,7 +2,6 @@ package mage.cards.repository;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.DaoManager;
-import com.j256.ormlite.dao.GenericRawResults;
import com.j256.ormlite.jdbc.JdbcConnectionSource;
import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.SelectArg;
@@ -30,7 +29,7 @@ public enum CardRepository {
private static final Logger logger = Logger.getLogger(CardRepository.class);
- private static final String JDBC_URL = "jdbc:h2:file:./db/cards.h2;AUTO_SERVER=TRUE";
+ private static final String JDBC_URL = "jdbc:h2:file:./db/cards.h2;AUTO_SERVER=TRUE;IGNORECASE=TRUE";
private static final String VERSION_ENTITY_NAME = "card";
// raise this if db structure was changed
private static final long CARD_DB_VERSION = 54;
@@ -352,17 +351,14 @@ public enum CardRepository {
return null;
}
- public CardInfo findPreferredCoreExpansionCard(String name, boolean caseInsensitive) {
- return findPreferredCoreExpansionCard(name, caseInsensitive, null);
+ public CardInfo findPreferredCoreExpansionCard(String name) {
+ return findPreferredCoreExpansionCard(name, null);
}
- public CardInfo findPreferredCoreExpansionCard(String name, boolean caseInsensitive, String preferredSetCode) {
+ public CardInfo findPreferredCoreExpansionCard(String name, String preferredSetCode) {
List cards;
- if (caseInsensitive) {
- cards = findCardsCaseInsensitive(name);
- } else {
- cards = findCards(name);
- }
+ cards = findCards(name);
+
return findPreferredOrLatestCard(cards, preferredSetCode);
}
@@ -399,13 +395,19 @@ public enum CardRepository {
return null;
}
- public CardInfo findCardWPreferredSet(String name, String expansion, boolean caseInsensitive) {
+ /**
+ * 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
+ * @return
+ */
+ public CardInfo findCardWPreferredSet(String name, String expansion) {
List cards;
- if (caseInsensitive) {
- cards = findCardsCaseInsensitive(name);
- } else {
- cards = findCards(name);
- }
+
+ cards = findCards(name);
+
if (!cards.isEmpty()) {
for (CardInfo cardinfo : cards) {
if (cardinfo.getSetCode() != null && expansion != null && expansion.equalsIgnoreCase(cardinfo.getSetCode())) {
@@ -413,7 +415,7 @@ public enum CardRepository {
}
}
}
- return findPreferredCoreExpansionCard(name, true);
+ return findPreferredCoreExpansionCard(name);
}
public List findCards(String name) {
@@ -421,34 +423,84 @@ public enum CardRepository {
}
/**
- * Find card's reprints from all sets
+ * Find a card's reprints from all sets.
+ * It allows for cards to be searched by their full name, or in the case of multi-name cards of the type "A // B"
+ * To search for them using "A", "B", or "A // B".
*
- * @param name
- * @param limitByMaxAmount return max amount of different cards (if 0 then return card from all sets)
- * @return
+ * Note of how the function works:
+ * Out of all card types (Split, MDFC, Adventure, Flip, Transform)
+ * ONLY Split cards (Fire // Ice) MUST be queried in the DB by the full name when querying by "name".
+ * Searching for it by either half will return an incorrect result.
+ * 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.
*/
public List findCards(String name, long limitByMaxAmount) {
+ List results;
+ QueryBuilder queryBuilder = cardDao.queryBuilder();
+ if (limitByMaxAmount > 0) {
+ queryBuilder.limit(limitByMaxAmount);
+ }
+
try {
- QueryBuilder queryBuilder = cardDao.queryBuilder();
- queryBuilder.where().eq("name", new SelectArg(name));
- if (limitByMaxAmount > 0) {
- queryBuilder.limit(limitByMaxAmount);
+ if (name.contains(" // ")) { //
+ // Try to see if it's a split card first. (Split card stored in DB under full card name)
+ // Could be made faster by searching assuming it's NOT a split card and first searching by the first
+ // half of the name, but this is easier to understand.
+ queryBuilder.where().eq("name", new SelectArg(name));
+ results = cardDao.query(queryBuilder.prepare());
+
+ // Result comes back empty, try to search using the first half (could be Adventure, MDFC, etc.)
+ if (results.isEmpty()) {
+ String mainCardName = name.split(" // ", 2)[0];
+ queryBuilder.where().eq("name", new SelectArg(mainCardName));
+ results = cardDao.query(queryBuilder.prepare()); // If still empty, then card can't be found
+ }
+ } else { // Cannot tell if string represents the full name of a card or only part of it.
+ // Assume it is the full card name
+ queryBuilder.where().eq("name", new SelectArg(name));
+ results = cardDao.query(queryBuilder.prepare());
+
+ if (results.isEmpty()) {
+ // Nothing found when looking for main name, try looking under the other names
+ queryBuilder.where()
+ .eq("flipCardName", new SelectArg(name)).or()
+ .eq("secondSideName", new SelectArg(name)).or()
+ .eq("adventureSpellName", new SelectArg(name)).or()
+ .eq("modalDoubleFacesSecondSideName", new SelectArg(name));
+ results = cardDao.query(queryBuilder.prepare());
+ } else {
+ // 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
+ queryBuilder.where()
+ .eq("setCode", new SelectArg(firstCardInfo.setCode)).and()
+ .eq("cardNumber", new SelectArg(firstCardInfo.cardNumber));
+ List tmpResults = cardDao.query(queryBuilder.prepare());
+
+ String fullSplitCardName = null;
+ for (CardInfo cardInfo : tmpResults) {
+ if (cardInfo.isSplitCard()) {
+ fullSplitCardName = cardInfo.name;
+ break;
+ }
+ }
+ if (fullSplitCardName == null) {
+ return Collections.emptyList();
+ }
+
+ queryBuilder.where().eq("name", new SelectArg(fullSplitCardName));
+ results = cardDao.query(queryBuilder.prepare());
+ }
+ }
}
-
- List result = cardDao.query(queryBuilder.prepare());
-
- // Got no results, could be because the name referred to a double-face cards (e.g. Malakir Rebirth // Malakir Mire)
- if (result.isEmpty() && name.contains(" // ")) {
- // If there IS a " // " then the card could be either a double-face card (e.g. Malakir Rebirth // Malakir Mire)
- // OR a split card (e.g. Assault // Battery).
- // Since you can't tell based on the name, we split the text based on " // " and try the operation again with
- // the string on the left side of " // " (double-faced cards are stored under the name on the left of the " // ").
- queryBuilder.where().eq("name", new SelectArg(name.split(" // ", 2)[0]));
-
- result = cardDao.query(queryBuilder.prepare());
- }
-
- return result;
+ return results;
} catch (SQLException ex) {
Logger.getLogger(CardRepository.class).error("Error during execution of raw sql statement", ex);
}
@@ -467,38 +519,6 @@ public enum CardRepository {
return Collections.emptyList();
}
- public List findCardsCaseInsensitive(String name) {
- try {
- String sqlName = name.toLowerCase(Locale.ENGLISH).replaceAll("'", "''");
- GenericRawResults rawResults = cardDao.queryRaw(
- "select * from " + CardRepository.VERSION_ENTITY_NAME + " where lower_name = '" + sqlName + '\'',
- cardDao.getRawRowMapper());
-
- List result = rawResults.getResults();
-
- // Got no results, could be because the name referred to a double-face cards (e.g. Malakir Rebirth // Malakir Mire)
- if (result.isEmpty() && sqlName.contains(" // ")) {
- // If there IS a " // " then the card could be either a double-face card (e.g. Malakir Rebirth // Malakir Mire)
- // OR a split card (e.g. Assault // Battery).
- // Since you can't tell based on the name, we split the text based on " // " and try the operation again with
- // the string on the left side of " // " (double-faced cards are stored under the name on the left of the " // ").
- String leftCardName = sqlName.split(" // ", 2)[0];
-
- GenericRawResults rawResults2 = cardDao.queryRaw(
- "select * from " + CardRepository.VERSION_ENTITY_NAME + " where lower_name = '" + leftCardName + '\'',
- cardDao.getRawRowMapper());
-
- result = rawResults2.getResults();
- }
-
- return result;
- } catch (SQLException ex) {
- Logger.getLogger(CardRepository.class).error("Error during execution of raw sql statement", ex);
- }
-
- return Collections.emptyList();
- }
-
/**
* Warning, don't use db functions in card's code - it generates heavy db loading in AI simulations. If you
* need that feature then check for simulation mode. See https://github.com/magefree/mage/issues/7014
diff --git a/Mage/src/main/java/mage/game/draft/DraftCube.java b/Mage/src/main/java/mage/game/draft/DraftCube.java
index 70b96132ec..7db7239a68 100644
--- a/Mage/src/main/java/mage/game/draft/DraftCube.java
+++ b/Mage/src/main/java/mage/game/draft/DraftCube.java
@@ -84,9 +84,9 @@ public abstract class DraftCube {
if (!cardId.getName().isEmpty()) {
CardInfo cardInfo = null;
if (!cardId.getExtension().isEmpty()) {
- cardInfo = CardRepository.instance.findCardWPreferredSet(cardId.getName(), cardId.getExtension(), false);
+ cardInfo = CardRepository.instance.findCardWPreferredSet(cardId.getName(), cardId.getExtension());
} else {
- cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(cardId.getName(), false);
+ cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(cardId.getName());
}
if (cardInfo != null) {