mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38: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 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) {
|
||||
|
||||
@@ -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));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
@@ -35,119 +35,111 @@ import java.util.List;
|
||||
*/
|
||||
public final class GameFormatQuest extends GameFormat {
|
||||
|
||||
private final boolean allowUnlocks;
|
||||
private int unlocksUsed = 0;
|
||||
private final boolean allowUnlocks;
|
||||
private int unlocksUsed = 0;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public GameFormatQuest(final String newName, final List<String> setsToAllow, final List<String> cardsToBan) {
|
||||
super(newName, setsToAllow, cardsToBan);
|
||||
allowUnlocks = false;
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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) {
|
||||
super(newName, setsToAllow, cardsToBan);
|
||||
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;
|
||||
}
|
||||
public GameFormatQuest(final String newName, final List<String> setsToAllow, final List<String> cardsToBan, boolean allowSetUnlocks) {
|
||||
super(newName, setsToAllow, cardsToBan);
|
||||
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.
|
||||
*
|
||||
* @return unmodifiable list of excluded sets.
|
||||
*/
|
||||
public List<String> getLockedSets() {
|
||||
/**
|
||||
* Get the list of excluded sets.
|
||||
*
|
||||
* @return unmodifiable list of excluded sets.
|
||||
*/
|
||||
public List<String> getLockedSets() {
|
||||
|
||||
List<String> exSets = new ArrayList<String>();
|
||||
if (this.allowedSetCodes.isEmpty()) {
|
||||
return exSets;
|
||||
}
|
||||
List<String> exSets = new ArrayList<String>();
|
||||
if (this.allowedSetCodes.isEmpty()) {
|
||||
return exSets;
|
||||
}
|
||||
|
||||
for (CardEdition ce : FModel.getMagicDb().getEditions()) {
|
||||
if (!isSetLegal(ce.getCode())) {
|
||||
exSets.add(ce.getCode());
|
||||
}
|
||||
}
|
||||
return exSets;
|
||||
}
|
||||
for (CardEdition ce : FModel.getMagicDb().getEditions()) {
|
||||
if (!isSetLegal(ce.getCode())) {
|
||||
exSets.add(ce.getCode());
|
||||
}
|
||||
}
|
||||
return exSets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a set to allowed set codes.
|
||||
*
|
||||
* @param setCode String, set code.
|
||||
*/
|
||||
public void unlockSet(final String setCode) {
|
||||
if (!canUnlockSets() || this.allowedSetCodes_ro.isEmpty() || this.allowedSetCodes_ro.contains(setCode)) {
|
||||
return;
|
||||
}
|
||||
this.allowedSetCodes.add(setCode);
|
||||
unlocksUsed++;
|
||||
}
|
||||
/**
|
||||
* Add a set to allowed set codes.
|
||||
*
|
||||
* @param setCode String, set code.
|
||||
*/
|
||||
public void unlockSet(final String setCode) {
|
||||
if (!canUnlockSets() || this.allowedSetCodes_ro.isEmpty() || this.allowedSetCodes_ro.contains(setCode)) {
|
||||
return;
|
||||
}
|
||||
this.allowedSetCodes.add(setCode);
|
||||
unlocksUsed++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current format contains sets with snow-land (horrible hack...).
|
||||
* @return boolean, contains snow-land sets.
|
||||
*
|
||||
*/
|
||||
public boolean hasSnowLands() {
|
||||
return (this.isSetLegal("ICE") || this.isSetLegal("CSP"));
|
||||
}
|
||||
/**
|
||||
* Checks if the current format contains sets with snow-land (horrible hack...).
|
||||
*
|
||||
* @return boolean, contains snow-land sets.
|
||||
*/
|
||||
public boolean hasSnowLands() {
|
||||
return (this.isSetLegal("ICE") || this.isSetLegal("CSP"));
|
||||
}
|
||||
|
||||
public boolean canUnlockSets() {
|
||||
return allowUnlocks;
|
||||
}
|
||||
public boolean canUnlockSets() {
|
||||
return allowUnlocks;
|
||||
}
|
||||
|
||||
public int getUnlocksUsed() {
|
||||
return unlocksUsed;
|
||||
}
|
||||
public int getUnlocksUsed() {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class Predicates.
|
||||
*/
|
||||
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> {
|
||||
private final GameFormatQuest qFormat;
|
||||
|
||||
private static class LegalInFormatQuest implements Predicate<CardEdition> {
|
||||
private final GameFormatQuest qFormat;
|
||||
private LegalInFormatQuest(final GameFormatQuest fmt) {
|
||||
this.qFormat = fmt;
|
||||
}
|
||||
|
||||
public LegalInFormatQuest(final GameFormatQuest fmt) {
|
||||
this.qFormat = fmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
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