mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Make booster quest pool generation respect starting pool set selections
This commit is contained in:
@@ -32,10 +32,7 @@ import forge.util.MyRandom;
|
|||||||
import forge.util.PredicateString.StringOp;
|
import forge.util.PredicateString.StringOp;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static forge.quest.QuestUtilCards.isLegalInQuestFormat;
|
import static forge.quest.QuestUtilCards.isLegalInQuestFormat;
|
||||||
|
|
||||||
@@ -77,7 +74,7 @@ public final class BoosterUtils {
|
|||||||
/**
|
/**
|
||||||
* Gets the quest starter deck.
|
* Gets the quest starter deck.
|
||||||
*
|
*
|
||||||
* @param filter
|
* @param formatStartingPool
|
||||||
* the filter
|
* the filter
|
||||||
* @param numCommons
|
* @param numCommons
|
||||||
* the num common
|
* the num common
|
||||||
@@ -89,8 +86,8 @@ public final class BoosterUtils {
|
|||||||
* the starting pool preferences
|
* the starting pool preferences
|
||||||
* @return the quest starter deck
|
* @return the quest starter deck
|
||||||
*/
|
*/
|
||||||
public static List<PaperCard> getQuestStarterDeck(final Predicate<PaperCard> filter, final int numCommons,
|
public static List<PaperCard> getQuestStarterDeck(final GameFormat formatStartingPool, final int numCommons,
|
||||||
final int numUncommons, final int numRares, final StartingPoolPreferences userPrefs, final QuestController questController) {
|
final int numUncommons, final int numRares, final StartingPoolPreferences userPrefs) {
|
||||||
|
|
||||||
if (possibleColors.isEmpty()) {
|
if (possibleColors.isEmpty()) {
|
||||||
possibleColors.add(MagicColor.BLACK);
|
possibleColors.add(MagicColor.BLACK);
|
||||||
@@ -101,12 +98,11 @@ public final class BoosterUtils {
|
|||||||
possibleColors.add(MagicColor.COLORLESS);
|
possibleColors.add(MagicColor.COLORLESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<PaperCard> cardPool = Lists.newArrayList(Iterables.filter(FModel.getMagicDb().getCommonCards().getAllCards(), filter));
|
|
||||||
final List<PaperCard> cards = new ArrayList<>();
|
final List<PaperCard> cards = new ArrayList<>();
|
||||||
|
|
||||||
if (userPrefs != null && userPrefs.getPoolType() == StartingPoolPreferences.PoolType.BOOSTERS) {
|
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());
|
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()) {
|
if (userPrefs != null && userPrefs.grantCompleteSet()) {
|
||||||
for (PaperCard card : cardPool) {
|
for (PaperCard card : cardPool) {
|
||||||
cards.add(card);
|
cards.add(card);
|
||||||
@@ -149,24 +152,35 @@ public final class BoosterUtils {
|
|||||||
* @return A list containing the booster packs
|
* @return A list containing the booster packs
|
||||||
*/
|
*/
|
||||||
public static List<InventoryItem> generateRandomBoosterPacks(final int quantity, final QuestController questController) {
|
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<>();
|
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++) {
|
for (int i = 0; i < quantity; i++) {
|
||||||
|
|
||||||
final int rollD100 = MyRandom.getRandom().nextInt(100);
|
CardEdition edition = Aggregates.random(possibleEditions);
|
||||||
|
|
||||||
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);
|
|
||||||
BoosterPack pack = BoosterPack.FN_FROM_SET.apply(edition);
|
BoosterPack pack = BoosterPack.FN_FROM_SET.apply(edition);
|
||||||
|
|
||||||
if (pack != null) {
|
if (pack != null) {
|
||||||
|
|||||||
@@ -17,8 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
package forge.quest;
|
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.collect.Lists;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import forge.card.CardEdition;
|
import forge.card.CardEdition;
|
||||||
@@ -27,7 +25,6 @@ import forge.deck.DeckGroup;
|
|||||||
import forge.game.GameFormat;
|
import forge.game.GameFormat;
|
||||||
import forge.game.event.GameEvent;
|
import forge.game.event.GameEvent;
|
||||||
import forge.game.event.GameEventMulligan;
|
import forge.game.event.GameEventMulligan;
|
||||||
import forge.item.PaperCard;
|
|
||||||
import forge.item.PreconDeck;
|
import forge.item.PreconDeck;
|
||||||
import forge.model.FModel;
|
import forge.model.FModel;
|
||||||
import forge.player.GamePlayerUtil;
|
import forge.player.GamePlayerUtil;
|
||||||
@@ -272,16 +269,12 @@ public class QuestController {
|
|||||||
|
|
||||||
if (startingCards != null) {
|
if (startingCards != null) {
|
||||||
this.myCards.addDeck(startingCards);
|
this.myCards.addDeck(startingCards);
|
||||||
}
|
} else {
|
||||||
else {
|
this.myCards.setupNewGameCardPool(formatStartingPool, difficulty, userPrefs);
|
||||||
Predicate<PaperCard> filter = Predicates.alwaysTrue();
|
|
||||||
if (formatStartingPool != null) {
|
|
||||||
filter = formatStartingPool.getFilterPrinted();
|
|
||||||
}
|
|
||||||
this.myCards.setupNewGameCardPool(filter, difficulty, userPrefs, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getAssets().setCredits(FModel.getQuestPreferences().getPrefInt(DifficultyPrefs.STARTING_CREDITS, difficulty));
|
this.getAssets().setCredits(FModel.getQuestPreferences().getPrefInt(DifficultyPrefs.STARTING_CREDITS, difficulty));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -298,20 +298,20 @@ public final class QuestUtilCards {
|
|||||||
/**
|
/**
|
||||||
* Setup new game card pool.
|
* Setup new game card pool.
|
||||||
*
|
*
|
||||||
* @param filter
|
* @param formatStartingPool
|
||||||
* the filter
|
* the starting pool format for the new quest
|
||||||
* @param idxDifficulty
|
* @param idxDifficulty
|
||||||
* the idx difficulty
|
* the idx difficulty
|
||||||
* @param userPrefs
|
* @param userPrefs
|
||||||
* user preferences
|
* 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 nC = questPreferences.getPrefInt(DifficultyPrefs.STARTING_COMMONS, idxDifficulty);
|
||||||
final int nU = questPreferences.getPrefInt(DifficultyPrefs.STARTING_UNCOMMONS, idxDifficulty);
|
final int nU = questPreferences.getPrefInt(DifficultyPrefs.STARTING_UNCOMMONS, idxDifficulty);
|
||||||
final int nR = questPreferences.getPrefInt(DifficultyPrefs.STARTING_RARES, 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));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,119 +35,111 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public final class GameFormatQuest extends GameFormat {
|
public final class GameFormatQuest extends GameFormat {
|
||||||
|
|
||||||
private final boolean allowUnlocks;
|
private final boolean allowUnlocks;
|
||||||
private int unlocksUsed = 0;
|
private int unlocksUsed = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new game format based on two lists.
|
* Instantiates a new game format based on two lists.
|
||||||
*
|
*
|
||||||
* @param newName
|
* @param newName String, the name
|
||||||
* String, the name
|
* @param setsToAllow List<String>, these are the allowed sets
|
||||||
* @param setsToAllow
|
* @param cardsToBan List<String>, these will be the banned cards
|
||||||
* List<String>, these are the allowed sets
|
*/
|
||||||
* @param cardsToBan
|
public GameFormatQuest(final String newName, final List<String> setsToAllow, final List<String> cardsToBan) {
|
||||||
* List<String>, these will be the banned cards
|
super(newName, setsToAllow, cardsToBan);
|
||||||
*/
|
allowUnlocks = false;
|
||||||
public GameFormatQuest(final String newName, final List<String> setsToAllow, final List<String> cardsToBan) {
|
}
|
||||||
super(newName, setsToAllow, cardsToBan);
|
|
||||||
allowUnlocks = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GameFormatQuest(final String newName, final List<String> setsToAllow, final List<String> cardsToBan, boolean allowSetUnlocks) {
|
public GameFormatQuest(final String newName, final List<String> setsToAllow, final List<String> cardsToBan, boolean allowSetUnlocks) {
|
||||||
super(newName, setsToAllow, cardsToBan);
|
super(newName, setsToAllow, cardsToBan);
|
||||||
allowUnlocks = allowSetUnlocks;
|
allowUnlocks = allowSetUnlocks;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Instantiates a new game format based on an existing format.
|
|
||||||
*
|
|
||||||
* @param toCopy
|
|
||||||
* an existing format
|
|
||||||
* @param allowSetUnlocks
|
|
||||||
*/
|
|
||||||
public GameFormatQuest(final GameFormat toCopy, boolean allowSetUnlocks) {
|
|
||||||
super(toCopy.getName(), toCopy.getAllowedSetCodes(), toCopy.getBannedCardNames(), toCopy.getRestrictedCards(), toCopy.getIndex());
|
|
||||||
allowUnlocks = allowSetUnlocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new game format based on an existing format.
|
||||||
|
*
|
||||||
|
* @param toCopy an existing format
|
||||||
|
* @param allowSetUnlocks
|
||||||
|
*/
|
||||||
|
public GameFormatQuest(final GameFormat toCopy, boolean allowSetUnlocks) {
|
||||||
|
super(toCopy.getName(), toCopy.getAllowedSetCodes(), toCopy.getBannedCardNames(), toCopy.getRestrictedCards(), toCopy.getIndex());
|
||||||
|
allowUnlocks = allowSetUnlocks;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of excluded sets.
|
* Get the list of excluded sets.
|
||||||
*
|
*
|
||||||
* @return unmodifiable list of excluded sets.
|
* @return unmodifiable list of excluded sets.
|
||||||
*/
|
*/
|
||||||
public List<String> getLockedSets() {
|
public List<String> getLockedSets() {
|
||||||
|
|
||||||
List<String> exSets = new ArrayList<String>();
|
List<String> exSets = new ArrayList<String>();
|
||||||
if (this.allowedSetCodes.isEmpty()) {
|
if (this.allowedSetCodes.isEmpty()) {
|
||||||
return exSets;
|
return exSets;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CardEdition ce : FModel.getMagicDb().getEditions()) {
|
for (CardEdition ce : FModel.getMagicDb().getEditions()) {
|
||||||
if (!isSetLegal(ce.getCode())) {
|
if (!isSetLegal(ce.getCode())) {
|
||||||
exSets.add(ce.getCode());
|
exSets.add(ce.getCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return exSets;
|
return exSets;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a set to allowed set codes.
|
* Add a set to allowed set codes.
|
||||||
*
|
*
|
||||||
* @param setCode String, set code.
|
* @param setCode String, set code.
|
||||||
*/
|
*/
|
||||||
public void unlockSet(final String setCode) {
|
public void unlockSet(final String setCode) {
|
||||||
if (!canUnlockSets() || this.allowedSetCodes_ro.isEmpty() || this.allowedSetCodes_ro.contains(setCode)) {
|
if (!canUnlockSets() || this.allowedSetCodes_ro.isEmpty() || this.allowedSetCodes_ro.contains(setCode)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.allowedSetCodes.add(setCode);
|
this.allowedSetCodes.add(setCode);
|
||||||
unlocksUsed++;
|
unlocksUsed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the current format contains sets with snow-land (horrible hack...).
|
* 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() {
|
public boolean hasSnowLands() {
|
||||||
return (this.isSetLegal("ICE") || this.isSetLegal("CSP"));
|
return (this.isSetLegal("ICE") || this.isSetLegal("CSP"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canUnlockSets() {
|
public boolean canUnlockSets() {
|
||||||
return allowUnlocks;
|
return allowUnlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUnlocksUsed() {
|
public int getUnlocksUsed() {
|
||||||
return unlocksUsed;
|
return unlocksUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract static class Predicates {
|
||||||
|
/**
|
||||||
|
* Checks if is legal in quest format.
|
||||||
|
*
|
||||||
|
* @param qFormat the format
|
||||||
|
* @return the predicate
|
||||||
|
*/
|
||||||
|
public static Predicate<CardEdition> isLegalInFormatQuest(final GameFormatQuest qFormat) {
|
||||||
|
return new LegalInFormatQuest(qFormat);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
private static final class LegalInFormatQuest implements Predicate<CardEdition> {
|
||||||
* The Class Predicates.
|
private final GameFormatQuest qFormat;
|
||||||
*/
|
|
||||||
public abstract static class Predicates {
|
|
||||||
/**
|
|
||||||
* Checks if is legal in quest format.
|
|
||||||
*
|
|
||||||
* @param qFormat the format
|
|
||||||
* @return the predicate
|
|
||||||
*/
|
|
||||||
public static Predicate<CardEdition> isLegalInFormatQuest(final GameFormatQuest qFormat) {
|
|
||||||
return new LegalInFormatQuest(qFormat);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class LegalInFormatQuest implements Predicate<CardEdition> {
|
private LegalInFormatQuest(final GameFormatQuest fmt) {
|
||||||
private final GameFormatQuest qFormat;
|
this.qFormat = fmt;
|
||||||
|
}
|
||||||
|
|
||||||
public LegalInFormatQuest(final GameFormatQuest fmt) {
|
@Override
|
||||||
this.qFormat = fmt;
|
public boolean apply(final CardEdition subject) {
|
||||||
}
|
return this.qFormat.isSetLegal(subject.getCode());
|
||||||
|
}
|
||||||
@Override
|
}
|
||||||
public boolean apply(final CardEdition subject) {
|
|
||||||
return this.qFormat.isSetLegal(subject.getCode());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user