use of mage.cards.ExpansionSet in project mage by magefree.
the class CardSelector method btnBoosterActionPerformed.
// GEN-LAST:event_btnClearActionPerformed
private void btnBoosterActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_btnBoosterActionPerformed
List<String> sets = getFilteredSets();
if (sets.size() == 1) {
if (!this.limited) {
this.limited = true;
cards.clear();
}
// accumulate boosters in one list
ExpansionSet expansionSet = Sets.getInstance().get(sets.get(0));
if (expansionSet != null) {
java.util.List<Card> booster = expansionSet.createBooster();
cards.addAll(booster);
filterCards();
}
} else {
MageFrame.getInstance().showMessage("An expansion set must be selected to be able to generate a booster.");
}
}
use of mage.cards.ExpansionSet in project mage by magefree.
the class HistoricalType2 method validate.
/**
* Overridden validate function. Changes the standard sets, then uses the
* regular validation function to test validity.
*
* @param deck - the deck to validate.
* @return
*/
@Override
public boolean validate(Deck deck) {
List<DeckValidatorError> leastInvalid = null;
boolean valid = false;
errorsList.clear();
// first, check whether misty and batterskull are in the same deck.
Map<String, Integer> counts = new HashMap<>();
countCards(counts, deck.getCards());
countCards(counts, deck.getSideboard());
if (counts.containsKey("Stoneforge Mystic") && counts.containsKey("Batterskull")) {
// if both, then skip all following tests by returning
return false;
}
// iterate through the array of standards.
for (String[] sets : standards) {
// clear the invalid list
errorsList.clear();
// add the sets to the setCodes.
setCodes = new ArrayList<>(Arrays.asList(sets));
// validate it. If it validates, clear the invalid cards and break.
if (super.validate(deck)) {
valid = true;
break;
}
// copy of the current invalid list.
if (leastInvalid == null) {
leastInvalid = new ArrayList<>(this.getErrorsList());
continue;
}
// to leastInvalid.
if (leastInvalid.size() > this.getErrorsList().size()) {
leastInvalid = new ArrayList<>(this.getErrorsList());
}
}
// After testing the first few standards, do the regular ones.
// set the initial starting and ending date, as well as the current.
GregorianCalendar start = new GregorianCalendar(2006, Calendar.SEPTEMBER, 1);
GregorianCalendar end = new GregorianCalendar(2008, Calendar.SEPTEMBER, 1);
GregorianCalendar current = new GregorianCalendar();
// the date for each standard.
while (end.before(current) && !valid) {
// clear the invalid list and set codes.
setCodes.clear();
errorsList.clear();
// increment the start and end dates.
start.set(Calendar.YEAR, start.get(Calendar.YEAR) + 1);
end.set(Calendar.YEAR, start.get(Calendar.YEAR) + 2);
// (code taken from standard.java)
for (ExpansionSet set : Sets.getInstance().values()) {
if (set.getSetType().isStandardLegal() && set.getReleaseDate().after(start.getTime()) && set.getReleaseDate().before(end.getTime())) {
setCodes.add(set.getCode());
}
}
// validate it. If it validates, clear the invalid cards and break.
if (super.validate(deck)) {
errorsList.clear();
valid = true;
break;
}
// to leastInvalid.
if (leastInvalid == null) {
leastInvalid = new ArrayList<>(this.getErrorsList());
} else if (leastInvalid.size() > this.getErrorsList().size()) {
leastInvalid = new ArrayList<>(this.getErrorsList());
}
}
// invalid that had the least errors.
if (!valid) {
this.errorsList = new ArrayList<>(leastInvalid);
}
// return the validity.
return valid;
}
use of mage.cards.ExpansionSet in project mage by magefree.
the class Standard method makeLegalSets.
static List<String> makeLegalSets() {
GregorianCalendar current = new GregorianCalendar();
// Get the second most recent fall set that's been released.
Date earliestDate = Sets.getInstance().values().stream().filter(set -> !set.getReleaseDate().after(current.getTime())).filter(Standard::isFallSet).sorted(ExpansionSet.getComparator()).skip(1).findFirst().get().getReleaseDate();
return Sets.getInstance().values().stream().filter(set -> set.getSetType().isStandardLegal()).filter(set -> !set.getReleaseDate().before(earliestDate)).map(ExpansionSet::getCode).collect(Collectors.toList());
}
use of mage.cards.ExpansionSet in project mage by magefree.
the class SuperType2 method validate.
/**
* Overridden validate function. Changes the standard sets, then uses the
* regular validation function to test validity.
*
* @param deck - the deck to validate.
* @return boolean if valid deck
*/
@Override
public boolean validate(Deck deck) {
List<DeckValidatorError> leastInvalid = null;
boolean valid = false;
errorsList.clear();
// first, check whether misty and batterskull are in the same deck.
Map<String, Integer> counts = new HashMap<>();
countCards(counts, deck.getCards());
countCards(counts, deck.getSideboard());
if (counts.containsKey("Stoneforge Mystic") && counts.containsKey("Batterskull")) {
// if both, then skip all following tests by returning
return false;
}
// iterate through the array of standards.
for (String[] sets : standards) {
// clear the invalid list
errorsList.clear();
// add the sets to the setCodes.
setCodes = new ArrayList<>(Arrays.asList(sets));
// misty and darksteel citadel
if (setCodes.contains("MRD") || setCodes.contains("SOM")) {
banned.add("Darksteel Citadel");
} else {
banned.remove("Darksteel Citadel");
}
// validate it. If it validates, clear the invalid cards and break.
if (super.validate(deck)) {
valid = true;
break;
}
// copy of the current invalid list.
if (leastInvalid == null) {
leastInvalid = new ArrayList<>(this.getErrorsList());
continue;
}
// to leastInvalid.
if (leastInvalid.size() > this.getErrorsList().size()) {
leastInvalid = new ArrayList<>(this.getErrorsList());
}
}
// After testing the first few standards, do the regular ones.
// set the initial starting and ending date, as well as the current.
GregorianCalendar start = new GregorianCalendar(2006, Calendar.SEPTEMBER, 1);
GregorianCalendar end = new GregorianCalendar(2008, Calendar.SEPTEMBER, 1);
GregorianCalendar current = new GregorianCalendar();
// the date for each standard.
while (end.before(current) && !valid) {
// clear the invalid list and set codes.
setCodes.clear();
errorsList.clear();
// increment the start and end dates.
start.set(Calendar.YEAR, start.get(Calendar.YEAR) + 1);
end.set(Calendar.YEAR, start.get(Calendar.YEAR) + 2);
// (code taken from standard.java)
for (ExpansionSet set : Sets.getInstance().values()) {
if (set.getSetType().isStandardLegal() && set.getReleaseDate().after(start.getTime()) && set.getReleaseDate().before(end.getTime())) {
setCodes.add(set.getCode());
}
}
// misty and darksteel citadel
if (setCodes.contains("MRD") || setCodes.contains("SOM")) {
banned.add("Darksteel Citadel");
} else {
banned.remove("Darksteel Citadel");
}
// validate it. If it validates, clear the invalid cards and break.
if (super.validate(deck)) {
errorsList.clear();
valid = true;
break;
}
// to leastInvalid.
if (leastInvalid == null) {
leastInvalid = new ArrayList<>(this.getErrorsList());
} else if (leastInvalid.size() > this.getErrorsList().size()) {
leastInvalid = new ArrayList<>(this.getErrorsList());
}
}
// invalid that had the least errors.
if (!valid) {
this.errorsList = new ArrayList<>(leastInvalid);
}
// return the validity.
return valid;
}
use of mage.cards.ExpansionSet in project mage by magefree.
the class LoadMissingCardDataNew method reloadCardsToDownload.
private void reloadCardsToDownload(String selectedItem) {
// find selected sets
selectedSets.clear();
boolean onlyTokens = false;
List<String> formatSets;
List<String> sourceSets = selectedSource.getSupportedSets();
switch(selectedItem) {
case ALL_IMAGES:
selectedSets.addAll(selectedSource.getSupportedSets());
break;
case ALL_STANDARD_IMAGES:
formatSets = ConstructedFormats.getSetsByFormat(ConstructedFormats.STANDARD);
formatSets.stream().filter(sourceSets::contains).forEachOrdered(selectedSets::add);
break;
case ALL_MODERN_IMAGES:
formatSets = ConstructedFormats.getSetsByFormat(ConstructedFormats.MODERN);
formatSets.stream().filter(sourceSets::contains).forEachOrdered(selectedSets::add);
break;
case ALL_TOKENS:
selectedSets.addAll(selectedSource.getSupportedSets());
onlyTokens = true;
break;
default:
// selects one set
ExpansionSet selectedExp = findSetByNameWithYear(selectedItem);
if (selectedExp != null) {
selectedSets.add(selectedExp.getCode());
}
break;
}
// find missing cards to download
cardsDownloadQueue.clear();
int numberTokenImagesAvailable = 0;
int numberCardImagesAvailable = 0;
for (CardDownloadData data : cardsMissing) {
if (data.isToken()) {
if (selectedSource.isTokenSource() && selectedSource.isTokenImageProvided(data.getSet(), data.getName(), data.getType()) && selectedSets.contains(data.getSet())) {
numberTokenImagesAvailable++;
cardsDownloadQueue.add(data);
}
} else {
if (!onlyTokens && selectedSource.isCardSource() && selectedSource.isCardImageProvided(data.getSet(), data.getName()) && selectedSets.contains(data.getSet())) {
numberCardImagesAvailable++;
cardsDownloadQueue.add(data);
}
}
}
updateProgressText(numberCardImagesAvailable, numberTokenImagesAvailable);
}
Aggregations