mirror of
https://github.com/correl/mage.git
synced 2024-11-25 11:09:53 +00:00
Some minor changes.
This commit is contained in:
parent
905fd65ebd
commit
bdaa78e144
4 changed files with 121 additions and 120 deletions
|
@ -13,7 +13,6 @@ import mage.cards.repository.ExpansionRepository;
|
||||||
import mage.constants.SetType;
|
import mage.constants.SetType;
|
||||||
import mage.deck.Standard;
|
import mage.deck.Standard;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for constructed formats (expansions and other editions).
|
* Utility class for constructed formats (expansions and other editions).
|
||||||
*
|
*
|
||||||
|
@ -21,8 +20,6 @@ import mage.deck.Standard;
|
||||||
*/
|
*/
|
||||||
public class ConstructedFormats {
|
public class ConstructedFormats {
|
||||||
|
|
||||||
private static final GregorianCalendar calendar = new GregorianCalendar();
|
|
||||||
|
|
||||||
public static final String ALL = "- All Sets";
|
public static final String ALL = "- All Sets";
|
||||||
public static final String STANDARD = "- Standard";
|
public static final String STANDARD = "- Standard";
|
||||||
public static final String EXTENDED = "- Extended";
|
public static final String EXTENDED = "- Extended";
|
||||||
|
@ -45,7 +42,7 @@ public class ConstructedFormats {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getSetsByFormat(final String format) {
|
public static List<String> getSetsByFormat(final String format) {
|
||||||
if(!format.equals(ALL)) {
|
if (!format.equals(ALL)) {
|
||||||
return underlyingSetCodesPerFormat.get(format);
|
return underlyingSetCodesPerFormat.get(format);
|
||||||
}
|
}
|
||||||
return all;
|
return all;
|
||||||
|
@ -66,62 +63,62 @@ public class ConstructedFormats {
|
||||||
formats.add(set.getName());
|
formats.add(set.getName());
|
||||||
if (set.getType().equals(SetType.CORE) || set.getType().equals(SetType.EXPANSION) || set.getType().equals(SetType.SUPPLEMENTAL_STANDARD_LEGAL)) {
|
if (set.getType().equals(SetType.CORE) || set.getType().equals(SetType.EXPANSION) || set.getType().equals(SetType.SUPPLEMENTAL_STANDARD_LEGAL)) {
|
||||||
if (STANDARD_CARDS.getSetCodes().contains(set.getCode())) {
|
if (STANDARD_CARDS.getSetCodes().contains(set.getCode())) {
|
||||||
if(underlyingSetCodesPerFormat.get(STANDARD) == null) {
|
if (underlyingSetCodesPerFormat.get(STANDARD) == null) {
|
||||||
underlyingSetCodesPerFormat.put(STANDARD, new ArrayList<String>());
|
underlyingSetCodesPerFormat.put(STANDARD, new ArrayList<>());
|
||||||
}
|
}
|
||||||
underlyingSetCodesPerFormat.get(STANDARD).add(set.getCode());
|
underlyingSetCodesPerFormat.get(STANDARD).add(set.getCode());
|
||||||
}
|
}
|
||||||
if (set.getReleaseDate().after(extendedDate)) {
|
if (set.getReleaseDate().after(extendedDate)) {
|
||||||
if(underlyingSetCodesPerFormat.get(EXTENDED) == null) {
|
if (underlyingSetCodesPerFormat.get(EXTENDED) == null) {
|
||||||
underlyingSetCodesPerFormat.put(EXTENDED, new ArrayList<String>());
|
underlyingSetCodesPerFormat.put(EXTENDED, new ArrayList<>());
|
||||||
}
|
}
|
||||||
underlyingSetCodesPerFormat.get(EXTENDED).add(set.getCode());
|
underlyingSetCodesPerFormat.get(EXTENDED).add(set.getCode());
|
||||||
}
|
}
|
||||||
if (set.getReleaseDate().after(frontierDate)) {
|
if (set.getReleaseDate().after(frontierDate)) {
|
||||||
if(underlyingSetCodesPerFormat.get(FRONTIER) == null) {
|
if (underlyingSetCodesPerFormat.get(FRONTIER) == null) {
|
||||||
underlyingSetCodesPerFormat.put(FRONTIER, new ArrayList<String>());
|
underlyingSetCodesPerFormat.put(FRONTIER, new ArrayList<>());
|
||||||
}
|
}
|
||||||
underlyingSetCodesPerFormat.get(FRONTIER).add(set.getCode());
|
underlyingSetCodesPerFormat.get(FRONTIER).add(set.getCode());
|
||||||
}
|
}
|
||||||
if (set.getReleaseDate().after(modernDate)) {
|
if (set.getReleaseDate().after(modernDate)) {
|
||||||
if(underlyingSetCodesPerFormat.get(MODERN) == null) {
|
if (underlyingSetCodesPerFormat.get(MODERN) == null) {
|
||||||
underlyingSetCodesPerFormat.put(MODERN, new ArrayList<String>());
|
underlyingSetCodesPerFormat.put(MODERN, new ArrayList<>());
|
||||||
}
|
}
|
||||||
underlyingSetCodesPerFormat.get(MODERN).add(set.getCode());
|
underlyingSetCodesPerFormat.get(MODERN).add(set.getCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(underlyingSetCodesPerFormat.get(set.getName()) == null) {
|
if (underlyingSetCodesPerFormat.get(set.getName()) == null) {
|
||||||
underlyingSetCodesPerFormat.put(set.getName(), new ArrayList<String>());
|
underlyingSetCodesPerFormat.put(set.getName(), new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
underlyingSetCodesPerFormat.get(set.getName()).add(set.getCode());
|
underlyingSetCodesPerFormat.get(set.getName()).add(set.getCode());
|
||||||
|
|
||||||
if(set.getType().equals(SetType.EXPANSION) && set.getBlockName() != null) {
|
if (set.getType().equals(SetType.EXPANSION) && set.getBlockName() != null) {
|
||||||
String blockDisplayName = getBlockDisplayName(set.getBlockName());
|
String blockDisplayName = getBlockDisplayName(set.getBlockName());
|
||||||
if(underlyingSetCodesPerFormat.get(blockDisplayName) == null) {
|
if (underlyingSetCodesPerFormat.get(blockDisplayName) == null) {
|
||||||
underlyingSetCodesPerFormat.put(blockDisplayName, new ArrayList<String>());
|
underlyingSetCodesPerFormat.put(blockDisplayName, new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
underlyingSetCodesPerFormat.get(blockDisplayName).add(set.getCode());
|
underlyingSetCodesPerFormat.get(blockDisplayName).add(set.getCode());
|
||||||
|
|
||||||
if(expansionInfo.get(blockDisplayName) == null) {
|
if (expansionInfo.get(blockDisplayName) == null) {
|
||||||
expansionInfo.put(blockDisplayName, set);
|
expansionInfo.put(blockDisplayName, set);
|
||||||
formats.add(blockDisplayName);
|
formats.add(blockDisplayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(expansionInfo.get(blockDisplayName).getReleaseDate().after(set.getReleaseDate())) {
|
if (expansionInfo.get(blockDisplayName).getReleaseDate().after(set.getReleaseDate())) {
|
||||||
expansionInfo.put(blockDisplayName, set);
|
expansionInfo.put(blockDisplayName, set);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(set.getType().equals(SetType.SUPPLEMENTAL) && set.getBlockName() != null) {
|
if (set.getType().equals(SetType.SUPPLEMENTAL) && set.getBlockName() != null) {
|
||||||
if(expansionInfo.get(set.getBlockName()) == null) {
|
if (expansionInfo.get(set.getBlockName()) == null) {
|
||||||
expansionInfo.put(set.getBlockName(), set);
|
expansionInfo.put(set.getBlockName(), set);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(expansionInfo.get(set.getBlockName()).getReleaseDate().before(set.getReleaseDate())) {
|
if (expansionInfo.get(set.getBlockName()).getReleaseDate().before(set.getReleaseDate())) {
|
||||||
expansionInfo.put(set.getBlockName(), set);
|
expansionInfo.put(set.getBlockName(), set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,69 +131,68 @@ public class ConstructedFormats {
|
||||||
ExpansionInfo expansionInfo1 = expansionInfo.get(name1);
|
ExpansionInfo expansionInfo1 = expansionInfo.get(name1);
|
||||||
ExpansionInfo expansionInfo2 = expansionInfo.get(name2);
|
ExpansionInfo expansionInfo2 = expansionInfo.get(name2);
|
||||||
|
|
||||||
if(expansionInfo1.getType().compareTo(expansionInfo2.getType()) == 0) {
|
if (expansionInfo1.getType().compareTo(expansionInfo2.getType()) == 0) {
|
||||||
SetType setType = expansionInfo1.getType();
|
SetType setType = expansionInfo1.getType();
|
||||||
if(setType.equals(SetType.EXPANSION)) {
|
switch (setType) {
|
||||||
|
case EXPANSION:
|
||||||
if(expansionInfo1.getBlockName() == null) {
|
if (expansionInfo1.getBlockName() == null) {
|
||||||
if(expansionInfo2.getBlockName() == null) {
|
if (expansionInfo2.getBlockName() == null) {
|
||||||
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
|
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(expansionInfo2.getBlockName() == null) {
|
if (expansionInfo2.getBlockName() == null) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Block comparison
|
//Block comparison
|
||||||
if(name1.endsWith("Block") && name2.endsWith("Block")) {
|
if (name1.endsWith("Block") && name2.endsWith("Block")) {
|
||||||
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
|
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(name1.endsWith("Block")) {
|
if (name1.endsWith("Block")) {
|
||||||
if(expansionInfo1.getBlockName().equals(expansionInfo2.getBlockName())) {
|
if (expansionInfo1.getBlockName().equals(expansionInfo2.getBlockName())) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(name2.endsWith("Block")) {
|
if (name2.endsWith("Block")) {
|
||||||
if(expansionInfo1.getBlockName().equals(expansionInfo2.getBlockName())) {
|
if (expansionInfo1.getBlockName().equals(expansionInfo2.getBlockName())) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
|
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
|
||||||
|
case SUPPLEMENTAL:
|
||||||
} else if(setType.equals(SetType.SUPPLEMENTAL)) {
|
if (expansionInfo1.getBlockName() == null) {
|
||||||
if(expansionInfo1.getBlockName() == null) {
|
if (expansionInfo2.getBlockName() == null) {
|
||||||
if(expansionInfo2.getBlockName() == null) {
|
|
||||||
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
|
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(expansionInfo2.getBlockName() == null) {
|
if (expansionInfo2.getBlockName() == null) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(expansionInfo1.getBlockName().equals(expansionInfo2.getBlockName())) {
|
if (expansionInfo1.getBlockName().equals(expansionInfo2.getBlockName())) {
|
||||||
//If release date is the same, sort alphabetically.
|
//If release date is the same, sort alphabetically.
|
||||||
if(expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate()) == 0) {
|
if (expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate()) == 0) {
|
||||||
return name1.compareTo(name2);
|
return name1.compareTo(name2);
|
||||||
}
|
}
|
||||||
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
|
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(expansionInfo1.getBlockName().startsWith("Duel Decks")) {
|
if (expansionInfo1.getBlockName().startsWith("Duel Decks")) {
|
||||||
if(expansionInfo1.getBlockName().startsWith("Duel Decks: Anthology")) {
|
if (expansionInfo1.getBlockName().startsWith("Duel Decks: Anthology")) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if(expansionInfo2.getBlockName().startsWith("Duel Decks")) {
|
if (expansionInfo2.getBlockName().startsWith("Duel Decks")) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,9 +200,7 @@ public class ConstructedFormats {
|
||||||
ExpansionInfo blockInfo2 = expansionInfo.get(expansionInfo2.getBlockName());
|
ExpansionInfo blockInfo2 = expansionInfo.get(expansionInfo2.getBlockName());
|
||||||
|
|
||||||
return blockInfo2.getReleaseDate().compareTo(blockInfo1.getReleaseDate());
|
return blockInfo2.getReleaseDate().compareTo(blockInfo1.getReleaseDate());
|
||||||
|
default:
|
||||||
|
|
||||||
} else {
|
|
||||||
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
|
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,7 +224,6 @@ public class ConstructedFormats {
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final Date extendedDate = new GregorianCalendar(2009, 8, 20).getTime();
|
private static final Date extendedDate = new GregorianCalendar(2009, 8, 20).getTime();
|
||||||
private static final Date frontierDate = new GregorianCalendar(2014, 7, 17).getTime();
|
private static final Date frontierDate = new GregorianCalendar(2014, 7, 17).getTime();
|
||||||
private static final Date modernDate = new GregorianCalendar(2003, 7, 20).getTime();
|
private static final Date modernDate = new GregorianCalendar(2003, 7, 20).getTime();
|
||||||
|
|
|
@ -142,6 +142,7 @@
|
||||||
<deckType name="Block Constructed - Shards of Alara" jar="mage-deck-constructed.jar" className="mage.deck.ShardsOfAlaraBlock"/>
|
<deckType name="Block Constructed - Shards of Alara" jar="mage-deck-constructed.jar" className="mage.deck.ShardsOfAlaraBlock"/>
|
||||||
<deckType name="Block Constructed - Theros" jar="mage-deck-constructed.jar" className="mage.deck.TherosBlock"/>
|
<deckType name="Block Constructed - Theros" jar="mage-deck-constructed.jar" className="mage.deck.TherosBlock"/>
|
||||||
<deckType name="Block Constructed - Zendikar" jar="mage-deck-constructed.jar" className="mage.deck.ZendikarBlock"/>
|
<deckType name="Block Constructed - Zendikar" jar="mage-deck-constructed.jar" className="mage.deck.ZendikarBlock"/>
|
||||||
|
<deckType name="Block Constructed Custom - Star Wars" jar="mage-deck-constructed.jar" className="mage.deck.StarWarsBlock"/>
|
||||||
<deckType name="Limited" jar="mage-deck-limited.jar" className="mage.deck.Limited"/>
|
<deckType name="Limited" jar="mage-deck-limited.jar" className="mage.deck.Limited"/>
|
||||||
</deckTypes>
|
</deckTypes>
|
||||||
</config>
|
</config>
|
||||||
|
|
|
@ -139,6 +139,7 @@
|
||||||
<deckType name="Block Constructed - Shards of Alara" jar="mage-deck-constructed-${project.version}.jar" className="mage.deck.ShardsOfAlaraBlock"/>
|
<deckType name="Block Constructed - Shards of Alara" jar="mage-deck-constructed-${project.version}.jar" className="mage.deck.ShardsOfAlaraBlock"/>
|
||||||
<deckType name="Block Constructed - Theros" jar="mage-deck-constructed.jar" className="mage.deck.TherosBlock"/>
|
<deckType name="Block Constructed - Theros" jar="mage-deck-constructed.jar" className="mage.deck.TherosBlock"/>
|
||||||
<deckType name="Block Constructed - Zendikar" jar="mage-deck-constructed-${project.version}.jar" className="mage.deck.ZendikarBlock"/>
|
<deckType name="Block Constructed - Zendikar" jar="mage-deck-constructed-${project.version}.jar" className="mage.deck.ZendikarBlock"/>
|
||||||
|
<deckType name="Block Constructed Construced - Star Wars" jar="mage-deck-constructed-${project.version}.jar" className="mage.deck.StarWarsBlock"/>
|
||||||
<deckType name="Limited" jar="mage-deck-limited-${project.version}.jar" className="mage.deck.Limited"/>
|
<deckType name="Limited" jar="mage-deck-limited-${project.version}.jar" className="mage.deck.Limited"/>
|
||||||
</deckTypes>
|
</deckTypes>
|
||||||
</config>
|
</config>
|
||||||
|
|
|
@ -30,7 +30,6 @@ package mage.cards.decks;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
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;
|
||||||
|
@ -112,14 +111,14 @@ public class Constructed extends DeckValidator {
|
||||||
if (!rarities.isEmpty()) {
|
if (!rarities.isEmpty()) {
|
||||||
for (Card card : deck.getCards()) {
|
for (Card card : deck.getCards()) {
|
||||||
if (!rarities.contains(card.getRarity())) {
|
if (!rarities.contains(card.getRarity())) {
|
||||||
if( !legalRarity(card) ){
|
if (!legalRarity(card)) {
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Card card : deck.getSideboard()) {
|
for (Card card : deck.getSideboard()) {
|
||||||
if (!rarities.contains(card.getRarity())) {
|
if (!rarities.contains(card.getRarity())) {
|
||||||
if( !legalRarity(card) ){
|
if (!legalRarity(card)) {
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,14 +127,14 @@ public class Constructed extends DeckValidator {
|
||||||
|
|
||||||
for (Card card : deck.getCards()) {
|
for (Card card : deck.getCards()) {
|
||||||
if (!isSetAllowed(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 (!isSetAllowed(card.getExpansionSetCode())) {
|
if (!isSetAllowed(card.getExpansionSetCode())) {
|
||||||
if( !legalSets(card) ){
|
if (!legalSets(card)) {
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,10 +146,11 @@ public class Constructed extends DeckValidator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the given card is legal in any of the given rarities
|
* Checks if the given card is legal in any of the given rarities
|
||||||
|
*
|
||||||
* @param card - the card to check
|
* @param card - the card to check
|
||||||
* @return Whether the card was printed at any of the given rarities.
|
* @return Whether the card was printed at any of the given rarities.
|
||||||
*/
|
*/
|
||||||
protected boolean legalRarity(Card card){
|
protected boolean legalRarity(Card card) {
|
||||||
// check if card is legal if taken from other set
|
// check if card is legal if taken from other set
|
||||||
boolean legal = false;
|
boolean legal = false;
|
||||||
List<CardInfo> cardInfos = CardRepository.instance.findCards(card.getName());
|
List<CardInfo> cardInfos = CardRepository.instance.findCards(card.getName());
|
||||||
|
@ -168,16 +168,22 @@ public class Constructed extends DeckValidator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a given set is legal in this format.
|
* Checks if a given set is legal in this format.
|
||||||
|
*
|
||||||
* @param code - the set code to check
|
* @param code - the set code to check
|
||||||
* @return Whether the set is legal in this format.
|
* @return Whether the set is legal in this format.
|
||||||
*/
|
*/
|
||||||
protected boolean isSetAllowed(String code) {
|
protected boolean isSetAllowed(String code) {
|
||||||
if(Sets.isCustomSet(code)) return allowAllCustomSets || allowedCustomSetCodes.contains(code);
|
// To check here for custom set makes no sens IMHO because the format does define what's aloowed and what not
|
||||||
else return setCodes.isEmpty() || setCodes.contains(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
|
||||||
* @return Whether the card was printed in any of this format's sets.
|
* @return Whether the card was printed in any of this format's sets.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue