mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 04:22:01 -08:00
* Game: fixed that Snow-Covered lands can be added to auto-generated or submitted/timeout decks (#7222);
This commit is contained in:
parent
10cf9c4a4e
commit
dd7c1939d3
6 changed files with 71 additions and 51 deletions
|
|
@ -20,6 +20,7 @@ public class CardCriteria {
|
|||
private String nameExact;
|
||||
private String rules;
|
||||
private final List<String> setCodes;
|
||||
private final List<String> ignoreSetCodes; // sets to ignore, use with little amount of sets (example: ignore sets with snow lands)
|
||||
private final List<CardType> types;
|
||||
private final List<CardType> notTypes;
|
||||
private final List<String> supertypes;
|
||||
|
|
@ -42,6 +43,7 @@ public class CardCriteria {
|
|||
|
||||
public CardCriteria() {
|
||||
this.setCodes = new ArrayList<>();
|
||||
this.ignoreSetCodes = new ArrayList<>();
|
||||
this.rarities = new ArrayList<>();
|
||||
this.types = new ArrayList<>();
|
||||
this.notTypes = new ArrayList<>();
|
||||
|
|
@ -130,6 +132,16 @@ public class CardCriteria {
|
|||
return this;
|
||||
}
|
||||
|
||||
public CardCriteria ignoreSetCodes(String... ignoreSetCodes) {
|
||||
this.ignoreSetCodes.addAll(Arrays.asList(ignoreSetCodes));
|
||||
return this;
|
||||
}
|
||||
|
||||
public CardCriteria ignoreSetsWithSnowLands() {
|
||||
this.ignoreSetCodes.addAll(CardRepository.snowLandSetCodes);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CardCriteria types(CardType... types) {
|
||||
this.types.addAll(Arrays.asList(types));
|
||||
return this;
|
||||
|
|
@ -216,6 +228,14 @@ public class CardCriteria {
|
|||
clausesCount++;
|
||||
}
|
||||
|
||||
for (String ignoreSetCode : ignoreSetCodes) {
|
||||
where.ne("setCode", ignoreSetCode);
|
||||
}
|
||||
if (!ignoreSetCodes.isEmpty()) {
|
||||
where.or(ignoreSetCodes.size());
|
||||
clausesCount++;
|
||||
}
|
||||
|
||||
if (types.size() != 7) { //if all types selected - no selection needed (Tribal and Conspiracy not selectable yet)
|
||||
for (CardType type : types) {
|
||||
where.like("types", new SelectArg('%' + type.name() + '%'));
|
||||
|
|
@ -357,6 +377,10 @@ public class CardCriteria {
|
|||
return setCodes;
|
||||
}
|
||||
|
||||
public List<String> getIgnoreSetCodes() {
|
||||
return ignoreSetCodes;
|
||||
}
|
||||
|
||||
public List<CardType> getTypes() {
|
||||
return types;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,14 @@ public enum CardRepository {
|
|||
private Set<String> classNames;
|
||||
private final RepositoryEventSource eventSource = new RepositoryEventSource();
|
||||
|
||||
public static final Set<String> snowLandSetCodes = new HashSet<>(Arrays.asList(
|
||||
"CSP",
|
||||
"MH1",
|
||||
"SLD",
|
||||
"ME2",
|
||||
"ICE"
|
||||
));
|
||||
|
||||
CardRepository() {
|
||||
File file = new File("db");
|
||||
if (!file.exists()) {
|
||||
|
|
@ -188,12 +196,8 @@ public enum CardRepository {
|
|||
return names;
|
||||
}
|
||||
|
||||
public Boolean haveSnowLands(String setCode) {
|
||||
return setCode.equals("CSP")
|
||||
|| setCode.equals("MH1")
|
||||
|| setCode.equals("SLD")
|
||||
|| setCode.equals("ME2")
|
||||
|| setCode.equals("ICE");
|
||||
public static Boolean haveSnowLands(String setCode) {
|
||||
return snowLandSetCodes.contains(setCode);
|
||||
}
|
||||
|
||||
public Set<String> getNonbasicLandNames() {
|
||||
|
|
|
|||
|
|
@ -6,51 +6,43 @@
|
|||
|
||||
package mage.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import mage.cards.Card;
|
||||
import mage.cards.repository.CardCriteria;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.cards.repository.ExpansionInfo;
|
||||
import mage.cards.repository.ExpansionRepository;
|
||||
import mage.cards.repository.*;
|
||||
import mage.constants.Rarity;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public final class TournamentUtil {
|
||||
|
||||
|
||||
/**
|
||||
* Tries to calculate the most appropiate sets to add basic lands for cards of a deck
|
||||
*
|
||||
*
|
||||
* @param setCodesDeck
|
||||
* @return setCode for lands
|
||||
*/
|
||||
|
||||
|
||||
public static Set<String> getLandSetCodeForDeckSets(Collection<String> setCodesDeck) {
|
||||
|
||||
|
||||
Set<String> landSetCodes = new HashSet<>();
|
||||
// decide from which sets basic lands are taken from
|
||||
for (String setCode :setCodesDeck) {
|
||||
for (String setCode : setCodesDeck) {
|
||||
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
|
||||
if (expansionInfo.hasBasicLands()) {
|
||||
if (expansionInfo.hasBasicLands() && !CardRepository.haveSnowLands(setCode)) {
|
||||
landSetCodes.add(expansionInfo.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
// if sets have no basic land, take land from block
|
||||
if (landSetCodes.isEmpty()) {
|
||||
for (String setCode :setCodesDeck) {
|
||||
for (String setCode : setCodesDeck) {
|
||||
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
|
||||
List<ExpansionInfo> blockSets = ExpansionRepository.instance.getSetsFromBlock(expansionInfo.getBlockName());
|
||||
for (ExpansionInfo blockSet: blockSets) {
|
||||
if (blockSet.hasBasicLands()) {
|
||||
for (ExpansionInfo blockSet : blockSets) {
|
||||
if (blockSet.hasBasicLands() && !CardRepository.haveSnowLands(blockSet.getCode())) {
|
||||
landSetCodes.add(blockSet.getCode());
|
||||
}
|
||||
}
|
||||
|
|
@ -60,7 +52,10 @@ public final class TournamentUtil {
|
|||
if (landSetCodes.isEmpty()) {
|
||||
// if sets have no basic lands and also it has no parent or parent has no lands get last set with lands
|
||||
// select a set with basic lands by random
|
||||
List<ExpansionInfo> basicLandSets = ExpansionRepository.instance.getSetsWithBasicLandsByReleaseDate();
|
||||
List<ExpansionInfo> basicLandSets = ExpansionRepository.instance.getSetsWithBasicLandsByReleaseDate()
|
||||
.stream()
|
||||
.filter(exp -> !CardRepository.haveSnowLands(exp.getCode()))
|
||||
.collect(Collectors.toList());
|
||||
if (!basicLandSets.isEmpty()) {
|
||||
landSetCodes.add(basicLandSets.get(RandomUtil.nextInt(basicLandSets.size())).getCode());
|
||||
}
|
||||
|
|
@ -71,11 +66,13 @@ public final class TournamentUtil {
|
|||
}
|
||||
return landSetCodes;
|
||||
}
|
||||
|
||||
|
||||
public static List<Card> getLands(String landName, int number, Set<String> landSets) {
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
if (!landSets.isEmpty()) {
|
||||
criteria.setCodes(landSets.toArray(new String[landSets.size()]));
|
||||
} else {
|
||||
criteria.ignoreSetsWithSnowLands();
|
||||
}
|
||||
criteria.rarities(Rarity.LAND).name(landName);
|
||||
List<CardInfo> lands = CardRepository.instance.findCards(criteria);
|
||||
|
|
@ -84,9 +81,9 @@ public final class TournamentUtil {
|
|||
for (int i = 0; i < number; i++) {
|
||||
Card land = lands.get(RandomUtil.nextInt(lands.size())).getCard();
|
||||
cards.add(land);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return cards;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue