mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
* Changed deck importer to use the same card prefered from newest core or expansion set.
This commit is contained in:
parent
44eabd501a
commit
2dbb4a71e1
4 changed files with 50 additions and 77 deletions
|
@ -25,11 +25,8 @@
|
|||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.cards.decks.importer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import mage.cards.decks.DeckCardInfo;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.cards.repository.CardInfo;
|
||||
|
@ -58,17 +55,15 @@ public class DecDeckImporter extends DeckImporter {
|
|||
String lineName = line.substring(delim).trim();
|
||||
try {
|
||||
int num = Integer.parseInt(lineNum);
|
||||
List<CardInfo> cards = CardRepository.instance.findCards(lineName);
|
||||
if (cards.isEmpty()) {
|
||||
CardInfo cardInfo = CardRepository.instance.findPreferedCoreExpansionCard(lineName);
|
||||
if (cardInfo == null) {
|
||||
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n");
|
||||
} else {
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < num; i++) {
|
||||
CardInfo cardInfo = cards.get(random.nextInt(cards.size()));
|
||||
if (!sideboard) {
|
||||
deckList.getCards().add(new DeckCardInfo(cardInfo.getName(),cardInfo.getCardNumber(), cardInfo.getSetCode()));
|
||||
deckList.getCards().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
|
||||
} else {
|
||||
deckList.getSideboard().add(new DeckCardInfo(cardInfo.getName(),cardInfo.getCardNumber(), cardInfo.getSetCode()));
|
||||
deckList.getSideboard().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,27 +63,28 @@ public class MWSDeckImporter extends DeckImporter {
|
|||
String lineName = line.substring(delim + 1).trim();
|
||||
try {
|
||||
int num = Integer.parseInt(lineNum);
|
||||
List<CardInfo> cards = null;
|
||||
CardInfo cardInfo = null;
|
||||
if (!setCode.isEmpty()) {
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
criteria.name(lineName);
|
||||
criteria.setCodes(setCode);
|
||||
List<CardInfo> cards = null;
|
||||
cards = CardRepository.instance.findCards(criteria);
|
||||
}
|
||||
if (cards == null || cards.isEmpty()) {
|
||||
cards = CardRepository.instance.findCards(lineName);
|
||||
if (!cards.isEmpty()) {
|
||||
cardInfo = cards.get(new Random().nextInt(cards.size()));
|
||||
}
|
||||
} else {
|
||||
cardInfo = CardRepository.instance.findPreferedCoreExpansionCard(lineName);
|
||||
}
|
||||
|
||||
if (cards.isEmpty()) {
|
||||
if (cardInfo == null) {
|
||||
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n");
|
||||
} else {
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < num; i++) {
|
||||
CardInfo cardInfo = cards.get(random.nextInt(cards.size()));
|
||||
if (!sideboard) {
|
||||
deckList.getCards().add(new DeckCardInfo(cardInfo.getName(),cardInfo.getCardNumber(), cardInfo.getSetCode()));
|
||||
deckList.getCards().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
|
||||
} else {
|
||||
deckList.getSideboard().add(new DeckCardInfo(cardInfo.getName(),cardInfo.getCardNumber(), cardInfo.getSetCode()));
|
||||
deckList.getSideboard().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,18 +28,12 @@
|
|||
package mage.cards.decks.importer;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import mage.cards.decks.DeckCardInfo;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.cards.repository.ExpansionInfo;
|
||||
import mage.cards.repository.ExpansionRepository;
|
||||
import mage.constants.SetType;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -56,6 +50,10 @@ public class TxtDeckImporter extends DeckImporter {
|
|||
|
||||
@Override
|
||||
protected void readLine(String line, DeckCardLists deckList) {
|
||||
if (line.toLowerCase().contains("sideboard")) {
|
||||
sideboard = true;
|
||||
return;
|
||||
}
|
||||
if (line.startsWith("//")) {
|
||||
return;
|
||||
}
|
||||
|
@ -69,11 +67,6 @@ public class TxtDeckImporter extends DeckImporter {
|
|||
emptyLinesInARow = 0;
|
||||
}
|
||||
|
||||
if (line.toLowerCase().startsWith("sideboard")) {
|
||||
sideboard = true;
|
||||
return;
|
||||
}
|
||||
|
||||
line = line.replace("\t", " "); // changing tabs to blanks as delimiter
|
||||
int delim = line.indexOf(' ');
|
||||
if (delim < 0) {
|
||||
|
@ -93,36 +86,15 @@ public class TxtDeckImporter extends DeckImporter {
|
|||
}
|
||||
try {
|
||||
int num = Integer.parseInt(lineNum.replaceAll("\\D+", ""));
|
||||
List<CardInfo> cards = CardRepository.instance.findCards(lineName);
|
||||
if (cards.isEmpty()) {
|
||||
CardInfo cardInfo = CardRepository.instance.findPreferedCoreExpansionCard(lineName);
|
||||
if (cardInfo == null) {
|
||||
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n");
|
||||
} else {
|
||||
// search the card released last with this name
|
||||
Date lastReleaseDate = new GregorianCalendar(1900, 1, 1).getTime();
|
||||
Date lastExpansionDate = new GregorianCalendar(1900, 1, 1).getTime();
|
||||
CardInfo cardToUse = null;
|
||||
for (CardInfo cardinfo : cards) {
|
||||
ExpansionInfo set = ExpansionRepository.instance.getSetByCode(cardinfo.getSetCode());
|
||||
if (set != null) {
|
||||
if ((set.getType().equals(SetType.EXPANSION) || set.getType().equals(SetType.CORE))
|
||||
&& (lastExpansionDate == null || set.getReleaseDate().after(lastExpansionDate))) {
|
||||
cardToUse = cardinfo;
|
||||
lastExpansionDate = set.getReleaseDate();
|
||||
}
|
||||
if (lastExpansionDate == null && (lastReleaseDate == null || set.getReleaseDate().after(lastReleaseDate))) {
|
||||
cardToUse = cardinfo;
|
||||
lastReleaseDate = set.getReleaseDate();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cardToUse == null) {
|
||||
cardToUse = cards.get(0);
|
||||
}
|
||||
for (int i = 0; i < num; i++) {
|
||||
if (!sideboard) {
|
||||
deckList.getCards().add(new DeckCardInfo(cardToUse.getName(), cardToUse.getCardNumber(), cardToUse.getSetCode()));
|
||||
deckList.getCards().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
|
||||
} else {
|
||||
deckList.getSideboard().add(new DeckCardInfo(cardToUse.getName(), cardToUse.getCardNumber(), cardToUse.getSetCode()));
|
||||
deckList.getSideboard().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,13 +39,13 @@ import com.j256.ormlite.table.TableUtils;
|
|||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.Callable;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.cards.Sets;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.SetType;
|
||||
import org.apache.log4j.Logger;
|
||||
|
@ -303,18 +303,24 @@ public enum CardRepository {
|
|||
public CardInfo findPreferedCoreExpansionCard(String name) {
|
||||
List<CardInfo> cards = findCards(name);
|
||||
if (!cards.isEmpty()) {
|
||||
CardInfo cardInfo = cards.get(random.nextInt(cards.size()));
|
||||
ExpansionSet set = Sets.getInstance().get(cardInfo.getSetCode());
|
||||
if (set.getSetType().equals(SetType.EXPANSION) || set.getSetType().equals(SetType.CORE)) {
|
||||
return cardInfo;
|
||||
}
|
||||
for (CardInfo cardInfoToCheck : cards) {
|
||||
set = Sets.getInstance().get(cardInfoToCheck.getSetCode());
|
||||
if (set.getSetType().equals(SetType.CORE) || set.getSetType().equals(SetType.EXPANSION)) {
|
||||
return cardInfoToCheck;
|
||||
Date lastReleaseDate = new GregorianCalendar(1900, 1, 1).getTime();
|
||||
Date lastExpansionDate = new GregorianCalendar(1900, 1, 1).getTime();
|
||||
CardInfo cardToUse = null;
|
||||
for (CardInfo cardinfo : cards) {
|
||||
ExpansionInfo set = ExpansionRepository.instance.getSetByCode(cardinfo.getSetCode());
|
||||
if (set != null) {
|
||||
if ((set.getType().equals(SetType.EXPANSION) || set.getType().equals(SetType.CORE))
|
||||
&& (lastExpansionDate == null || set.getReleaseDate().after(lastExpansionDate))) {
|
||||
cardToUse = cardinfo;
|
||||
lastExpansionDate = set.getReleaseDate();
|
||||
}
|
||||
if (lastExpansionDate == null && (lastReleaseDate == null || set.getReleaseDate().after(lastReleaseDate))) {
|
||||
cardToUse = cardinfo;
|
||||
lastReleaseDate = set.getReleaseDate();
|
||||
}
|
||||
}
|
||||
}
|
||||
return cardInfo;
|
||||
return cardToUse;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -323,7 +329,6 @@ public enum CardRepository {
|
|||
try {
|
||||
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
|
||||
queryBuilder.where().eq("name", new SelectArg(name));
|
||||
|
||||
return cardDao.query(queryBuilder.prepare());
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue