mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
Exclude custom sets from constructed formats.
This commit is contained in:
parent
238c88a8b6
commit
74a017586a
3 changed files with 42 additions and 25 deletions
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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 (!isSetAllowed(card.getExpansionSetCode())) {
|
||||||
if (!setCodes.contains(card.getExpansionSetCode())) {
|
if( !legalSets(card) ){
|
||||||
if( !legalSets(card) ){
|
valid = false;
|
||||||
valid = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Card card : deck.getSideboard()) {
|
|
||||||
if (!setCodes.contains(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());
|
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue