mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
Use specialized map in PreferencesStore,
QuestUtilCards - use different booster templates for shop and awarded boosters QuestWinLose - simplified code
This commit is contained in:
@@ -34,6 +34,7 @@ import forge.Card;
|
|||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.card.BoosterTemplate;
|
import forge.card.BoosterTemplate;
|
||||||
import forge.card.CardEdition;
|
import forge.card.CardEdition;
|
||||||
|
import forge.card.IUnOpenedProduct;
|
||||||
import forge.card.UnOpenedProduct;
|
import forge.card.UnOpenedProduct;
|
||||||
import forge.control.FControl;
|
import forge.control.FControl;
|
||||||
import forge.game.GameEndReason;
|
import forge.game.GameEndReason;
|
||||||
@@ -398,13 +399,11 @@ public class QuestWinLose extends ControlWinLose {
|
|||||||
}
|
}
|
||||||
// Mulligan to zero
|
// Mulligan to zero
|
||||||
final int cntCardsHumanStartedWith = humanRating.getOpeningHandSize();
|
final int cntCardsHumanStartedWith = humanRating.getOpeningHandSize();
|
||||||
final int mulliganReward = Singletons.getModel().getQuestPreferences()
|
final int mulliganReward = Singletons.getModel().getQuestPreferences().getPrefInt(QPref.REWARDS_MULLIGAN0);
|
||||||
.getPrefInt(QPref.REWARDS_MULLIGAN0);
|
|
||||||
|
|
||||||
if (0 == cntCardsHumanStartedWith) {
|
if (0 == cntCardsHumanStartedWith) {
|
||||||
credGameplay += mulliganReward;
|
credGameplay += mulliganReward;
|
||||||
sb.append(String
|
sb.append(String.format("Mulliganed to zero and still won! " + "Bonus: %d credits.<br>", mulliganReward));
|
||||||
.format("Mulliganed to zero and still won! " + "Bonus: %d credits.<br>", mulliganReward));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Early turn bonus
|
// Early turn bonus
|
||||||
@@ -578,56 +577,29 @@ public class QuestWinLose extends ControlWinLose {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> chooseSets = new ArrayList<String>();
|
|
||||||
|
|
||||||
int maxChoices = 1;
|
int maxChoices = 1;
|
||||||
|
|
||||||
if (this.wonMatch) {
|
if (this.wonMatch) {
|
||||||
maxChoices++;
|
maxChoices++;
|
||||||
final int wins = qData.getAchievements().getWin();
|
final int wins = qData.getAchievements().getWin();
|
||||||
if (wins > 0 && (wins + 1) % 5 == 0) { maxChoices++; }
|
if (wins + 1 % 5 == 0) { maxChoices++; }
|
||||||
if (wins > 0 && (wins + 1) % 20 == 0) { maxChoices++; }
|
if (wins + 1 % 20 == 0) { maxChoices++; }
|
||||||
if (wins > 0 && (wins + 1) % 50 == 0) { maxChoices++; }
|
if (wins + 1 % 50 == 0) { maxChoices++; }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sets.size() > maxChoices) {
|
List<CardEdition> options = new ArrayList<CardEdition>();
|
||||||
if (maxChoices > 1) {
|
|
||||||
boolean[] choices = new boolean[sets.size()];
|
while(!sets.isEmpty() && maxChoices > 0) {
|
||||||
for (int i = 0; i < sets.size(); i++) {
|
int ix = MyRandom.getRandom().nextInt(sets.size());
|
||||||
choices[i] = false;
|
String set = sets.get(ix);
|
||||||
}
|
sets.remove(ix);
|
||||||
|
options.add(Singletons.getModel().getEditions().get(set));
|
||||||
int toEnable = maxChoices;
|
maxChoices--;
|
||||||
|
|
||||||
while (toEnable > 0) {
|
|
||||||
int index = MyRandom.getRandom().nextInt(sets.size());
|
|
||||||
if (!choices[index]) {
|
|
||||||
choices[index] = true;
|
|
||||||
toEnable--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < sets.size(); i++) {
|
|
||||||
if (choices[i]) {
|
|
||||||
chooseSets.add(sets.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
chooseSets.add(sets.get(MyRandom.getRandom().nextInt(sets.size())));
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
chooseSets.addAll(sets);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final String setPrompt = "Choose bonus booster set:";
|
final CardEdition chooseEd = GuiChoose.one("Choose bonus booster set:", options);
|
||||||
List<CardEdition> chooseEditions = new ArrayList<CardEdition>();
|
|
||||||
for (String ed : chooseSets) {
|
|
||||||
chooseEditions.add(Singletons.getModel().getEditions().get(ed));
|
|
||||||
}
|
|
||||||
final CardEdition chooseEd = GuiChoose.one(setPrompt, chooseEditions);
|
|
||||||
|
|
||||||
cardsWon = (new UnOpenedProduct(Singletons.getModel().getBoosters().get(chooseEd.getCode()))).get();
|
IUnOpenedProduct product = new UnOpenedProduct(Singletons.getModel().getBoosters().get(chooseEd.getCode()));
|
||||||
|
cardsWon = product.get();
|
||||||
qData.getCards().addAllCards(cardsWon);
|
qData.getCards().addAllCards(cardsWon);
|
||||||
this.lblTemp1 = new TitleLabel("Bonus " + chooseEd.getName() + " booster pack!");
|
this.lblTemp1 = new TitleLabel("Bonus " + chooseEd.getName() + " booster pack!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class ForgePreferences extends PreferencesStore<ForgePreferences.FPref> {
|
|||||||
UI_PREFERRED_AVATARS_ONLY ("false"),
|
UI_PREFERRED_AVATARS_ONLY ("false"),
|
||||||
UI_TARGETING_OVERLAY ("false"),
|
UI_TARGETING_OVERLAY ("false"),
|
||||||
UI_ENABLE_SOUNDS ("true"),
|
UI_ENABLE_SOUNDS ("true"),
|
||||||
UI_ALT_SOUND_SYSTEM ("false"),
|
UI_ALT_SOUND_SYSTEM ("false"),
|
||||||
UI_RANDOM_CARD_ART ("false"),
|
UI_RANDOM_CARD_ART ("false"),
|
||||||
UI_CURRENT_AI_PROFILE (AiProfileUtil.AI_PROFILE_RANDOM_MATCH),
|
UI_CURRENT_AI_PROFILE (AiProfileUtil.AI_PROFILE_RANDOM_MATCH),
|
||||||
UI_CLONE_MODE_SOURCE ("false"), /** */
|
UI_CLONE_MODE_SOURCE ("false"), /** */
|
||||||
@@ -138,7 +138,7 @@ public class ForgePreferences extends PreferencesStore<ForgePreferences.FPref> {
|
|||||||
|
|
||||||
/** Instantiates a ForgePreferences object. */
|
/** Instantiates a ForgePreferences object. */
|
||||||
public ForgePreferences() {
|
public ForgePreferences() {
|
||||||
super(NewConstants.MAIN_PREFS_FILE);
|
super(NewConstants.MAIN_PREFS_FILE, FPref.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ package forge.properties;
|
|||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.EnumMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -31,11 +31,12 @@ import forge.util.FileUtil;
|
|||||||
* Loads preferred values when instantiated.
|
* Loads preferred values when instantiated.
|
||||||
* If a requested value is not present, default is returned.
|
* If a requested value is not present, default is returned.
|
||||||
*/
|
*/
|
||||||
public abstract class PreferencesStore<T extends Enum<?>> {
|
public abstract class PreferencesStore<T extends Enum<T>> {
|
||||||
private final Map<T, String> preferenceValues = new HashMap<T, String>();
|
private final Map<T, String> preferenceValues;
|
||||||
private final String filename;
|
private final String filename;
|
||||||
|
|
||||||
public PreferencesStore(String filename0) {
|
public PreferencesStore(String filename0, Class<T> clasz) {
|
||||||
|
preferenceValues = new EnumMap<T, String>(clasz);
|
||||||
filename = filename0;
|
filename = filename0;
|
||||||
|
|
||||||
List<String> lines = FileUtil.readFile(filename);
|
List<String> lines = FileUtil.readFile(filename);
|
||||||
|
|||||||
@@ -503,14 +503,23 @@ public final class QuestUtilCards {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private SealedProductTemplate getBoosterTemplate() {
|
private SealedProductTemplate getShopBoosterTemplate() {
|
||||||
return new SealedProductTemplate(Lists.newArrayList(
|
return new SealedProductTemplate(Lists.newArrayList(
|
||||||
Pair.of(BoosterGenerator.COMMON, this.qpref.getPrefInt(QPref.SHOP_SINGLES_COMMON)),
|
Pair.of(BoosterGenerator.COMMON, this.qpref.getPrefInt(QPref.SHOP_SINGLES_COMMON)),
|
||||||
Pair.of(BoosterGenerator.UNCOMMON, this.qpref.getPrefInt(QPref.SHOP_SINGLES_UNCOMMON)),
|
Pair.of(BoosterGenerator.UNCOMMON, this.qpref.getPrefInt(QPref.SHOP_SINGLES_UNCOMMON)),
|
||||||
Pair.of(BoosterGenerator.RARE_MYTHIC, this.qpref.getPrefInt(QPref.SHOP_SINGLES_RARE))
|
Pair.of(BoosterGenerator.RARE_MYTHIC, this.qpref.getPrefInt(QPref.SHOP_SINGLES_RARE))
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private SealedProductTemplate getBoosterTemplate() {
|
||||||
|
return new SealedProductTemplate(Lists.newArrayList(
|
||||||
|
Pair.of(BoosterGenerator.COMMON, this.qpref.getPrefInt(QPref.BOOSTER_COMMONS)),
|
||||||
|
Pair.of(BoosterGenerator.UNCOMMON, this.qpref.getPrefInt(QPref.BOOSTER_UNCOMMONS)),
|
||||||
|
Pair.of(BoosterGenerator.RARE_MYTHIC, this.qpref.getPrefInt(QPref.BOOSTER_RARES))
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate cards in shop.
|
* Generate cards in shop.
|
||||||
*/
|
*/
|
||||||
@@ -526,7 +535,7 @@ public final class QuestUtilCards {
|
|||||||
final int totalPacks = Math.min(levelPacks + winPacks, maxPacks);
|
final int totalPacks = Math.min(levelPacks + winPacks, maxPacks);
|
||||||
|
|
||||||
|
|
||||||
SealedProductTemplate tpl = getBoosterTemplate();
|
SealedProductTemplate tpl = getShopBoosterTemplate();
|
||||||
UnOpenedProduct unopened = qc.getFormat() == null ? new UnOpenedProduct( tpl ) : new UnOpenedProduct( tpl, qc.getFormat().getFilterPrinted());
|
UnOpenedProduct unopened = qc.getFormat() == null ? new UnOpenedProduct( tpl ) : new UnOpenedProduct( tpl, qc.getFormat().getFilterPrinted());
|
||||||
|
|
||||||
for (int i = 0; i < totalPacks; i++) {
|
for (int i = 0; i < totalPacks; i++) {
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ public class QuestPreferences extends PreferencesStore<QuestPreferences.QPref> i
|
|||||||
|
|
||||||
/** Instantiates a QuestPreferences object. */
|
/** Instantiates a QuestPreferences object. */
|
||||||
public QuestPreferences() {
|
public QuestPreferences() {
|
||||||
super(NewConstants.QUEST_PREFS_FILE);
|
super(NewConstants.QUEST_PREFS_FILE, QPref.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected QPref[] getEnumValues() {
|
protected QPref[] getEnumValues() {
|
||||||
|
|||||||
Reference in New Issue
Block a user