mirror of
https://github.com/correl/mage.git
synced 2024-11-15 11:09:30 +00:00
commit
9c202a2902
5 changed files with 69 additions and 57 deletions
|
@ -25,6 +25,11 @@
|
|||
<artifactId>mage-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mage</groupId>
|
||||
<artifactId>mage-deck-constructed</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.jspf</groupId>
|
||||
<artifactId>jspf-core</artifactId>
|
||||
|
|
|
@ -13,6 +13,8 @@ import java.util.Map;
|
|||
import mage.cards.repository.ExpansionInfo;
|
||||
import mage.cards.repository.ExpansionRepository;
|
||||
import mage.constants.SetType;
|
||||
import mage.deck.Standard;
|
||||
|
||||
|
||||
/**
|
||||
* Utility class for constructed formats (expansions and other editions).
|
||||
|
@ -27,7 +29,8 @@ public class ConstructedFormats {
|
|||
public static final String STANDARD = "- Standard";
|
||||
public static final String EXTENDED = "- Extended";
|
||||
public static final String MODERN = "- Modern";
|
||||
|
||||
public static final Standard STANDARD_CARDS = new Standard();
|
||||
|
||||
private static final Map<String, List<String>> underlyingSetCodesPerFormat = new HashMap<>();
|
||||
private static final List<String> formats = new ArrayList<>();
|
||||
|
||||
|
@ -41,7 +44,7 @@ public class ConstructedFormats {
|
|||
public static String getDefault() {
|
||||
return STANDARD;
|
||||
}
|
||||
|
||||
|
||||
public static List<String> getSetsByFormat(final String format) {
|
||||
if(!format.equals(ALL)) {
|
||||
return underlyingSetCodesPerFormat.get(format);
|
||||
|
@ -55,23 +58,15 @@ public class ConstructedFormats {
|
|||
buildLists();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void buildLists() {
|
||||
GregorianCalendar cutoff;
|
||||
// month is zero based so January = 0
|
||||
if (calendar.get(Calendar.MONTH) > 8) {
|
||||
cutoff = new GregorianCalendar(calendar.get(Calendar.YEAR) - 1, Calendar.SEPTEMBER, 1);
|
||||
}
|
||||
else {
|
||||
cutoff = new GregorianCalendar(calendar.get(Calendar.YEAR) - 2, Calendar.SEPTEMBER, 1);
|
||||
}
|
||||
final Map<String, ExpansionInfo> expansionInfo = new HashMap<>();
|
||||
formats.clear(); // prevent NPE on sorting if this is not the first try
|
||||
for (ExpansionInfo set : ExpansionRepository.instance.getAll()) {
|
||||
expansionInfo.put(set.getName(), set);
|
||||
formats.add(set.getName());
|
||||
if (set.getType().equals(SetType.CORE) || set.getType().equals(SetType.EXPANSION)) {
|
||||
if (set.getReleaseDate().after(cutoff.getTime())) {
|
||||
if (STANDARD_CARDS.getSetCodes().contains(set.getCode())) {
|
||||
if(underlyingSetCodesPerFormat.get(STANDARD) == null) {
|
||||
underlyingSetCodesPerFormat.put(STANDARD, new ArrayList<String>());
|
||||
}
|
||||
|
@ -90,13 +85,13 @@ public class ConstructedFormats {
|
|||
underlyingSetCodesPerFormat.get(MODERN).add(set.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(underlyingSetCodesPerFormat.get(set.getName()) == null) {
|
||||
underlyingSetCodesPerFormat.put(set.getName(), new ArrayList<String>());
|
||||
}
|
||||
|
||||
|
||||
underlyingSetCodesPerFormat.get(set.getName()).add(set.getCode());
|
||||
|
||||
|
||||
if(set.getType().equals(SetType.EXPANSION) && set.getBlockName() != null) {
|
||||
String blockDisplayName = getBlockDisplayName(set.getBlockName());
|
||||
if(underlyingSetCodesPerFormat.get(blockDisplayName) == null) {
|
||||
|
@ -104,84 +99,84 @@ public class ConstructedFormats {
|
|||
}
|
||||
|
||||
underlyingSetCodesPerFormat.get(blockDisplayName).add(set.getCode());
|
||||
|
||||
|
||||
if(expansionInfo.get(blockDisplayName) == null) {
|
||||
expansionInfo.put(blockDisplayName, set);
|
||||
formats.add(blockDisplayName);
|
||||
}
|
||||
|
||||
|
||||
if(expansionInfo.get(blockDisplayName).getReleaseDate().after(set.getReleaseDate())) {
|
||||
expansionInfo.put(blockDisplayName, set);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(set.getType().equals(SetType.SUPPLEMENTAL) && set.getBlockName() != null) {
|
||||
if(expansionInfo.get(set.getBlockName()) == null) {
|
||||
expansionInfo.put(set.getBlockName(), set);
|
||||
}
|
||||
|
||||
|
||||
if(expansionInfo.get(set.getBlockName()).getReleaseDate().before(set.getReleaseDate())) {
|
||||
expansionInfo.put(set.getBlockName(), set);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Collections.sort(formats, new Comparator<String>() {
|
||||
|
||||
@Override
|
||||
public int compare(String name1, String name2) {
|
||||
ExpansionInfo expansionInfo1 = expansionInfo.get(name1);
|
||||
ExpansionInfo expansionInfo2 = expansionInfo.get(name2);
|
||||
|
||||
|
||||
if(expansionInfo1.getType().compareTo(expansionInfo2.getType()) == 0) {
|
||||
SetType setType = expansionInfo1.getType();
|
||||
if(setType.equals(SetType.EXPANSION)) {
|
||||
|
||||
|
||||
if(expansionInfo1.getBlockName() == null) {
|
||||
if(expansionInfo2.getBlockName() == null) {
|
||||
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if(expansionInfo2.getBlockName() == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//Block comparison
|
||||
if(name1.endsWith("Block") && name2.endsWith("Block")) {
|
||||
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
|
||||
}
|
||||
|
||||
|
||||
if(name1.endsWith("Block")) {
|
||||
if(expansionInfo1.getBlockName().equals(expansionInfo2.getBlockName())) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(name2.endsWith("Block")) {
|
||||
if(expansionInfo1.getBlockName().equals(expansionInfo2.getBlockName())) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
|
||||
|
||||
|
||||
} else if(setType.equals(SetType.SUPPLEMENTAL)) {
|
||||
if(expansionInfo1.getBlockName() == null) {
|
||||
if(expansionInfo2.getBlockName() == null) {
|
||||
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if(expansionInfo2.getBlockName() == null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if(expansionInfo1.getBlockName().equals(expansionInfo2.getBlockName())) {
|
||||
//If release date is the same, sort alphabetically.
|
||||
if(expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate()) == 0) {
|
||||
|
@ -189,7 +184,7 @@ public class ConstructedFormats {
|
|||
}
|
||||
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
|
||||
}
|
||||
|
||||
|
||||
if(expansionInfo1.getBlockName().startsWith("Duel Decks")) {
|
||||
if(expansionInfo1.getBlockName().startsWith("Duel Decks: Anthology")) {
|
||||
return 1;
|
||||
|
@ -199,20 +194,20 @@ public class ConstructedFormats {
|
|||
if(expansionInfo2.getBlockName().startsWith("Duel Decks")) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ExpansionInfo blockInfo1 = expansionInfo.get(expansionInfo1.getBlockName());
|
||||
ExpansionInfo blockInfo2 = expansionInfo.get(expansionInfo2.getBlockName());
|
||||
|
||||
|
||||
return blockInfo2.getReleaseDate().compareTo(blockInfo1.getReleaseDate());
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
|
||||
}
|
||||
}
|
||||
return expansionInfo1.getType().compareTo(expansionInfo2.getType());
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
if (!formats.isEmpty()) {
|
||||
formats.add(0, MODERN);
|
||||
|
@ -221,15 +216,15 @@ public class ConstructedFormats {
|
|||
}
|
||||
formats.add(0, ALL);
|
||||
}
|
||||
|
||||
|
||||
private static String getBlockDisplayName(String blockName) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("* ").append(blockName).append(" Block");
|
||||
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static final Date extendedDate = new GregorianCalendar(2009, 8, 20).getTime();
|
||||
|
||||
private static final Date modernDate = new GregorianCalendar(2003, 7, 20).getTime();
|
||||
|
|
|
@ -28,13 +28,16 @@
|
|||
|
||||
package mage.deck;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.cards.Sets;
|
||||
import mage.cards.decks.Constructed;
|
||||
import mage.constants.SetType;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import mage.constants.SetType;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -45,18 +48,23 @@ public class Standard extends Constructed {
|
|||
public Standard() {
|
||||
super("Constructed - Standard");
|
||||
GregorianCalendar current = new GregorianCalendar();
|
||||
GregorianCalendar cutoff;
|
||||
// month is zero based so January = 0
|
||||
if (current.get(Calendar.MONTH) > 8) {
|
||||
cutoff = new GregorianCalendar(current.get(Calendar.YEAR) - 1, Calendar.SEPTEMBER, 1);
|
||||
}
|
||||
else {
|
||||
cutoff = new GregorianCalendar(current.get(Calendar.YEAR) - 2, Calendar.SEPTEMBER, 1);
|
||||
}
|
||||
for (ExpansionSet set: Sets.getInstance().values()) {
|
||||
if (set.getReleaseDate().after(cutoff.getTime()) &&
|
||||
(set.getSetType() == SetType.CORE || set.getSetType() == SetType.EXPANSION)){
|
||||
List<ExpansionSet> sets = new ArrayList(Sets.getInstance().values());
|
||||
Collections.sort(sets, new Comparator<ExpansionSet>() {
|
||||
@Override
|
||||
public int compare(final ExpansionSet lhs, ExpansionSet rhs) {
|
||||
return lhs.getReleaseDate().after(rhs.getReleaseDate()) ? -1 : 1;
|
||||
}
|
||||
});
|
||||
int blocksAdded = 0;
|
||||
for (Iterator<ExpansionSet> iter = sets.iterator(); iter.hasNext() && blocksAdded < 3; ) {
|
||||
ExpansionSet set = iter.next();
|
||||
if (set.getSetType() == SetType.CORE || set.getSetType() == SetType.EXPANSION) { // Still adding core sets because of Magic Origins
|
||||
setCodes.add(set.getCode());
|
||||
if (set.getReleaseDate().before(current.getTime()) // This stops spoiled sets from counting as "new" blocks
|
||||
&& set.getParentSet() == null
|
||||
&& set.getSetType() == SetType.EXPANSION) {
|
||||
blocksAdded++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public class ShadowsOverInnistrad extends ExpansionSet {
|
|||
}
|
||||
|
||||
private ShadowsOverInnistrad() {
|
||||
super("Shadows over Innistrad", "SOI", "mage.sets.shadowsoverinnistrad", new GregorianCalendar(2016, 4, 8).getTime(), SetType.EXPANSION);
|
||||
super("Shadows over Innistrad", "SOI", "mage.sets.shadowsoverinnistrad", new GregorianCalendar(2016, 3, 8).getTime(), SetType.EXPANSION);
|
||||
this.blockName = "Shadows over Innistrad";
|
||||
this.hasBoosters = true;
|
||||
this.numBoosterLands = 1;
|
||||
|
|
|
@ -60,6 +60,10 @@ public class Constructed extends DeckValidator {
|
|||
super(name);
|
||||
}
|
||||
|
||||
public List<String> getSetCodes() {
|
||||
return setCodes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate(Deck deck) {
|
||||
logger.debug("DECK validate start: " + name + " deckname: " + deck.getName());
|
||||
|
@ -141,7 +145,7 @@ public class Constructed extends DeckValidator {
|
|||
logger.debug("DECK validate end: " + name + " deckname: " + deck.getName() + " invalids:" + invalid.size());
|
||||
return valid;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the given card is legal in any of the given rarities
|
||||
* @param card - the card to check
|
||||
|
|
Loading…
Reference in a new issue