mirror of
https://github.com/magefree/mage.git
synced 2025-12-21 11:02:00 -08:00
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()) {
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public class AddLandDialog extends MageDialog {
|
|||
private static final Logger logger = Logger.getLogger(MageDialog.class);
|
||||
|
||||
private Deck deck;
|
||||
private final Set<String> setCodesland = new HashSet<>();
|
||||
private final Set<String> landSetCodes = new HashSet<>();
|
||||
|
||||
private static final int DEFAULT_SEALED_DECK_CARD_NUMBER = 40;
|
||||
|
||||
|
|
@ -71,27 +71,27 @@ public class AddLandDialog extends MageDialog {
|
|||
|
||||
public void showDialog(Deck deck, DeckEditorMode mode) {
|
||||
this.deck = deck;
|
||||
SortedSet<String> landSets = new TreeSet<>();
|
||||
SortedSet<String> landSetNames = new TreeSet<>();
|
||||
if (!mode.equals(DeckEditorMode.FREE_BUILDING)) {
|
||||
// decide from which sets basic lands are taken from
|
||||
for (String setCode : deck.getExpansionSetCodes()) {
|
||||
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
|
||||
if (expansionInfo != null && expansionInfo.hasBasicLands()) {
|
||||
this.setCodesland.add(expansionInfo.getCode());
|
||||
landSets.add(expansionInfo.getName());
|
||||
this.landSetCodes.add(expansionInfo.getCode());
|
||||
landSetNames.add(expansionInfo.getName());
|
||||
}
|
||||
}
|
||||
|
||||
// if sets have no basic land, take land from block
|
||||
if (this.setCodesland.isEmpty()) {
|
||||
if (this.landSetCodes.isEmpty()) {
|
||||
for (String setCode : deck.getExpansionSetCodes()) {
|
||||
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
|
||||
if (expansionInfo != null) {
|
||||
List<ExpansionInfo> blockSets = ExpansionRepository.instance.getSetsFromBlock(expansionInfo.getBlockName());
|
||||
for (ExpansionInfo blockSet : blockSets) {
|
||||
if (blockSet.hasBasicLands()) {
|
||||
this.setCodesland.add(blockSet.getCode());
|
||||
landSets.add(blockSet.getName());
|
||||
this.landSetCodes.add(blockSet.getCode());
|
||||
landSetNames.add(blockSet.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -99,19 +99,19 @@ public class AddLandDialog extends MageDialog {
|
|||
}
|
||||
}
|
||||
// if still no set with lands found, add list of all available
|
||||
if (this.setCodesland.isEmpty()) {
|
||||
if (this.landSetCodes.isEmpty()) {
|
||||
List<ExpansionInfo> basicLandSets = ExpansionRepository.instance.getSetsWithBasicLandsByReleaseDate();
|
||||
for (ExpansionInfo expansionInfo : basicLandSets) {
|
||||
landSets.add(expansionInfo.getName());
|
||||
landSetNames.add(expansionInfo.getName());
|
||||
}
|
||||
}
|
||||
if (landSets.isEmpty()) {
|
||||
if (landSetNames.isEmpty()) {
|
||||
throw new IllegalArgumentException("No set with basic land was found");
|
||||
}
|
||||
if (landSets.size() > 1) {
|
||||
landSets.add("<Random lands>");
|
||||
if (landSetNames.size() > 1) {
|
||||
landSetNames.add("<Random lands>");
|
||||
}
|
||||
cbLandSet.setModel(new DefaultComboBoxModel(landSets.toArray()));
|
||||
cbLandSet.setModel(new DefaultComboBoxModel(landSetNames.toArray()));
|
||||
|
||||
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
|
||||
this.setVisible(true);
|
||||
|
|
@ -123,7 +123,7 @@ public class AddLandDialog extends MageDialog {
|
|||
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
if (landSetName.equals("<Random lands>")) {
|
||||
criteria.setCodes(setCodesland.toArray(new String[setCodesland.size()]));
|
||||
criteria.setCodes(landSetCodes.toArray(new String[landSetCodes.size()]));
|
||||
} else {
|
||||
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByName(landSetName);
|
||||
if (expansionInfo == null) {
|
||||
|
|
|
|||
|
|
@ -149,6 +149,7 @@ import mage.target.common.TargetPermanentOrPlayer;
|
|||
import mage.target.common.TargetSpellOrPermanent;
|
||||
import mage.util.Copier;
|
||||
import mage.util.MessageToClient;
|
||||
import mage.util.TournamentUtil;
|
||||
import mage.util.TreeNode;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
@ -1637,42 +1638,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
|
||||
private static void addBasicLands(Deck deck, String landName, int number) {
|
||||
Random random = new Random();
|
||||
Set<String> landSets = new HashSet<>();
|
||||
|
||||
// decide from which sets basic lands are taken from
|
||||
for (String setCode : deck.getExpansionSetCodes()) {
|
||||
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 : deck.getExpansionSetCodes()) {
|
||||
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(deck.getExpansionSetCodes());
|
||||
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
if (!landSets.isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -130,14 +130,10 @@ public class Deck implements Serializable {
|
|||
public Set<String> getExpansionSetCodes() {
|
||||
Set<String> sets = new LinkedHashSet<>();
|
||||
for (Card card : getCards()) {
|
||||
if (!sets.contains(card.getExpansionSetCode())) {
|
||||
sets.add(card.getExpansionSetCode());
|
||||
}
|
||||
sets.add(card.getExpansionSetCode());
|
||||
}
|
||||
for (Card card : getSideboard()) {
|
||||
if (!sets.contains(card.getExpansionSetCode())) {
|
||||
sets.add(card.getExpansionSetCode());
|
||||
}
|
||||
sets.add(card.getExpansionSetCode());
|
||||
}
|
||||
return sets;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,12 @@
|
|||
package mage.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import mage.cards.Card;
|
||||
import mage.cards.repository.CardCriteria;
|
||||
import mage.cards.repository.CardInfo;
|
||||
|
|
@ -32,44 +34,44 @@ public class TournamentUtil {
|
|||
* @return setCode for lands
|
||||
*/
|
||||
|
||||
public static Set<String> getLandSetCodeForDeckSets(Set<String> setCodesDeck) {
|
||||
public static Set<String> getLandSetCodeForDeckSets(Collection<String> setCodesDeck) {
|
||||
|
||||
Set<String> setCodesland = new HashSet<>();
|
||||
Set<String> landSetCodes = new HashSet<>();
|
||||
// decide from which sets basic lands are taken from
|
||||
for (String setCode :setCodesDeck) {
|
||||
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
|
||||
if (expansionInfo.hasBasicLands()) {
|
||||
setCodesland.add(expansionInfo.getCode());
|
||||
landSetCodes.add(expansionInfo.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
// if sets have no basic land, take land from block
|
||||
if (setCodesland.isEmpty()) {
|
||||
if (landSetCodes.isEmpty()) {
|
||||
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()) {
|
||||
setCodesland.add(blockSet.getCode());
|
||||
landSetCodes.add(blockSet.getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if still no set with lands found, take one by random
|
||||
if (setCodesland.isEmpty()) {
|
||||
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
|
||||
Random generator = new Random();
|
||||
List<ExpansionInfo> basicLandSets = ExpansionRepository.instance.getSetsWithBasicLandsByReleaseDate();
|
||||
if (basicLandSets.size() > 0) {
|
||||
setCodesland.add(basicLandSets.get(generator.nextInt(basicLandSets.size())).getCode());
|
||||
landSetCodes.add(basicLandSets.get(generator.nextInt(basicLandSets.size())).getCode());
|
||||
}
|
||||
}
|
||||
|
||||
if (setCodesland.isEmpty()) {
|
||||
if (landSetCodes.isEmpty()) {
|
||||
throw new IllegalArgumentException("No set with basic land was found");
|
||||
}
|
||||
return setCodesland;
|
||||
return landSetCodes;
|
||||
}
|
||||
|
||||
public static List<Card> getLands(String landName, int number, Set<String> landSets) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue