forked from External/mage
reuse shared code for picking basic land sets
This commit is contained in:
parent
05dd1daee6
commit
a90d0e5597
5 changed files with 31 additions and 101 deletions
|
|
@ -41,6 +41,7 @@ import mage.client.util.sets.ConstructedFormats;
|
|||
import mage.constants.CardType;
|
||||
import mage.constants.ColoredManaSymbol;
|
||||
import mage.constants.Rarity;
|
||||
import mage.util.TournamentUtil;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -285,42 +286,7 @@ public class DeckGenerator {
|
|||
*/
|
||||
private static Map<String, List<CardInfo>> generateBasicLands(List<String> setsToUse) {
|
||||
|
||||
List<String> landSets = new LinkedList<>();
|
||||
|
||||
// decide from which sets basic lands are taken from
|
||||
for (String setCode :setsToUse) {
|
||||
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
|
||||
if (expansionInfo.hasBasicLands()) {
|
||||
landSets.add(expansionInfo.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
// if sets have no basic land, take land from block
|
||||
if (landSets.isEmpty()) {
|
||||
for (String setCode :setsToUse) {
|
||||
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
|
||||
List<ExpansionInfo> blockSets = ExpansionRepository.instance.getSetsFromBlock(expansionInfo.getBlockName());
|
||||
for (ExpansionInfo blockSet: blockSets) {
|
||||
if (blockSet.hasBasicLands()) {
|
||||
landSets.add(blockSet.getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if still no set with lands found, take one by random
|
||||
if (landSets.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
|
||||
Random generator = new Random();
|
||||
List<ExpansionInfo> basicLandSets = ExpansionRepository.instance.getSetsWithBasicLandsByReleaseDate();
|
||||
if (basicLandSets.size() > 0) {
|
||||
landSets.add(basicLandSets.get(generator.nextInt(basicLandSets.size())).getCode());
|
||||
}
|
||||
}
|
||||
|
||||
if (landSets.isEmpty()) {
|
||||
throw new IllegalArgumentException("No set with basic land was found");
|
||||
}
|
||||
Set<String> landSets = TournamentUtil.getLandSetCodeForDeckSets(setsToUse);
|
||||
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
if (!landSets.isEmpty()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue