Added two new quest preferences for controlling the number of cards to keep before selling extras.

This commit is contained in:
Krazy
2015-05-25 18:05:25 +00:00
parent 3b4ddd9ecc
commit c110824b17
5 changed files with 106 additions and 81 deletions

View File

@@ -379,6 +379,16 @@ public enum VSubmenuQuestPrefs implements IVSubmenu<CSubmenuQuestPrefs> {
pnlShop.add(new FLabel.Builder().text("Wins to Uncap Sale Price").fontAlign(SwingConstants.RIGHT).build(), labelConstraints);
pnlShop.add(new PrefInput(QPref.SHOP_WINS_FOR_NO_SELL_LIMIT, QuestPreferencesErrType.SHOP), fieldConstraints);
FLabel extraCardsToKeep = new FLabel.Builder().text("Copies of Cards to Keep").fontAlign(SwingConstants.RIGHT).build();
extraCardsToKeep.setToolTipText("The number of copies of cards to keep before selling extras.");
pnlShop.add(extraCardsToKeep, labelConstraints);
pnlShop.add(new PrefInput(QPref.SHOP_EXTRAS_TO_KEEP, QuestPreferencesErrType.DIFFICULTY), fieldConstraints + ", wrap");
FLabel extraLandsToKeep = new FLabel.Builder().text("Copies of Basic Lands to Keep").fontAlign(SwingConstants.RIGHT).build();
extraLandsToKeep.setToolTipText("The number of copies of basic lands to keep before selling extras.");
pnlShop.add(extraLandsToKeep, labelConstraints);
pnlShop.add(new PrefInput(QPref.SHOP_EXTRA_BASIC_LANDS_TO_KEEP, QuestPreferencesErrType.DIFFICULTY), fieldConstraints + ", wrap");
pnlShop.add(new FLabel.Builder().text("Item Level Restriction").fontAlign(SwingConstants.RIGHT).build(), labelConstraints);
pnlShop.add(new PrefInput(QPref.ITEM_LEVEL_RESTRICTION, QuestPreferencesErrType.SHOP), fieldConstraints);

View File

@@ -83,6 +83,8 @@ public class QuestPrefsScreen extends FScreen {
scroller.add(new PrefsOption("Common Singles", QPref.SHOP_SINGLES_COMMON, PrefsGroup.SHOP));
scroller.add(new PrefsOption("Uncommon Singles", QPref.SHOP_SINGLES_UNCOMMON, PrefsGroup.SHOP));
scroller.add(new PrefsOption("Rare Singles", QPref.SHOP_SINGLES_RARE, PrefsGroup.SHOP));
scroller.add(new PrefsOption("Copies of Cards to Keep", QPref.SHOP_EXTRAS_TO_KEEP, PrefsGroup.SHOP));
scroller.add(new PrefsOption("Copies of Basic Lands to Keep", QPref.SHOP_EXTRA_BASIC_LANDS_TO_KEEP, PrefsGroup.SHOP));
//Difficulty Adjustments (All)
scroller.add(new PrefsHeader("Difficulty Adjustments (All)", FSkinImage.QUEST_NOTES, PrefsGroup.DIFFICULTY_ALL));

View File

@@ -18,14 +18,14 @@ public class BooleanExpression {
private boolean inName, inType, inText, inCost;
private static enum Operator {
private enum Operator {
AND("&", 0), OR("|", 0), NOT("!", 1), OPEN_PAREN("(", 2), CLOSE_PAREN(")", 2), ESCAPE("\\", -1);
private final String token;
private final int precedence;
private Operator(final String token, final int precedence) {
Operator(final String token, final int precedence) {
this.token = token;
this.precedence = precedence;
}
@@ -101,7 +101,7 @@ public class BooleanExpression {
operands.push(valueOf(currentValue.trim()));
}
while (operators.size() > 0) {
while (!operators.isEmpty()) {
resolve(true);
}
@@ -156,7 +156,7 @@ public class BooleanExpression {
if (inCost) {
predicates.add(CardRulesPredicates.cost(StringOp.CONTAINS_IC, value));
}
if (predicates.size() > 0) {
if (!predicates.isEmpty()) {
return Predicates.or(predicates);
}
return Predicates.alwaysTrue();

View File

@@ -10,6 +10,7 @@ import forge.itemmanager.IItemManager;
import forge.itemmanager.SItemManagerUtil;
import forge.model.FModel;
import forge.properties.ForgePreferences.FPref;
import forge.quest.data.QuestPreferences.QPref;
import forge.quest.io.ReadPriceList;
import forge.util.ItemPool;
import forge.util.gui.SOptionPane;
@@ -27,10 +28,10 @@ public class QuestSpellShop {
private static ItemPool<InventoryItem> decksUsingMyCards;
public static Integer getCardValue(final InventoryItem card) {
String ns = null;
String ns;
int value = 1337; // previously this was the returned default
boolean foil = false;
int foilMultiplier = 1;
int foilMultiplier;
if (card instanceof PaperCard) {
ns = card.getName() + "|" + ((PaperCard) card).getEdition();
@@ -104,7 +105,7 @@ public class QuestSpellShop {
value *= foilMultiplier;
}
return Integer.valueOf(value);
return value;
}
public static final Function<Entry<InventoryItem, Integer>, Comparable<?>> fnPriceCompare = new Function<Entry<InventoryItem, Integer>, Comparable<?>>() {
@@ -128,21 +129,20 @@ public class QuestSpellShop {
public static final Function<Entry<InventoryItem, Integer>, Comparable<?>> fnDeckCompare = new Function<Entry<InventoryItem, Integer>, Comparable<?>>() {
@Override
public Comparable<?> apply(final Entry<InventoryItem, Integer> from) {
final Integer iValue = decksUsingMyCards.count(from.getKey());
return iValue == null ? Integer.valueOf(0) : iValue;
return decksUsingMyCards.count(from.getKey());
}
};
public static final Function<Entry<? extends InventoryItem, Integer>, Object> fnDeckGet = new Function<Entry<? extends InventoryItem, Integer>, Object>() {
@Override
public Object apply(final Entry<? extends InventoryItem, Integer> from) {
final Integer iValue = decksUsingMyCards.count(from.getKey());
return iValue == null ? "" : iValue.toString();
return iValue.toString();
}
};
public static void buy(Iterable<Entry<InventoryItem, Integer>> items, IItemManager<InventoryItem> shopManager, IItemManager<InventoryItem> inventoryManager, boolean confirmPurchase) {
long totalCost = 0;
ItemPool<InventoryItem> itemsToBuy = new ItemPool<InventoryItem>(InventoryItem.class);
ItemPool<InventoryItem> itemsToBuy = new ItemPool<>(InventoryItem.class);
for (Entry<InventoryItem, Integer> itemEntry : items) {
final InventoryItem item = itemEntry.getKey();
if (item instanceof PaperCard || item instanceof SealedProduct || item instanceof PreconDeck) {
@@ -169,7 +169,7 @@ public class QuestSpellShop {
return;
}
ItemPool<InventoryItem> itemsToAdd = new ItemPool<InventoryItem>(InventoryItem.class);
ItemPool<InventoryItem> itemsToAdd = new ItemPool<>(InventoryItem.class);
for (Entry<InventoryItem, Integer> itemEntry : itemsToBuy) {
final InventoryItem item = itemEntry.getKey();
@@ -197,6 +197,7 @@ public class QuestSpellShop {
booster = (BoosterBox) ((BoosterBox) item).clone();
}
FModel.getQuest().getCards().buyPack(booster, value);
assert booster != null;
final List<PaperCard> newCards = booster.getCards();
itemsToAdd.addAllFlat(newCards);
@@ -219,7 +220,7 @@ public class QuestSpellShop {
remainingCards.addAll(((BoxedProduct) booster).getExtraCards());
if (remainingCards.size() > 0) {
if (!remainingCards.isEmpty()) {
GuiBase.getInterface().showCardList(booster.getName(), "You have found the following cards inside:", remainingCards);
}
@@ -252,7 +253,7 @@ public class QuestSpellShop {
public static void sell(Iterable<Entry<InventoryItem, Integer>> items, IItemManager<InventoryItem> shopManager, IItemManager<InventoryItem> inventoryManager, boolean confirmSale) {
long totalReceived = 0;
ItemPool<InventoryItem> itemsToSell = new ItemPool<InventoryItem>(InventoryItem.class);
ItemPool<InventoryItem> itemsToSell = new ItemPool<>(InventoryItem.class);
for (Entry<InventoryItem, Integer> itemEntry : items) {
final InventoryItem item = itemEntry.getKey();
if (item instanceof PaperCard) {
@@ -288,10 +289,11 @@ public class QuestSpellShop {
}
public static void sellExtras(IItemManager<InventoryItem> shopManager, IItemManager<InventoryItem> inventoryManager) {
List<Entry<InventoryItem, Integer>> cardsToRemove = new LinkedList<Map.Entry<InventoryItem,Integer>>();
List<Entry<InventoryItem, Integer>> cardsToRemove = new LinkedList<>();
for (Entry<InventoryItem, Integer> item : inventoryManager.getPool()) {
PaperCard card = (PaperCard)item.getKey();
int numToKeep = card.getRules().getType().isBasic() ? 50 : 4;
int numToKeep = card.getRules().getType().isBasic() ?
FModel.getQuestPreferences().getPrefInt(QPref.SHOP_EXTRA_BASIC_LANDS_TO_KEEP) : FModel.getQuestPreferences().getPrefInt(QPref.SHOP_EXTRAS_TO_KEEP);
if ("Relentless Rats".equals(card.getName()) || "Shadowborn Apostle".equals(card.getName())) {
numToKeep = Integer.MAX_VALUE;
}
@@ -316,7 +318,7 @@ public class QuestSpellShop {
// fills number of decks using each card
public static void updateDecksForEachCard() {
decksUsingMyCards = new ItemPool<InventoryItem>(InventoryItem.class);
decksUsingMyCards = new ItemPool<>(InventoryItem.class);
for (final Deck deck : FModel.getQuest().getMyDecks()) {
CardPool main = deck.getMain();
for (final Entry<PaperCard, Integer> e : main) {

View File

@@ -154,6 +154,10 @@ public class QuestPreferences extends PreferencesStore<QuestPreferences.QPref> i
// Wins until the selling price limit is removed
SHOP_WINS_FOR_NO_SELL_LIMIT("50"),
//The number of cards to keep before selling
SHOP_EXTRAS_TO_KEEP("4"),
SHOP_EXTRA_BASIC_LANDS_TO_KEEP("50"),
ITEM_LEVEL_RESTRICTION("1");
private final String strDefaultVal;
@@ -264,9 +268,16 @@ public class QuestPreferences extends PreferencesStore<QuestPreferences.QPref> i
}
break;
case SHOP_EXTRA_BASIC_LANDS_TO_KEEP:
if (val < 10) {
return "Value too small (minimum 10).";
}
break;
case SHOP_MAX_PACKS:
case SHOP_MAX_SELLING_PRICE:
case SHOP_WINS_FOR_ADDITIONAL_PACK:
case SHOP_EXTRAS_TO_KEEP:
case WINS_NEW_DRAFT:
case WINS_ROTATE_DRAFT:
case WINS_UNLOCK_SET: