From 8c46f23e02e3e6a4966c2b38d0ca3feed28cbe81 Mon Sep 17 00:00:00 2001 From: spjspj Date: Tue, 18 Apr 2017 20:58:03 +1000 Subject: [PATCH] Increased performance function for finding a card in DB with a specific set. Cube from deck (custom cube) now respects chosen set for a given card. --- .../mage/tournament/cubes/CubeFromDeck.java | 2 +- .../mage/cards/repository/CardRepository.java | 18 ++++++++++++++++++ .../main/java/mage/game/draft/DraftCube.java | 6 +----- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/cubes/CubeFromDeck.java b/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/cubes/CubeFromDeck.java index ef34d70b6e..6c8198d584 100644 --- a/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/cubes/CubeFromDeck.java +++ b/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/cubes/CubeFromDeck.java @@ -49,7 +49,7 @@ public class CubeFromDeck extends DraftCube { if (cards != null) { for (DeckCardInfo card : cards.getCards()) { - cubeCards.add(new CardIdentity(card.getCardName(), "")); + cubeCards.add(new CardIdentity(card.getCardName(), card.getSetCode())); } } } diff --git a/Mage/src/main/java/mage/cards/repository/CardRepository.java b/Mage/src/main/java/mage/cards/repository/CardRepository.java index e9bbac3889..046a996b54 100644 --- a/Mage/src/main/java/mage/cards/repository/CardRepository.java +++ b/Mage/src/main/java/mage/cards/repository/CardRepository.java @@ -419,6 +419,24 @@ public enum CardRepository { } return null; } + + public CardInfo findCardWPreferredSet(String name, String expansion, boolean caseInsensitive) { + List cards; + if (caseInsensitive) { + cards = findCardsCaseInsensitive(name); + } else { + cards = findCards(name); + } + if (!cards.isEmpty()) { + CardInfo cardToUse = null; + for (CardInfo cardinfo : cards) { + if (cardinfo.getSetCode() != null && expansion != null && expansion.equalsIgnoreCase(cardinfo.getSetCode())) { + return cardinfo; + } + } + } + return findPreferedCoreExpansionCard(name, true); + } public List findCards(String name) { try { diff --git a/Mage/src/main/java/mage/game/draft/DraftCube.java b/Mage/src/main/java/mage/game/draft/DraftCube.java index 2aa75d0dfc..b84641a05c 100644 --- a/Mage/src/main/java/mage/game/draft/DraftCube.java +++ b/Mage/src/main/java/mage/game/draft/DraftCube.java @@ -107,11 +107,7 @@ public abstract class DraftCube { if (!cardId.getName().isEmpty()) { CardInfo cardInfo = null; if (!cardId.getExtension().isEmpty()) { - CardCriteria criteria = new CardCriteria().name(cardId.getName()).setCodes(cardId.extension); - List cardList = CardRepository.instance.findCards(criteria); - if (cardList != null && !cardList.isEmpty()) { - cardInfo = cardList.get(0); - } + cardInfo = CardRepository.instance.findCardWPreferredSet(cardId.getName(), cardId.getExtension(), false); } else { cardInfo = CardRepository.instance.findPreferedCoreExpansionCard(cardId.getName(), false); }