Second iteration of the new challenge rewards code. Put the card chooser into a new class. Currently its only type option is "duplicate", new types may be added later.

Cleaned up unused imports.
This commit is contained in:
RumbleBBU
2013-01-23 13:29:39 +00:00
parent 40a06048e9
commit 00294612c0
5 changed files with 120 additions and 32 deletions

1
.gitattributes vendored
View File

@@ -13939,6 +13939,7 @@ src/main/java/forge/quest/QuestEventDifficulty.java -text
src/main/java/forge/quest/QuestEventDuel.java svneol=native#text/plain
src/main/java/forge/quest/QuestEventManager.java svneol=native#text/plain
src/main/java/forge/quest/QuestMode.java -text
src/main/java/forge/quest/QuestRewardCardChooser.java -text
src/main/java/forge/quest/QuestUtil.java svneol=native#text/plain
src/main/java/forge/quest/QuestUtilCards.java -text
src/main/java/forge/quest/QuestUtilUnlockSets.java -text

View File

@@ -42,10 +42,12 @@ import forge.gui.home.quest.CSubmenuDuels;
import forge.gui.toolbox.FSkin;
import forge.item.CardDb;
import forge.item.CardPrinted;
import forge.item.InventoryItem;
import forge.properties.ForgePreferences.FPref;
import forge.quest.QuestEventChallenge;
import forge.quest.QuestController;
import forge.quest.QuestEvent;
import forge.quest.QuestRewardCardChooser;
import forge.quest.bazaar.QuestItemType;
import forge.quest.data.QuestPreferences;
import forge.quest.data.QuestPreferences.QPref;
@@ -55,7 +57,9 @@ import java.awt.Color;
import java.awt.Dimension;
import java.awt.Image;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.swing.BorderFactory;
@@ -641,7 +645,7 @@ public class QuestWinLose extends ControlWinLose {
*
*/
private void awardChallengeWin() {
final List<CardPrinted> cardsWon = ((QuestEventChallenge) qEvent).getCardRewardList();
final List<InventoryItem> itemsWon = ((QuestEventChallenge) qEvent).getCardRewardList();
final long questRewardCredits = ((QuestEventChallenge) qEvent).getCreditsReward();
final StringBuilder sb = new StringBuilder();
@@ -650,6 +654,18 @@ public class QuestWinLose extends ControlWinLose {
qData.getAssets().addCredits(questRewardCredits);
final List<CardPrinted> cardsWon = new ArrayList<CardPrinted>();
for (InventoryItem ii : itemsWon) {
if (ii instanceof CardPrinted) {
cardsWon.add((CardPrinted) ii);
} else if (ii instanceof QuestRewardCardChooser) {
final CardPrinted chosenCard = ((QuestRewardCardChooser) ii).toCardPrinted();
if (null != chosenCard) {
cardsWon.add(chosenCard);
}
}
}
// Generate Swing components and attach.
this.icoTemp = QuestWinLose.getResizedIcon(FSkin.getIcon(FSkin.QuestIcons.ICO_BOX), 0.5);
this.lblTemp1 = new TitleLabel("Challenge Rewards for \"" + ((QuestEventChallenge) qEvent).getTitle() + "\"");

View File

@@ -20,7 +20,6 @@ package forge.quest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
@@ -33,11 +32,10 @@ import forge.card.BoosterGenerator;
import forge.card.CardRulesPredicates;
import forge.card.CardRules;
import forge.card.UnOpenedProduct;
import forge.gui.GuiChoose;
import forge.item.CardDb;
import forge.item.CardPrinted;
import forge.item.InventoryItem;
import forge.util.Aggregates;
import forge.item.ItemPool;
import forge.util.MyRandom;
// The BoosterPack generates cards for the Card Pool in Quest Mode
@@ -223,10 +221,10 @@ public final class BoosterUtils {
* String, the reward to parse
* @return List<CardPrinted>
*/
private static List<CardPrinted> parseReward(final String s) {
private static List<InventoryItem> parseReward(final String s) {
String[] temp = s.split(" ");
List<CardPrinted> exactCards = new ArrayList<CardPrinted>();
List<InventoryItem> rewards = new ArrayList<InventoryItem>();
if ((temp.length > 2 && (temp[2].equalsIgnoreCase("rare") || temp[2].equalsIgnoreCase("rares")))
|| (temp.length > 1 && (temp[1].equalsIgnoreCase("rare") || temp[1].equalsIgnoreCase("rares")))) {
@@ -266,34 +264,20 @@ public final class BoosterUtils {
if (Singletons.getModel().getQuest().getFormat() != null) {
rarAndColor = Predicates.and(Singletons.getModel().getQuest().getFormat().getFilterPrinted(), rarAndColor);
}
return (new UnOpenedProduct(openWay, new BoosterGenerator(rarAndColor))).open(); // qty))
rewards.addAll(new UnOpenedProduct(openWay, new BoosterGenerator(rarAndColor)).open());
} else if (temp.length == 2 && temp[0].equalsIgnoreCase("duplicate") && temp[1].equalsIgnoreCase("card")) {
// Type 2: a duplicate card of the players choice
final ItemPool<CardPrinted> playerCards = Singletons.getModel().getQuest().getAssets().getCardPool();
if (!playerCards.isEmpty()) { // Maybe a redundant check since it's hard to win a duel without any cards...
List<CardPrinted> cardChoices = new ArrayList<CardPrinted>();
for (final Map.Entry<CardPrinted, Integer> card : playerCards) {
cardChoices.add(card.getKey());
}
Collections.sort(cardChoices);
final CardPrinted duplicate = GuiChoose.one("You have won a duplicate card!", cardChoices);
if (duplicate != null) {
exactCards.add(duplicate);
}
}
rewards.add(new QuestRewardCardChooser("duplicate"));
} else if (temp.length > 0) {
// Type 3: assume we are asking for a single copy of a specific card
final CardPrinted specific = CardDb.instance().getCard(s);
if (specific != null) {
exactCards.add(specific);
rewards.add(specific);
}
}
// Return the duplicate, a specified card, or an empty list
return exactCards;
return rewards;
}
@@ -307,10 +291,10 @@ public final class BoosterUtils {
* Properties string of reward (97 multicolor rares)
* @return List<CardPrinted>
*/
public static List<CardPrinted> generateCardRewardList(final String s) {
public static List<InventoryItem> generateCardRewardList(final String s) {
final String[] items = s.split(";");
final List<CardPrinted> rewards = new ArrayList<CardPrinted>();
final List<InventoryItem> rewards = new ArrayList<InventoryItem>();
for (final String item : items) {
@@ -326,7 +310,7 @@ public final class BoosterUtils {
input = item;
}
if (input != null) {
List<CardPrinted> reward = parseReward(input);
List<InventoryItem> reward = parseReward(input);
if (reward != null) {
rewards.addAll(reward);

View File

@@ -20,8 +20,7 @@ package forge.quest;
import java.util.ArrayList;
import java.util.List;
import forge.card.UnOpenedProduct;
import forge.item.CardPrinted;
import forge.item.InventoryItem;
/**
* <p>
@@ -64,7 +63,7 @@ public class QuestEventChallenge extends QuestEvent {
private List<String> aiExtraCards = new ArrayList<String>();
/** The card reward list. */
private List<CardPrinted> cardRewardList = null;
private List<InventoryItem> cardRewardList = null;
/**
* Instantiates a new quest challenge.
@@ -248,9 +247,9 @@ public class QuestEventChallenge extends QuestEvent {
*
* @return the card reward list
*/
public final List<CardPrinted> getCardRewardList() {
public final List<InventoryItem> getCardRewardList() {
if (cardRewardList == null) {
this.cardRewardList = new ArrayList<CardPrinted>(BoosterUtils.generateCardRewardList(cardReward));
this.cardRewardList = new ArrayList<InventoryItem>(BoosterUtils.generateCardRewardList(cardReward));
}
return this.cardRewardList;
}

View File

@@ -0,0 +1,88 @@
package forge.quest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import forge.Singletons;
import forge.gui.GuiChoose;
import forge.item.CardPrinted;
import forge.item.InventoryItem;
import forge.item.ItemPool;
/**
* Resolves a card chooser InventoryItem into a CardPrinted.
* The initial version includes "duplicate", other type may be added later.
*
*/
public class QuestRewardCardChooser implements InventoryItem {
private String type;
/** The constructor.
* The parameter indicates the more specific type.
* @param setType String, the type of the choosable card.
*/
public QuestRewardCardChooser(final String setType) {
type = setType;
}
/**
* The name (this should not be displayed anywhere).
*
* @return the name
*/
@Override
public String getName() {
return "a chosen card";
}
/**
* A QuestRewardCardChooser ought to always be resolved to an actual card, hence no images.
*
* @return an empty string
*/
@Override
public String getImageFilename() {
return "";
}
/**
* The item type.
*
* @return item type
*/
@Override
public String getItemType() {
return type;
}
/**
* Produces a CardPrinted of the player's choice.
*
* @return a CardPrinted or null if could not choose one.
*/
public final CardPrinted toCardPrinted() {
if ("duplicate".equals(type)) {
final ItemPool<CardPrinted> playerCards = Singletons.getModel().getQuest().getAssets().getCardPool();
if (!playerCards.isEmpty()) { // Maybe a redundant check since it's hard to win a duel without any cards...
List<CardPrinted> cardChoices = new ArrayList<CardPrinted>();
for (final Map.Entry<CardPrinted, Integer> card : playerCards) {
cardChoices.add(card.getKey());
}
Collections.sort(cardChoices);
final CardPrinted duplicate = GuiChoose.one("You have won a duplicate card!", cardChoices);
return duplicate;
}
} else {
throw new RuntimeException("Unknown QuestRewardCardType: " + type);
}
return null;
}
}