"New" column added to Quest shop interface.

This commit is contained in:
Maxmtg
2011-09-04 11:13:03 +00:00
parent b8412d4648
commit 263be6f3d1
5 changed files with 81 additions and 33 deletions

View File

@@ -347,6 +347,7 @@ public class Gui_WinLose extends JFrame implements NewConstants {
model.quest.clearAvailableQuests();
}
model.quest.getCards().resetNewList();
giveQuestRewards(wonMatch);
model.match.reset();

View File

@@ -48,7 +48,11 @@ public class CardPoolView implements Iterable<Entry<CardPrinted, Integer>> {
@Override
public final Iterator<Entry<CardPrinted, Integer>> iterator() { return cards.entrySet().iterator(); }
// Cards manipulation
// Cards read only operations
public final boolean contains(final CardPrinted card) {
if (cards == null) { return false; }
return cards.containsKey(card);
}
public final int count(final CardPrinted card) {
if (cards == null) { return 0; }
Integer boxed = cards.get(card);
@@ -60,21 +64,23 @@ public class CardPoolView implements Iterable<Entry<CardPrinted, Integer>> {
return result;
}
public final int countDistinct() { return cards.size(); }
public final boolean isEmpty() { return cards.isEmpty(); }
public final boolean isEmpty() { return cards == null || cards.isEmpty(); }
public final List<Entry<CardPrinted, Integer>> getOrderedList() {
if (!isListInSync) {
cardsListOrdered.clear();
if (cards != null) {
for (Entry<CardPrinted, Integer> e : cards.entrySet()) {
cardsListOrdered.add(e);
}
}
isListInSync = true;
}
if (!isListInSync) { rebuildOrderedList(); }
return cardsListOrdered;
}
private void rebuildOrderedList() {
cardsListOrdered.clear();
if (cards != null) {
for (Entry<CardPrinted, Integer> e : cards.entrySet()) {
cardsListOrdered.add(e);
}
}
isListInSync = true;
}
public final List<CardPrinted> toFlatList() {
List<CardPrinted> result = new ArrayList<CardPrinted>();
for (Entry<CardPrinted, Integer> e : this) {

View File

@@ -51,11 +51,13 @@ public final class DeckEditorShop extends DeckEditorBase {
private double multiplier;
private QuestData questData;
private CardPoolView newCardsList;
// get pricelist:
private ReadPriceList r = new ReadPriceList();
private Map<String, Integer> mapPrices = r.getPriceList();
private Map<CardPrinted, Integer> decksUsingMyCards;
public void show(final Command exitCommand) {
@@ -67,7 +69,7 @@ public final class DeckEditorShop extends DeckEditorBase {
exitCommand.execute();
}
};
// do not change this!!!!
this.addWindowListener(new WindowAdapter() {
@Override
@@ -88,6 +90,7 @@ public final class DeckEditorShop extends DeckEditorBase {
forSale = questData.getCards().getShopList();
}
CardPoolView owned = questData.getCards().getCardpool().getView();
newCardsList = questData.getCards().getNewCards();
setDecks(forSale, owned);
@@ -139,6 +142,7 @@ public final class DeckEditorShop extends DeckEditorBase {
top.setup(columns, cardView);
columnsBelow.add(new TableColumnInfo<CardPrinted>("#Dk", 30, fnDeckCompare, fnDeckGet));
columnsBelow.add(new TableColumnInfo<CardPrinted>("New", 30, fnNewCompare, fnNewGet));
columnsBelow.add(new TableColumnInfo<CardPrinted>("Price", 40, fnPriceCompare, fnPriceGet));
bottom.setup(columnsBelow, cardView);
@@ -155,7 +159,7 @@ public final class DeckEditorShop extends DeckEditorBase {
* @param qd
* a {@link forge.quest.data.QuestData} object.
*/
public DeckEditorShop(forge.quest.data.QuestData qd) {
public DeckEditorShop(final QuestData qd) {
questData = qd;
try {
filterBoxes = null;
@@ -299,4 +303,16 @@ public final class DeckEditorShop extends DeckEditorBase {
Integer iValue = decksUsingMyCards.get(from.getKey());
return iValue == null ? "" : iValue.toString();
} };
@SuppressWarnings("rawtypes")
private final Lambda1<Comparable, Entry<CardPrinted, Integer>> fnNewCompare =
new Lambda1<Comparable, Entry<CardPrinted, Integer>>() { @Override
public Comparable apply(final Entry<CardPrinted, Integer> from) {
return newCardsList.contains(from.getKey()) ? Integer.valueOf(1) : Integer.valueOf(0);
} };
private final Lambda1<Object, Entry<CardPrinted, Integer>> fnNewGet =
new Lambda1<Object, Entry<CardPrinted, Integer>>() { @Override
public Object apply(final Entry<CardPrinted, Integer> from) {
return newCardsList.contains(from.getKey()) ? "NEW" : "";
} };
}

View File

@@ -109,8 +109,14 @@ public final class QuestData {
}
private void initTransients() {
// These are helper classes that hold no data.
myCards = new QuestUtilCards(this);
myRewards = new QuestUtilRewards(this);
// to avoid NPE some pools will be created here if they are null
if (null == newCardList) { newCardList = new CardPool(); }
if (null == shopList) { shopList = new CardPool(); }
}
public void newGame(final int diff, final String m0de, final boolean standardStart) {

View File

@@ -21,8 +21,7 @@ public final class QuestUtilCards {
private QuestData q;
public QuestUtilCards(final QuestData qd) { q = qd; }
public void generateBasicLands(int nBasic, int nSnow)
{
public void generateBasicLands(final int nBasic, final int nSnow) {
CardDb db = CardDb.instance();
q.cardPool.add(db.getCard("Forest", "M10"), nBasic);
q.cardPool.add(db.getCard("Mountain", "M10"), nBasic);
@@ -36,7 +35,6 @@ public final class QuestUtilCards {
q.cardPool.add(db.getCard("Snow-Covered Island", "ICE"), nSnow);
q.cardPool.add(db.getCard("Snow-Covered Plains", "ICE"), nSnow);
}
//adds 11 cards, to the current card pool
//(I chose 11 cards instead of 15 in order to make things more challenging)
@@ -62,31 +60,43 @@ public final class QuestUtilCards {
public void addAllCards(final Iterable<CardPrinted> newCards) {
for (CardPrinted card : newCards) {
q.cardPool.add(card);
addSingleCard(card);
}
}
public void addSingleCard(CardPrinted card) {
q.cardPool.add(card);
public CardPrinted addRandomRare() { return addRandomRare(1).get(0); }
// register card into that list so that it would appear as a new one.
q.newCardList.add(card);
}
private static final Predicate<CardPrinted> rarePredicate = CardPrinted.Predicates.Presets.isRareOrMythic;
public CardPrinted addRandomRare() {
CardPrinted card = rarePredicate.random(CardDb.instance().getAllCards());
addSingleCard(card);
return card;
}
public List<CardPrinted> addRandomRare(final int n) {
List<CardPrinted> newCards = CardPrinted.Predicates.Presets.isRareOrMythic.random(CardDb.instance().getAllCards(), n);
List<CardPrinted> newCards = rarePredicate.random(CardDb.instance().getAllCards(), n);
addAllCards(newCards);
return newCards;
}
public void setupNewGameCardPool(Predicate<CardPrinted> filter, int idxDifficulty)
public void setupNewGameCardPool(final Predicate<CardPrinted> filter, final int idxDifficulty)
{
int nC = QuestPreferences.getStartingCommons(idxDifficulty);
int nU = QuestPreferences.getStartingUncommons(idxDifficulty);
int nR = QuestPreferences.getStartingRares(idxDifficulty);
addAllCards(QuestBoosterPack.getQuestStarterDeck(filter, nC, nU, nR));
}
public void buyCard(final CardPrinted card, final int value) {
if (q.credits >= value) {
q.credits -= value;
q.cardPool.add(card);
q.shopList.remove(card);
addSingleCard(card);
}
}
@@ -109,37 +119,39 @@ public final class QuestUtilCards {
public double getSellMutliplier() {
double multi = 0.20 + (0.001 * q.getWin());
if (multi > 0.6)
if (multi > 0.6) {
multi = 0.6;
}
int lvlEstates = q.isFantasy() ? q.inventory.getItemLevel("Estates") : 0;
switch (lvlEstates) {
case 1: multi += 0.01; break;
case 2: multi += 0.0175; break;
case 3: multi += 0.025; break;
default: break;
}
return multi;
}
public int getSellPriceLimit() {
return q.getWin() <= 50 ? 1000 : Integer.MAX_VALUE;
return q.getWin() <= 50 ? 1000 : Integer.MAX_VALUE;
}
public void generateCardsInShop() {
ReadBoosterPack pack = new ReadBoosterPack();
int levelPacks = q.getLevel() > 0 ? 4 / q.getLevel() : 4;
int winPacks = q.getWin() / 10;
int totalPacks = Math.min(levelPacks + winPacks, 6);
CardPoolView fromBoosters = pack.getShopCards(totalPacks);
q.shopList.clear();
q.shopList.addAll(fromBoosters);
}
public CardPool getCardpool() {
return q.cardPool;
return q.cardPool;
}
public CardPoolView getShopList() {
@@ -147,6 +159,13 @@ public final class QuestUtilCards {
generateCardsInShop();
}
return q.shopList;
}
}
public CardPoolView getNewCards() {
return q.newCardList;
}
public void resetNewList() {
q.newCardList.clear();
}
}