Exclude custom sets from constructed formats.

This commit is contained in:
Lymia Aluysia 2016-09-24 14:15:47 -05:00
parent 238c88a8b6
commit 74a017586a
No known key found for this signature in database
GPG key ID: DB2E204C989251F7
3 changed files with 42 additions and 25 deletions

View file

@ -68,6 +68,8 @@ public abstract class ExpansionSet implements Serializable {
protected String packageName; protected String packageName;
protected int maxCardNumberInBooster; // used to ommit cards with collector numbers beyond the regular cards in a set for boosters protected int maxCardNumberInBooster; // used to ommit cards with collector numbers beyond the regular cards in a set for boosters
protected boolean isCustomSet = false;
protected final EnumMap<Rarity, List<CardInfo>> savedCards; protected final EnumMap<Rarity, List<CardInfo>> savedCards;
public ExpansionSet(String name, String code, String packageName, Date releaseDate, SetType setType) { public ExpansionSet(String name, String code, String packageName, Date releaseDate, SetType setType) {
@ -374,6 +376,8 @@ public abstract class ExpansionSet implements Serializable {
return null; return null;
} }
public boolean isCustomSet() { return isCustomSet; }
public void removeSavedCards() { public void removeSavedCards() {
savedCards.clear(); savedCards.clear();
} }

View file

@ -30,11 +30,7 @@ package mage.cards;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import mage.cards.decks.DeckCardInfo; import mage.cards.decks.DeckCardInfo;
import mage.cards.decks.DeckCardLists; import mage.cards.decks.DeckCardLists;
@ -61,6 +57,8 @@ public class Sets extends HashMap<String, ExpansionSet> {
return fINSTANCE; return fINSTANCE;
} }
private Set<String> customSets = new HashSet<>();
private Sets() { private Sets() {
ArrayList<String> packages = new ArrayList<>(); ArrayList<String> packages = new ArrayList<>();
packages.add("mage.sets"); packages.add("mage.sets");
@ -72,8 +70,14 @@ public class Sets extends HashMap<String, ExpansionSet> {
} }
} }
private void addSet(ExpansionSet set) { public void addSet(ExpansionSet set) {
if(containsKey(set.getCode())) throw new IllegalArgumentException("Set code "+set.getCode()+" already exists.");
this.put(set.getCode(), set); this.put(set.getCode(), set);
if(set.isCustomSet) customSets.add(set.getCode());
}
public static boolean isCustomSet(String setCode) {
return getInstance().customSets.contains(setCode);
} }
/** /**

View file

@ -27,13 +27,10 @@
*/ */
package mage.cards.decks; package mage.cards.decks;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.Sets;
import mage.cards.repository.CardInfo; import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository; import mage.cards.repository.CardRepository;
import mage.constants.Rarity; import mage.constants.Rarity;
@ -52,6 +49,9 @@ public class Constructed extends DeckValidator {
protected List<String> setCodes = new ArrayList<>(); protected List<String> setCodes = new ArrayList<>();
protected List<Rarity> rarities = new ArrayList<>(); protected List<Rarity> rarities = new ArrayList<>();
protected boolean allowAllCustomSets = false;
protected Set<String> allowedCustomSetCodes = new HashSet<>();
public Constructed() { public Constructed() {
super("Constructed"); super("Constructed");
} }
@ -126,22 +126,21 @@ public class Constructed extends DeckValidator {
} }
} }
if (!setCodes.isEmpty()) {
for (Card card : deck.getCards()) { for (Card card : deck.getCards()) {
if (!setCodes.contains(card.getExpansionSetCode())) { if (!isSetAllowed(card.getExpansionSetCode())) {
if( !legalSets(card) ){ if( !legalSets(card) ){
valid = false; valid = false;
} }
} }
} }
for (Card card : deck.getSideboard()) { for (Card card : deck.getSideboard()) {
if (!setCodes.contains(card.getExpansionSetCode())) { if (!isSetAllowed(card.getExpansionSetCode())) {
if( !legalSets(card) ){ if( !legalSets(card) ){
valid = false; valid = false;
} }
} }
} }
}
logger.debug("DECK validate end: " + name + " deckname: " + deck.getName() + " invalids:" + invalid.size()); logger.debug("DECK validate end: " + name + " deckname: " + deck.getName() + " invalids:" + invalid.size());
return valid; return valid;
} }
@ -167,6 +166,16 @@ public class Constructed extends DeckValidator {
return legal; return legal;
} }
/**
* Checks if a given set is legal in this format.
* @param code - the set code to check
* @return Whether the set is legal in this format.
*/
protected boolean isSetAllowed(String code) {
if(Sets.isCustomSet(code)) return allowAllCustomSets || allowedCustomSetCodes.contains(code);
else return setCodes.isEmpty() || setCodes.contains(code);
}
/** /**
* Checks if the given card is legal in any of the given sets * Checks if the given card is legal in any of the given sets
* @param card - the card to check * @param card - the card to check
@ -177,7 +186,7 @@ public class Constructed extends DeckValidator {
boolean legal = false; boolean legal = false;
List<CardInfo> cardInfos = CardRepository.instance.findCards(card.getName()); List<CardInfo> cardInfos = CardRepository.instance.findCards(card.getName());
for (CardInfo cardInfo : cardInfos) { for (CardInfo cardInfo : cardInfos) {
if (setCodes.contains(cardInfo.getSetCode())) { if (isSetAllowed(cardInfo.getSetCode())) {
legal = true; legal = true;
break; break;
} }