From b5732d01945ec2d0bcc375a7bc1cde1c16d6e666 Mon Sep 17 00:00:00 2001 From: myk Date: Sat, 23 Feb 2013 01:05:18 +0000 Subject: [PATCH] ensure cards are bought in the correct quantity too --- .../controllers/CEditorQuestCardShop.java | 2 +- src/main/java/forge/quest/QuestUtilCards.java | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/forge/gui/deckeditor/controllers/CEditorQuestCardShop.java b/src/main/java/forge/gui/deckeditor/controllers/CEditorQuestCardShop.java index 707e1cca220..eaf6361342f 100644 --- a/src/main/java/forge/gui/deckeditor/controllers/CEditorQuestCardShop.java +++ b/src/main/java/forge/gui/deckeditor/controllers/CEditorQuestCardShop.java @@ -319,7 +319,7 @@ public final class CEditorQuestCardShop extends ACEditorBase i; ++i) { diff --git a/src/main/java/forge/quest/QuestUtilCards.java b/src/main/java/forge/quest/QuestUtilCards.java index 77aff849349..c75e9392a5e 100644 --- a/src/main/java/forge/quest/QuestUtilCards.java +++ b/src/main/java/forge/quest/QuestUtilCards.java @@ -167,7 +167,7 @@ public final class QuestUtilCards { */ public void addAllCards(final Iterable newCards) { for (final CardPrinted card : newCards) { - this.addSingleCard(card); + this.addSingleCard(card, 1); } } @@ -177,11 +177,11 @@ public final class QuestUtilCards { * @param card * the card */ - public void addSingleCard(final CardPrinted card) { - this.qa.getCardPool().add(card); + public void addSingleCard(final CardPrinted card, int qty) { + this.qa.getCardPool().add(card, qty); // register card into that list so that it would appear as a new one. - this.qa.getNewCardList().add(card); + this.qa.getNewCardList().add(card, qty); } private static final Predicate RARE_PREDICATE = IPaperCard.Predicates.Presets.IS_RARE_OR_MYTHIC; @@ -207,7 +207,7 @@ public final class QuestUtilCards { final Predicate myFilter = applyFormatFilter(QuestUtilCards.RARE_PREDICATE); final CardPrinted card = Aggregates.random(Iterables.filter(CardDb.instance().getAllCards(), myFilter)); - this.addSingleCard(card); + this.addSingleCard(card, 1); return card; } @@ -250,11 +250,12 @@ public final class QuestUtilCards { * @param value * the value */ - public void buyCard(final CardPrinted card, final int value) { - if (this.qa.getCredits() >= value) { - this.qa.setCredits(this.qa.getCredits() - value); - this.qa.getShopList().remove(card); - this.addSingleCard(card); + public void buyCard(final CardPrinted card, int qty, final int value) { + int totalCost = qty * value; + if (this.qa.getCredits() >= totalCost) { + this.qa.setCredits(this.qa.getCredits() - totalCost); + this.qa.getShopList().remove(card, qty); + this.addSingleCard(card, qty); } }