Refactor set's legality, Modern Horizons now available for modern formats;

This commit is contained in:
Oleg Agafonov 2019-03-04 04:49:49 +04:00
parent 6bfea7bfd9
commit e30eecead3
29 changed files with 86 additions and 89 deletions

View file

@ -600,20 +600,6 @@ public abstract class ExpansionSet implements Serializable {
return new ArrayList<>();
}
public boolean isCustomSet() {
return setType == SetType.CUSTOM_SET;
}
public boolean isEternalLegal() {
// any official sets except un-sets
return setType != SetType.CUSTOM_SET && setType != SetType.JOKESET;
}
public boolean isStandardLegal() {
// any official sets that was in standard
return setType == SetType.CORE || setType == SetType.EXPANSION || setType == SetType.SUPPLEMENTAL_STANDARD_LEGAL;
}
public void removeSavedCards() {
savedCards.clear();
}

View file

@ -51,15 +51,11 @@ public class Sets extends HashMap<String, ExpansionSet> {
throw new IllegalArgumentException("Set code " + set.getCode() + " already exists.");
}
this.put(set.getCode(), set);
if (set.isCustomSet()) {
if (set.getSetType().isCustomSet()) {
customSets.add(set.getCode());
}
}
public static boolean isCustomSet(String setCode) {
return getInstance().customSets.contains(setCode);
}
/**
* Generates card pool of cardsCount cards that have manacost of allowed
* colors.

View file

@ -12,7 +12,6 @@ import com.j256.ormlite.support.DatabaseConnection;
import com.j256.ormlite.table.TableUtils;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SetType;
import mage.constants.SuperType;
import mage.game.events.Listener;
import mage.util.RandomUtil;
@ -407,8 +406,7 @@ public enum CardRepository {
return cardinfo;
}
if ((set.getType() == SetType.EXPANSION || set.getType() == SetType.CORE)
&& (lastExpansionDate == null || set.getReleaseDate().after(lastExpansionDate))) {
if (set.getType().isStandardLegal() && (lastExpansionDate == null || set.getReleaseDate().after(lastExpansionDate))) {
cardToUse = cardinfo;
lastExpansionDate = set.getReleaseDate();
}

View file

@ -80,7 +80,7 @@ public final class CardScanner {
Collection<ExpansionSet> sets = Sets.getInstance().values();
List<Card> cards = new ArrayList<>();
for (ExpansionSet set : sets) {
if (ignoreCustomSets && set.isCustomSet()) {
if (ignoreCustomSets && set.getSetType().isCustomSet()) {
continue;
}
for (ExpansionSet.SetCardInfo setInfo : set.getSetCardInfo()) {

View file

@ -3,12 +3,12 @@ package mage.cards.repository;
import com.j256.ormlite.field.DataType;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import java.util.Date;
import mage.cards.ExpansionSet;
import mage.constants.SetType;
import java.util.Date;
/**
*
* @author North
*/
@DatabaseTable(tableName = "expansion")
@ -16,7 +16,7 @@ public class ExpansionInfo {
@DatabaseField(unique = true)
protected String name;
@DatabaseField(id = true,unique = true)
@DatabaseField(id = true, unique = true)
protected String code;
@DatabaseField
protected String blockName;
@ -74,5 +74,4 @@ public class ExpansionInfo {
public String toString() {
return name;
}
}

View file

@ -1,7 +1,6 @@
package mage.constants;
/**
*
* @author North
*/
public enum SetType {
@ -10,6 +9,7 @@ public enum SetType {
MAGIC_ONLINE("Magic Online"),
SUPPLEMENTAL("Supplemental"),
SUPPLEMENTAL_STANDARD_LEGAL("Standard Legal Supplemental"),
SUPPLEMENTAL_MODERN_LEGAL("Modern Legal Supplemental"),
PROMOTIONAL("Promotional"),
JOKESET("Joke Set"),
CUSTOM_SET("Unofficial Set");
@ -24,4 +24,27 @@ public enum SetType {
public String toString() {
return text;
}
public boolean isCustomSet() {
return this == SetType.CUSTOM_SET;
}
public boolean isJokeSet() {
return this == SetType.JOKESET;
}
public boolean isEternalLegal() {
// any official sets except un-sets
return this != SetType.CUSTOM_SET && this != SetType.JOKESET;
}
public boolean isStandardLegal() {
// any official sets that was in standard
return this == SetType.CORE || this == SetType.EXPANSION || this == SetType.SUPPLEMENTAL_STANDARD_LEGAL;
}
public boolean isModernLegal() {
// any official sets that was in modern (standard + Modern Horizons)
return this.isStandardLegal() || this == SetType.SUPPLEMENTAL_MODERN_LEGAL;
}
}