Fixed some problems with constructed formats definition and custom sets.

This commit is contained in:
LevelX2 2016-10-03 20:25:08 +02:00
parent 7dfcb15c3c
commit 9a00dd20ca
5 changed files with 45 additions and 34 deletions

View file

@ -25,6 +25,10 @@ public class ConstructedFormats {
public static final String EXTENDED = "- Extended";
public static final String FRONTIER = "- Frontier";
public static final String MODERN = "- Modern";
public static final String VINTAGE_LEGACY = "- Vintage / Legacy";
;
public static final String CUSTOM = "- Custom";
;
public static final Standard STANDARD_CARDS = new Standard();
private static final Map<String, List<String>> underlyingSetCodesPerFormat = new HashMap<>();
@ -50,50 +54,49 @@ public class ConstructedFormats {
}
public static void ensureLists() {
if (getSetsByFormat(ConstructedFormats.STANDARD) == null) {
if (underlyingSetCodesPerFormat.isEmpty()) {
buildLists();
}
}
private static void buildLists() {
underlyingSetCodesPerFormat.put(STANDARD, new ArrayList<>());
underlyingSetCodesPerFormat.put(EXTENDED, new ArrayList<>());
underlyingSetCodesPerFormat.put(FRONTIER, new ArrayList<>());
underlyingSetCodesPerFormat.put(MODERN, new ArrayList<>());
underlyingSetCodesPerFormat.put(VINTAGE_LEGACY, new ArrayList<>());
underlyingSetCodesPerFormat.put(CUSTOM, new ArrayList<>());
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());
underlyingSetCodesPerFormat.put(set.getName(), new ArrayList<>());
underlyingSetCodesPerFormat.get(set.getName()).add(set.getCode());
// create the play formats
if (set.getType().equals(SetType.CUSTOM_SET)) {
underlyingSetCodesPerFormat.get(CUSTOM).add(set.getCode());
continue;
}
underlyingSetCodesPerFormat.get(VINTAGE_LEGACY).add(set.getCode());
if (set.getType().equals(SetType.CORE) || set.getType().equals(SetType.EXPANSION) || set.getType().equals(SetType.SUPPLEMENTAL_STANDARD_LEGAL)) {
if (STANDARD_CARDS.getSetCodes().contains(set.getCode())) {
if (underlyingSetCodesPerFormat.get(STANDARD) == null) {
underlyingSetCodesPerFormat.put(STANDARD, new ArrayList<>());
}
underlyingSetCodesPerFormat.get(STANDARD).add(set.getCode());
}
if (set.getReleaseDate().after(extendedDate)) {
if (underlyingSetCodesPerFormat.get(EXTENDED) == null) {
underlyingSetCodesPerFormat.put(EXTENDED, new ArrayList<>());
}
underlyingSetCodesPerFormat.get(EXTENDED).add(set.getCode());
}
if (set.getReleaseDate().after(frontierDate)) {
if (underlyingSetCodesPerFormat.get(FRONTIER) == null) {
underlyingSetCodesPerFormat.put(FRONTIER, new ArrayList<>());
}
underlyingSetCodesPerFormat.get(FRONTIER).add(set.getCode());
}
if (set.getReleaseDate().after(modernDate)) {
if (underlyingSetCodesPerFormat.get(MODERN) == null) {
underlyingSetCodesPerFormat.put(MODERN, new ArrayList<>());
}
underlyingSetCodesPerFormat.get(MODERN).add(set.getCode());
}
}
if (underlyingSetCodesPerFormat.get(set.getName()) == null) {
underlyingSetCodesPerFormat.put(set.getName(), new ArrayList<>());
}
underlyingSetCodesPerFormat.get(set.getName()).add(set.getCode());
// Create the Block formats
if (set.getType().equals(SetType.EXPANSION) && set.getBlockName() != null) {
String blockDisplayName = getBlockDisplayName(set.getBlockName());
if (underlyingSetCodesPerFormat.get(blockDisplayName) == null) {
@ -209,10 +212,13 @@ public class ConstructedFormats {
});
if (!formats.isEmpty()) {
formats.add(0, CUSTOM);
formats.add(0, VINTAGE_LEGACY);
formats.add(0, MODERN);
formats.add(0, FRONTIER);
formats.add(0, EXTENDED);
formats.add(0, FRONTIER);
formats.add(0, STANDARD);
}
formats.add(0, ALL);
}

View file

@ -24,11 +24,13 @@
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
*/
package mage.deck;
import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.cards.decks.Constructed;
import mage.constants.SetType;
/**
*
@ -38,7 +40,11 @@ public class Legacy extends Constructed {
public Legacy() {
super("Constructed - Legacy");
for (ExpansionSet set : Sets.getInstance().values()) {
if (set.getSetType() != SetType.CUSTOM_SET) {
setCodes.add(set.getCode());
}
}
banned.add("Advantageous Proclamation");
banned.add("Amulet of Quoz");
banned.add("Ancestral Recall");
@ -112,6 +118,6 @@ public class Legacy extends Constructed {
banned.add("Worldknit");
banned.add("Yawgmoth's Bargain");
banned.add("Yawgmoth's Will");
}
}

View file

@ -27,7 +27,10 @@
*/
package mage.deck;
import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.cards.decks.Constructed;
import mage.constants.SetType;
/**
*
@ -37,7 +40,11 @@ public class Vintage extends Constructed {
public Vintage() {
super("Constructed - Vintage");
for (ExpansionSet set : Sets.getInstance().values()) {
if (set.getSetType() != SetType.CUSTOM_SET) {
setCodes.add(set.getCode());
}
}
banned.add("Advantageous Proclamation");
banned.add("Amulet of Quoz");
banned.add("Backup Plan");

View file

@ -284,7 +284,7 @@ public class Session {
lockSet = true;
logger.debug("SESSION LOCK SET sessionId: " + sessionId);
} else {
logger.error("CAN'T GET LOCK - userId: " + userId);
logger.error("CAN'T GET LOCK - userId: " + userId + " hold count: " + lock.getHoldCount());
}
User user = UserManager.getInstance().getUser(userId);
if (user == null || !user.isConnected()) {

View file

@ -48,9 +48,6 @@ public class Constructed extends DeckValidator {
protected List<String> setCodes = new ArrayList<>();
protected List<Rarity> rarities = new ArrayList<>();
protected boolean allowAllCustomSets = false;
protected Set<String> allowedCustomSetCodes = new HashSet<>();
public Constructed() {
super("Constructed");
}
@ -173,12 +170,7 @@ public class Constructed extends DeckValidator {
* @return Whether the set is legal in this format.
*/
protected boolean isSetAllowed(String code) {
// To check here for custom set makes no sens IMHO because the format does define what's aloowed and what not
// if (Sets.isCustomSet(code)) {
// return allowAllCustomSets || allowedCustomSetCodes.contains(code);
// } else {
return setCodes.isEmpty() || setCodes.contains(code);
// }
}
/**