mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Quest set unlocks logics written from scratch
This commit is contained in:
@@ -20,6 +20,8 @@ package forge.card;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
import forge.util.StorageView;
|
import forge.util.StorageView;
|
||||||
|
|
||||||
public final class EditionCollection extends StorageView<CardEdition> {
|
public final class EditionCollection extends StorageView<CardEdition> {
|
||||||
@@ -78,5 +80,12 @@ public final class EditionCollection extends StorageView<CardEdition> {
|
|||||||
final CardEdition set = this.get(code);
|
final CardEdition set = this.get(code);
|
||||||
return set == null ? "" : set.getCode2();
|
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);
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public enum CSubmenuChallenges implements ICDoc {
|
|||||||
|
|
||||||
view.getBtnUnlock().setCommand(
|
view.getBtnUnlock().setCommand(
|
||||||
new Command() { @Override
|
new Command() { @Override
|
||||||
public void execute() { SSubmenuQuestUtil.showSetUnlock(); } });
|
public void execute() { SSubmenuQuestUtil.chooseAndUnlockEdition(); CSubmenuChallenges.this.update(); } });
|
||||||
|
|
||||||
view.getBtnStart().addActionListener(
|
view.getBtnStart().addActionListener(
|
||||||
new ActionListener() { @Override
|
new ActionListener() { @Override
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public enum CSubmenuDuels implements ICDoc {
|
|||||||
|
|
||||||
view.getBtnUnlock().setCommand(
|
view.getBtnUnlock().setCommand(
|
||||||
new Command() { @Override
|
new Command() { @Override
|
||||||
public void execute() { SSubmenuQuestUtil.showSetUnlock(); } });
|
public void execute() { SSubmenuQuestUtil.chooseAndUnlockEdition(); CSubmenuDuels.this.update();} });
|
||||||
|
|
||||||
view.getBtnStart().addActionListener(
|
view.getBtnStart().addActionListener(
|
||||||
new ActionListener() { @Override
|
new ActionListener() { @Override
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ import java.util.Map;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
|
import com.sun.mail.iap.Argument;
|
||||||
|
|
||||||
import forge.Command;
|
import forge.Command;
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
@@ -19,6 +22,7 @@ import forge.properties.ForgeProps;
|
|||||||
import forge.properties.NewConstants;
|
import forge.properties.NewConstants;
|
||||||
import forge.quest.QuestController;
|
import forge.quest.QuestController;
|
||||||
import forge.quest.QuestMode;
|
import forge.quest.QuestMode;
|
||||||
|
import forge.quest.StartingPoolType;
|
||||||
import forge.quest.data.GameFormatQuest;
|
import forge.quest.data.GameFormatQuest;
|
||||||
import forge.quest.data.QuestData;
|
import forge.quest.data.QuestData;
|
||||||
import forge.quest.data.QuestPreferences.QPref;
|
import forge.quest.data.QuestPreferences.QPref;
|
||||||
@@ -181,23 +185,8 @@ public enum CSubmenuQuestData implements ICDoc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GameFormat fmtPrizes = null;
|
GameFormat fmtPrizes = null;
|
||||||
switch(view.getPrizedPoolType()) {
|
StartingPoolType prizedPoolType = view.getPrizedPoolType();
|
||||||
case Complete:
|
if ( null == prizedPoolType ) {
|
||||||
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
|
|
||||||
fmtPrizes = fmtStartPool;
|
fmtPrizes = fmtStartPool;
|
||||||
if ( null == fmtPrizes && dckStartPool != null) { // build it form deck
|
if ( null == fmtPrizes && dckStartPool != null) { // build it form deck
|
||||||
List<String> sets = new ArrayList<String>();
|
List<String> sets = new ArrayList<String>();
|
||||||
@@ -213,8 +202,25 @@ public enum CSubmenuQuestData implements ICDoc {
|
|||||||
}
|
}
|
||||||
fmtPrizes = new GameFormat("From deck", sets, null);
|
fmtPrizes = new GameFormat("From deck", sets, null);
|
||||||
}
|
}
|
||||||
|
} else
|
||||||
|
switch(prizedPoolType) {
|
||||||
|
case Complete:
|
||||||
|
fmtPrizes = null;
|
||||||
break;
|
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import javax.swing.JOptionPane;
|
|||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.SwingWorker;
|
import javax.swing.SwingWorker;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||||
|
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
|
||||||
import forge.Card;
|
import forge.Card;
|
||||||
@@ -160,11 +162,8 @@ public class SSubmenuQuestUtil {
|
|||||||
view0.getLblLosses().setText("Losses: " + qA.getLost());
|
view0.getLblLosses().setText("Losses: " + qA.getLost());
|
||||||
|
|
||||||
// Show or hide the set unlocking button
|
// Show or hide the set unlocking button
|
||||||
if (qCtrl.getFormatNumberUnlockable() > 0) {
|
|
||||||
view0.getBtnUnlock().setVisible(true);
|
view0.getBtnUnlock().setVisible(qCtrl.getUnlocksTokens() > 0);
|
||||||
} else {
|
|
||||||
view0.getBtnUnlock().setVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Challenge in wins
|
// Challenge in wins
|
||||||
final int num = SSubmenuQuestUtil.nextChallengeInWins();
|
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();
|
final QuestController qData = Singletons.getModel().getQuest();
|
||||||
CardEdition toUnlock = QuestUtilUnlockSets.unlockSet(qData, false, null);
|
ImmutablePair<CardEdition, Integer> toUnlock = QuestUtilUnlockSets.chooseSetToUnlock(qData, false, null);
|
||||||
if (toUnlock != null) {
|
if (toUnlock == null) {
|
||||||
QuestUtilUnlockSets.doUnlock(qData, toUnlock);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
|
|||||||
@@ -338,24 +338,18 @@ public class QuestController {
|
|||||||
* Quest format has unlockable sets available at the moment.
|
* Quest format has unlockable sets available at the moment.
|
||||||
* @return int number of unlockable sets.
|
* @return int number of unlockable sets.
|
||||||
*/
|
*/
|
||||||
public int getFormatNumberUnlockable() {
|
public int getUnlocksTokens() {
|
||||||
if (this.questFormat == null) {
|
if (this.questFormat == null || !this.questFormat.canUnlockSets()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int wins = this.model.getAchievements().getWin();
|
final int wins = this.model.getAchievements().getWin();
|
||||||
if (wins < 10) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int toUnlock = this.questFormat.getExcludedSetCodes().size();
|
int cntLocked = this.questFormat.getLockedSets().size();
|
||||||
if (toUnlock > 1 + wins / 50) {
|
int unlocksAvaliable = wins / 20;
|
||||||
toUnlock = 1 + wins / 50;
|
int unlocksSpent = this.questFormat.getUnlocksUsed();
|
||||||
}
|
|
||||||
if (toUnlock > 8) {
|
return unlocksAvaliable > unlocksSpent ? Math.min(unlocksAvaliable - unlocksSpent, cntLocked) : 0;
|
||||||
toUnlock = 8;
|
|
||||||
}
|
|
||||||
return toUnlock;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,12 +19,15 @@ package forge.quest;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
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.Singletons;
|
||||||
import forge.card.BoosterData;
|
import forge.card.BoosterData;
|
||||||
import forge.card.CardEdition;
|
import forge.card.CardEdition;
|
||||||
@@ -33,6 +36,7 @@ import forge.gui.CardListViewer;
|
|||||||
import forge.gui.GuiChoose;
|
import forge.gui.GuiChoose;
|
||||||
import forge.item.CardPrinted;
|
import forge.item.CardPrinted;
|
||||||
import forge.quest.io.ReadPriceList;
|
import forge.quest.io.ReadPriceList;
|
||||||
|
import forge.util.IStorageView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a helper class for unlocking new sets during a format-limited
|
* 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
|
* @param presetChoices List<CardEdition> a pregenerated list of options, NOT IMPLEMENTED YET
|
||||||
* @return CardEdition, the unlocked edition if any.
|
* @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) {
|
List<CardEdition> presetChoices) {
|
||||||
|
|
||||||
if (qData.getFormat() == null || qData.getFormat().getExcludedSetCodes().isEmpty()) {
|
if (qData.getFormat() == null || !qData.getFormat().canUnlockSets()) {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
List<CardEdition> choices = unlockableSets(qData);
|
|
||||||
|
|
||||||
if (choices == null || choices.size() < 1) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ReadPriceList prices = new ReadPriceList();
|
final ReadPriceList prices = new ReadPriceList();
|
||||||
final Map<String, Integer> mapPrices = prices.getPriceList();
|
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 (CardEdition ed : getUnlockableEditions(qData)) {
|
||||||
for (int i = 0; i < choices.size(); i++) {
|
int price = 7500;
|
||||||
if (mapPrices.containsKey(choices.get(i).getName() + " Booster Pack")) {
|
if (mapPrices.containsKey(ed.getName() + " Booster Pack")) {
|
||||||
long newPrice = new Double(60 * Math.pow(Math.sqrt(mapPrices.get(choices.get(i).getName() + " Booster Pack")), 1.65)).longValue();
|
price = Math.max( 50 * mapPrices.get(ed.getName() + " Booster Pack"), 7500 );
|
||||||
if (newPrice < 7500) { newPrice = 7500; }
|
|
||||||
unlockPrices.add(newPrice);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
unlockPrices.add((long) 7500);
|
|
||||||
}
|
}
|
||||||
|
setPrices.add(ImmutablePair.of(ed, price));
|
||||||
}
|
}
|
||||||
|
|
||||||
final String setPrompt = "You have " + qData.getAssets().getCredits() + " credits. Unlock:";
|
final String setPrompt = "You have " + qData.getAssets().getCredits() + " credits. Unlock:";
|
||||||
List<String> options = new ArrayList<String>();
|
List<String> options = new ArrayList<String>();
|
||||||
for (int i = 0; i < choices.size(); i++) {
|
for (ImmutablePair<CardEdition, Integer> ee : setPrices) {
|
||||||
options.add(choices.get(i).getName() + " [PRICE: " + unlockPrices.get(i) + " credits]");
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Examine choice */
|
|
||||||
for (int i = 0; i < options.size(); i++) {
|
ImmutablePair<CardEdition, Integer> toBuy = setPrices.get(index);
|
||||||
if (choice.equals(options.get(i))) {
|
|
||||||
chooseEd = choices.get(i);
|
int price = toBuy.right;
|
||||||
price = unlockPrices.get(i);
|
CardEdition choosenEdition = toBuy.left;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qData.getAssets().getCredits() < price) {
|
if (qData.getAssets().getCredits() < price) {
|
||||||
JOptionPane.showMessageDialog(null, "Unfortunately, you cannot afford that set yet.\n"
|
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.",
|
+ "You have only " + qData.getAssets().getCredits() + " credits.",
|
||||||
"Failed to unlock " + chooseEd.getName(),
|
"Failed to unlock " + choosenEdition.getName(),
|
||||||
JOptionPane.PLAIN_MESSAGE);
|
JOptionPane.PLAIN_MESSAGE);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int unlockConfirm = JOptionPane.showConfirmDialog(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"
|
+ "You have " + qData.getAssets().getCredits() + " credits.\n\n"
|
||||||
+ "Are you sure you want to unlock " + chooseEd.getName() + "?",
|
+ "Are you sure you want to unlock " + choosenEdition.getName() + "?",
|
||||||
"Confirm Unlocking " + chooseEd.getName(), JOptionPane.YES_NO_OPTION);
|
"Confirm Unlocking " + choosenEdition.getName(), JOptionPane.YES_NO_OPTION);
|
||||||
if (unlockConfirm == JOptionPane.NO_OPTION) {
|
if (unlockConfirm == JOptionPane.NO_OPTION) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
return toBuy;
|
||||||
qData.getAssets().subtractCredits(price);
|
|
||||||
JOptionPane.showMessageDialog(null, "You have successfully unlocked " + chooseEd.getName() + "!",
|
|
||||||
chooseEd.getName() + " unlocked!",
|
|
||||||
JOptionPane.PLAIN_MESSAGE);
|
|
||||||
return chooseEd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,110 +114,53 @@ public class QuestUtilUnlockSets {
|
|||||||
*
|
*
|
||||||
* @return unmodifiable list, assorted sets that are not currently in the format.
|
* @return unmodifiable list, assorted sets that are not currently in the format.
|
||||||
*/
|
*/
|
||||||
private static List<CardEdition> unlockableSets(final QuestController qData) {
|
private static final List<CardEdition> emptyEditions = Collections.unmodifiableList(new ArrayList<CardEdition>());
|
||||||
if (qData.getFormat() == null || qData.getFormat().getExcludedSetCodes().isEmpty()) {
|
private static List<CardEdition> getUnlockableEditions(final QuestController qData) {
|
||||||
return null;
|
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...
|
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.");
|
throw new RuntimeException("BUG? Could not find unlockable sets even though we should.");
|
||||||
}
|
}
|
||||||
List<CardEdition> options = new ArrayList<CardEdition>();
|
List<CardEdition> options = new ArrayList<CardEdition>();
|
||||||
|
|
||||||
// Sort current sets by index
|
// Sort current sets by index
|
||||||
TreeMap<Integer, CardEdition> sortedFormat = new TreeMap<Integer, CardEdition>();
|
List<CardEdition> allowedSets = Lists.newArrayList(Iterables.transform(qData.getFormat().getAllowedSetCodes(), Singletons.getModel().getEditions().FN_EDITION_BY_CODE));
|
||||||
for (String edCode : qData.getFormat().getAllowedSetCodes()) {
|
Collections.sort(allowedSets);
|
||||||
sortedFormat.put(new Integer(Singletons.getModel().getEditions().get(edCode).getIndex()), Singletons.getModel().getEditions().get(edCode));
|
|
||||||
}
|
|
||||||
List<CardEdition> currentSets = new ArrayList<CardEdition>(sortedFormat.values());
|
|
||||||
|
|
||||||
// Sort unlockable sets by index
|
// Sort unlockable sets by index
|
||||||
TreeMap<Integer, CardEdition> sortedExcluded = new TreeMap<Integer, CardEdition>();
|
List<CardEdition> excludedSets = Lists.newArrayList(Iterables.transform(qData.getFormat().getLockedSets(), Singletons.getModel().getEditions().FN_EDITION_BY_CODE));
|
||||||
for (String edCode : qData.getFormat().getExcludedSetCodes()) {
|
Collections.sort(excludedSets);
|
||||||
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
|
// get a number of sets between an excluded and any included set
|
||||||
CardEdition first = currentSets.get(0);
|
List<ImmutablePair<CardEdition, Integer>> excludedWithDistances = new ArrayList<ImmutablePair<CardEdition,Integer>>();
|
||||||
CardEdition last = currentSets.get(currentSets.size() - 1);
|
for(CardEdition ex : excludedSets) {
|
||||||
List<CardEdition> fillers = new ArrayList<CardEdition>();
|
int distance = Integer.MAX_VALUE;
|
||||||
|
for(CardEdition in : allowedSets) {
|
||||||
// Add nearby sets first
|
int d = Math.abs(ex.getIndex() - in.getIndex());
|
||||||
for (CardEdition ce : excludedSets) {
|
if ( d < distance )
|
||||||
if (first.getIndex() == ce.getIndex() + 1 || last.getIndex() + 1 == ce.getIndex())
|
distance = d;
|
||||||
{
|
|
||||||
options.add(ce);
|
|
||||||
// System.out.println("Added adjacent set: " + ce.getName());
|
|
||||||
}
|
}
|
||||||
|
excludedWithDistances.add(ImmutablePair.of(ex, distance));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill in the in-between sets
|
// sort by distance, then by code desc
|
||||||
int j = 0;
|
Collections.sort(excludedWithDistances, new Comparator<ImmutablePair<CardEdition, Integer>>() {
|
||||||
// Find the first excluded set between current sets first and current sets last
|
@Override
|
||||||
while (j < excludedSets.size() && excludedSets.get(j).getIndex() < currentSets.get(0).getIndex()) {
|
public int compare(ImmutablePair<CardEdition, Integer> o1, ImmutablePair<CardEdition, Integer> o2) {
|
||||||
j++;
|
int d1 = o2.right - o1.right;
|
||||||
}
|
return d1 != 0 ? d1 : o1.left.getIndex() - o2.left.getIndex();
|
||||||
// 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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 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
|
for (ImmutablePair<CardEdition, Integer> set : excludedWithDistances) {
|
||||||
if (fillers.size() + options.size() < nrChoices && excludedSets.size() > fillers.size() + options.size()) {
|
options.add(set.left);
|
||||||
// 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));
|
|
||||||
// System.out.println("Padded with: " + fillers.get(i).getName());
|
// System.out.println("Padded with: " + fillers.get(i).getName());
|
||||||
}
|
}
|
||||||
|
Collections.reverse(options);
|
||||||
|
|
||||||
return Collections.unmodifiableList(options);
|
return Collections.unmodifiableList(options);
|
||||||
}
|
}
|
||||||
@@ -243,30 +173,26 @@ public class QuestUtilUnlockSets {
|
|||||||
*/
|
*/
|
||||||
public static void doUnlock(QuestController qData, final CardEdition unlockedSet) {
|
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());
|
qData.getFormat().unlockSet(unlockedSet.getCode());
|
||||||
|
|
||||||
List<CardPrinted> displayCards = new ArrayList<CardPrinted>();
|
List<CardPrinted> cardsWon = new ArrayList<CardPrinted>();
|
||||||
|
|
||||||
if (Singletons.getModel().getTournamentPacks().contains(unlockedSet.getCode())) {
|
if (starters.contains(unlockedSet.getCode())) {
|
||||||
final List<CardPrinted> cardsWon = (new UnOpenedProduct(Singletons.getModel().getTournamentPacks().get(unlockedSet.getCode()))).open();
|
UnOpenedProduct starter = new UnOpenedProduct(starters.get(unlockedSet.getCode()));
|
||||||
|
cardsWon.addAll(starter.open());
|
||||||
|
}
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
qData.getCards().addAllCards(cardsWon);
|
qData.getCards().addAllCards(cardsWon);
|
||||||
displayCards.addAll(cardsWon);
|
final CardListViewer cardView = new CardListViewer(unlockedSet.getName(), "You get the following bonus cards:", cardsWon);
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final CardListViewer cardView = new CardListViewer(unlockedSet.getName(),
|
|
||||||
"You get the following bonus cards:", displayCards);
|
|
||||||
cardView.show();
|
cardView.show();
|
||||||
|
|
||||||
qData.save();
|
qData.save();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
package forge.quest.data;
|
package forge.quest.data;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@@ -36,7 +35,8 @@ import forge.game.GameFormat;
|
|||||||
*/
|
*/
|
||||||
public final class GameFormatQuest extends 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.
|
* 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) {
|
public GameFormatQuest(final String newName, final List<String> setsToAllow, final List<String> cardsToBan) {
|
||||||
super(newName, setsToAllow, 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) {
|
||||||
@@ -64,50 +65,29 @@ public final class GameFormatQuest extends GameFormat {
|
|||||||
* @param allowSetUnlocks
|
* @param allowSetUnlocks
|
||||||
*/
|
*/
|
||||||
public GameFormatQuest(final GameFormat toCopy, boolean allowSetUnlocks) {
|
public GameFormatQuest(final GameFormat toCopy, boolean allowSetUnlocks) {
|
||||||
this(toCopy.getName(), toCopy.getAllowedSetCodes(), toCopy.getBannedCardNames());
|
super(toCopy.getName(), toCopy.getAllowedSetCodes(), toCopy.getBannedCardNames());
|
||||||
allowUnlocks = allowSetUnlocks;
|
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.
|
* Get the list of excluded sets.
|
||||||
*
|
*
|
||||||
* @return unmodifiable list of excluded sets.
|
* @return unmodifiable list of excluded sets.
|
||||||
*/
|
*/
|
||||||
public List<String> getExcludedSetCodes() {
|
public List<String> getLockedSets() {
|
||||||
if (this.allowedSetCodes.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> exSets = new ArrayList<String>();
|
List<String> exSets = new ArrayList<String>();
|
||||||
|
if (this.allowedSetCodes.isEmpty()) {
|
||||||
|
return exSets;
|
||||||
|
}
|
||||||
|
|
||||||
for (CardEdition ce : Singletons.getModel().getEditions()) {
|
for (CardEdition ce : Singletons.getModel().getEditions()) {
|
||||||
if (!isSetLegal(ce.getCode())) {
|
if (!isSetLegal(ce.getCode())) {
|
||||||
exSets.add(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.
|
* @param setCode String, set code.
|
||||||
*/
|
*/
|
||||||
public void unlockSet(final String setCode) {
|
public void unlockSet(final String setCode) {
|
||||||
if (this.allowedSetCodes.isEmpty()) {
|
if (!canUnlockSets() || this.allowedSetCodes.isEmpty() || this.allowedSetCodes.contains(setCode)) {
|
||||||
return; // We are already allowing all sets!
|
return;
|
||||||
} else if (this.allowedSetCodes.contains(setCode)) {
|
|
||||||
return; // Already on the list
|
|
||||||
}
|
}
|
||||||
this.allowedSetCodes.add(setCode);
|
this.allowedSetCodes.add(setCode);
|
||||||
updateFilters();
|
unlocksUsed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -138,6 +116,11 @@ public final class GameFormatQuest extends GameFormat {
|
|||||||
return allowUnlocks;
|
return allowUnlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getUnlocksUsed() {
|
||||||
|
return unlocksUsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class Predicates.
|
* The Class Predicates.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -391,6 +391,8 @@ public class QuestDataIO {
|
|||||||
writer.startNode("format");
|
writer.startNode("format");
|
||||||
GameFormatQuest format = (GameFormatQuest) source;
|
GameFormatQuest format = (GameFormatQuest) source;
|
||||||
writer.addAttribute("name", format.getName());
|
writer.addAttribute("name", format.getName());
|
||||||
|
writer.addAttribute("unlocksUsed", Integer.toString(format.getUnlocksUsed()));
|
||||||
|
writer.addAttribute("canUnlock", format.canUnlockSets() ? "1" : "0");
|
||||||
writer.endNode();
|
writer.endNode();
|
||||||
|
|
||||||
for (String set : format.getAllowedSetCodes()) {
|
for (String set : format.getAllowedSetCodes()) {
|
||||||
@@ -409,6 +411,8 @@ public class QuestDataIO {
|
|||||||
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
|
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
|
||||||
reader.moveDown();
|
reader.moveDown();
|
||||||
String name = reader.getAttribute("name");
|
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> allowedSets = new ArrayList<String>();
|
||||||
List<String> bannedCards = new ArrayList<String>();
|
List<String> bannedCards = new ArrayList<String>();
|
||||||
reader.moveUp();
|
reader.moveUp();
|
||||||
@@ -425,7 +429,21 @@ public class QuestDataIO {
|
|||||||
}
|
}
|
||||||
reader.moveUp();
|
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
|
@Override
|
||||||
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
|
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
|
||||||
final String value = reader.getValue();
|
final String value = reader.getValue();
|
||||||
return GameType.smartValueOf(value, GameType.Quest); // does not
|
return GameType.smartValueOf(value, GameType.Quest);
|
||||||
// matter -
|
|
||||||
// this field
|
|
||||||
// is
|
|
||||||
// deprecated
|
|
||||||
// anyway
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user