Make booster quest pool generation respect starting pool set selections

This commit is contained in:
Krazy
2017-08-02 01:42:01 +00:00
parent 61784fd48d
commit b04ac67860
4 changed files with 136 additions and 137 deletions

View File

@@ -32,10 +32,7 @@ import forge.util.MyRandom;
import forge.util.PredicateString.StringOp;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.*;
import static forge.quest.QuestUtilCards.isLegalInQuestFormat;
@@ -77,7 +74,7 @@ public final class BoosterUtils {
/**
* Gets the quest starter deck.
*
* @param filter
* @param formatStartingPool
* the filter
* @param numCommons
* the num common
@@ -89,8 +86,8 @@ public final class BoosterUtils {
* the starting pool preferences
* @return the quest starter deck
*/
public static List<PaperCard> getQuestStarterDeck(final Predicate<PaperCard> filter, final int numCommons,
final int numUncommons, final int numRares, final StartingPoolPreferences userPrefs, final QuestController questController) {
public static List<PaperCard> getQuestStarterDeck(final GameFormat formatStartingPool, final int numCommons,
final int numUncommons, final int numRares, final StartingPoolPreferences userPrefs) {
if (possibleColors.isEmpty()) {
possibleColors.add(MagicColor.BLACK);
@@ -101,12 +98,11 @@ public final class BoosterUtils {
possibleColors.add(MagicColor.COLORLESS);
}
final List<PaperCard> cardPool = Lists.newArrayList(Iterables.filter(FModel.getMagicDb().getCommonCards().getAllCards(), filter));
final List<PaperCard> cards = new ArrayList<>();
if (userPrefs != null && userPrefs.getPoolType() == StartingPoolPreferences.PoolType.BOOSTERS) {
for (InventoryItem inventoryItem : generateRandomBoosterPacks(userPrefs.getNumberOfBoosters(), questController)) {
for (InventoryItem inventoryItem : generateRandomBoosterPacks(userPrefs.getNumberOfBoosters(), formatStartingPool.editionLegalPredicate)) {
cards.addAll(((BoosterPack) inventoryItem).getCards());
}
@@ -114,6 +110,13 @@ public final class BoosterUtils {
}
Predicate<PaperCard> filter = Predicates.alwaysTrue();
if (formatStartingPool != null) {
filter = formatStartingPool.getFilterPrinted();
}
final List<PaperCard> cardPool = Lists.newArrayList(Iterables.filter(FModel.getMagicDb().getCommonCards().getAllCards(), filter));
if (userPrefs != null && userPrefs.grantCompleteSet()) {
for (PaperCard card : cardPool) {
cards.add(card);
@@ -149,24 +152,35 @@ public final class BoosterUtils {
* @return A list containing the booster packs
*/
public static List<InventoryItem> generateRandomBoosterPacks(final int quantity, final QuestController questController) {
if (questController.getFormat() != null) {
return generateRandomBoosterPacks(quantity, isLegalInQuestFormat(questController.getFormat()));
} else {
final int rollD100 = MyRandom.getRandom().nextInt(100);
return generateRandomBoosterPacks(quantity, rollD100 < 40 ? filterT2booster : (rollD100 < 75 ? filterExtButT2 : filterNotExt));
}
}
/**
* Generates a number of booster packs from random editions using the specified edition predicate.
* @param quantity The number of booster packs to generate
* @param editionFilter The filter to use for picking booster editions
* @return A list containing the booster packs
*/
public static List<InventoryItem> generateRandomBoosterPacks(final int quantity, final Predicate<CardEdition> editionFilter) {
List<InventoryItem> output = new ArrayList<>();
Predicate<CardEdition> filter = Predicates.and(CardEdition.Predicates.CAN_MAKE_BOOSTER, editionFilter);
Iterable<CardEdition> possibleEditions = Iterables.filter(FModel.getMagicDb().getEditions(), filter);
if (!possibleEditions.iterator().hasNext()) {
System.err.println("No sets found in starting pool that can create boosters.");
return output;
}
for (int i = 0; i < quantity; i++) {
final int rollD100 = MyRandom.getRandom().nextInt(100);
Predicate<CardEdition> filter = rollD100 < 40 ? filterT2booster : (rollD100 < 75 ? filterExtButT2 : filterNotExt);
if (questController.getFormat() != null) {
filter = Predicates.and(CardEdition.Predicates.CAN_MAKE_BOOSTER, isLegalInQuestFormat(questController.getFormat()));
}
Iterable<CardEdition> rightEditions = Iterables.filter(FModel.getMagicDb().getEditions(), filter);
if (!rightEditions.iterator().hasNext()) {
continue;
}
CardEdition edition = Aggregates.random(rightEditions);
CardEdition edition = Aggregates.random(possibleEditions);
BoosterPack pack = BoosterPack.FN_FROM_SET.apply(edition);
if (pack != null) {

View File

@@ -17,8 +17,6 @@
*/
package forge.quest;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Lists;
import com.google.common.eventbus.Subscribe;
import forge.card.CardEdition;
@@ -27,7 +25,6 @@ import forge.deck.DeckGroup;
import forge.game.GameFormat;
import forge.game.event.GameEvent;
import forge.game.event.GameEventMulligan;
import forge.item.PaperCard;
import forge.item.PreconDeck;
import forge.model.FModel;
import forge.player.GamePlayerUtil;
@@ -272,16 +269,12 @@ public class QuestController {
if (startingCards != null) {
this.myCards.addDeck(startingCards);
}
else {
Predicate<PaperCard> filter = Predicates.alwaysTrue();
if (formatStartingPool != null) {
filter = formatStartingPool.getFilterPrinted();
}
this.myCards.setupNewGameCardPool(filter, difficulty, userPrefs, this);
} else {
this.myCards.setupNewGameCardPool(formatStartingPool, difficulty, userPrefs);
}
this.getAssets().setCredits(FModel.getQuestPreferences().getPrefInt(DifficultyPrefs.STARTING_CREDITS, difficulty));
}
/**

View File

@@ -298,20 +298,20 @@ public final class QuestUtilCards {
/**
* Setup new game card pool.
*
* @param filter
* the filter
* @param formatStartingPool
* the starting pool format for the new quest
* @param idxDifficulty
* the idx difficulty
* @param userPrefs
* user preferences
*/
public void setupNewGameCardPool(final Predicate<PaperCard> filter, final int idxDifficulty, final StartingPoolPreferences userPrefs, final QuestController questController) {
public void setupNewGameCardPool(final GameFormat formatStartingPool, final int idxDifficulty, final StartingPoolPreferences userPrefs) {
final int nC = questPreferences.getPrefInt(DifficultyPrefs.STARTING_COMMONS, idxDifficulty);
final int nU = questPreferences.getPrefInt(DifficultyPrefs.STARTING_UNCOMMONS, idxDifficulty);
final int nR = questPreferences.getPrefInt(DifficultyPrefs.STARTING_RARES, idxDifficulty);
addAllCards(BoosterUtils.getQuestStarterDeck(filter, nC, nU, nR, userPrefs, questController));
addAllCards(BoosterUtils.getQuestStarterDeck(formatStartingPool, nC, nU, nR, userPrefs));
}

View File

@@ -41,12 +41,9 @@ public final class GameFormatQuest extends GameFormat {
/**
* Instantiates a new game format based on two lists.
*
* @param newName
* String, the name
* @param setsToAllow
* List<String>, these are the allowed sets
* @param cardsToBan
* List<String>, these will be the banned cards
* @param newName String, the name
* @param setsToAllow List<String>, these are the allowed sets
* @param cardsToBan List<String>, these will be the banned cards
*/
public GameFormatQuest(final String newName, final List<String> setsToAllow, final List<String> cardsToBan) {
super(newName, setsToAllow, cardsToBan);
@@ -57,11 +54,11 @@ public final class GameFormatQuest extends GameFormat {
super(newName, setsToAllow, cardsToBan);
allowUnlocks = allowSetUnlocks;
}
/**
* Instantiates a new game format based on an existing format.
*
* @param toCopy
* an existing format
* @param toCopy an existing format
* @param allowSetUnlocks
*/
public GameFormatQuest(final GameFormat toCopy, boolean allowSetUnlocks) {
@@ -69,7 +66,6 @@ public final class GameFormatQuest extends GameFormat {
allowUnlocks = allowSetUnlocks;
}
/**
* Get the list of excluded sets.
*
@@ -105,8 +101,8 @@ public final class GameFormatQuest extends GameFormat {
/**
* Checks if the current format contains sets with snow-land (horrible hack...).
* @return boolean, contains snow-land sets.
*
* @return boolean, contains snow-land sets.
*/
public boolean hasSnowLands() {
return (this.isSetLegal("ICE") || this.isSetLegal("CSP"));
@@ -120,10 +116,6 @@ public final class GameFormatQuest extends GameFormat {
return unlocksUsed;
}
/**
* The Class Predicates.
*/
public abstract static class Predicates {
/**
* Checks if is legal in quest format.
@@ -135,10 +127,10 @@ public final class GameFormatQuest extends GameFormat {
return new LegalInFormatQuest(qFormat);
}
private static class LegalInFormatQuest implements Predicate<CardEdition> {
private static final class LegalInFormatQuest implements Predicate<CardEdition> {
private final GameFormatQuest qFormat;
public LegalInFormatQuest(final GameFormatQuest fmt) {
private LegalInFormatQuest(final GameFormatQuest fmt) {
this.qFormat = fmt;
}
@@ -147,7 +139,7 @@ public final class GameFormatQuest extends GameFormat {
return this.qFormat.isSetLegal(subject.getCode());
}
}
}
}