mirror of
https://github.com/magefree/mage.git
synced 2026-01-10 21:02:08 -08:00
Client add land set search uses now ExpansionRepository.
This commit is contained in:
parent
ec3565e5f7
commit
5a8a7b19de
3 changed files with 79 additions and 72 deletions
|
|
@ -27,17 +27,19 @@
|
|||
*/
|
||||
package mage.client.dialog;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import javax.swing.JLayeredPane;
|
||||
import mage.Mana;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.Sets;
|
||||
import mage.cards.decks.Deck;
|
||||
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.client.MageFrame;
|
||||
import mage.constants.Rarity;
|
||||
|
||||
|
|
@ -48,7 +50,7 @@ import mage.constants.Rarity;
|
|||
public class AddLandDialog extends MageDialog {
|
||||
|
||||
private Deck deck;
|
||||
private Set<String> setCodesland;
|
||||
private Set<String> setCodesland = new HashSet<String>();
|
||||
|
||||
private static int DEFAULT_SEALED_DECK_CARD_NUMBER = 40;
|
||||
|
||||
|
|
@ -60,8 +62,42 @@ public class AddLandDialog extends MageDialog {
|
|||
|
||||
public void showDialog(Deck deck) {
|
||||
this.deck = deck;
|
||||
this.setCodesland = Sets.getSetsWithBasicLandsAsCodes(deck.getExpansionSetCodes());
|
||||
|
||||
// decide from which sets basic lands are taken from
|
||||
for (String setCode :deck.getExpansionSetCodes()) {
|
||||
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
|
||||
if (expansionInfo.hasBasicLands()) {
|
||||
this.setCodesland.add(expansionInfo.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
// if sets have no basic land, take land from block
|
||||
if (this.setCodesland.isEmpty()) {
|
||||
for (String setCode :deck.getExpansionSetCodes()) {
|
||||
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
|
||||
ExpansionInfo [] blockSets = ExpansionRepository.instance.getSetsFromBlock(expansionInfo.getBlockName());
|
||||
for (ExpansionInfo blockSet: blockSets) {
|
||||
if (blockSet.hasBasicLands()) {
|
||||
this.setCodesland.add(blockSet.getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if still no set with lands found, take one by random
|
||||
if (this.setCodesland.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();
|
||||
ExpansionInfo [] landSets = ExpansionRepository.instance.getSetsWithBasicLandsByReleaseDate();
|
||||
if (landSets.length > 0) {
|
||||
this.setCodesland.add(landSets[generator.nextInt(landSets.length)-1].getCode());
|
||||
}
|
||||
}
|
||||
|
||||
if (this.setCodesland.isEmpty()) {
|
||||
throw new IllegalArgumentException("No set with basic land was found");
|
||||
}
|
||||
|
||||
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ import mage.abilities.mana.ManaAbility;
|
|||
import mage.abilities.mana.ManaOptions;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.Cards;
|
||||
import mage.cards.Sets;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.cards.repository.CardCriteria;
|
||||
import mage.cards.repository.CardInfo;
|
||||
|
|
@ -78,8 +77,12 @@ import org.apache.log4j.Logger;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.lang.String;
|
||||
import java.util.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map.Entry;
|
||||
import mage.cards.repository.ExpansionInfo;
|
||||
import mage.cards.repository.ExpansionRepository;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -1302,7 +1305,42 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
|||
|
||||
private static void addBasicLands(Deck deck, String landName, int number) {
|
||||
Random random = new Random();
|
||||
Set<String> landSets = Sets.getSetsWithBasicLandsAsCodes(deck.getExpansionSetCodes());
|
||||
Set<String> landSets = new HashSet<String>();
|
||||
|
||||
// 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);
|
||||
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();
|
||||
ExpansionInfo [] basicLandSets = ExpansionRepository.instance.getSetsWithBasicLandsByReleaseDate();
|
||||
if (basicLandSets.length > 0) {
|
||||
landSets.add(basicLandSets[generator.nextInt(basicLandSets.length)-1].getCode());
|
||||
}
|
||||
}
|
||||
|
||||
if (landSets.isEmpty()) {
|
||||
throw new IllegalArgumentException("No set with basic land was found");
|
||||
}
|
||||
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
if (!landSets.isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -169,71 +169,4 @@ public class Sets extends HashMap<String, ExpansionSet> {
|
|||
}
|
||||
}
|
||||
|
||||
public ExpansionSet[] getSortedByReleaseDate() {
|
||||
ExpansionSet[] sets = Sets.getInstance().values().toArray(new ExpansionSet[0]);
|
||||
Arrays.sort(sets, new Comparator<ExpansionSet>() {
|
||||
@Override
|
||||
public int compare(ExpansionSet o1, ExpansionSet o2) {
|
||||
return o2.getReleaseDate().compareTo(o1.getReleaseDate());
|
||||
}
|
||||
});
|
||||
return sets;
|
||||
}
|
||||
|
||||
public ExpansionSet[] getWithBoosterSortedByReleaseDate() {
|
||||
ExpansionSet[] allSets = getSortedByReleaseDate();
|
||||
ArrayList<ExpansionSet> boosterSets = new ArrayList<ExpansionSet>();
|
||||
for (ExpansionSet set: allSets) {
|
||||
if (set.hasBoosters) {
|
||||
boosterSets.add(set);
|
||||
}
|
||||
}
|
||||
return boosterSets.toArray(new ExpansionSet[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives back the set codes from the sets that include basic lands.
|
||||
* If the input set itself does not incluse basic lands, but it has a parent set,
|
||||
* only this parent set code is added to the return sets.
|
||||
*
|
||||
* @param setCodes
|
||||
* @return - setCodes that have basic lands
|
||||
*/
|
||||
public static Set<String> getSetsWithBasicLandsAsCodes(Set<String> setCodes) {
|
||||
Set<String> landSets = new LinkedHashSet<String>();
|
||||
if (setCodes != null && !setCodes.isEmpty()) {
|
||||
// Add parent sets with the basic lands if the setlist don't include them
|
||||
for (String setCode: setCodes) {
|
||||
ExpansionSet expansionSet = Sets.findSet(setCode);
|
||||
if (expansionSet.hasBasicLands()) {
|
||||
landSets.add(setCode);
|
||||
} else if (expansionSet.getParentSet() != null && !landSets.contains(expansionSet.getParentSet().getCode())) {
|
||||
landSets.add(expansionSet.getParentSet().getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (landSets.isEmpty()) {
|
||||
// if set has no 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();
|
||||
int maxRndValue = 0;
|
||||
String selectedSetCode = null;
|
||||
for (ExpansionSet set :Sets.getInstance().getSortedByReleaseDate()) {
|
||||
if (set.hasBasicLands) {
|
||||
int rndValue = generator.nextInt(100);
|
||||
if (rndValue >= maxRndValue) {
|
||||
maxRndValue = rndValue;
|
||||
selectedSetCode = set.getCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (selectedSetCode != null) {
|
||||
landSets.add(selectedSetCode);
|
||||
} else {
|
||||
throw new IllegalArgumentException("No set with basic land was found");
|
||||
}
|
||||
}
|
||||
return landSets;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue