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,42 +332,36 @@ 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) {
return false; return false;
} }
for (SetInfo set : c.getSets()) { for (SetInfo set : c.getSets()) {
if (set != null && sets.contains(set.toString())) { if (set != null && sets.contains(set.toString())) {
return true; return true;
} }
} }
return false; return false;
} }
}; };
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>
@@ -188,7 +191,7 @@ public class Gui_WinLose extends JFrame implements NewConstants {
if ( model.qa != null ) if ( model.qa != null )
computerLife = model.qa.getComputerLife(); computerLife = model.qa.getComputerLife();
AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0], humanList, computerList, humanLife, computerLife, model.qa ); AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0], humanList, computerList, humanLife, computerLife, model.qa);
} else { } else {
AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0]); AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0]);
} }
@@ -234,10 +237,10 @@ public class Gui_WinLose extends JFrame implements NewConstants {
int rewardAltWinCondition = q.getCreditsRewardForAltWin(whyAiLost); int rewardAltWinCondition = q.getCreditsRewardForAltWin(whyAiLost);
if (rewardAltWinCondition > 0) { if (rewardAltWinCondition > 0) {
String winConditionName = "Unknown (bug)"; String winConditionName = "Unknown (bug)";
if ( game.getWinCondition() == GameEndReason.WinsGameSpellEffect ) { if (game.getWinCondition() == GameEndReason.WinsGameSpellEffect) {
winConditionName = game.getWinSpellEffect(); winConditionName = game.getWinSpellEffect();
} else { } else {
switch( whyAiLost ) { switch(whyAiLost) {
case Poisoned: winConditionName = "Poison"; break; case Poisoned: winConditionName = "Poison"; break;
case Milled: winConditionName = "Milled"; break; case Milled: winConditionName = "Milled"; break;
default: break; default: break;
@@ -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,20 +376,39 @@ public class Gui_WinLose extends JFrame implements NewConstants {
quitButton_actionPerformed(null); quitButton_actionPerformed(null);
} }
protected void giveBooster()
{
String[] boosterTypes = {"Legacy", "Extended", "T2"};
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();
sb.append("You have won the following new cards:\n");
for (String cardName : cardsWon) {
sb.append(cardName + "\n");
}
String fileName = "BookIcon.png";
ImageIcon icon = getIcon(fileName);
JOptionPane.showMessageDialog(null, sb.toString(), "", JOptionPane.INFORMATION_MESSAGE, icon);
}
protected void giveQuestRewards(final boolean wonMatch) { protected void giveQuestRewards(final boolean wonMatch) {
// Award a random booster, as frequent as set in difficulty setup // Award a random booster, as frequent as set in difficulty setup
if (model.quest.shouldAddCards(wonMatch)) { if (model.quest.shouldAddCards(wonMatch)) {
ArrayList<String> cardsWon = model.quest.addCards(); giveBooster();
StringBuilder sb = new StringBuilder();
sb.append("You have won the following new cards:\n");
for (String cardName : cardsWon) {
sb.append(cardName + "\n");
}
String fileName = "BookIcon.png";
ImageIcon icon = getIcon(fileName);
JOptionPane.showMessageDialog(null, sb.toString(), "", JOptionPane.INFORMATION_MESSAGE, icon);
} }
// Award credits // Award credits

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++) {