Merge pull request #1850 from halljared/master

Fixes #1836
This commit is contained in:
Derek M 2016-04-12 08:18:15 -04:00
commit 9c202a2902
5 changed files with 69 additions and 57 deletions

View file

@ -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>

View file

@ -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,6 +29,7 @@ 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<>();
@ -57,21 +60,13 @@ public class ConstructedFormats {
}
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>());
}

View file

@ -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);
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;
}
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)){
});
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++;
}
}
}
}

View file

@ -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;

View file

@ -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());