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

@ -27,13 +27,10 @@
*/
package mage.cards.decks;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;
import mage.cards.Card;
import mage.cards.Sets;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.constants.Rarity;
@ -52,6 +49,9 @@ 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");
}
@ -126,22 +126,21 @@ public class Constructed extends DeckValidator {
}
}
if (!setCodes.isEmpty()) {
for (Card card : deck.getCards()) {
if (!setCodes.contains(card.getExpansionSetCode())) {
if( !legalSets(card) ){
valid = false;
}
}
}
for (Card card : deck.getSideboard()) {
if (!setCodes.contains(card.getExpansionSetCode())) {
if( !legalSets(card) ){
valid = false;
}
for (Card card : deck.getCards()) {
if (!isSetAllowed(card.getExpansionSetCode())) {
if( !legalSets(card) ){
valid = false;
}
}
}
for (Card card : deck.getSideboard()) {
if (!isSetAllowed(card.getExpansionSetCode())) {
if( !legalSets(card) ){
valid = false;
}
}
}
logger.debug("DECK validate end: " + name + " deckname: " + deck.getName() + " invalids:" + invalid.size());
return valid;
}
@ -167,6 +166,16 @@ public class Constructed extends DeckValidator {
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
* @param card - the card to check
@ -177,7 +186,7 @@ public class Constructed extends DeckValidator {
boolean legal = false;
List<CardInfo> cardInfos = CardRepository.instance.findCards(card.getName());
for (CardInfo cardInfo : cardInfos) {
if (setCodes.contains(cardInfo.getSetCode())) {
if (isSetAllowed(cardInfo.getSetCode())) {
legal = true;
break;
}