mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
checkstyle and refactor
This commit is contained in:
@@ -26,7 +26,8 @@ public class BoosterGenerator {
|
|||||||
|
|
||||||
// Function to open a booster as it is.
|
// Function to open a booster as it is.
|
||||||
/** The Constant IDENTITY_PICK. */
|
/** The Constant IDENTITY_PICK. */
|
||||||
public static final Lambda1<List<CardPrinted>, BoosterGenerator> IDENTITY_PICK = new Lambda1<List<CardPrinted>, BoosterGenerator>() {
|
public static final Lambda1<List<CardPrinted>, BoosterGenerator> IDENTITY_PICK
|
||||||
|
= new Lambda1<List<CardPrinted>, BoosterGenerator>() {
|
||||||
@Override
|
@Override
|
||||||
public List<CardPrinted> apply(final BoosterGenerator arg1) {
|
public List<CardPrinted> apply(final BoosterGenerator arg1) {
|
||||||
return arg1.getBoosterPack();
|
return arg1.getBoosterPack();
|
||||||
@@ -43,7 +44,7 @@ public class BoosterGenerator {
|
|||||||
* @return the simple picker
|
* @return the simple picker
|
||||||
*/
|
*/
|
||||||
public static Closure1<List<CardPrinted>, BoosterGenerator> getSimplePicker(final BoosterGenerator source) {
|
public static Closure1<List<CardPrinted>, BoosterGenerator> getSimplePicker(final BoosterGenerator source) {
|
||||||
return new Closure1<List<CardPrinted>, BoosterGenerator>(IDENTITY_PICK, source);
|
return new Closure1<List<CardPrinted>, BoosterGenerator>(BoosterGenerator.IDENTITY_PICK, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
// These lists are to hold cards grouped by rarity in advance.
|
// These lists are to hold cards grouped by rarity in advance.
|
||||||
@@ -59,7 +60,7 @@ public class BoosterGenerator {
|
|||||||
// private List<CardPrinted> commonCreatures;
|
// private List<CardPrinted> commonCreatures;
|
||||||
// private List<CardPrinted> commonNonCreatures;
|
// private List<CardPrinted> commonNonCreatures;
|
||||||
|
|
||||||
private static final List<CardPrinted> emptyList = Collections.unmodifiableList(new ArrayList<CardPrinted>(0));
|
private static final List<CardPrinted> EMPTY_LIST = Collections.unmodifiableList(new ArrayList<CardPrinted>(0));
|
||||||
|
|
||||||
// Modern boosters contain 10 commons, 3 uncommmons, 1 rare/mythic
|
// Modern boosters contain 10 commons, 3 uncommmons, 1 rare/mythic
|
||||||
// They also contain 1 land and 1 token/rules, but we don't pick them now.
|
// They also contain 1 land and 1 token/rules, but we don't pick them now.
|
||||||
@@ -78,8 +79,8 @@ public class BoosterGenerator {
|
|||||||
* the cards
|
* the cards
|
||||||
*/
|
*/
|
||||||
public BoosterGenerator(final Iterable<CardPrinted> cards) {
|
public BoosterGenerator(final Iterable<CardPrinted> cards) {
|
||||||
for (CardPrinted c : cards) {
|
for (final CardPrinted c : cards) {
|
||||||
addToRarity(c);
|
this.addToRarity(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,8 +91,8 @@ public class BoosterGenerator {
|
|||||||
* the d pool
|
* the d pool
|
||||||
*/
|
*/
|
||||||
public BoosterGenerator(final Deck dPool) {
|
public BoosterGenerator(final Deck dPool) {
|
||||||
for (Entry<CardPrinted, Integer> e : dPool.getMain()) {
|
for (final Entry<CardPrinted, Integer> e : dPool.getMain()) {
|
||||||
addToRarity(e.getKey());
|
this.addToRarity(e.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,34 +108,35 @@ public class BoosterGenerator {
|
|||||||
if (!cardSet.canGenerateBooster()) {
|
if (!cardSet.canGenerateBooster()) {
|
||||||
throw new InvalidParameterException("BoosterGenerator: Set " + cardSet + " cannot generate boosters!");
|
throw new InvalidParameterException("BoosterGenerator: Set " + cardSet + " cannot generate boosters!");
|
||||||
}
|
}
|
||||||
CardSet.BoosterData bs = cardSet.getBoosterData();
|
final CardSet.BoosterData bs = cardSet.getBoosterData();
|
||||||
|
|
||||||
numCommons = bs.getCommon();
|
this.numCommons = bs.getCommon();
|
||||||
numUncommons = bs.getUncommon();
|
this.numUncommons = bs.getUncommon();
|
||||||
numRareSlots = bs.getRare();
|
this.numRareSlots = bs.getRare();
|
||||||
numSpecials = bs.getSpecial();
|
this.numSpecials = bs.getSpecial();
|
||||||
numDoubleFaced = bs.getDoubleFaced();
|
this.numDoubleFaced = bs.getDoubleFaced();
|
||||||
|
|
||||||
Predicate<CardPrinted> filter = CardPrinted.Predicates.printedInSets(cardSet.getCode());
|
final Predicate<CardPrinted> filter = CardPrinted.Predicates.printedInSets(cardSet.getCode());
|
||||||
List<CardPrinted> cardsInThisSet = filter.select(CardDb.instance().getAllCards());
|
final List<CardPrinted> cardsInThisSet = filter.select(CardDb.instance().getAllCards());
|
||||||
|
|
||||||
for (CardPrinted c : cardsInThisSet) {
|
for (final CardPrinted c : cardsInThisSet) {
|
||||||
addToRarity(c);
|
this.addToRarity(c);
|
||||||
// System.out.println(c);
|
// System.out.println(c);
|
||||||
}
|
}
|
||||||
// System.out.println("done");
|
// System.out.println("done");
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<CardPrinted> pickRandomCards(final List<CardPrinted> source, final int count) {
|
private List<CardPrinted> pickRandomCards(final List<CardPrinted> source, final int count) {
|
||||||
return pickRandomCards(source, count, false);
|
return this.pickRandomCards(source, count, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<CardPrinted> pickRandomCards(final List<CardPrinted> source, final int count, boolean singleton) {
|
private List<CardPrinted> pickRandomCards(final List<CardPrinted> source,
|
||||||
|
final int count, final boolean singleton) {
|
||||||
int listSize = source == null ? 0 : source.size();
|
int listSize = source == null ? 0 : source.size();
|
||||||
if (count <= 0 || listSize == 0) {
|
if ((count <= 0) || (listSize == 0)) {
|
||||||
return emptyList;
|
return BoosterGenerator.EMPTY_LIST;
|
||||||
}
|
}
|
||||||
List<CardPrinted> result = new ArrayList<CardPrinted>(count);
|
final List<CardPrinted> result = new ArrayList<CardPrinted>(count);
|
||||||
|
|
||||||
int index = Integer.MAX_VALUE;
|
int index = Integer.MAX_VALUE;
|
||||||
for (int iCard = 0; iCard < count; iCard++) {
|
for (int iCard = 0; iCard < count; iCard++) {
|
||||||
@@ -154,20 +156,21 @@ public class BoosterGenerator {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<CardPrinted> pickRandomRaresOrMythics(final List<CardPrinted> rares, final List<CardPrinted> mythics, final int count) {
|
private List<CardPrinted> pickRandomRaresOrMythics(final List<CardPrinted> rares, final List<CardPrinted> mythics,
|
||||||
int raresSize = rares == null ? 0 : rares.size();
|
final int count) {
|
||||||
int mythicsSize = mythics == null ? 0 : mythics.size();
|
final int raresSize = rares == null ? 0 : rares.size();
|
||||||
if (count <= 0 || raresSize == 0) {
|
final int mythicsSize = mythics == null ? 0 : mythics.size();
|
||||||
return emptyList;
|
if ((count <= 0) || (raresSize == 0)) {
|
||||||
|
return BoosterGenerator.EMPTY_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<CardPrinted> result = new ArrayList<CardPrinted>(count);
|
final List<CardPrinted> result = new ArrayList<CardPrinted>(count);
|
||||||
|
|
||||||
int indexRares = Integer.MAX_VALUE;
|
int indexRares = Integer.MAX_VALUE;
|
||||||
int indexMythics = Integer.MAX_VALUE;
|
int indexMythics = Integer.MAX_VALUE;
|
||||||
for (int iCard = 0; iCard < count; iCard++) {
|
for (int iCard = 0; iCard < count; iCard++) {
|
||||||
int rollD8 = MyRandom.getRandom().nextInt(8);
|
final int rollD8 = MyRandom.getRandom().nextInt(8);
|
||||||
boolean takeMythic = mythicsSize > 0 && rollD8 < 1;
|
final boolean takeMythic = (mythicsSize > 0) && (rollD8 < 1);
|
||||||
if (takeMythic) {
|
if (takeMythic) {
|
||||||
if (indexRares >= raresSize) {
|
if (indexRares >= raresSize) {
|
||||||
Collections.shuffle(mythics, MyRandom.getRandom());
|
Collections.shuffle(mythics, MyRandom.getRandom());
|
||||||
@@ -187,25 +190,30 @@ public class BoosterGenerator {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the booster pack.
|
* Gets the booster pack.
|
||||||
*
|
*
|
||||||
* @return the booster pack
|
* @return the booster pack
|
||||||
*/
|
*/
|
||||||
public final List<CardPrinted> getBoosterPack() {
|
public final List<CardPrinted> getBoosterPack() {
|
||||||
return getBoosterPack(numCommons, numUncommons, numRareSlots, 0, 0, numSpecials, numDoubleFaced, 0, 0);
|
return this.getBoosterPack(this.numCommons, this.numUncommons, this.numRareSlots, 0, 0, this.numSpecials,
|
||||||
|
this.numDoubleFaced, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final List<CardPrinted> getSingletonBoosterPack( final int nAnyCard) {
|
/**
|
||||||
List<CardPrinted> temp = new ArrayList<CardPrinted>();
|
* Gets the singleton booster pack.
|
||||||
|
*
|
||||||
|
* @param nAnyCard the n any card
|
||||||
|
* @return the singleton booster pack
|
||||||
|
*/
|
||||||
|
public final List<CardPrinted> getSingletonBoosterPack(final int nAnyCard) {
|
||||||
|
final List<CardPrinted> temp = new ArrayList<CardPrinted>();
|
||||||
|
|
||||||
temp.addAll(pickRandomCards(allButLands, nAnyCard, true));
|
temp.addAll(this.pickRandomCards(this.allButLands, nAnyCard, true));
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* So many parameters are needed for custom limited cardpools,.
|
* So many parameters are needed for custom limited cardpools,.
|
||||||
*
|
*
|
||||||
@@ -233,9 +241,9 @@ public class BoosterGenerator {
|
|||||||
final int nRares, final int nMythics, final int nSpecs, final int nDoubls, final int nAnyCard,
|
final int nRares, final int nMythics, final int nSpecs, final int nDoubls, final int nAnyCard,
|
||||||
final int nLands) {
|
final int nLands) {
|
||||||
|
|
||||||
List<CardPrinted> temp = new ArrayList<CardPrinted>();
|
final List<CardPrinted> temp = new ArrayList<CardPrinted>();
|
||||||
|
|
||||||
temp.addAll(pickRandomCards(commons, nCom));
|
temp.addAll(this.pickRandomCards(this.commons, nCom));
|
||||||
/*
|
/*
|
||||||
* if( nComCreat > 0 || nComNonCr > 0) { if
|
* if( nComCreat > 0 || nComNonCr > 0) { if
|
||||||
* (commonNonCreatures.isEmpty()) {
|
* (commonNonCreatures.isEmpty()) {
|
||||||
@@ -245,50 +253,50 @@ public class BoosterGenerator {
|
|||||||
* temp.addAll(pickRandomCards(commonNonCreatures, nComNonCr)); }
|
* temp.addAll(pickRandomCards(commonNonCreatures, nComNonCr)); }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
temp.addAll(pickRandomCards(uncommons, nUnc));
|
temp.addAll(this.pickRandomCards(this.uncommons, nUnc));
|
||||||
|
|
||||||
if (nRareSlots > 0) {
|
if (nRareSlots > 0) {
|
||||||
temp.addAll(pickRandomRaresOrMythics(rares, mythics, nRareSlots));
|
temp.addAll(this.pickRandomRaresOrMythics(this.rares, this.mythics, nRareSlots));
|
||||||
}
|
}
|
||||||
if (nRares > 0 || nMythics > 0) {
|
if ((nRares > 0) || (nMythics > 0)) {
|
||||||
temp.addAll(pickRandomCards(rares, nRares));
|
temp.addAll(this.pickRandomCards(this.rares, nRares));
|
||||||
temp.addAll(pickRandomCards(mythics, nMythics));
|
temp.addAll(this.pickRandomCards(this.mythics, nMythics));
|
||||||
}
|
}
|
||||||
if (nDoubls > 0) {
|
if (nDoubls > 0) {
|
||||||
temp.addAll(pickRandomCards(doubleFaced, nDoubls));
|
temp.addAll(this.pickRandomCards(this.doubleFaced, nDoubls));
|
||||||
}
|
}
|
||||||
|
|
||||||
temp.addAll(pickRandomCards(specials, nSpecs));
|
temp.addAll(this.pickRandomCards(this.specials, nSpecs));
|
||||||
|
|
||||||
temp.addAll(pickRandomCards(allButLands, nAnyCard));
|
temp.addAll(this.pickRandomCards(this.allButLands, nAnyCard));
|
||||||
|
|
||||||
temp.addAll(pickRandomCards(basicLands, nLands));
|
temp.addAll(this.pickRandomCards(this.basicLands, nLands));
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addToRarity(final CardPrinted c) {
|
private void addToRarity(final CardPrinted c) {
|
||||||
if(c.isAlternate()) {
|
if (c.isAlternate()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (c.isDoubleFaced() && numDoubleFaced > 0) {
|
if (c.isDoubleFaced() && (this.numDoubleFaced > 0)) {
|
||||||
doubleFaced.add(c);
|
this.doubleFaced.add(c);
|
||||||
} else {
|
} else {
|
||||||
switch (c.getRarity()) {
|
switch (c.getRarity()) {
|
||||||
case Common:
|
case Common:
|
||||||
commons.add(c);
|
this.commons.add(c);
|
||||||
break;
|
break;
|
||||||
case Uncommon:
|
case Uncommon:
|
||||||
uncommons.add(c);
|
this.uncommons.add(c);
|
||||||
break;
|
break;
|
||||||
case Rare:
|
case Rare:
|
||||||
rares.add(c);
|
this.rares.add(c);
|
||||||
break;
|
break;
|
||||||
case MythicRare:
|
case MythicRare:
|
||||||
mythics.add(c);
|
this.mythics.add(c);
|
||||||
break;
|
break;
|
||||||
case Special:
|
case Special:
|
||||||
specials.add(c);
|
this.specials.add(c);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -296,9 +304,9 @@ public class BoosterGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (c.getCard().getType().isBasicLand()) {
|
if (c.getCard().getType().isBasicLand()) {
|
||||||
basicLands.add(c);
|
this.basicLands.add(c);
|
||||||
} else {
|
} else {
|
||||||
allButLands.add(c);
|
this.allButLands.add(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,13 +39,13 @@ public final class BoosterUtils {
|
|||||||
*/
|
*/
|
||||||
public static List<CardPrinted> getQuestStarterDeck(final Predicate<CardPrinted> filter, final int numCommon,
|
public static List<CardPrinted> getQuestStarterDeck(final Predicate<CardPrinted> filter, final int numCommon,
|
||||||
final int numUncommon, final int numRare) {
|
final int numUncommon, final int numRare) {
|
||||||
ArrayList<CardPrinted> cards = new ArrayList<CardPrinted>();
|
final ArrayList<CardPrinted> cards = new ArrayList<CardPrinted>();
|
||||||
|
|
||||||
// Each color should have around the same amount of monocolored cards
|
// Each color should have around the same amount of monocolored cards
|
||||||
// There should be 3 Colorless cards for every 4 cards in a single color
|
// There should be 3 Colorless cards for every 4 cards in a single color
|
||||||
// There should be 1 Multicolor card for every 4 cards in a single color
|
// There should be 1 Multicolor card for every 4 cards in a single color
|
||||||
|
|
||||||
List<Predicate<CardRules>> colorFilters = new ArrayList<Predicate<CardRules>>();
|
final List<Predicate<CardRules>> colorFilters = new ArrayList<Predicate<CardRules>>();
|
||||||
colorFilters.add(CardRules.Predicates.Presets.isMulticolor);
|
colorFilters.add(CardRules.Predicates.Presets.isMulticolor);
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
@@ -60,28 +60,29 @@ public final class BoosterUtils {
|
|||||||
colorFilters.add(CardRules.Predicates.Presets.isGreen);
|
colorFilters.add(CardRules.Predicates.Presets.isGreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterable<CardPrinted> cardpool = CardDb.instance().getAllUniqueCards();
|
final Iterable<CardPrinted> cardpool = CardDb.instance().getAllUniqueCards();
|
||||||
|
|
||||||
cards.addAll(generateDefinetlyColouredCards(cardpool,
|
cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool,
|
||||||
Predicate.and(filter, CardPrinted.Predicates.Presets.isCommon), numCommon, colorFilters));
|
Predicate.and(filter, CardPrinted.Predicates.Presets.isCommon), numCommon, colorFilters));
|
||||||
cards.addAll(generateDefinetlyColouredCards(cardpool,
|
cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool,
|
||||||
Predicate.and(filter, CardPrinted.Predicates.Presets.isUncommon), numUncommon, colorFilters));
|
Predicate.and(filter, CardPrinted.Predicates.Presets.isUncommon), numUncommon, colorFilters));
|
||||||
|
|
||||||
int nRares = numRare, nMythics = 0;
|
int nRares = numRare, nMythics = 0;
|
||||||
Predicate<CardPrinted> filterMythics = Predicate.and(filter, CardPrinted.Predicates.Presets.isMythicRare);
|
final Predicate<CardPrinted> filterMythics = Predicate.and(filter, CardPrinted.Predicates.Presets.isMythicRare);
|
||||||
boolean haveMythics = filterMythics.any(cardpool);
|
final boolean haveMythics = filterMythics.any(cardpool);
|
||||||
for (int iSlot = 0; haveMythics && iSlot < numRare; iSlot++) {
|
for (int iSlot = 0; haveMythics && (iSlot < numRare); iSlot++) {
|
||||||
if (MyRandom.getRandom().nextInt(7) < 1) { // a bit higher chance to get
|
if (MyRandom.getRandom().nextInt(7) < 1) { // a bit higher chance to
|
||||||
// a mythic
|
// get
|
||||||
|
// a mythic
|
||||||
nRares--;
|
nRares--;
|
||||||
nMythics++;
|
nMythics++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cards.addAll(generateDefinetlyColouredCards(cardpool,
|
cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool,
|
||||||
Predicate.and(filter, CardPrinted.Predicates.Presets.isRare), nRares, colorFilters));
|
Predicate.and(filter, CardPrinted.Predicates.Presets.isRare), nRares, colorFilters));
|
||||||
if (nMythics > 0) {
|
if (nMythics > 0) {
|
||||||
cards.addAll(generateDefinetlyColouredCards(cardpool, filterMythics, nMythics, colorFilters));
|
cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, filterMythics, nMythics, colorFilters));
|
||||||
}
|
}
|
||||||
return cards;
|
return cards;
|
||||||
}
|
}
|
||||||
@@ -102,9 +103,9 @@ public final class BoosterUtils {
|
|||||||
private static ArrayList<CardPrinted> generateDefinetlyColouredCards(final Iterable<CardPrinted> source,
|
private static ArrayList<CardPrinted> generateDefinetlyColouredCards(final Iterable<CardPrinted> source,
|
||||||
final Predicate<CardPrinted> filter, final int cntNeeded, final List<Predicate<CardRules>> allowedColors) {
|
final Predicate<CardPrinted> filter, final int cntNeeded, final List<Predicate<CardRules>> allowedColors) {
|
||||||
// If color is null, use colorOrder progression to grab cards
|
// If color is null, use colorOrder progression to grab cards
|
||||||
ArrayList<CardPrinted> result = new ArrayList<CardPrinted>();
|
final ArrayList<CardPrinted> result = new ArrayList<CardPrinted>();
|
||||||
|
|
||||||
int size = allowedColors == null ? 0 : allowedColors.size();
|
final int size = allowedColors == null ? 0 : allowedColors.size();
|
||||||
Collections.shuffle(allowedColors);
|
Collections.shuffle(allowedColors);
|
||||||
|
|
||||||
int cntMade = 0, iAttempt = 0;
|
int cntMade = 0, iAttempt = 0;
|
||||||
@@ -113,7 +114,7 @@ public final class BoosterUtils {
|
|||||||
int allowedMisses = (2 + size + 2) * cntNeeded; // lol, 2+2 is not magic
|
int allowedMisses = (2 + size + 2) * cntNeeded; // lol, 2+2 is not magic
|
||||||
// constant!
|
// constant!
|
||||||
|
|
||||||
while (cntMade < cntNeeded && allowedMisses > 0) {
|
while ((cntMade < cntNeeded) && (allowedMisses > 0)) {
|
||||||
CardPrinted card = null;
|
CardPrinted card = null;
|
||||||
|
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
@@ -128,7 +129,7 @@ public final class BoosterUtils {
|
|||||||
card = filter.random(source);
|
card = filter.random(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (card != null && !result.contains(card)) {
|
if ((card != null) && !result.contains(card)) {
|
||||||
result.add(card);
|
result.add(card);
|
||||||
cntMade++;
|
cntMade++;
|
||||||
} else {
|
} else {
|
||||||
@@ -153,8 +154,8 @@ public final class BoosterUtils {
|
|||||||
* @return the list
|
* @return the list
|
||||||
*/
|
*/
|
||||||
public static List<CardPrinted> generateCards(final int num, final CardRarity rarity, final String color) {
|
public static List<CardPrinted> generateCards(final int num, final CardRarity rarity, final String color) {
|
||||||
Predicate<CardPrinted> whatYouWant = getPredicateForConditions(rarity, color);
|
final Predicate<CardPrinted> whatYouWant = BoosterUtils.getPredicateForConditions(rarity, color);
|
||||||
return generateDistinctCards(CardDb.instance().getAllUniqueCards(), whatYouWant, num);
|
return BoosterUtils.generateDistinctCards(CardDb.instance().getAllUniqueCards(), whatYouWant, num);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -170,25 +171,26 @@ public final class BoosterUtils {
|
|||||||
* the color
|
* the color
|
||||||
* @return the list
|
* @return the list
|
||||||
*/
|
*/
|
||||||
public static List<CardPrinted> generateCards(final Predicate<CardPrinted> filter, final int num, final CardRarity rarity,
|
public static List<CardPrinted> generateCards(final Predicate<CardPrinted> filter, final int num,
|
||||||
final String color) {
|
final CardRarity rarity, final String color) {
|
||||||
Predicate<CardPrinted> whatYouWant = Predicate.and(filter, getPredicateForConditions(rarity, color));
|
final Predicate<CardPrinted> whatYouWant = Predicate.and(filter,
|
||||||
return generateDistinctCards(CardDb.instance().getAllUniqueCards(), whatYouWant, num);
|
BoosterUtils.getPredicateForConditions(rarity, color));
|
||||||
|
return BoosterUtils.generateDistinctCards(CardDb.instance().getAllUniqueCards(), whatYouWant, num);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<CardPrinted> generateDistinctCards(final Iterable<CardPrinted> source,
|
private static List<CardPrinted> generateDistinctCards(final Iterable<CardPrinted> source,
|
||||||
final Predicate<CardPrinted> filter, final int cntNeeded) {
|
final Predicate<CardPrinted> filter, final int cntNeeded) {
|
||||||
ArrayList<CardPrinted> result = new ArrayList<CardPrinted>();
|
final ArrayList<CardPrinted> result = new ArrayList<CardPrinted>();
|
||||||
int cntMade = 0;
|
int cntMade = 0;
|
||||||
|
|
||||||
// This will prevent endless loop @ wh
|
// This will prevent endless loop @ wh
|
||||||
int allowedMisses = (2 + 2) * cntNeeded; // lol, 2+2 is not magic
|
int allowedMisses = (2 + 2) * cntNeeded; // lol, 2+2 is not magic
|
||||||
// constant!
|
// constant!
|
||||||
|
|
||||||
while (cntMade < cntNeeded && allowedMisses > 0) {
|
while ((cntMade < cntNeeded) && (allowedMisses > 0)) {
|
||||||
CardPrinted card = filter.random(source);
|
final CardPrinted card = filter.random(source);
|
||||||
|
|
||||||
if (card != null && !result.contains(card)) {
|
if ((card != null) && !result.contains(card)) {
|
||||||
result.add(card);
|
result.add(card);
|
||||||
cntMade++;
|
cntMade++;
|
||||||
} else {
|
} else {
|
||||||
@@ -219,7 +221,7 @@ public final class BoosterUtils {
|
|||||||
if (StringUtils.isBlank(color)) {
|
if (StringUtils.isBlank(color)) {
|
||||||
colorFilter = Predicate.getTrue(CardRules.class);
|
colorFilter = Predicate.getTrue(CardRules.class);
|
||||||
} else {
|
} else {
|
||||||
String col = color.toLowerCase();
|
final String col = color.toLowerCase();
|
||||||
if (col.startsWith("wh")) {
|
if (col.startsWith("wh")) {
|
||||||
colorFilter = CardRules.Predicates.Presets.isWhite;
|
colorFilter = CardRules.Predicates.Presets.isWhite;
|
||||||
} else if (col.startsWith("bla")) {
|
} else if (col.startsWith("bla")) {
|
||||||
@@ -251,18 +253,18 @@ public final class BoosterUtils {
|
|||||||
* @return the variety
|
* @return the variety
|
||||||
*/
|
*/
|
||||||
public static List<CardPrinted> getVariety(final List<CardPrinted> in) {
|
public static List<CardPrinted> getVariety(final List<CardPrinted> in) {
|
||||||
List<CardPrinted> out = new ArrayList<CardPrinted>();
|
final List<CardPrinted> out = new ArrayList<CardPrinted>();
|
||||||
Collections.shuffle(in, MyRandom.getRandom());
|
Collections.shuffle(in, MyRandom.getRandom());
|
||||||
|
|
||||||
for (int i = 0; i < Constant.Color.COLORS.length; i++) {
|
for (int i = 0; i < Constant.Color.COLORS.length; i++) {
|
||||||
CardPrinted check = findCardOfColor(in, i);
|
final CardPrinted check = BoosterUtils.findCardOfColor(in, i);
|
||||||
if (check != null) {
|
if (check != null) {
|
||||||
out.add(check);
|
out.add(check);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}// getVariety()
|
} // getVariety()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find card of color.
|
* Find card of color.
|
||||||
@@ -274,7 +276,7 @@ public final class BoosterUtils {
|
|||||||
* @return the card printed
|
* @return the card printed
|
||||||
*/
|
*/
|
||||||
public static CardPrinted findCardOfColor(final List<CardPrinted> in, final int color) {
|
public static CardPrinted findCardOfColor(final List<CardPrinted> in, final int color) {
|
||||||
Predicate<CardRules> filter = CardRules.Predicates.Presets.colors.get(color);
|
final Predicate<CardRules> filter = CardRules.Predicates.Presets.colors.get(color);
|
||||||
if (null == filter) {
|
if (null == filter) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ public class CardCharacteristics {
|
|||||||
private ArrayList<Trigger> triggers = new ArrayList<Trigger>();
|
private ArrayList<Trigger> triggers = new ArrayList<Trigger>();
|
||||||
private ArrayList<StaticAbility> staticAbilities = new ArrayList<StaticAbility>();
|
private ArrayList<StaticAbility> staticAbilities = new ArrayList<StaticAbility>();
|
||||||
private ArrayList<String> staticAbilityStrings = new ArrayList<String>();
|
private ArrayList<String> staticAbilityStrings = new ArrayList<String>();
|
||||||
private String ImageFilename = "";
|
private String imageFilename = "";
|
||||||
private String imageName = "";
|
private String imageName = "";
|
||||||
private Map<String, String> sVars = new TreeMap<String, String>();
|
private Map<String, String> sVars = new TreeMap<String, String>();
|
||||||
private ArrayList<SetInfo> Sets = new ArrayList<SetInfo>();
|
private ArrayList<SetInfo> sets = new ArrayList<SetInfo>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name.
|
* Gets the name.
|
||||||
@@ -300,7 +300,7 @@ public class CardCharacteristics {
|
|||||||
* @return the imageFilename
|
* @return the imageFilename
|
||||||
*/
|
*/
|
||||||
public final String getImageFilename() {
|
public final String getImageFilename() {
|
||||||
return ImageFilename;
|
return imageFilename;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -310,7 +310,7 @@ public class CardCharacteristics {
|
|||||||
* the imageFilename to set
|
* the imageFilename to set
|
||||||
*/
|
*/
|
||||||
public final void setImageFilename(final String imageFilename0) {
|
public final void setImageFilename(final String imageFilename0) {
|
||||||
ImageFilename = imageFilename0; // TODO: Add 0 to parameter's name.
|
imageFilename = imageFilename0; // TODO: Add 0 to parameter's name.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -339,7 +339,7 @@ public class CardCharacteristics {
|
|||||||
* @return the sets
|
* @return the sets
|
||||||
*/
|
*/
|
||||||
public final ArrayList<SetInfo> getSets() {
|
public final ArrayList<SetInfo> getSets() {
|
||||||
return Sets;
|
return sets;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -349,7 +349,7 @@ public class CardCharacteristics {
|
|||||||
* the sets to set
|
* the sets to set
|
||||||
*/
|
*/
|
||||||
public final void setSets(final ArrayList<SetInfo> sets0) {
|
public final void setSets(final ArrayList<SetInfo> sets0) {
|
||||||
Sets = new ArrayList<SetInfo>(sets0); // TODO: Add 0 to parameter's
|
sets = new ArrayList<SetInfo>(sets0); // TODO: Add 0 to parameter's
|
||||||
// name.
|
// name.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public final class CardColor implements Comparable<CardColor> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** The null color. */
|
/** The null color. */
|
||||||
public static CardColor nullColor = new CardColor();
|
private static CardColor nullColor = new CardColor();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks for any color.
|
* Checks for any color.
|
||||||
@@ -264,4 +264,22 @@ public final class CardColor implements Comparable<CardColor> {
|
|||||||
return "multi";
|
return "multi";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the null color.
|
||||||
|
*
|
||||||
|
* @return the nullColor
|
||||||
|
*/
|
||||||
|
public static CardColor getNullColor() {
|
||||||
|
return nullColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the null color.
|
||||||
|
*
|
||||||
|
* @param nullColor the nullColor to set
|
||||||
|
*/
|
||||||
|
public static void setNullColor(CardColor nullColor) {
|
||||||
|
CardColor.nullColor = nullColor; // TODO: Add 0 to parameter's name.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public abstract class PresetColumns {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static CardColor toColor(final InventoryItem i) {
|
private static CardColor toColor(final InventoryItem i) {
|
||||||
return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getColor() : CardColor.nullColor;
|
return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getColor() : CardColor.getNullColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String toPTL(final InventoryItem i) {
|
private static String toPTL(final InventoryItem i) {
|
||||||
|
|||||||
Reference in New Issue
Block a user