mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
Added fallback for quest match rewards when no boosters are in the selected sets.
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
package forge;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import forge.card.CardDb;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardRules;
|
||||
@@ -14,6 +10,10 @@ import forge.item.SealedProduct;
|
||||
import forge.util.storage.IStorage;
|
||||
import forge.util.storage.StorageBase;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
|
||||
/**
|
||||
* The class holding game invariants, such as cards, editions, game formats. All that data, which is not supposed to be changed by player
|
||||
@@ -37,8 +37,8 @@ public class StaticData {
|
||||
this.editions = new CardEdition.Collection(new CardEdition.Reader(new File(editionFolder)));
|
||||
lastInstance = this;
|
||||
|
||||
final Map<String, CardRules> regularCards = new TreeMap<String, CardRules>(String.CASE_INSENSITIVE_ORDER);
|
||||
final Map<String, CardRules> variantsCards = new TreeMap<String, CardRules>(String.CASE_INSENSITIVE_ORDER);
|
||||
final Map<String, CardRules> regularCards = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
final Map<String, CardRules> variantsCards = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
for (CardRules card : reader.loadCards()) {
|
||||
if (null == card) continue;
|
||||
@@ -59,15 +59,15 @@ public class StaticData {
|
||||
commonCards.initialize(false, false);
|
||||
variantCards.initialize(false, false);
|
||||
|
||||
this.boosters = new StorageBase<SealedProduct.Template>("Boosters", editions.getBoosterGenerator());
|
||||
this.specialBoosters = new StorageBase<SealedProduct.Template>("Special boosters", new SealedProduct.Template.Reader(new File(blockDataFolder, "boosters-special.txt")));
|
||||
this.tournaments = new StorageBase<SealedProduct.Template>("Starter sets", new SealedProduct.Template.Reader(new File(blockDataFolder, "starters.txt")));
|
||||
this.fatPacks = new StorageBase<FatPack.Template>("Fat packs", new FatPack.Template.Reader(blockDataFolder + "fatpacks.txt"));
|
||||
this.boosterBoxes = new StorageBase<BoosterBox.Template>("Booster boxes", new BoosterBox.Template.Reader(blockDataFolder + "boosterboxes.txt"));
|
||||
this.printSheets = new StorageBase<PrintSheet>("Special print runs", new PrintSheet.Reader(new File(blockDataFolder, "printsheets.txt")));
|
||||
this.boosters = new StorageBase<>("Boosters", editions.getBoosterGenerator());
|
||||
this.specialBoosters = new StorageBase<>("Special boosters", new SealedProduct.Template.Reader(new File(blockDataFolder, "boosters-special.txt")));
|
||||
this.tournaments = new StorageBase<>("Starter sets", new SealedProduct.Template.Reader(new File(blockDataFolder, "starters.txt")));
|
||||
this.fatPacks = new StorageBase<>("Fat packs", new FatPack.Template.Reader(blockDataFolder + "fatpacks.txt"));
|
||||
this.boosterBoxes = new StorageBase<>("Booster boxes", new BoosterBox.Template.Reader(blockDataFolder + "boosterboxes.txt"));
|
||||
this.printSheets = new StorageBase<>("Special print runs", new PrintSheet.Reader(new File(blockDataFolder, "printsheets.txt")));
|
||||
}
|
||||
|
||||
public final static StaticData instance() {
|
||||
public static StaticData instance() {
|
||||
return lastInstance;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class StaticData {
|
||||
return this.editions;
|
||||
}
|
||||
|
||||
/** @return {@link forge.util.storage.IStorageView}<{@link forge.item.FatPackTemplate}> */
|
||||
/** @return {@link forge.util.storage.IStorage}<{@link forge.item.SealedProduct.Template}> */
|
||||
public IStorage<FatPack.Template> getFatPacks() {
|
||||
return fatPacks;
|
||||
}
|
||||
@@ -84,12 +84,12 @@ public class StaticData {
|
||||
return boosterBoxes;
|
||||
}
|
||||
|
||||
/** @return {@link forge.util.storage.IStorageView}<{@link forge.card.BoosterTemplate}> */
|
||||
/** @return {@link forge.util.storage.IStorage}<{@link forge.item.SealedProduct.Template}> */
|
||||
public final IStorage<SealedProduct.Template> getTournamentPacks() {
|
||||
return tournaments;
|
||||
}
|
||||
|
||||
/** @return {@link forge.util.storage.IStorageView}<{@link forge.card.BoosterTemplate}> */
|
||||
/** @return {@link forge.util.storage.IStorage}<{@link forge.item.SealedProduct.Template}> */
|
||||
public final IStorage<SealedProduct.Template> getBoosters() {
|
||||
return boosters;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class UnOpenedProduct implements IUnOpenedProduct {
|
||||
|
||||
public UnOpenedProduct(SealedProduct.Template template, Iterable<PaperCard> cards) {
|
||||
tpl = template;
|
||||
sheets = new TreeMap<String, PrintSheet>();
|
||||
sheets = new TreeMap<>();
|
||||
prebuildSheets(cards);
|
||||
}
|
||||
|
||||
@@ -62,15 +62,15 @@ public class UnOpenedProduct implements IUnOpenedProduct {
|
||||
}
|
||||
|
||||
// If they request cards from an arbitrary pool, there's no use to cache printsheets.
|
||||
private final List<PaperCard> getBoosterPack() {
|
||||
List<PaperCard> result = new ArrayList<PaperCard>();
|
||||
private List<PaperCard> getBoosterPack() {
|
||||
List<PaperCard> result = new ArrayList<>();
|
||||
for(Pair<String, Integer> slot : tpl.getSlots()) {
|
||||
PrintSheet ps = sheets.get(slot.getLeft());
|
||||
if(ps.isEmpty() && poolLimited ) {
|
||||
throw new IllegalStateException("The cardpool has been depleted and has no more cards for slot " + slot.getKey());
|
||||
}
|
||||
|
||||
List<PaperCard> foundCards = ps.random(slot.getRight().intValue(), true);
|
||||
List<PaperCard> foundCards = ps.random(slot.getRight(), true);
|
||||
if(poolLimited)
|
||||
ps.removeAll(foundCards);
|
||||
result.addAll(foundCards);
|
||||
@@ -79,4 +79,3 @@ public class UnOpenedProduct implements IUnOpenedProduct {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
package forge.quest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import forge.LobbyPlayer;
|
||||
import forge.assets.FSkinProp;
|
||||
import forge.card.BoosterSlots;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.IUnOpenedProduct;
|
||||
import forge.card.UnOpenedProduct;
|
||||
@@ -22,11 +17,8 @@ import forge.game.player.PlayerStatistics;
|
||||
import forge.game.player.PlayerView;
|
||||
import forge.interfaces.IButton;
|
||||
import forge.interfaces.IWinLoseView;
|
||||
import forge.item.BoosterPack;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.SealedProduct;
|
||||
import forge.item.TournamentPack;
|
||||
import forge.item.*;
|
||||
import forge.item.IPaperCard.Predicates;
|
||||
import forge.model.FModel;
|
||||
import forge.player.GamePlayerUtil;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
@@ -36,6 +28,13 @@ import forge.quest.data.QuestPreferences.DifficultyPrefs;
|
||||
import forge.quest.data.QuestPreferences.QPref;
|
||||
import forge.util.MyRandom;
|
||||
import forge.util.gui.SGuiChoose;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class QuestWinLoseController {
|
||||
private final GameView lastGame;
|
||||
@@ -212,11 +211,11 @@ public class QuestWinLoseController {
|
||||
// TODO use q.qdPrefs to write bonus credits in prefs file
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
||||
int credTotal = 0;
|
||||
int credBase = 0;
|
||||
int credTotal;
|
||||
int credBase;
|
||||
int credGameplay = 0;
|
||||
int credUndefeated = 0;
|
||||
int credEstates = 0;
|
||||
int credEstates;
|
||||
|
||||
// Basic win bonus
|
||||
final int base = FModel.getQuestPreferences().getPrefInt(QPref.REWARDS_BASE);
|
||||
@@ -391,7 +390,7 @@ public class QuestWinLoseController {
|
||||
*/
|
||||
private void awardRandomRare(final String message) {
|
||||
final PaperCard c = qData.getCards().addRandomRare();
|
||||
final List<PaperCard> cardsWon = new ArrayList<PaperCard>();
|
||||
final List<PaperCard> cardsWon = new ArrayList<>();
|
||||
cardsWon.add(c);
|
||||
|
||||
view.showCards(message, cardsWon);
|
||||
@@ -409,7 +408,7 @@ public class QuestWinLoseController {
|
||||
|
||||
final List<PaperCard> cardsWon = new ArrayList<>();
|
||||
List<PaperCard> cardsToAdd;
|
||||
String typeWon = "";
|
||||
String typeWon;
|
||||
boolean addDraftToken = false;
|
||||
|
||||
switch (currentStreak) {
|
||||
@@ -466,7 +465,7 @@ public class QuestWinLoseController {
|
||||
qData.getAchievements().addDraftToken();
|
||||
}
|
||||
|
||||
if (cardsWon.size() > 0) {
|
||||
if (!cardsWon.isEmpty()) {
|
||||
view.showCards("You have achieved a " + (currentStreak == 0 ? "50" : currentStreak) + " win streak and won " + cardsWon.size() + " " + typeWon + " card" + ((cardsWon.size() != 1) ? "s" : "") + "!", cardsWon);
|
||||
}
|
||||
}
|
||||
@@ -491,11 +490,12 @@ public class QuestWinLoseController {
|
||||
*
|
||||
*/
|
||||
private void awardBooster() {
|
||||
List<PaperCard> cardsWon = null;
|
||||
List<PaperCard> cardsWon;
|
||||
|
||||
String title;
|
||||
if (qData.getFormat() == null) {
|
||||
final List<GameFormat> formats = new ArrayList<GameFormat>();
|
||||
|
||||
final List<GameFormat> formats = new ArrayList<>();
|
||||
final String preferredFormat = FModel.getQuestPreferences().getPref(QPref.BOOSTER_FORMAT);
|
||||
|
||||
GameFormat pref = null;
|
||||
@@ -515,9 +515,10 @@ public class QuestWinLoseController {
|
||||
qData.getCards().addAllCards(cardsWon);
|
||||
|
||||
title = "Bonus booster pack from the \"" + selected.getName() + "\" format!";
|
||||
}
|
||||
else {
|
||||
final List<String> sets = new ArrayList<String>();
|
||||
|
||||
} else {
|
||||
|
||||
final List<String> sets = new ArrayList<>();
|
||||
|
||||
for (final SealedProduct.Template bd : FModel.getMagicDb().getBoosters()) {
|
||||
if (bd != null && qData.getFormat().isSetLegal(bd.getEdition())) {
|
||||
@@ -525,6 +526,19 @@ public class QuestWinLoseController {
|
||||
}
|
||||
}
|
||||
|
||||
boolean customBooster = false;
|
||||
|
||||
//No boosters found for current quest settings
|
||||
if (sets.isEmpty()) {
|
||||
customBooster = true;
|
||||
CardEdition.Collection editions = FModel.getMagicDb().getEditions();
|
||||
for (CardEdition edition : editions) {
|
||||
if (qData.getFormat().isSetLegal(edition.getCode())) {
|
||||
sets.add(edition.getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int maxChoices = 1;
|
||||
if (wonMatch) {
|
||||
maxChoices++;
|
||||
@@ -535,7 +549,7 @@ public class QuestWinLoseController {
|
||||
maxChoices += qData.getAssets().getItemLevel(QuestItemType.MEMBERSHIP_TOKEN);
|
||||
}
|
||||
|
||||
final List<CardEdition> options = new ArrayList<CardEdition>();
|
||||
final List<CardEdition> options = new ArrayList<>();
|
||||
|
||||
while (!sets.isEmpty() && maxChoices > 0) {
|
||||
final int ix = MyRandom.getRandom().nextInt(sets.size());
|
||||
@@ -547,10 +561,18 @@ public class QuestWinLoseController {
|
||||
|
||||
final CardEdition chooseEd = SGuiChoose.one("Choose bonus booster set", options);
|
||||
|
||||
final IUnOpenedProduct product = new UnOpenedProduct(FModel.getMagicDb().getBoosters().get(chooseEd.getCode()));
|
||||
cardsWon = product.get();
|
||||
if (customBooster) {
|
||||
List<PaperCard> cards = FModel.getMagicDb().getCommonCards().getAllCards(Predicates.printedInSet(chooseEd.getCode()));
|
||||
final IUnOpenedProduct product = new UnOpenedProduct(getBoosterTemplate(), cards);
|
||||
cardsWon = product.get();
|
||||
} else {
|
||||
final IUnOpenedProduct product = new UnOpenedProduct(FModel.getMagicDb().getBoosters().get(chooseEd.getCode()));
|
||||
cardsWon = product.get();
|
||||
}
|
||||
|
||||
qData.getCards().addAllCards(cardsWon);
|
||||
title = "Bonus " + chooseEd.getName() + " booster pack!";
|
||||
|
||||
}
|
||||
|
||||
if (cardsWon != null) {
|
||||
@@ -559,6 +581,14 @@ public class QuestWinLoseController {
|
||||
}
|
||||
}
|
||||
|
||||
private SealedProduct.Template getBoosterTemplate() {
|
||||
return new SealedProduct.Template(ImmutableList.of(
|
||||
Pair.of(BoosterSlots.COMMON, FModel.getQuestPreferences().getPrefInt(QPref.BOOSTER_COMMONS)),
|
||||
Pair.of(BoosterSlots.UNCOMMON, FModel.getQuestPreferences().getPrefInt(QPref.BOOSTER_UNCOMMONS)),
|
||||
Pair.of(BoosterSlots.RARE_MYTHIC, FModel.getQuestPreferences().getPrefInt(QPref.BOOSTER_RARES))
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* awardChallengeWin.
|
||||
@@ -571,11 +601,11 @@ public class QuestWinLoseController {
|
||||
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("Challenge completed.\n\n");
|
||||
sb.append("Challenge bounty: " + questRewardCredits + " credits.");
|
||||
sb.append("Challenge bounty: ").append(questRewardCredits).append(" credits.");
|
||||
|
||||
qData.getAssets().addCredits(questRewardCredits);
|
||||
|
||||
view.showMessage(sb.toString(), "Challenge Rewards for \"" + ((QuestEventChallenge) qEvent).getTitle() + "\"", FSkinProp.ICO_QUEST_BOX);
|
||||
view.showMessage(sb.toString(), "Challenge Rewards for \"" + qEvent.getTitle() + "\"", FSkinProp.ICO_QUEST_BOX);
|
||||
|
||||
awardSpecialReward(null);
|
||||
}
|
||||
@@ -594,20 +624,19 @@ public class QuestWinLoseController {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<PaperCard> cardsWon = new ArrayList<PaperCard>();
|
||||
final List<PaperCard> cardsWon = new ArrayList<>();
|
||||
|
||||
for (final InventoryItem ii : itemsWon) {
|
||||
if (ii instanceof PaperCard) {
|
||||
cardsWon.add((PaperCard) ii);
|
||||
}
|
||||
else if (ii instanceof TournamentPack || ii instanceof BoosterPack) {
|
||||
final List<PaperCard> boosterCards = new ArrayList<PaperCard>();
|
||||
SealedProduct booster = null;
|
||||
final List<PaperCard> boosterCards = new ArrayList<>();
|
||||
SealedProduct booster;
|
||||
if (ii instanceof BoosterPack) {
|
||||
booster = (BoosterPack) ((BoosterPack) ii).clone();
|
||||
boosterCards.addAll(booster.getCards());
|
||||
}
|
||||
else if (ii instanceof TournamentPack) {
|
||||
} else {
|
||||
booster = (TournamentPack) ((TournamentPack) ii).clone();
|
||||
boosterCards.addAll(booster.getCards());
|
||||
}
|
||||
@@ -618,7 +647,7 @@ public class QuestWinLoseController {
|
||||
}
|
||||
else if (ii instanceof IQuestRewardCard) {
|
||||
final List<PaperCard> cardChoices = ((IQuestRewardCard) ii).getChoices();
|
||||
final PaperCard chosenCard = (null == cardChoices ? null : SGuiChoose.one("Choose " + ((IQuestRewardCard) ii).getName(), cardChoices));
|
||||
final PaperCard chosenCard = (null == cardChoices ? null : SGuiChoose.one("Choose " + ii.getName(), cardChoices));
|
||||
if (null != chosenCard) {
|
||||
cardsWon.add(chosenCard);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user