mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 05:09:16 -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
|
|
@ -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