mirror of
https://github.com/correl/mage.git
synced 2024-12-26 11:09:27 +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
|
* authors and should not be interpreted as representing official policies, either expressed
|
||||||
* or implied, of BetaSteward_at_googlemail.com.
|
* or implied, of BetaSteward_at_googlemail.com.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package mage.cards.decks.importer;
|
package mage.cards.decks.importer;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
import mage.cards.decks.DeckCardInfo;
|
import mage.cards.decks.DeckCardInfo;
|
||||||
import mage.cards.decks.DeckCardLists;
|
import mage.cards.decks.DeckCardLists;
|
||||||
import mage.cards.repository.CardInfo;
|
import mage.cards.repository.CardInfo;
|
||||||
|
@ -58,17 +55,15 @@ public class DecDeckImporter extends DeckImporter {
|
||||||
String lineName = line.substring(delim).trim();
|
String lineName = line.substring(delim).trim();
|
||||||
try {
|
try {
|
||||||
int num = Integer.parseInt(lineNum);
|
int num = Integer.parseInt(lineNum);
|
||||||
List<CardInfo> cards = CardRepository.instance.findCards(lineName);
|
CardInfo 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");
|
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n");
|
||||||
} else {
|
} else {
|
||||||
Random random = new Random();
|
|
||||||
for (int i = 0; i < num; i++) {
|
for (int i = 0; i < num; i++) {
|
||||||
CardInfo cardInfo = cards.get(random.nextInt(cards.size()));
|
|
||||||
if (!sideboard) {
|
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 {
|
} 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();
|
String lineName = line.substring(delim + 1).trim();
|
||||||
try {
|
try {
|
||||||
int num = Integer.parseInt(lineNum);
|
int num = Integer.parseInt(lineNum);
|
||||||
List<CardInfo> cards = null;
|
CardInfo cardInfo = null;
|
||||||
if (!setCode.isEmpty()) {
|
if (!setCode.isEmpty()) {
|
||||||
CardCriteria criteria = new CardCriteria();
|
CardCriteria criteria = new CardCriteria();
|
||||||
criteria.name(lineName);
|
criteria.name(lineName);
|
||||||
criteria.setCodes(setCode);
|
criteria.setCodes(setCode);
|
||||||
|
List<CardInfo> cards = null;
|
||||||
cards = CardRepository.instance.findCards(criteria);
|
cards = CardRepository.instance.findCards(criteria);
|
||||||
|
if (!cards.isEmpty()) {
|
||||||
|
cardInfo = cards.get(new Random().nextInt(cards.size()));
|
||||||
}
|
}
|
||||||
if (cards == null || cards.isEmpty()) {
|
} else {
|
||||||
cards = CardRepository.instance.findCards(lineName);
|
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");
|
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n");
|
||||||
} else {
|
} else {
|
||||||
Random random = new Random();
|
|
||||||
for (int i = 0; i < num; i++) {
|
for (int i = 0; i < num; i++) {
|
||||||
CardInfo cardInfo = cards.get(random.nextInt(cards.size()));
|
|
||||||
if (!sideboard) {
|
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 {
|
} 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;
|
package mage.cards.decks.importer;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.GregorianCalendar;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import mage.cards.decks.DeckCardInfo;
|
import mage.cards.decks.DeckCardInfo;
|
||||||
import mage.cards.decks.DeckCardLists;
|
import mage.cards.decks.DeckCardLists;
|
||||||
import mage.cards.repository.CardInfo;
|
import mage.cards.repository.CardInfo;
|
||||||
import mage.cards.repository.CardRepository;
|
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
|
@Override
|
||||||
protected void readLine(String line, DeckCardLists deckList) {
|
protected void readLine(String line, DeckCardLists deckList) {
|
||||||
|
if (line.toLowerCase().contains("sideboard")) {
|
||||||
|
sideboard = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (line.startsWith("//")) {
|
if (line.startsWith("//")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -69,11 +67,6 @@ public class TxtDeckImporter extends DeckImporter {
|
||||||
emptyLinesInARow = 0;
|
emptyLinesInARow = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.toLowerCase().startsWith("sideboard")) {
|
|
||||||
sideboard = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
line = line.replace("\t", " "); // changing tabs to blanks as delimiter
|
line = line.replace("\t", " "); // changing tabs to blanks as delimiter
|
||||||
int delim = line.indexOf(' ');
|
int delim = line.indexOf(' ');
|
||||||
if (delim < 0) {
|
if (delim < 0) {
|
||||||
|
@ -93,36 +86,15 @@ public class TxtDeckImporter extends DeckImporter {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
int num = Integer.parseInt(lineNum.replaceAll("\\D+", ""));
|
int num = Integer.parseInt(lineNum.replaceAll("\\D+", ""));
|
||||||
List<CardInfo> cards = CardRepository.instance.findCards(lineName);
|
CardInfo 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");
|
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n");
|
||||||
} else {
|
} 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++) {
|
for (int i = 0; i < num; i++) {
|
||||||
if (!sideboard) {
|
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 {
|
} 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.io.File;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import mage.cards.ExpansionSet;
|
|
||||||
import mage.cards.Sets;
|
|
||||||
import mage.constants.CardType;
|
import mage.constants.CardType;
|
||||||
import mage.constants.SetType;
|
import mage.constants.SetType;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
@ -303,18 +303,24 @@ public enum CardRepository {
|
||||||
public CardInfo findPreferedCoreExpansionCard(String name) {
|
public CardInfo findPreferedCoreExpansionCard(String name) {
|
||||||
List<CardInfo> cards = findCards(name);
|
List<CardInfo> cards = findCards(name);
|
||||||
if (!cards.isEmpty()) {
|
if (!cards.isEmpty()) {
|
||||||
CardInfo cardInfo = cards.get(random.nextInt(cards.size()));
|
Date lastReleaseDate = new GregorianCalendar(1900, 1, 1).getTime();
|
||||||
ExpansionSet set = Sets.getInstance().get(cardInfo.getSetCode());
|
Date lastExpansionDate = new GregorianCalendar(1900, 1, 1).getTime();
|
||||||
if (set.getSetType().equals(SetType.EXPANSION) || set.getSetType().equals(SetType.CORE)) {
|
CardInfo cardToUse = null;
|
||||||
return cardInfo;
|
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();
|
||||||
}
|
}
|
||||||
for (CardInfo cardInfoToCheck : cards) {
|
if (lastExpansionDate == null && (lastReleaseDate == null || set.getReleaseDate().after(lastReleaseDate))) {
|
||||||
set = Sets.getInstance().get(cardInfoToCheck.getSetCode());
|
cardToUse = cardinfo;
|
||||||
if (set.getSetType().equals(SetType.CORE) || set.getSetType().equals(SetType.EXPANSION)) {
|
lastReleaseDate = set.getReleaseDate();
|
||||||
return cardInfoToCheck;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cardInfo;
|
}
|
||||||
|
return cardToUse;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -323,7 +329,6 @@ public enum CardRepository {
|
||||||
try {
|
try {
|
||||||
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
|
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
|
||||||
queryBuilder.where().eq("name", new SelectArg(name));
|
queryBuilder.where().eq("name", new SelectArg(name));
|
||||||
|
|
||||||
return cardDao.query(queryBuilder.prepare());
|
return cardDao.query(queryBuilder.prepare());
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue