Player can choose which booster to receive in the course of quest: containing only T2 cards, Extanded or Legacy (the way it was before)

This commit is contained in:
Maxmtg
2011-08-22 04:33:15 +00:00
parent 766e872518
commit 825e64e9f2
3 changed files with 52 additions and 34 deletions

View File

@@ -1,6 +1,6 @@
package forge; package forge;
import java.util.ArrayList; import java.util.List;
import net.slightlymagic.braids.util.UtilFunctions; import net.slightlymagic.braids.util.UtilFunctions;
import net.slightlymagic.braids.util.generator.GeneratorFunctions; import net.slightlymagic.braids.util.generator.GeneratorFunctions;
@@ -332,24 +332,19 @@ public class CardFilter {
}//getColor() }//getColor()
/** /**
* Filter a Generator of cards so that it contains only the ones that * Filter a Generator of cards so that it contains only the ones that exist in certain sets.
* exist in certain sets.
* *
* @param inputGenerator a sequence Generator of Card instances; must * @param inputGenerator a sequence Generator of Card instances; must not be null.
* not be null.
* *
* @param sets an ArrayList of Strings identifying the valid sets; * @param sets an ArrayList of Strings identifying the valid sets; must not be null.
* must not be null.
* *
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public static Generator<Card> getSets(Generator<Card> inputGenerator, public static Generator<Card> getSets(Generator<Card> inputGenerator, final List<String> sets)
final ArrayList<String> sets)
{ {
UtilFunctions.checkNotNull("inputGenerator", inputGenerator); UtilFunctions.checkNotNull("inputGenerator", inputGenerator);
UtilFunctions.checkNotNull("sets", sets); UtilFunctions.checkNotNull("sets", sets);
Lambda1<Boolean, Card> predicate = new Lambda1<Boolean, Card>() { Lambda1<Boolean, Card> predicate = new Lambda1<Boolean, Card>() {
public Boolean apply(Card c) { public Boolean apply(Card c) {
if (c == null) { if (c == null) {
@@ -367,7 +362,6 @@ public class CardFilter {
}; };
return GeneratorFunctions.filterGenerator(predicate, inputGenerator); return GeneratorFunctions.filterGenerator(predicate, inputGenerator);
}//getSets(Generator,ArrayList) }//getSets(Generator,ArrayList)

View File

@@ -6,6 +6,7 @@ import forge.game.GameLossReason;
import forge.game.GamePlayerRating; import forge.game.GamePlayerRating;
import forge.game.GameSummary; import forge.game.GameSummary;
import forge.game.PlayerIndex; import forge.game.PlayerIndex;
import forge.gui.GuiUtils;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
import forge.properties.NewConstants; import forge.properties.NewConstants;
import forge.properties.NewConstants.LANG.Gui_WinLose.WINLOSE_TEXT; import forge.properties.NewConstants.LANG.Gui_WinLose.WINLOSE_TEXT;
@@ -32,6 +33,8 @@ import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/** /**
* <p>Gui_WinLose class.</p> * <p>Gui_WinLose class.</p>
@@ -265,8 +268,7 @@ public class Gui_WinLose extends JFrame implements NewConstants {
} }
int cntCardsHumanStartedWith = humanRating.getOpeningHandSize(); int cntCardsHumanStartedWith = humanRating.getOpeningHandSize();
if ( 0 == cntCardsHumanStartedWith ) if (0 == cntCardsHumanStartedWith) {
{
int reward = QuestPreferences.getMatchMullToZero(); int reward = QuestPreferences.getMatchMullToZero();
sb.append(String.format("Mulliganed to zero and still won! Bonus: <b>%d credits</b>.<br>", reward)); sb.append(String.format("Mulliganed to zero and still won! Bonus: <b>%d credits</b>.<br>", reward));
} }
@@ -374,10 +376,22 @@ public class Gui_WinLose extends JFrame implements NewConstants {
quitButton_actionPerformed(null); quitButton_actionPerformed(null);
} }
protected void giveQuestRewards(final boolean wonMatch) { protected void giveBooster()
// Award a random booster, as frequent as set in difficulty setup {
if (model.quest.shouldAddCards(wonMatch)) { String[] boosterTypes = {"Legacy", "Extended", "T2"};
ArrayList<String> cardsWon = model.quest.addCards(); String boosterType = GuiUtils.getChoice("Choose prize booster type", boosterTypes);
List<String> setsToGive = null;
if (boosterTypes[2].equals( boosterType )) { // T2
setsToGive = new ArrayList<String>();
setsToGive.addAll( Arrays.asList(new String[]{"M12","NPH","MBS","M11","ROE","WWK","ZEN"}) );
}
if (boosterTypes[1].equals( boosterType )) { // Ext
setsToGive = new ArrayList<String>();
setsToGive.addAll( Arrays.asList(new String[]{"M12","NPH","MBS","M11","ROE","WWK","ZEN","M10","ARB","CFX","ALA","MOR","SHM","EVE","LRW"}) );
}
ArrayList<String> cardsWon = model.quest.addCards(setsToGive);
// TODO: Make a better presentation of cards - with pictures at least
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("You have won the following new cards:\n"); sb.append("You have won the following new cards:\n");
@@ -387,9 +401,16 @@ public class Gui_WinLose extends JFrame implements NewConstants {
String fileName = "BookIcon.png"; String fileName = "BookIcon.png";
ImageIcon icon = getIcon(fileName); ImageIcon icon = getIcon(fileName);
JOptionPane.showMessageDialog(null, sb.toString(), "", JOptionPane.INFORMATION_MESSAGE, icon); JOptionPane.showMessageDialog(null, sb.toString(), "", JOptionPane.INFORMATION_MESSAGE, icon);
} }
protected void giveQuestRewards(final boolean wonMatch) {
// Award a random booster, as frequent as set in difficulty setup
if (model.quest.shouldAddCards(wonMatch)) {
giveBooster();
}
// Award credits // Award credits
if (wonMatch) { if (wonMatch) {
long creds = model.quest.getCreditsToAdd(model.match); long creds = model.quest.getCreditsToAdd(model.match);

View File

@@ -374,8 +374,11 @@ public class QuestData {
/** /**
* <p>addCards.</p> * <p>addCards.</p>
*/ */
public ArrayList<String> addCards() { public ArrayList<String> addCards( List<String> setsFilter ) {
Generator<Card> cards = YieldUtils.toGenerator(AllZone.getCardFactory()); Generator<Card> cards = YieldUtils.toGenerator(AllZone.getCardFactory());
if ( setsFilter != null )
cards = CardFilter.getSets(cards, setsFilter);
int nCommon = QuestPreferences.getNumCommon(); int nCommon = QuestPreferences.getNumCommon();
int nUncommon = QuestPreferences.getNumUncommon(); int nUncommon = QuestPreferences.getNumUncommon();
int nRare = QuestPreferences.getNumRare(); int nRare = QuestPreferences.getNumRare();
@@ -852,7 +855,7 @@ public class QuestData {
public static void main(String[] args) { public static void main(String[] args) {
QuestData q = new QuestData(); QuestData q = new QuestData();
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
q.addCards(); q.addCards( null );
} }
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {