Quest set unlocks logics written from scratch

This commit is contained in:
Maxmtg
2012-11-15 21:08:51 +00:00
parent f16902c415
commit b0264f9a47
9 changed files with 172 additions and 234 deletions

View File

@@ -20,6 +20,8 @@ package forge.card;
import java.util.Map;
import java.util.TreeMap;
import com.google.common.base.Function;
import forge.util.StorageView;
public final class EditionCollection extends StorageView<CardEdition> {
@@ -78,5 +80,12 @@ public final class EditionCollection extends StorageView<CardEdition> {
final CardEdition set = this.get(code);
return set == null ? "" : set.getCode2();
}
public final Function<String, CardEdition> FN_EDITION_BY_CODE = new Function<String, CardEdition>() {
@Override
public CardEdition apply(String code) {
return EditionCollection.this.get(code);
};
};
}

View File

@@ -48,7 +48,7 @@ public enum CSubmenuChallenges implements ICDoc {
view.getBtnUnlock().setCommand(
new Command() { @Override
public void execute() { SSubmenuQuestUtil.showSetUnlock(); } });
public void execute() { SSubmenuQuestUtil.chooseAndUnlockEdition(); CSubmenuChallenges.this.update(); } });
view.getBtnStart().addActionListener(
new ActionListener() { @Override

View File

@@ -43,7 +43,7 @@ public enum CSubmenuDuels implements ICDoc {
view.getBtnUnlock().setCommand(
new Command() { @Override
public void execute() { SSubmenuQuestUtil.showSetUnlock(); } });
public void execute() { SSubmenuQuestUtil.chooseAndUnlockEdition(); CSubmenuDuels.this.update();} });
view.getBtnStart().addActionListener(
new ActionListener() { @Override

View File

@@ -9,6 +9,9 @@ import java.util.Map;
import java.util.Map.Entry;
import javax.swing.JOptionPane;
import com.sun.mail.iap.Argument;
import forge.Command;
import forge.deck.Deck;
import forge.Singletons;
@@ -19,6 +22,7 @@ import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import forge.quest.QuestController;
import forge.quest.QuestMode;
import forge.quest.StartingPoolType;
import forge.quest.data.GameFormatQuest;
import forge.quest.data.QuestData;
import forge.quest.data.QuestPreferences.QPref;
@@ -181,23 +185,8 @@ public enum CSubmenuQuestData implements ICDoc {
}
GameFormat fmtPrizes = null;
switch(view.getPrizedPoolType()) {
case Complete:
fmtPrizes = null;
break;
case CustomFormat:
if ( customPrizeFormatCodes.isEmpty() )
{
int answer = JOptionPane.showConfirmDialog(null, "You have defined custom format as containing no sets.\nThis will choose all editions without restriction as prized.\n\nContinue?");
if ( JOptionPane.YES_OPTION != answer )
return;
}
fmtPrizes = customPrizeFormatCodes.isEmpty() ? null : new GameFormat("Custom Prizes", customPrizeFormatCodes, null); // chosen sets and no banend cards
break;
case Rotating:
fmtPrizes = view.getPrizedRotatingFormat();
break;
default: // same as starting
StartingPoolType prizedPoolType = view.getPrizedPoolType();
if ( null == prizedPoolType ) {
fmtPrizes = fmtStartPool;
if ( null == fmtPrizes && dckStartPool != null) { // build it form deck
List<String> sets = new ArrayList<String>();
@@ -213,10 +202,27 @@ public enum CSubmenuQuestData implements ICDoc {
}
fmtPrizes = new GameFormat("From deck", sets, null);
}
break;
}
} else
switch(prizedPoolType) {
case Complete:
fmtPrizes = null;
break;
case CustomFormat:
if ( customPrizeFormatCodes.isEmpty() )
{
int answer = JOptionPane.showConfirmDialog(null, "You have defined custom format as containing no sets.\nThis will choose all editions without restriction as prized.\n\nContinue?");
if ( JOptionPane.YES_OPTION != answer )
return;
}
fmtPrizes = customPrizeFormatCodes.isEmpty() ? null : new GameFormat("Custom Prizes", customPrizeFormatCodes, null); // chosen sets and no banend cards
break;
case Rotating:
fmtPrizes = view.getPrizedRotatingFormat();
break;
default:
throw new RuntimeException("Should not get this result");
}
final Object o = JOptionPane.showInputDialog(null, "Poets will remember your quest as:", "Quest Name", JOptionPane.OK_CANCEL_OPTION);
if (o == null) { return; }

View File

@@ -8,6 +8,8 @@ import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import org.apache.commons.lang3.tuple.ImmutablePair;
import com.google.common.base.Supplier;
import forge.Card;
@@ -160,11 +162,8 @@ public class SSubmenuQuestUtil {
view0.getLblLosses().setText("Losses: " + qA.getLost());
// Show or hide the set unlocking button
if (qCtrl.getFormatNumberUnlockable() > 0) {
view0.getBtnUnlock().setVisible(true);
} else {
view0.getBtnUnlock().setVisible(false);
}
view0.getBtnUnlock().setVisible(qCtrl.getUnlocksTokens() > 0);
// Challenge in wins
final int num = SSubmenuQuestUtil.nextChallengeInWins();
@@ -245,12 +244,20 @@ public class SSubmenuQuestUtil {
}
/** */
public static void showSetUnlock() {
public static void chooseAndUnlockEdition() {
final QuestController qData = Singletons.getModel().getQuest();
CardEdition toUnlock = QuestUtilUnlockSets.unlockSet(qData, false, null);
if (toUnlock != null) {
QuestUtilUnlockSets.doUnlock(qData, toUnlock);
ImmutablePair<CardEdition, Integer> toUnlock = QuestUtilUnlockSets.chooseSetToUnlock(qData, false, null);
if (toUnlock == null) {
return;
}
CardEdition unlocked = toUnlock.left;
qData.getAssets().subtractCredits(toUnlock.right);
JOptionPane.showMessageDialog(null, "You have successfully unlocked " + unlocked.getName() + "!",
unlocked.getName() + " unlocked!",
JOptionPane.PLAIN_MESSAGE);
QuestUtilUnlockSets.doUnlock(qData, unlocked);
}
/** */

View File

@@ -338,24 +338,18 @@ public class QuestController {
* Quest format has unlockable sets available at the moment.
* @return int number of unlockable sets.
*/
public int getFormatNumberUnlockable() {
if (this.questFormat == null) {
public int getUnlocksTokens() {
if (this.questFormat == null || !this.questFormat.canUnlockSets()) {
return 0;
}
final int wins = this.model.getAchievements().getWin();
if (wins < 10) {
return 0;
}
int toUnlock = this.questFormat.getExcludedSetCodes().size();
if (toUnlock > 1 + wins / 50) {
toUnlock = 1 + wins / 50;
}
if (toUnlock > 8) {
toUnlock = 8;
}
return toUnlock;
int cntLocked = this.questFormat.getLockedSets().size();
int unlocksAvaliable = wins / 20;
int unlocksSpent = this.questFormat.getUnlocksUsed();
return unlocksAvaliable > unlocksSpent ? Math.min(unlocksAvaliable - unlocksSpent, cntLocked) : 0;
}
}

View File

@@ -19,12 +19,15 @@ package forge.quest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import javax.swing.JOptionPane;
import org.apache.commons.lang3.tuple.ImmutablePair;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import forge.Singletons;
import forge.card.BoosterData;
import forge.card.CardEdition;
@@ -33,6 +36,7 @@ import forge.gui.CardListViewer;
import forge.gui.GuiChoose;
import forge.item.CardPrinted;
import forge.quest.io.ReadPriceList;
import forge.util.IStorageView;
/**
* This is a helper class for unlocking new sets during a format-limited
@@ -48,78 +52,61 @@ public class QuestUtilUnlockSets {
* @param presetChoices List<CardEdition> a pregenerated list of options, NOT IMPLEMENTED YET
* @return CardEdition, the unlocked edition if any.
*/
public static CardEdition unlockSet(final QuestController qData, final boolean freeUnlock,
public static ImmutablePair<CardEdition, Integer> chooseSetToUnlock(final QuestController qData, final boolean freeUnlock,
List<CardEdition> presetChoices) {
if (qData.getFormat() == null || qData.getFormat().getExcludedSetCodes().isEmpty()) {
return null;
}
List<CardEdition> choices = unlockableSets(qData);
if (choices == null || choices.size() < 1) {
if (qData.getFormat() == null || !qData.getFormat().canUnlockSets()) {
return null;
}
final ReadPriceList prices = new ReadPriceList();
final Map<String, Integer> mapPrices = prices.getPriceList();
final List<ImmutablePair<CardEdition, Integer>> setPrices = new ArrayList<ImmutablePair<CardEdition,Integer>>();
List<Long> unlockPrices = new ArrayList<Long>();
for (int i = 0; i < choices.size(); i++) {
if (mapPrices.containsKey(choices.get(i).getName() + " Booster Pack")) {
long newPrice = new Double(60 * Math.pow(Math.sqrt(mapPrices.get(choices.get(i).getName() + " Booster Pack")), 1.65)).longValue();
if (newPrice < 7500) { newPrice = 7500; }
unlockPrices.add(newPrice);
}
else {
unlockPrices.add((long) 7500);
for (CardEdition ed : getUnlockableEditions(qData)) {
int price = 7500;
if (mapPrices.containsKey(ed.getName() + " Booster Pack")) {
price = Math.max( 50 * mapPrices.get(ed.getName() + " Booster Pack"), 7500 );
}
setPrices.add(ImmutablePair.of(ed, price));
}
final String setPrompt = "You have " + qData.getAssets().getCredits() + " credits. Unlock:";
List<String> options = new ArrayList<String>();
for (int i = 0; i < choices.size(); i++) {
options.add(choices.get(i).getName() + " [PRICE: " + unlockPrices.get(i) + " credits]");
for (ImmutablePair<CardEdition, Integer> ee : setPrices) {
options.add(String.format("%s [PRICE: %d credits]", ee.left.getName(), ee.right));
}
final String choice = GuiChoose.oneOrNone(setPrompt, options);
CardEdition chooseEd = null;
long price = 0;
if (choice == null) {
int index = options.indexOf(GuiChoose.oneOrNone(setPrompt, options));
if (index < 0 || index >= options.size()) {
return null;
}
/* Examine choice */
for (int i = 0; i < options.size(); i++) {
if (choice.equals(options.get(i))) {
chooseEd = choices.get(i);
price = unlockPrices.get(i);
break;
}
}
ImmutablePair<CardEdition, Integer> toBuy = setPrices.get(index);
int price = toBuy.right;
CardEdition choosenEdition = toBuy.left;
if (qData.getAssets().getCredits() < price) {
JOptionPane.showMessageDialog(null, "Unfortunately, you cannot afford that set yet.\n"
+ "To unlock " + chooseEd.getName() + ", you need " + price + " credits.\n"
+ "To unlock " + choosenEdition.getName() + ", you need " + price + " credits.\n"
+ "You have only " + qData.getAssets().getCredits() + " credits.",
"Failed to unlock " + chooseEd.getName(),
"Failed to unlock " + choosenEdition.getName(),
JOptionPane.PLAIN_MESSAGE);
return null;
}
final int unlockConfirm = JOptionPane.showConfirmDialog(null,
"Unlocking " + chooseEd.getName() + " will cost you " + price + " credits.\n"
"Unlocking " + choosenEdition.getName() + " will cost you " + price + " credits.\n"
+ "You have " + qData.getAssets().getCredits() + " credits.\n\n"
+ "Are you sure you want to unlock " + chooseEd.getName() + "?",
"Confirm Unlocking " + chooseEd.getName(), JOptionPane.YES_NO_OPTION);
+ "Are you sure you want to unlock " + choosenEdition.getName() + "?",
"Confirm Unlocking " + choosenEdition.getName(), JOptionPane.YES_NO_OPTION);
if (unlockConfirm == JOptionPane.NO_OPTION) {
return null;
}
qData.getAssets().subtractCredits(price);
JOptionPane.showMessageDialog(null, "You have successfully unlocked " + chooseEd.getName() + "!",
chooseEd.getName() + " unlocked!",
JOptionPane.PLAIN_MESSAGE);
return chooseEd;
return toBuy;
}
/**
@@ -127,110 +114,53 @@ public class QuestUtilUnlockSets {
*
* @return unmodifiable list, assorted sets that are not currently in the format.
*/
private static List<CardEdition> unlockableSets(final QuestController qData) {
if (qData.getFormat() == null || qData.getFormat().getExcludedSetCodes().isEmpty()) {
return null;
private static final List<CardEdition> emptyEditions = Collections.unmodifiableList(new ArrayList<CardEdition>());
private static List<CardEdition> getUnlockableEditions(final QuestController qData) {
if (qData.getFormat() == null || !qData.getFormat().canUnlockSets()) {
return emptyEditions;
}
final int nrChoices = qData.getFormatNumberUnlockable();
final int nrChoices = qData.getUnlocksTokens();
if (nrChoices < 1) { // Should never happen if we made it this far but better safe than sorry...
throw new RuntimeException("BUG? Could not find unlockable sets even though we should.");
}
List<CardEdition> options = new ArrayList<CardEdition>();
// Sort current sets by index
TreeMap<Integer, CardEdition> sortedFormat = new TreeMap<Integer, CardEdition>();
for (String edCode : qData.getFormat().getAllowedSetCodes()) {
sortedFormat.put(new Integer(Singletons.getModel().getEditions().get(edCode).getIndex()), Singletons.getModel().getEditions().get(edCode));
}
List<CardEdition> currentSets = new ArrayList<CardEdition>(sortedFormat.values());
List<CardEdition> allowedSets = Lists.newArrayList(Iterables.transform(qData.getFormat().getAllowedSetCodes(), Singletons.getModel().getEditions().FN_EDITION_BY_CODE));
Collections.sort(allowedSets);
// Sort unlockable sets by index
TreeMap<Integer, CardEdition> sortedExcluded = new TreeMap<Integer, CardEdition>();
for (String edCode : qData.getFormat().getExcludedSetCodes()) {
sortedExcluded.put(new Integer(Singletons.getModel().getEditions().get(edCode).getIndex()), Singletons.getModel().getEditions().get(edCode));
}
List<CardEdition> excludedSets = new ArrayList<CardEdition>(sortedExcluded.values());
// Collect 'previous' and 'next' editions
CardEdition first = currentSets.get(0);
CardEdition last = currentSets.get(currentSets.size() - 1);
List<CardEdition> fillers = new ArrayList<CardEdition>();
// Add nearby sets first
for (CardEdition ce : excludedSets) {
if (first.getIndex() == ce.getIndex() + 1 || last.getIndex() + 1 == ce.getIndex())
{
options.add(ce);
// System.out.println("Added adjacent set: " + ce.getName());
List<CardEdition> excludedSets = Lists.newArrayList(Iterables.transform(qData.getFormat().getLockedSets(), Singletons.getModel().getEditions().FN_EDITION_BY_CODE));
Collections.sort(excludedSets);
// get a number of sets between an excluded and any included set
List<ImmutablePair<CardEdition, Integer>> excludedWithDistances = new ArrayList<ImmutablePair<CardEdition,Integer>>();
for(CardEdition ex : excludedSets) {
int distance = Integer.MAX_VALUE;
for(CardEdition in : allowedSets) {
int d = Math.abs(ex.getIndex() - in.getIndex());
if ( d < distance )
distance = d;
}
excludedWithDistances.add(ImmutablePair.of(ex, distance));
}
// Fill in the in-between sets
int j = 0;
// Find the first excluded set between current sets first and current sets last
while (j < excludedSets.size() && excludedSets.get(j).getIndex() < currentSets.get(0).getIndex()) {
j++;
}
// Consider all sets until current sets last
while (j < excludedSets.size() && excludedSets.get(j).getIndex() < currentSets.get(currentSets.size() - 1).getIndex()) {
if (!options.contains(excludedSets.get(j)) && !fillers.contains(excludedSets.get(j))) {
// System.out.println("Added in-between set " + excludedSets.get(j).getCode());
fillers.add(excludedSets.get(j));
}
j++;
}
// Add more nearby sets
for (CardEdition ce : excludedSets) {
if (first.getIndex() == ce.getIndex() + 2 || last.getIndex() + 2 == ce.getIndex())
{
if (!fillers.contains(ce) && !options.contains(ce)) {
fillers.add(ce);
// System.out.println("Added adjacent filler set: " + ce.getName());
}
}
}
// sort by distance, then by code desc
Collections.sort(excludedWithDistances, new Comparator<ImmutablePair<CardEdition, Integer>>() {
@Override
public int compare(ImmutablePair<CardEdition, Integer> o1, ImmutablePair<CardEdition, Integer> o2) {
int d1 = o2.right - o1.right;
return d1 != 0 ? d1 : o1.left.getIndex() - o2.left.getIndex();
}
});
// Look for nearby core sets or block starting sets...
for (BoosterData bd : Singletons.getModel().getTournamentPacks()) {
if (qData.getFormat().getExcludedSetCodes().contains(bd.getEdition())
&& !(fillers.contains(Singletons.getModel().getEditions().get(bd.getEdition())))
&& !(options.contains(Singletons.getModel().getEditions().get(bd.getEdition())))) {
// Set is not yet on any of the lists, see if it is 'close' to any of the sets we currently have
CardEdition curEd = Singletons.getModel().getEditions().get(bd.getEdition());
int edIdx = curEd.getIndex();
for (String cmpCode : qData.getFormat().getAllowedSetCodes()) {
int cmpIdx = Singletons.getModel().getEditions().get(cmpCode).getIndex();
// Note that we need to check for fillers.contains() again inside this 'for' loop!
if (!fillers.contains(curEd) && (cmpIdx == edIdx + 1 || edIdx == cmpIdx + 1)) {
fillers.add(curEd);
// System.out.println("Added nearby starter/core set " + curEd.getName());
}
else if (!fillers.contains(curEd) && (cmpIdx == edIdx + 2 || edIdx == cmpIdx + 2)) {
fillers.add(curEd);
//System.out.println("Added nearby2 starter/core set " + curEd.getName());
}
}
}
}
// Add padding if necessary
if (fillers.size() + options.size() < nrChoices && excludedSets.size() > fillers.size() + options.size()) {
// Pad in order.
for (CardEdition ce : excludedSets) {
if (!fillers.contains(ce) && !options.contains(ce)) {
fillers.add(ce);
if (fillers.size() + options.size() >= nrChoices) {
break;
}
}
}
}
for (int i = 0; (options.size() < nrChoices) && i < fillers.size(); i++) {
options.add(fillers.get(i));
for (ImmutablePair<CardEdition, Integer> set : excludedWithDistances) {
options.add(set.left);
// System.out.println("Padded with: " + fillers.get(i).getName());
}
Collections.reverse(options);
return Collections.unmodifiableList(options);
}
@@ -243,30 +173,26 @@ public class QuestUtilUnlockSets {
*/
public static void doUnlock(QuestController qData, final CardEdition unlockedSet) {
IStorageView<BoosterData> starters = Singletons.getModel().getTournamentPacks();
IStorageView<BoosterData> boosters = Singletons.getModel().getBoosters();
qData.getFormat().unlockSet(unlockedSet.getCode());
List<CardPrinted> displayCards = new ArrayList<CardPrinted>();
List<CardPrinted> cardsWon = new ArrayList<CardPrinted>();
if (Singletons.getModel().getTournamentPacks().contains(unlockedSet.getCode())) {
final List<CardPrinted> cardsWon = (new UnOpenedProduct(Singletons.getModel().getTournamentPacks().get(unlockedSet.getCode()))).open();
qData.getCards().addAllCards(cardsWon);
displayCards.addAll(cardsWon);
if (starters.contains(unlockedSet.getCode())) {
UnOpenedProduct starter = new UnOpenedProduct(starters.get(unlockedSet.getCode()));
cardsWon.addAll(starter.open());
}
else if (Singletons.getModel().getBoosters().contains(unlockedSet.getCode())) {
for (int i = 0; i < 3; i++) {
final List<CardPrinted> cardsWon = (new UnOpenedProduct(Singletons.getModel().getBoosters().get(unlockedSet.getCode()))).open();
qData.getCards().addAllCards(cardsWon);
displayCards.addAll(cardsWon);
}
else if (boosters.contains(unlockedSet.getCode())) {
UnOpenedProduct booster = new UnOpenedProduct(boosters.get(unlockedSet.getCode()));
cardsWon.addAll(booster.open());
cardsWon.addAll(booster.open());
cardsWon.addAll(booster.open());
}
final CardListViewer cardView = new CardListViewer(unlockedSet.getName(),
"You get the following bonus cards:", displayCards);
qData.getCards().addAllCards(cardsWon);
final CardListViewer cardView = new CardListViewer(unlockedSet.getName(), "You get the following bonus cards:", cardsWon);
cardView.show();
qData.save();
}
}

View File

@@ -17,7 +17,6 @@
*/
package forge.quest.data;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
@@ -36,7 +35,8 @@ import forge.game.GameFormat;
*/
public final class GameFormatQuest extends GameFormat {
private boolean allowUnlocks = true;
private final boolean allowUnlocks;
private int unlocksUsed = 0;
/**
* Instantiates a new game format based on two lists.
@@ -50,6 +50,7 @@ public final class GameFormatQuest extends GameFormat {
*/
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) {
@@ -64,50 +65,29 @@ public final class GameFormatQuest extends GameFormat {
* @param allowSetUnlocks
*/
public GameFormatQuest(final GameFormat toCopy, boolean allowSetUnlocks) {
this(toCopy.getName(), toCopy.getAllowedSetCodes(), toCopy.getBannedCardNames());
super(toCopy.getName(), toCopy.getAllowedSetCodes(), toCopy.getBannedCardNames());
allowUnlocks = allowSetUnlocks;
}
/**
*
* Updates the filters based on the current list data.
*/
public void updateFilters() {
// nothing to do here.
// predicates hold references to lists and thus get auto updated.
// remove this method after reading.
}
/**
* Empty the whole list.
*/
public void emptyAllowedSets() {
if (allowedSetCodes.isEmpty()) {
return;
}
allowedSetCodes.clear();
}
/**
* Get the list of excluded sets.
*
* @return unmodifiable list of excluded sets.
*/
public List<String> getExcludedSetCodes() {
if (this.allowedSetCodes.isEmpty()) {
return null;
}
public List<String> getLockedSets() {
List<String> exSets = new ArrayList<String>();
if (this.allowedSetCodes.isEmpty()) {
return exSets;
}
for (CardEdition ce : Singletons.getModel().getEditions()) {
if (!isSetLegal(ce.getCode())) {
exSets.add(ce.getCode());
}
}
return Collections.unmodifiableList(exSets);
return exSets;
}
/**
@@ -116,13 +96,11 @@ public final class GameFormatQuest extends GameFormat {
* @param setCode String, set code.
*/
public void unlockSet(final String setCode) {
if (this.allowedSetCodes.isEmpty()) {
return; // We are already allowing all sets!
} else if (this.allowedSetCodes.contains(setCode)) {
return; // Already on the list
if (!canUnlockSets() || this.allowedSetCodes.isEmpty() || this.allowedSetCodes.contains(setCode)) {
return;
}
this.allowedSetCodes.add(setCode);
updateFilters();
unlocksUsed++;
}
/**
@@ -138,6 +116,11 @@ public final class GameFormatQuest extends GameFormat {
return allowUnlocks;
}
public int getUnlocksUsed() {
return unlocksUsed;
}
/**
* The Class Predicates.
*/

View File

@@ -391,6 +391,8 @@ public class QuestDataIO {
writer.startNode("format");
GameFormatQuest format = (GameFormatQuest) source;
writer.addAttribute("name", format.getName());
writer.addAttribute("unlocksUsed", Integer.toString(format.getUnlocksUsed()));
writer.addAttribute("canUnlock", format.canUnlockSets() ? "1" : "0");
writer.endNode();
for (String set : format.getAllowedSetCodes()) {
@@ -409,6 +411,8 @@ public class QuestDataIO {
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
reader.moveDown();
String name = reader.getAttribute("name");
String unlocksUsed = reader.getAttribute("unlocksUsed");
boolean canUnlock = !("0".equals(reader.getAttribute("canUnlock")));
List<String> allowedSets = new ArrayList<String>();
List<String> bannedCards = new ArrayList<String>();
reader.moveUp();
@@ -425,7 +429,21 @@ public class QuestDataIO {
}
reader.moveUp();
}
return new GameFormatQuest(name, allowedSets, bannedCards);
GameFormatQuest res = new GameFormatQuest(name, allowedSets, bannedCards);
try {
if ( StringUtils.isNotEmpty(unlocksUsed)) {
setFinalField(GameFormatQuest.class, "unlocksUsed", res, Integer.parseInt(unlocksUsed));
}
setFinalField(GameFormatQuest.class, "allowUnlocks", res, canUnlock);
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
return res;
}
}
@@ -444,12 +462,7 @@ public class QuestDataIO {
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
final String value = reader.getValue();
return GameType.smartValueOf(value, GameType.Quest); // does not
// matter -
// this field
// is
// deprecated
// anyway
return GameType.smartValueOf(value, GameType.Quest);
}
}