mirror of
https://github.com/correl/mage.git
synced 2024-12-25 19:25:41 +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 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;
|
||||
|
||||
public ExpansionSet(String name, String code, String packageName, Date releaseDate, SetType setType) {
|
||||
|
@ -374,6 +376,8 @@ public abstract class ExpansionSet implements Serializable {
|
|||
return null;
|
||||
}
|
||||
|
||||
public boolean isCustomSet() { return isCustomSet; }
|
||||
|
||||
public void removeSavedCards() {
|
||||
savedCards.clear();
|
||||
}
|
||||
|
|
|
@ -30,11 +30,7 @@ package mage.cards;
|
|||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
import mage.cards.decks.DeckCardInfo;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
|
@ -61,6 +57,8 @@ public class Sets extends HashMap<String, ExpansionSet> {
|
|||
return fINSTANCE;
|
||||
}
|
||||
|
||||
private Set<String> customSets = new HashSet<>();
|
||||
|
||||
private Sets() {
|
||||
ArrayList<String> packages = new ArrayList<>();
|
||||
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);
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue