Moved some methods from QuestData to helper classes, the whole class rearranged

Moved shop-related things to QuestUtilCards.java (eg. number of shop boosters calculation)
CardShop now shows how many decks use the given card
Quest deck editor: press space to add card to your deck - that simple
CardPool no longer allows incorrect remove numbers
removed lots of senseless javadocs
This commit is contained in:
Maxmtg
2011-09-02 22:51:47 +00:00
parent 90d5514aaa
commit adb3ae979b
19 changed files with 544 additions and 989 deletions

4
.gitattributes vendored
View File

@@ -9562,7 +9562,6 @@ src/main/java/forge/Gui_MigrateLocalMWSSetPictures_HQ.java svneol=native#text/pl
src/main/java/forge/Gui_MultipleBlockers4.java svneol=native#text/plain src/main/java/forge/Gui_MultipleBlockers4.java svneol=native#text/plain
src/main/java/forge/Gui_NewGame.java svneol=native#text/plain src/main/java/forge/Gui_NewGame.java svneol=native#text/plain
src/main/java/forge/Gui_ProgressBarWindow.java svneol=native#text/plain src/main/java/forge/Gui_ProgressBarWindow.java svneol=native#text/plain
src/main/java/forge/Gui_QuestOptions.java svneol=native#text/plain
src/main/java/forge/Gui_WinLose.java svneol=native#text/plain src/main/java/forge/Gui_WinLose.java svneol=native#text/plain
src/main/java/forge/HandSizeOp.java svneol=native#text/plain src/main/java/forge/HandSizeOp.java svneol=native#text/plain
src/main/java/forge/HttpUtil.java svneol=native#text/plain src/main/java/forge/HttpUtil.java svneol=native#text/plain
@@ -9824,6 +9823,8 @@ src/main/java/forge/quest/data/QuestDataIO.java svneol=native#text/plain
src/main/java/forge/quest/data/QuestMatchState.java svneol=native#text/plain src/main/java/forge/quest/data/QuestMatchState.java svneol=native#text/plain
src/main/java/forge/quest/data/QuestPreferences.java svneol=native#text/plain src/main/java/forge/quest/data/QuestPreferences.java svneol=native#text/plain
src/main/java/forge/quest/data/QuestUtil.java svneol=native#text/plain src/main/java/forge/quest/data/QuestUtil.java svneol=native#text/plain
src/main/java/forge/quest/data/QuestUtilCards.java -text
src/main/java/forge/quest/data/QuestUtilRewards.java -text
src/main/java/forge/quest/data/bazaar/QuestStallDefinition.java svneol=native#text/plain src/main/java/forge/quest/data/bazaar/QuestStallDefinition.java svneol=native#text/plain
src/main/java/forge/quest/data/bazaar/QuestStallManager.java svneol=native#text/plain src/main/java/forge/quest/data/bazaar/QuestStallManager.java svneol=native#text/plain
src/main/java/forge/quest/data/bazaar/QuestStallPurchasable.java svneol=native#text/plain src/main/java/forge/quest/data/bazaar/QuestStallPurchasable.java svneol=native#text/plain
@@ -9848,6 +9849,7 @@ src/main/java/forge/quest/data/pet/QuestPetWolf.java svneol=native#text/plain
src/main/java/forge/quest/data/pet/package-info.java svneol=native#text/plain src/main/java/forge/quest/data/pet/package-info.java svneol=native#text/plain
src/main/java/forge/quest/gui/QuestAbstractPanel.java svneol=native#text/plain src/main/java/forge/quest/gui/QuestAbstractPanel.java svneol=native#text/plain
src/main/java/forge/quest/gui/QuestFrame.java svneol=native#text/plain src/main/java/forge/quest/gui/QuestFrame.java svneol=native#text/plain
src/main/java/forge/quest/gui/QuestOptions.java svneol=native#text/plain
src/main/java/forge/quest/gui/bazaar/QuestBazaarItem.java svneol=native#text/plain src/main/java/forge/quest/gui/bazaar/QuestBazaarItem.java svneol=native#text/plain
src/main/java/forge/quest/gui/bazaar/QuestBazaarPanel.java svneol=native#text/plain src/main/java/forge/quest/gui/bazaar/QuestBazaarPanel.java svneol=native#text/plain
src/main/java/forge/quest/gui/bazaar/QuestBazaarStall.java svneol=native#text/plain src/main/java/forge/quest/gui/bazaar/QuestBazaarStall.java svneol=native#text/plain

View File

@@ -245,7 +245,7 @@ public class Gui_WinLose extends JFrame implements NewConstants {
GamePlayerRating humanRating = game.getPlayerRating(PlayerIndex.HUMAN); GamePlayerRating humanRating = game.getPlayerRating(PlayerIndex.HUMAN);
GameLossReason whyAiLost = aiRating.getLossReason(); GameLossReason whyAiLost = aiRating.getLossReason();
int rewardAltWinCondition = q.getCreditsRewardForAltWin(whyAiLost); int rewardAltWinCondition = q.getRewards().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) {
@@ -264,7 +264,7 @@ public class Gui_WinLose extends JFrame implements NewConstants {
} }
int winTurn = game.getTurnGameEnded(); int winTurn = game.getTurnGameEnded();
int turnCredits = q.getCreditsRewardForWinByTurn(winTurn); int turnCredits = q.getRewards().getCreditsRewardForWinByTurn(winTurn);
if (winTurn == 0) { // this case should never happen - anyway, no reward if we got here if (winTurn == 0) { // this case should never happen - anyway, no reward if we got here
} else if (winTurn == 1) { sb.append("Won in one turn!"); } else if (winTurn == 1) { sb.append("Won in one turn!");
@@ -340,7 +340,7 @@ public class Gui_WinLose extends JFrame implements NewConstants {
} }
//System.out.println("QuestData cardpoolsize:" + AllZone.getQuestData().getCardpool().size()); //System.out.println("QuestData cardpoolsize:" + AllZone.getQuestData().getCardpool().size());
model.quest.clearShopList(); model.quest.getCards().clearShopList();
if (model.quest.getAvailableQuests() != null) { if (model.quest.getAvailableQuests() != null) {
@@ -388,7 +388,7 @@ public class Gui_WinLose extends JFrame implements NewConstants {
setsToGive.addAll(Arrays.asList(new String[]{"M12","NPH","MBS","M11","ROE","WWK","ZEN","M10","ARB","CFX","ALA","MOR","SHM","EVE","LRW"})); setsToGive.addAll(Arrays.asList(new String[]{"M12","NPH","MBS","M11","ROE","WWK","ZEN","M10","ARB","CFX","ALA","MOR","SHM","EVE","LRW"}));
} }
ArrayList<CardPrinted> cardsWon = model.quest.addCards(setsToGive); ArrayList<CardPrinted> cardsWon = model.quest.getCards().addCards(setsToGive);
ImageIcon icon = getIcon("BookIcon.png"); ImageIcon icon = getIcon("BookIcon.png");
CardListViewer c = new CardListViewer("Booster", "You have won the following new cards", cardsWon, icon); CardListViewer c = new CardListViewer("Booster", "You have won the following new cards", cardsWon, icon);
c.show(); c.show();
@@ -397,13 +397,13 @@ public class Gui_WinLose extends JFrame implements NewConstants {
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.getRewards().willGiveBooster(wonMatch)) {
giveBooster(); giveBooster();
} }
// Award credits // Award credits
if (wonMatch) { if (wonMatch) {
long creds = model.quest.getCreditsToAdd(model.match); long creds = model.quest.getRewards().getCreditsToAdd(model.match);
model.quest.addCredits(creds); model.quest.addCredits(creds);
String s = getCreditsAwardedText(creds, model.match, model.quest); String s = getCreditsAwardedText(creds, model.match, model.quest);
@@ -418,7 +418,7 @@ public class Gui_WinLose extends JFrame implements NewConstants {
int wins = model.quest.getWin(); int wins = model.quest.getWin();
if (wins > 0 && wins % 80 == 0) // at every 80 wins, give 10 random rares if (wins > 0 && wins % 80 == 0) // at every 80 wins, give 10 random rares
{ {
ArrayList<CardPrinted> randomRares = model.quest.addRandomRare(10); List<CardPrinted> randomRares = model.quest.getCards().addRandomRare(10);
ImageIcon icon = getIcon("BoxIcon.png"); ImageIcon icon = getIcon("BoxIcon.png");
String title = "You just won 10 random rares!"; String title = "You just won 10 random rares!";
@@ -443,7 +443,7 @@ public class Gui_WinLose extends JFrame implements NewConstants {
sb.append(cardName.getName()); sb.append(cardName.getName());
sb.append("\r\n"); sb.append("\r\n");
} }
model.quest.addAllCards(questRewardCards); model.quest.getCards().addAllCards(questRewardCards);
sb.append("\r\n"); sb.append("\r\n");
} }
sb.append("Quest Bounty: "); sb.append("Quest Bounty: ");
@@ -476,9 +476,8 @@ public class Gui_WinLose extends JFrame implements NewConstants {
} }
// Random rare given at 50% chance (65% with luck upgrade) // Random rare given at 50% chance (65% with luck upgrade)
if (model.quest.shouldAddAdditionalCards(wonMatch)) { if (wonMatch && model.quest.getRewards().getLuckyCoinResult()) {
CardPrinted card = model.quest.getCards().addRandomRare();
CardPrinted card = model.quest.addRandomRare();
ArrayList<CardPrinted> rares = new ArrayList<CardPrinted>(); ArrayList<CardPrinted> rares = new ArrayList<CardPrinted>();
rares.add(card); rares.add(card);

View File

@@ -125,14 +125,11 @@ public class ReadBoosterPack implements NewConstants {
* @param questLevel a int. * @param questLevel a int.
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public CardPoolView getShopCards(int numberWins, int questLevel) { public CardPoolView getShopCards(int totalPacks) {
CardPool list = new CardPool(); CardPool list = new CardPool();
// Number of Packs granted // Number of Packs granted
int levelPacks = questLevel > 0 ? 8 / questLevel / 2 : 4;
int winPacks = numberWins / 10;
int totalPacks = Math.min(levelPacks + winPacks, 6);
for (int i = 0; i < totalPacks; i++) { for (int i = 0; i < totalPacks; i++) {
// TODO: Balance CardPool Availability // TODO: Balance CardPool Availability
@@ -153,57 +150,28 @@ public class ReadBoosterPack implements NewConstants {
} }
//return CardList of 5 or 6 cards, one for each color and maybe an artifact //return CardList of 5 or 6 cards, one for each color and maybe an artifact
/**
* <p>getVariety.</p>
*
* @param in a {@link forge.CardList} object.
* @return a {@link forge.CardList} object.
*/
private List<CardPrinted> getVariety(List<CardPrinted> in) { private List<CardPrinted> getVariety(List<CardPrinted> in) {
List<CardPrinted> out = new ArrayList<CardPrinted>(); List<CardPrinted> out = new ArrayList<CardPrinted>();
Collections.shuffle(in, MyRandom.random); Collections.shuffle(in, MyRandom.random);
for (int i = 0; i < Constant.Color.Colors.length; i++) { for (int i = 0; i < Constant.Color.Colors.length; i++) {
CardPrinted check = findColor(in, i); CardPrinted check = findCardOfColor(in, i);
if (check != null) { out.add(check); } if (check != null) { out.add(check); }
} }
return out; return out;
}//getVariety() }//getVariety()
/** private CardPrinted findCardOfColor(final List<CardPrinted> in, final int color) {
* <p>findColor.</p> Predicate<CardRules> filter = CardRules.Predicates.Presets.colors.get(color);
*
* @param in a {@link forge.CardList} object.
* @param color a {@link java.lang.String} object.
* @return a {@link forge.Card} object.
*/
private CardPrinted findColor(final List<CardPrinted> in, final int color) {
Predicate<CardRules> filter = null;
switch (color) {
case 0: filter = CardRules.Predicates.Presets.isWhite; break;
case 1: filter = CardRules.Predicates.Presets.isBlue; break;
case 2: filter = CardRules.Predicates.Presets.isBlack; break;
case 3: filter = CardRules.Predicates.Presets.isRed; break;
case 4: filter = CardRules.Predicates.Presets.isGreen; break;
case 5: filter = CardRules.Predicates.Presets.isColorless; break;
default: break;
}
if (null == filter) { return null; } if (null == filter) { return null; }
return filter.first(in, CardPrinted.fnGetRules); return filter.first(in, CardPrinted.fnGetRules);
} }
private CardPrinted getRandomCard(final List<CardPrinted> list) {
/**
* <p>getRandomCard.</p>
*
* @param list a {@link forge.CardList} object.
* @return a {@link forge.Card} object.
*/
private CardPrinted getRandomCard(List<CardPrinted> list) {
for (int i = 0; i < 10; i++)
Collections.shuffle(list, MyRandom.random); Collections.shuffle(list, MyRandom.random);
int index = MyRandom.random.nextInt(list.size()); int index = MyRandom.random.nextInt(list.size());
Collections.shuffle(list, MyRandom.random);
return list.get(index); return list.get(index);
}//getRandomCard() }//getRandomCard()

View File

@@ -154,10 +154,7 @@ public class ReadQuest_Assignment implements Runnable, NewConstants {
qa.setComputerLife(100); qa.setComputerLife(100);
s = readLine(); s = readLine();
if (s.equals("Repeatable")) qa.setRepeatable(s.equals("Repeatable"));
qa.setRepeatable(true);
else
qa.setRepeatable(false);
s = readLine(); s = readLine();
int wins = Integer.valueOf(s); int wins = Integer.valueOf(s);

View File

@@ -43,15 +43,11 @@ public final class CardPool extends CardPoolView {
for (Entry<CardPrinted, Integer> e : map) { add(e.getKey(), e.getValue()); } for (Entry<CardPrinted, Integer> e : map) { add(e.getKey(), e.getValue()); }
isListInSync = false; isListInSync = false;
} }
public void addAll(final Entry<CardPrinted, Integer>[] map) {
for (Entry<CardPrinted, Integer> e : map) { add(e.getKey(), e.getValue()); }
isListInSync = false;
}
public void remove(final CardPrinted card) { remove(card, 1); } public void remove(final CardPrinted card) { remove(card, 1); }
public void remove(final CardPrinted card, final int amount) { public void remove(final CardPrinted card, final int amount) {
int count = count(card); int count = count(card);
if (count == 0) { return; } if (count == 0 || amount <= 0) { return; }
if (count <= amount) { cards.remove(card); } if (count <= amount) { cards.remove(card); }
else { cards.put(card, count - amount); } else { cards.put(card, count - amount); }
isListInSync = false; isListInSync = false;

View File

@@ -15,7 +15,7 @@ import java.util.*;
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public class Deck implements Comparable<Deck>, Serializable { public final class Deck implements Comparable<Deck>, Serializable {
/** /**
* *
*/ */
@@ -70,7 +70,7 @@ public class Deck implements Comparable<Deck>, Serializable {
* *
* @param type a {@link java.lang.String} object. * @param type a {@link java.lang.String} object.
*/ */
public Deck(String type) { public Deck(final String type) {
this(); this();
setDeckType(type); setDeckType(type);
} }
@@ -164,28 +164,12 @@ public class Deck implements Comparable<Deck>, Serializable {
* *
* @param cardName a {@link java.lang.String} object. * @param cardName a {@link java.lang.String} object.
*/ */
public void addMain(String cardName) { addMain( CardDb.instance().getCard(cardName) ); } public void addMain(final String cardName) { addMain(CardDb.instance().getCard(cardName)); }
public void addMain(CardPrinted card) { main.add(card); } public void addMain(final CardPrinted card) { main.add(card); }
public void addMain(CardPoolView list) { main.addAll(list); } public void addMain(final CardPoolView list) { main.addAll(list); }
public void removeMain(final CardPrinted card) { main.remove(card); }
public void removeMain(final CardPrinted card, final int amount) { main.remove(card, amount); }
/** public int countMain() { return main.countAll(); }
* <p>countMain.</p>
*
* @return a int.
*/
public int countMain() {
return main.countAll();
}
/**
* <p>removeMain.</p>
*
* @param c a {@link forge.Card} object.
*/
public void removeMain(CardPrinted card) {
main.remove(card);
}
/** /**
* <p>addSideboard.</p> * <p>addSideboard.</p>
@@ -197,7 +181,6 @@ public class Deck implements Comparable<Deck>, Serializable {
public final void addSideboard(final CardPrinted card, final int amount) { sideboard.add(card, amount); } public final void addSideboard(final CardPrinted card, final int amount) { sideboard.add(card, amount); }
public final void addSideboard(final CardPoolView cards) { sideboard.addAll(cards); } public final void addSideboard(final CardPoolView cards) { sideboard.addAll(cards); }
/** /**
* <p>countSideboard.</p> * <p>countSideboard.</p>
* *

View File

@@ -57,9 +57,6 @@ public final class DeckEditor extends DeckEditorBase implements NewConstants {
private JButton removeButton = new JButton(); private JButton removeButton = new JButton();
private JButton addButton = new JButton(); private JButton addButton = new JButton();
private JButton analysisButton = new JButton(); private JButton analysisButton = new JButton();
private JScrollPane jScrollPane3 = new JScrollPane();
private JPanel jPanel3 = new JPanel();
private GridLayout gridLayout1 = new GridLayout();
private JLabel labelFilterName = new JLabel(); private JLabel labelFilterName = new JLabel();
private JLabel labelFilterType = new JLabel(); private JLabel labelFilterType = new JLabel();
@@ -227,10 +224,6 @@ public final class DeckEditor extends DeckEditorBase implements NewConstants {
// Do not lower statsLabel any lower, we want this to be visible at 1024 // Do not lower statsLabel any lower, we want this to be visible at 1024
// x 768 screen size // x 768 screen size
this.setTitle("Deck Editor"); this.setTitle("Deck Editor");
jScrollPane3.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jPanel3.setLayout(gridLayout1);
gridLayout1.setColumns(1);
gridLayout1.setRows(0);
Container pane = this.getContentPane(); Container pane = this.getContentPane();
MigLayout layout = new MigLayout("fill"); MigLayout layout = new MigLayout("fill");

View File

@@ -1,6 +1,8 @@
package forge.gui.deckeditor; package forge.gui.deckeditor;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent; import java.awt.event.ItemEvent;
import java.awt.event.ItemListener; import java.awt.event.ItemListener;
@@ -85,5 +87,4 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
top.setFilter(buildFilter()); top.setFilter(buildFilter());
} }
} }

View File

@@ -11,6 +11,7 @@ import forge.card.CardPrinted;
import forge.deck.Deck; import forge.deck.Deck;
import forge.deck.DeckManager; import forge.deck.DeckManager;
import forge.error.ErrorViewer; import forge.error.ErrorViewer;
import forge.gui.GuiUtils;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
import forge.properties.NewConstants; import forge.properties.NewConstants;
import forge.view.swing.OldGuiNewGame; import forge.view.swing.OldGuiNewGame;
@@ -99,9 +100,10 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
top.setup(columns, cardView); top.setup(columns, cardView);
bottom.setup(columns, cardView); bottom.setup(columns, cardView);
//Use both so that when "un"maximizing, the frame isn't tiny this.setSize(1024, 740);
setSize(1024, 740); GuiUtils.centerFrame(this);
//setExtendedState(Frame.MAXIMIZED_BOTH); this.setResizable(false);
} }
public DeckEditorDraft() { public DeckEditorDraft() {

View File

@@ -9,6 +9,7 @@ import forge.card.CardPoolView;
import forge.card.CardPrinted; import forge.card.CardPrinted;
import forge.deck.Deck; import forge.deck.Deck;
import forge.error.ErrorViewer; import forge.error.ErrorViewer;
import forge.gui.GuiUtils;
import forge.properties.NewConstants; import forge.properties.NewConstants;
import forge.view.swing.OldGuiNewGame; import forge.view.swing.OldGuiNewGame;
@@ -42,24 +43,9 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
private JButton removeButton = new JButton(); private JButton removeButton = new JButton();
private JButton analysisButton = new JButton(); private JButton analysisButton = new JButton();
private GridLayout gridLayout1 = new GridLayout(); private JLabel labelSortHint = new JLabel();
private JLabel jLabel1 = new JLabel();
/** {@inheritDoc} */
@Override
public void setTitle(String message) {
super.setTitle(message);
}
/**
* <p>
* show.
* </p>
*
* @param exitCommand
* a {@link forge.Command} object.
*/
public void show(final Command exitCommand) { public void show(final Command exitCommand) {
final Command exit = new Command() { final Command exit = new Command() {
private static final long serialVersionUID = -7428793574300520612L; private static final long serialVersionUID = -7428793574300520612L;
@@ -100,7 +86,7 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
CardPoolView bottomPool = deck.getMain(); CardPoolView bottomPool = deck.getMain();
CardPool cardpool = new CardPool(); CardPool cardpool = new CardPool();
cardpool.addAll(AllZone.getQuestData().getCardpool()); cardpool.addAll(AllZone.getQuestData().getCards().getCardpool());
// remove bottom cards that are in the deck from the card pool // remove bottom cards that are in the deck from the card pool
cardpool.removeAll(bottomPool); cardpool.removeAll(bottomPool);
@@ -136,15 +122,9 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
top.setup(columns, cardView); top.setup(columns, cardView);
bottom.setup(columns, cardView); bottom.setup(columns, cardView);
setSize(1024, 768); this.setSize(1024, 768);
GuiUtils.centerFrame(this);
this.setResizable(false); this.setResizable(false);
Dimension screen = getToolkit().getScreenSize();
Rectangle bounds = getBounds();
bounds.width = 1024;
bounds.height = 768;
bounds.x = (screen.width - bounds.width) / 2;
bounds.y = (screen.height - bounds.height) / 2;
setBounds(bounds);
// TODO use this as soon the deck editor has resizable GUI // TODO use this as soon the deck editor has resizable GUI
// //Use both so that when "un"maximizing, the frame isn't tiny // //Use both so that when "un"maximizing, the frame isn't tiny
@@ -205,7 +185,6 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
/** /**
* Type filtering * Type filtering
*/ */
filterBoxes.land.setBounds(340, 400, 48, 20); filterBoxes.land.setBounds(340, 400, 48, 20);
filterBoxes.creature.setBounds(385, 400, 65, 20); filterBoxes.creature.setBounds(385, 400, 65, 20);
filterBoxes.sorcery.setBounds(447, 400, 62, 20); filterBoxes.sorcery.setBounds(447, 400, 62, 20);
@@ -245,11 +224,9 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
// Do not lower statsLabel any lower, we want this to be visible at 1024 // Do not lower statsLabel any lower, we want this to be visible at 1024
// x 768 screen size // x 768 screen size
this.setTitle("Deck Editor"); this.setTitle("Deck Editor");
gridLayout1.setColumns(1);
gridLayout1.setRows(0);
jLabel1.setText("Click on the column name (like name or color) to sort the cards"); labelSortHint.setText("Click on the column name (like name or color) to sort the cards");
jLabel1.setBounds(new Rectangle(20, 1, 400, 19)); labelSortHint.setBounds(new Rectangle(20, 1, 400, 19));
this.getContentPane().add(top.getTableDecorated(), null); this.getContentPane().add(top.getTableDecorated(), null);
this.getContentPane().add(bottom.getTableDecorated(), null); this.getContentPane().add(bottom.getTableDecorated(), null);
@@ -258,7 +235,7 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
this.getContentPane().add(analysisButton, null); this.getContentPane().add(analysisButton, null);
this.getContentPane().add(bottom.getLabel(), null); this.getContentPane().add(bottom.getLabel(), null);
this.getContentPane().add(top.getLabel(), null); this.getContentPane().add(top.getLabel(), null);
this.getContentPane().add(jLabel1, null); this.getContentPane().add(labelSortHint, null);
this.getContentPane().add(cardView, null); this.getContentPane().add(cardView, null);
for (JCheckBox box : filterBoxes.allTypes) { for (JCheckBox box : filterBoxes.allTypes) {
@@ -268,6 +245,13 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
for (JCheckBox box : filterBoxes.allColors) { for (JCheckBox box : filterBoxes.allColors) {
this.getContentPane().add(box, null); this.getContentPane().add(box, null);
} }
top.getTable().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(final KeyEvent e) {
if (e.getKeyChar() == ' ') { addButtonActionPerformed(null); }
}
});
} }
@@ -295,7 +279,7 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
public void addCheatCard(CardPrinted card) { public void addCheatCard(CardPrinted card) {
top.addCard(card); top.addCard(card);
AllZone.getQuestData().getCardpool().add(card); AllZone.getQuestData().getCards().getCardpool().add(card);
} }
} }

View File

@@ -280,13 +280,13 @@ public class DeckEditorQuestMenu extends JMenuBar {
Deck newDeck = DeckManager.readDeck(file); Deck newDeck = DeckManager.readDeck(file);
questData.addDeck(newDeck); questData.addDeck(newDeck);
CardPool cardpool = new CardPool(questData.getCardpool()); CardPool cardpool = new CardPool(questData.getCards().getCardpool());
CardPool decklist = new CardPool(); CardPool decklist = new CardPool();
for (Entry<CardPrinted, Integer> s : newDeck.getMain()) { for (Entry<CardPrinted, Integer> s : newDeck.getMain()) {
CardPrinted cp = s.getKey(); CardPrinted cp = s.getKey();
decklist.add(cp, s.getValue()); decklist.add(cp, s.getValue());
cardpool.add(cp, s.getValue()); cardpool.add(cp, s.getValue());
questData.getCardpool().add(cp, s.getValue()); questData.getCards().getCardpool().add(cp, s.getValue());
} }
deckDisplay.setDecks(cardpool, decklist); deckDisplay.setDecks(cardpool, decklist);
@@ -347,7 +347,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
if (StringUtils.isBlank(deckName)) { return; } if (StringUtils.isBlank(deckName)) { return; }
setPlayerDeckName(deckName); setPlayerDeckName(deckName);
CardPool cards = new CardPool(questData.getCardpool().getView()); CardPool cards = new CardPool(questData.getCards().getCardpool().getView());
CardPoolView deck = questData.getDeck(deckName).getMain(); CardPoolView deck = questData.getDeck(deckName).getMain();
// show in pool all cards except ones used in deck // show in pool all cards except ones used in deck
@@ -358,7 +358,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
private final ActionListener newDeckActionListener = new ActionListener() { private final ActionListener newDeckActionListener = new ActionListener() {
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
deckDisplay.setDecks(questData.getCardpool().getView(), new CardPool()); deckDisplay.setDecks(questData.getCards().getCardpool().getView(), new CardPool());
setPlayerDeckName(""); setPlayerDeckName("");
} }
}; };
@@ -441,7 +441,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
questData.removeDeck(currentDeck.getName()); questData.removeDeck(currentDeck.getName());
//show card pool //show card pool
deckDisplay.setDecks(questData.getCardpool().getView(), new CardPool()); deckDisplay.setDecks(questData.getCards().getCardpool().getView(), new CardPool());
setPlayerDeckName(""); setPlayerDeckName("");
} }

View File

@@ -1,7 +1,5 @@
package forge.gui.deckeditor; package forge.gui.deckeditor;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
@@ -9,15 +7,15 @@ import java.awt.event.WindowEvent;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.TreeMap;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import net.slightlymagic.braids.util.lambda.Lambda1; import net.slightlymagic.braids.util.lambda.Lambda1;
@@ -27,6 +25,7 @@ import forge.card.CardPoolView;
import forge.card.CardPrinted; import forge.card.CardPrinted;
import forge.deck.Deck; import forge.deck.Deck;
import forge.error.ErrorViewer; import forge.error.ErrorViewer;
import forge.gui.GuiUtils;
import forge.quest.data.QuestData; import forge.quest.data.QuestData;
import forge.view.swing.OldGuiNewGame; import forge.view.swing.OldGuiNewGame;
@@ -38,7 +37,7 @@ import forge.view.swing.OldGuiNewGame;
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public class DeckEditorShop extends DeckEditorBase { public final class DeckEditorShop extends DeckEditorBase {
/** Constant <code>serialVersionUID=3988857075791576483L</code> */ /** Constant <code>serialVersionUID=3988857075791576483L</code> */
private static final long serialVersionUID = 3988857075791576483L; private static final long serialVersionUID = 3988857075791576483L;
@@ -46,9 +45,6 @@ public class DeckEditorShop extends DeckEditorBase {
private JButton buyButton = new JButton(); private JButton buyButton = new JButton();
private JButton sellButton = new JButton(); private JButton sellButton = new JButton();
private JScrollPane jScrollPane3 = new JScrollPane();
private JPanel jPanel3 = new JPanel();
private GridLayout gridLayout1 = new GridLayout();
private JLabel creditsLabel = new JLabel(); private JLabel creditsLabel = new JLabel();
private JLabel jLabel1 = new JLabel(); private JLabel jLabel1 = new JLabel();
private JLabel sellPercentageLabel = new JLabel(); private JLabel sellPercentageLabel = new JLabel();
@@ -60,18 +56,9 @@ public class DeckEditorShop extends DeckEditorBase {
// get pricelist: // get pricelist:
private ReadPriceList r = new ReadPriceList(); private ReadPriceList r = new ReadPriceList();
private Map<String, Integer> mapPrices = r.getPriceList(); private Map<String, Integer> mapPrices = r.getPriceList();
private Map<CardPrinted, Integer> decksUsingMyCards;
/** {@inheritDoc} */
/**
* <p>
* show.
* </p>
*
* @param exitCommand
* a {@link forge.Command} object.
*/
public void show(final Command exitCommand) { public void show(final Command exitCommand) {
final Command exit = new Command() { final Command exit = new Command() {
private static final long serialVersionUID = -7428793574300520612L; private static final long serialVersionUID = -7428793574300520612L;
@@ -92,21 +79,23 @@ public class DeckEditorShop extends DeckEditorBase {
setup(); setup();
multiplier = questData.getSellMutliplier(); decksUsingMyCards = countDecksForEachCard();
CardPoolView forSale = questData.getShopList(); multiplier = questData.getCards().getSellMutliplier();
CardPoolView forSale = questData.getCards().getShopList();
if (forSale.isEmpty()) { if (forSale.isEmpty()) {
questData.generateCardsInShop(); questData.getCards().generateCardsInShop();
forSale = questData.getShopList(); forSale = questData.getCards().getShopList();
} }
CardPoolView owned = questData.getCardpool().getView(); CardPoolView owned = questData.getCards().getCardpool().getView();
setDecks(forSale, owned); setDecks(forSale, owned);
double multiPercent = multiplier * 100; double multiPercent = multiplier * 100;
NumberFormat formatter = new DecimalFormat("#0.00"); NumberFormat formatter = new DecimalFormat("#0.00");
String maxSellingPrice = ""; String maxSellingPrice = "";
int maxSellPrice = questData.getSellPriceLimit(); int maxSellPrice = questData.getCards().getSellPriceLimit();
if (maxSellPrice < Integer.MAX_VALUE) { maxSellingPrice = String.format(" Max selling price: %d", maxSellPrice); } if (maxSellPrice < Integer.MAX_VALUE) { maxSellingPrice = String.format(" Max selling price: %d", maxSellPrice); }
sellPercentageLabel.setText("(Sell percentage: " + formatter.format(multiPercent) + "% of value)" + maxSellingPrice); sellPercentageLabel.setText("(Sell percentage: " + formatter.format(multiPercent) + "% of value)" + maxSellingPrice);
@@ -115,6 +104,21 @@ public class DeckEditorShop extends DeckEditorBase {
bottom.sort(1, true); bottom.sort(1, true);
} // show(Command) } // show(Command)
// fills number of decks using each card
private Map<CardPrinted, Integer> countDecksForEachCard() {
Map<CardPrinted, Integer> result = new HashMap<CardPrinted, Integer>();
for (String deckName : questData.getDeckNames()) {
Deck deck = questData.getDeck(deckName);
for (Entry<CardPrinted, Integer> e : deck.getMain()) {
CardPrinted card = e.getKey();
Integer iValue = result.get(card);
int cntDecks = iValue == null ? 1 : 1 + iValue.intValue();
result.put(card, Integer.valueOf(cntDecks));
}
}
return result;
}
/** /**
* <p> * <p>
* setup. * setup.
@@ -128,27 +132,21 @@ public class DeckEditorShop extends DeckEditorBase {
columns.add(new TableColumnInfo<CardPrinted>("Color", 50, PresetColumns.fnColorCompare, PresetColumns.fnColorGet)); columns.add(new TableColumnInfo<CardPrinted>("Color", 50, PresetColumns.fnColorCompare, PresetColumns.fnColorGet));
columns.add(new TableColumnInfo<CardPrinted>("Type", 100, PresetColumns.fnTypeCompare, PresetColumns.fnTypeGet)); columns.add(new TableColumnInfo<CardPrinted>("Type", 100, PresetColumns.fnTypeCompare, PresetColumns.fnTypeGet));
columns.add(new TableColumnInfo<CardPrinted>("Stats", 40, PresetColumns.fnStatsCompare, PresetColumns.fnStatsGet)); columns.add(new TableColumnInfo<CardPrinted>("Stats", 40, PresetColumns.fnStatsCompare, PresetColumns.fnStatsGet));
columns.add(new TableColumnInfo<CardPrinted>("R", 35, PresetColumns.fnRarityCompare, PresetColumns.fnRarityGet)); columns.add(new TableColumnInfo<CardPrinted>("R", 30, PresetColumns.fnRarityCompare, PresetColumns.fnRarityGet));
columns.add(new TableColumnInfo<CardPrinted>("Set", 40, PresetColumns.fnSetCompare, PresetColumns.fnSetGet)); columns.add(new TableColumnInfo<CardPrinted>("Set", 35, PresetColumns.fnSetCompare, PresetColumns.fnSetGet));
List<TableColumnInfo<CardPrinted>> columnsBelow = new ArrayList<TableColumnInfo<CardPrinted>>(columns);
columns.add(new TableColumnInfo<CardPrinted>("Price", 40, fnPriceCompare, fnPriceGet)); columns.add(new TableColumnInfo<CardPrinted>("Price", 40, fnPriceCompare, fnPriceGet));
top.setup(columns, cardView); top.setup(columns, cardView);
bottom.setup(columns, cardView);
setSize(1024, 768); columnsBelow.add(new TableColumnInfo<CardPrinted>("#Dk", 30, fnDeckCompare, fnDeckGet));
columnsBelow.add(new TableColumnInfo<CardPrinted>("Price", 40, fnPriceCompare, fnPriceGet));
bottom.setup(columnsBelow, cardView);
this.setSize(1024, 768);
GuiUtils.centerFrame(this);
this.setResizable(false); this.setResizable(false);
Dimension screen = getToolkit().getScreenSize(); }
Rectangle bounds = getBounds();
bounds.width = 1024;
bounds.height = 768;
bounds.x = (screen.width - bounds.width) / 2;
bounds.y = (screen.height - bounds.height) / 2;
setBounds(bounds);
// TODO use this as soon the deck editor has resizable GUI
// //Use both so that when "un"maximizing, the frame isn't tiny
// setSize(1024, 740);
// setExtendedState(Frame.MAXIMIZED_BOTH);
}// setupAndDisplay()
/** /**
* <p> * <p>
@@ -211,12 +209,7 @@ public class DeckEditorShop extends DeckEditorBase {
// Do not lower statsLabel any lower, we want this to be visible at 1024 // Do not lower statsLabel any lower, we want this to be visible at 1024
// x 768 screen size // x 768 screen size
this.setTitle("Card Shop"); this.setTitle("Card Shop");
jScrollPane3.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jScrollPane3.setBounds(new Rectangle(6, 168, 225, 143));
jPanel3.setBounds(new Rectangle(7, 21, 224, 141));
jPanel3.setLayout(gridLayout1);
gridLayout1.setColumns(1);
gridLayout1.setRows(0);
creditsLabel.setBounds(new Rectangle(19, 365, 720, 31)); creditsLabel.setBounds(new Rectangle(19, 365, 720, 31));
creditsLabel.setText("Total credits: " + questData.getCredits()); creditsLabel.setText("Total credits: " + questData.getCredits());
if (!OldGuiNewGame.useLAFFonts.isSelected()) if (!OldGuiNewGame.useLAFFonts.isSelected())
@@ -227,6 +220,7 @@ public class DeckEditorShop extends DeckEditorBase {
sellPercentageLabel.setFont(new java.awt.Font("Dialog", 0, 14)); sellPercentageLabel.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel1.setText("Click on the column name (like name or color) to sort the cards"); jLabel1.setText("Click on the column name (like name or color) to sort the cards");
jLabel1.setBounds(new Rectangle(20, 1, 400, 19)); jLabel1.setBounds(new Rectangle(20, 1, 400, 19));
this.getContentPane().add(cardView, null); this.getContentPane().add(cardView, null);
this.getContentPane().add(top.getTableDecorated(), null); this.getContentPane().add(top.getTableDecorated(), null);
this.getContentPane().add(bottom.getTableDecorated(), null); this.getContentPane().add(bottom.getTableDecorated(), null);
@@ -263,7 +257,7 @@ public class DeckEditorShop extends DeckEditorBase {
bottom.addCard(c); bottom.addCard(c);
top.removeCard(c); top.removeCard(c);
questData.buyCard(c, value); questData.getCards().buyCard(c, value);
creditsLabel.setText("Total credits: " + questData.getCredits()); creditsLabel.setText("Total credits: " + questData.getCredits());
} else { } else {
@@ -271,14 +265,7 @@ public class DeckEditorShop extends DeckEditorBase {
} }
} }
/**
* <p>
* sellButton_actionPerformed.
* </p>
*
* @param e
* a {@link java.awt.event.ActionEvent} object.
*/
void sellButton_actionPerformed(ActionEvent e) { void sellButton_actionPerformed(ActionEvent e) {
CardPrinted c = bottom.getSelectedCard(); CardPrinted c = bottom.getSelectedCard();
if (c == null) { return; } if (c == null) { return; }
@@ -286,20 +273,10 @@ public class DeckEditorShop extends DeckEditorBase {
bottom.removeCard(c); bottom.removeCard(c);
top.addCard(c); top.addCard(c);
int price = Math.min((int) (multiplier * getCardValue(c)), questData.getSellPriceLimit()); int price = Math.min((int) (multiplier * getCardValue(c)), questData.getCards().getSellPriceLimit());
questData.sellCard(c, price); questData.getCards().sellCard(c, price);
questData.addCardToShopList(c);
creditsLabel.setText("Total credits: " + questData.getCredits()); creditsLabel.setText("Total credits: " + questData.getCredits());
int leftInPool = questData.getCardpool().count(c);
// remove sold cards from all decks:
for (String deckName : questData.getDeckNames()) {
Deck deck = questData.getDeck(deckName);
for (int cntInDeck = deck.getMain().count(c); cntInDeck > leftInPool; cntInDeck--) {
deck.removeMain(c);
}
}
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@@ -310,4 +287,17 @@ public class DeckEditorShop extends DeckEditorBase {
new Lambda1<Object, Entry<CardPrinted, Integer>>() { @Override new Lambda1<Object, Entry<CardPrinted, Integer>>() { @Override
public Object apply(final Entry<CardPrinted, Integer> from) { return getCardValue(from.getKey()); } }; public Object apply(final Entry<CardPrinted, Integer> from) { return getCardValue(from.getKey()); } };
@SuppressWarnings("rawtypes")
private final Lambda1<Comparable, Entry<CardPrinted, Integer>> fnDeckCompare =
new Lambda1<Comparable, Entry<CardPrinted, Integer>>() { @Override
public Comparable apply(final Entry<CardPrinted, Integer> from) {
Integer iValue = decksUsingMyCards.get(from.getKey());
return iValue == null ? Integer.valueOf(0) : iValue;
} };
private final Lambda1<Object, Entry<CardPrinted, Integer>> fnDeckGet =
new Lambda1<Object, Entry<CardPrinted, Integer>>() { @Override
public Object apply(final Entry<CardPrinted, Integer> from) {
Integer iValue = decksUsingMyCards.get(from.getKey());
return iValue == null ? "" : iValue.toString();
} };
} }

View File

@@ -1,12 +1,9 @@
package forge.quest.data; package forge.quest.data;
import forge.Constant;
import forge.card.CardDb; import forge.card.CardDb;
import forge.card.CardPrinted; import forge.card.CardPrinted;
import forge.card.CardRarity; import forge.card.CardRarity;
import forge.card.CardRules; import forge.card.CardRules;
import forge.properties.NewConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@@ -22,49 +19,12 @@ import net.slightlymagic.maxmtg.Predicate;
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public class QuestBoosterPack implements NewConstants { public final class QuestBoosterPack {
ArrayList<String> choices;
/** public static List<CardPrinted> getQuestStarterDeck(final Predicate<CardPrinted> filter,
* <p>Constructor for QuestBoosterPack.</p> final int numCommon, final int numUncommon, final int numRare)
*/ {
public QuestBoosterPack() { ArrayList<CardPrinted> cards = new ArrayList<CardPrinted>();
choices = new ArrayList<String>();
choices.add("Multicolor");
for (String s : Constant.Color.Colors) {
choices.add(s);
choices.add(s);
}
}
/**
* <p>
* getQuestStarterDeck.
* </p>
*
* @param allCards
* the card pool from which we can generate the deck
*
* @param numCommon
* a int.
*
* @param numUncommon
* a int.
*
* @param numRare
* a int.
*
* @param standardPool
* whether to restrict the card pool to what is currently
* considered the Standard block. To update the sets that are
* considered standard, modify this method.
*
* @return a {@link java.util.ArrayList} object.
*/
public List<CardPrinted> getQuestStarterDeck( final Predicate<CardPrinted> filter,
int numCommon, int numUncommon, int numRare ) {
ArrayList<CardPrinted> names = new ArrayList<CardPrinted>();
// Each color should have around the same amount of monocolored cards // Each color should have around the same amount of monocolored cards
// There should be 3 Colorless cards for every 4 cards in a single color // There should be 3 Colorless cards for every 4 cards in a single color
@@ -85,14 +45,13 @@ public class QuestBoosterPack implements NewConstants {
Iterable<CardPrinted> cardpool = CardDb.instance().getAllUniqueCards(); Iterable<CardPrinted> cardpool = CardDb.instance().getAllUniqueCards();
names.addAll(generateDefinetlyColouredCards(cardpool, cards.addAll(generateDefinetlyColouredCards(cardpool,
Predicate.and(filter, CardPrinted.Predicates.Presets.isCommon), numCommon, colorFilters)); Predicate.and(filter, CardPrinted.Predicates.Presets.isCommon), numCommon, colorFilters));
names.addAll(generateDefinetlyColouredCards(cardpool, cards.addAll(generateDefinetlyColouredCards(cardpool,
Predicate.and(filter, CardPrinted.Predicates.Presets.isUncommon), numUncommon, colorFilters)); Predicate.and(filter, CardPrinted.Predicates.Presets.isUncommon), numUncommon, colorFilters));
names.addAll(generateDefinetlyColouredCards(cardpool, cards.addAll(generateDefinetlyColouredCards(cardpool,
Predicate.and(filter, CardPrinted.Predicates.Presets.isRareOrMythic), numRare, colorFilters)); Predicate.and(filter, CardPrinted.Predicates.Presets.isRareOrMythic), numRare, colorFilters));
return cards;
return names;
} }
/** /**
@@ -104,7 +63,7 @@ public class QuestBoosterPack implements NewConstants {
* @param allowedColors a List<Predicate<CardRules>> * @param allowedColors a List<Predicate<CardRules>>
* @return a list of card names * @return a list of card names
*/ */
public final ArrayList<CardPrinted> generateDefinetlyColouredCards( private static ArrayList<CardPrinted> generateDefinetlyColouredCards(
final Iterable<CardPrinted> source, final Iterable<CardPrinted> source,
final Predicate<CardPrinted> filter, final Predicate<CardPrinted> filter,
final int cntNeeded, final int cntNeeded,
@@ -148,13 +107,13 @@ public class QuestBoosterPack implements NewConstants {
} }
public ArrayList<CardPrinted> generateDistinctCards( private static ArrayList<CardPrinted> generateDistinctCards(
final Iterable<CardPrinted> source, final Iterable<CardPrinted> source,
final Predicate<CardPrinted> filter, final Predicate<CardPrinted> filter,
final int cntNeeded) final int cntNeeded)
{ {
ArrayList<CardPrinted> result = new ArrayList<CardPrinted>(); ArrayList<CardPrinted> result = new ArrayList<CardPrinted>();
int cntMade = 0, iAttempt = 0; int cntMade = 0;
// This will prevent endless loop @ wh // This will prevent endless loop @ wh
int allowedMisses = (2 + 2) * cntNeeded; // lol, 2+2 is not magic constant! int allowedMisses = (2 + 2) * cntNeeded; // lol, 2+2 is not magic constant!
@@ -167,7 +126,6 @@ public class QuestBoosterPack implements NewConstants {
cntMade++; cntMade++;
} }
else { allowedMisses--; } else { allowedMisses--; }
iAttempt++;
} }
return result; return result;
@@ -175,17 +133,17 @@ public class QuestBoosterPack implements NewConstants {
// Left if only for backwards compatibility // Left if only for backwards compatibility
public ArrayList<CardPrinted> generateCards(int num, CardRarity rarity, String color) { public ArrayList<CardPrinted> generateCards(final int num, final CardRarity rarity, final String color) {
Predicate<CardPrinted> whatYouWant = getPredicateForConditions(rarity, color); Predicate<CardPrinted> whatYouWant = getPredicateForConditions(rarity, color);
return generateDistinctCards(CardDb.instance().getAllUniqueCards(), whatYouWant, num); return generateDistinctCards(CardDb.instance().getAllUniqueCards(), whatYouWant, num);
} }
public ArrayList<CardPrinted> generateCards(Predicate<CardPrinted> filter, int num, CardRarity rarity, String color) { public static ArrayList<CardPrinted> generateCards(final Predicate<CardPrinted> filter, int num, CardRarity rarity, String color) {
Predicate<CardPrinted> whatYouWant = Predicate.and(filter, getPredicateForConditions(rarity, color)); Predicate<CardPrinted> whatYouWant = Predicate.and(filter, getPredicateForConditions(rarity, color));
return generateDistinctCards(CardDb.instance().getAllUniqueCards(), whatYouWant, num); return generateDistinctCards(CardDb.instance().getAllUniqueCards(), whatYouWant, num);
} }
protected Predicate<CardPrinted> getPredicateForConditions(CardRarity rarity, String color) private static Predicate<CardPrinted> getPredicateForConditions(final CardRarity rarity, final String color)
{ {
Predicate<CardPrinted> rFilter; Predicate<CardPrinted> rFilter;
switch (rarity) { switch (rarity) {

View File

@@ -1,17 +1,10 @@
package forge.quest.data; package forge.quest.data;
import forge.*; import forge.MyRandom;
import forge.card.CardDb;
import forge.card.CardPool; import forge.card.CardPool;
import forge.card.CardPoolView;
import forge.card.CardPrinted; import forge.card.CardPrinted;
import forge.card.CardRarity;
import forge.deck.Deck; import forge.deck.Deck;
import forge.error.ErrorViewer; import forge.error.ErrorViewer;
import forge.game.GameLossReason;
import forge.game.GamePlayerRating;
import forge.game.GameSummary;
import forge.game.PlayerIndex;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
import forge.properties.NewConstants; import forge.properties.NewConstants;
import forge.quest.data.item.QuestInventory; import forge.quest.data.item.QuestInventory;
@@ -24,12 +17,10 @@ import java.util.Map;
import net.slightlymagic.maxmtg.Predicate; import net.slightlymagic.maxmtg.Predicate;
//when you create QuestDataOld and AFTER you copy the AI decks over //when you create QuestDataOld and AFTER you copy the AI decks over
//you have to call one of these two methods below //you have to call one of these two methods below
//see Gui_QuestOptions for more details //see Gui_QuestOptions for more details
//
//static readAIQuestDeckFiles(QuestDataOld data, ArrayList aiDeckNames) //static readAIQuestDeckFiles(QuestDataOld data, ArrayList aiDeckNames)
//OR non-static readAIQuestDeckFiles() //OR non-static readAIQuestDeckFiles()
//which reads the files "questDecks-easy", "questDecks-medium","questDecks-hard", //which reads the files "questDecks-easy", "questDecks-medium","questDecks-hard",
@@ -42,42 +33,6 @@ import net.slightlymagic.maxmtg.Predicate;
*/ */
public final class QuestData { public final class QuestData {
int rankIndex;
int win;
int lost;
int life;
int questsPlayed;
long credits;
int diffIndex;
String difficulty;
String mode = "";
Map<String, Deck> myDecks = new HashMap<String, Deck>();
CardPool cardPool = new CardPool();
CardPool shopList = new CardPool();
List<Integer> availableQuests = new ArrayList<Integer>();
List<Integer> completedQuests = new ArrayList<Integer>();
private transient QuestBoosterPack boosterPack;
//used by shouldAddAdditionalCards()
private long randomSeed = 0;
private transient String[] rankArray;
/** Constant <code>FANTASY="Fantasy"</code> */
public static final String FANTASY = "Fantasy";
/** Constant <code>REALISTIC="Realistic"</code> */
public static final String REALISTIC = "Realistic";
QuestInventory inventory = new QuestInventory();
//This field holds the version of the Quest Data //This field holds the version of the Quest Data
/** Constant <code>CURRENT_VERSION_NUMBER=2</code> */ /** Constant <code>CURRENT_VERSION_NUMBER=2</code> */
public static final int CURRENT_VERSION_NUMBER = 2; public static final int CURRENT_VERSION_NUMBER = 2;
@@ -87,34 +42,49 @@ public final class QuestData {
//DO NOT RENAME THIS FIELD //DO NOT RENAME THIS FIELD
int versionNumber = CURRENT_VERSION_NUMBER; int versionNumber = CURRENT_VERSION_NUMBER;
QuestPetManager petManager = new QuestPetManager(); int rankIndex; // level
int win; // number of wins
int lost;
/** long credits; // this money is good for all modes
* <p>Constructor for QuestData.</p>
*/
public QuestData() {
cardPool.add(CardDb.instance().getCard("Forest", "M10"), QuestPreferences.getStartingBasic()); int life; // for fantasy mode, how much life bought at shop to start game with
cardPool.add(CardDb.instance().getCard("Mountain", "M10"), QuestPreferences.getStartingBasic()); QuestInventory inventory = new QuestInventory(); // different gadgets
cardPool.add(CardDb.instance().getCard("Swamp", "M10"), QuestPreferences.getStartingBasic()); QuestPetManager petManager = new QuestPetManager(); // pets that start match with you
cardPool.add(CardDb.instance().getCard("Island", "M10"), QuestPreferences.getStartingBasic());
cardPool.add(CardDb.instance().getCard("Plains", "M10"), QuestPreferences.getStartingBasic());
cardPool.add(CardDb.instance().getCard("Snow-Covered Forest", "ICE"), QuestPreferences.getStartingSnowBasic());
cardPool.add(CardDb.instance().getCard("Snow-Covered Mountain", "ICE"), QuestPreferences.getStartingSnowBasic());
cardPool.add(CardDb.instance().getCard("Snow-Covered Swamp", "ICE"), QuestPreferences.getStartingSnowBasic());
cardPool.add(CardDb.instance().getCard("Snow-Covered Island", "ICE"), QuestPreferences.getStartingSnowBasic());
cardPool.add(CardDb.instance().getCard("Snow-Covered Plains", "ICE"), QuestPreferences.getStartingSnowBasic());
initTransients(); // Diffuculty - they store both index and title
randomizeOpponents(); int diffIndex;
} String difficulty;
/** // Quest mode - there should be an enum :(
* <p>initTransients.</p> String mode = "";
*/ public static final String FANTASY = "Fantasy";
private void initTransients() { public static final String REALISTIC = "Realistic";
rankArray = new String[]{
// Decks collected by player
Map<String, Deck> myDecks = new HashMap<String, Deck>();
// Cards associated with quest
CardPool cardPool = new CardPool(); // player's belonging
CardPool shopList = new CardPool(); // the current shop list
CardPool newCardList = new CardPool(); // cards acquired since last game-win/loss
// Quests history
int questsPlayed;
List<Integer> availableQuests = new ArrayList<Integer>();
List<Integer> completedQuests = new ArrayList<Integer>();
// own randomizer seed
private long randomSeed = 0;
// Utility class to access cards, has access to private fields
// Moved some methods there that otherwise would make this class even more complex
private transient QuestUtilCards myCards;
private transient QuestUtilRewards myRewards;
public static final String[] RANK_TITLES = new String[]{
"Level 0 - Confused Wizard", "Level 0 - Confused Wizard",
"Level 1 - Mana Mage", "Level 1 - Mana Mage",
"Level 2 - Death by Megrim", "Level 2 - Death by Megrim",
@@ -126,550 +96,87 @@ public final class QuestData {
"Level 8 - Immobilized by Fear", "Level 8 - Immobilized by Fear",
"Level 9 - Lands = Friends", "Level 9 - Lands = Friends",
"Saltblasted for your talent", "Saltblasted for your talent",
"Serra Angel is your girlfriend",}; "Serra Angel is your girlfriend",
};
boosterPack = new QuestBoosterPack();
}
//adds cards to card pool and sets difficulty
/** /**
* <p>newGame.</p> * <p>Constructor for QuestData.</p>
*
* @param difficulty a int.
* @param m a {@link java.lang.String} object.
* @param standardStart a boolean.
*/ */
public void newGame(int difficulty, String m, boolean standardStart) { public QuestData() {
setDifficulty(difficulty); initTransients();
myCards.generateBasicLands(QuestPreferences.getStartingBasic(), QuestPreferences.getStartingSnowBasic());
randomizeOpponents();
}
private void initTransients() {
myCards = new QuestUtilCards(this);
myRewards = new QuestUtilRewards(this);
}
public void newGame(final int diff, final String m0de, final boolean standardStart) {
setDifficulty(diff);
Predicate<CardPrinted> filter = standardStart Predicate<CardPrinted> filter = standardStart
? CardPrinted.Predicates.Presets.isStandard ? CardPrinted.Predicates.Presets.isStandard
: Predicate.getTrue(CardPrinted.class); : Predicate.getTrue(CardPrinted.class);
List<CardPrinted> list = boosterPack.getQuestStarterDeck( myCards.setupNewGameCardPool(filter, diff);
filter,
QuestPreferences.getStartingCommons(difficulty),
QuestPreferences.getStartingUncommons(difficulty),
QuestPreferences.getStartingRares(difficulty));
//because cardPool already has basic land added to it
addAllCards(list);
credits = QuestPreferences.getStartingCredits(); credits = QuestPreferences.getStartingCredits();
mode = m; mode = m0de;
if (mode.equals(FANTASY)) { life = mode.equals(FANTASY) ? 15 : 20;
life = 15;
} else {
life = 20;
}
} }
/** // All belongins
* This method should be called whenever the opponents should change. public QuestInventory getInventory() { return inventory; }
*/ public QuestPetManager getPetManager() { return petManager; }
public void randomizeOpponents() { // Cards - class uses data from here
randomSeed = MyRandom.random.nextLong(); public QuestUtilCards getCards() { return myCards; }
} public QuestUtilRewards getRewards() { return myRewards; }
// Quests performance
public int getQuestsPlayed() { return questsPlayed; }
public void addQuestsPlayed() { questsPlayed++; }
/** public List<Integer> getAvailableQuests() { return availableQuests != null ? new ArrayList<Integer>(availableQuests) : null; }
* <p>saveData.</p> public void setAvailableQuests(final List<Integer> list) { availableQuests = list; }
*/ public void clearAvailableQuests() { availableQuests.clear(); }
public void saveData() { public List<Integer> getCompletedQuests() { return completedQuests != null ? new ArrayList<Integer>(completedQuests) : null; }
QuestDataIO.saveData(this);
}
// Wins & Losses
public CardPool getCardpool() { public int getLost() { return lost; }
return cardPool; public void addLost() { lost++; }
} public int getWin() { return win; }
public void addWin() { //changes getRank()
/**
* <p>Getter for the field <code>shopList</code>.</p>
*
* @return a {@link java.util.List} object.
*/
public CardPoolView getShopList() {
if (shopList.isEmpty()) {
generateCardsInShop();
}
return shopList;
}
/**
* <p>Setter for the field <code>shopList</code>.</p>
*
* @param list a {@link java.util.List} object.
*/
public void generateCardsInShop() {
ReadBoosterPack pack = new ReadBoosterPack();
CardPoolView fromBoosters = pack.getShopCards(getWin(), getLevel());
shopList.clear();
shopList.addAll(fromBoosters);
}
/**
* <p>Getter for the field <code>availableQuests</code>.</p>
*
* @return a {@link java.util.List} object.
*/
public List<Integer> getAvailableQuests() {
if (availableQuests != null) {
return new ArrayList<Integer>(availableQuests);
} else {
return null;
}
}
/**
* <p>Setter for the field <code>availableQuests</code>.</p>
*
* @param list a {@link java.util.List} object.
*/
public void setAvailableQuests(List<Integer> list) {
availableQuests = list;
}
/**
* <p>clearAvailableQuests.</p>
*/
public void clearAvailableQuests() {
availableQuests.clear();
}
/**
* <p>Getter for the field <code>completedQuests</code>.</p>
*
* @return a {@link java.util.List} object.
*/
public List<Integer> getCompletedQuests() {
if (completedQuests != null) {
return new ArrayList<Integer>(completedQuests);
} else {
return null;
}
}
/**
* <p>Setter for the field <code>completedQuests</code>.</p>
*
* @param list a {@link java.util.List} object.
*/
public void setCompletedQuests(List<Integer> list) {
completedQuests = list;
}
/**
* <p>clearShopList.</p>
*/
public void clearShopList() {
if (null != shopList) { shopList.clear(); }
}
/**
* <p>removeDeck.</p>
*
* @param deckName a {@link java.lang.String} object.
*/
public void removeDeck(String deckName) {
myDecks.remove(deckName);
}
/**
* <p>addDeck.</p>
*
* @param d a {@link forge.deck.Deck} object.
*/
public void addDeck(Deck d) {
myDecks.put(d.getName(), d);
}
//this Deck object is a Constructed deck
//deck.getDeckType() is Constant.GameType.Sealed
//sealed since the card pool is the Deck sideboard
/**
* <p>getDeck.</p>
*
* @param deckName a {@link java.lang.String} object.
* @return a {@link forge.deck.Deck} object.
*/
public Deck getDeck(String deckName) {
//have to always set the card pool aka the Deck sideboard
//because new cards may have been added to the card pool by addCards()
if (!myDecks.containsKey(deckName)) {
ErrorViewer.showError(new Exception(),
"QuestData : getDeckFromMap(String deckName) error, deck name not found - %s", deckName);
}
Deck d = myDecks.get(deckName);
d.clearSideboard();
return d;
}
//returns human player decks
//returns ArrayList of String deck names
/**
* <p>getDeckNames.</p>
*
* @return a {@link java.util.List} object.
*/
public List<String> getDeckNames() {
return new ArrayList<String>(myDecks.keySet());
}
//adds 11 cards, to the current card pool
//(I chose 11 cards instead of 15 in order to make things more challenging)
/**
* <p>addCards.</p>
*/
public ArrayList<CardPrinted> addCards( List<String> setsFilter ) {
int nCommon = QuestPreferences.getNumCommon();
int nUncommon = QuestPreferences.getNumUncommon();
int nRare = QuestPreferences.getNumRare();
Predicate<CardPrinted> fSets = CardPrinted.Predicates.printedInSets(setsFilter, true);
ArrayList<CardPrinted> newCards = new ArrayList<CardPrinted>();
newCards.addAll(boosterPack.generateCards(fSets, nCommon, CardRarity.Common, null));
newCards.addAll(boosterPack.generateCards(fSets, nUncommon, CardRarity.Uncommon, null));
newCards.addAll(boosterPack.generateCards(fSets, nRare, CardRarity.Rare, null));
addAllCards(newCards);
return newCards;
}
/**
* <p>addRandomRare.</p>
*
* @param n a int.
* @return a {@link java.util.ArrayList} object.
*/
public ArrayList<CardPrinted> addRandomRare(int n) {
ArrayList<CardPrinted> newCards = new ArrayList<CardPrinted>();
newCards.addAll(boosterPack.generateCards(n, CardRarity.Rare, null));
addAllCards(newCards);
return newCards;
}
public void addAllCards(Iterable<CardPrinted> newCards) {
for (CardPrinted card : newCards) {
cardPool.add( card );
}
}
/**
* <p>addRandomRare.</p>
*
* @return a {@link java.lang.String} object.
*/
public CardPrinted addRandomRare() {
return addRandomRare(1).get(0);
}
/**
* <p>addCardToShopList.</p>
*
* @param c a {@link forge.Card} object.
*/
public void addCardToShopList(CardPrinted c) {
shopList.add(c);
}
public final int getCreditsRewardForAltWin(final GameLossReason whyAiLost) {
int rewardAltWinCondition = 0;
switch (whyAiLost) {
case LifeReachedZero:
break; // nothing special here, ordinary kill
case Milled:
rewardAltWinCondition = QuestPreferences.getMatchRewardMilledWinBonus();
break;
case Poisoned:
rewardAltWinCondition = QuestPreferences.getMatchRewardPoisonWinBonus();
break;
case DidNotLoseYet: // must be player's alternate win condition: felidar, helix pinnacle and like this
rewardAltWinCondition = QuestPreferences.getMatchRewardAltWinBonus();
break;
case SpellEffect: // Door to Nothingness or something like this
rewardAltWinCondition = QuestPreferences.getMatchRewardAltWinBonus();
break;
default: // this .checkstyle forces us to write some idiotic code
rewardAltWinCondition = 0;
}
return rewardAltWinCondition;
}
public final int getCreditsRewardForWinByTurn(final int iTurn) {
if (iTurn == 1) {
return QuestPreferences.getMatchRewardWinFirst();
} else if (iTurn <= 5) {
return QuestPreferences.getMatchRewardWinByFifth();
} else if (iTurn <= 10) {
return QuestPreferences.getMatchRewardWinByTen();
} else if (iTurn <= 15) {
return QuestPreferences.getMatchRewardWinByFifteen();
}
return 0;
}
/**
* <p>getCreditsToAdd.</p>
*
* @param matchState a {@link forge.quest.data.QuestMatchState} object.
* @return a long.
*/
public final long getCreditsToAdd(final QuestMatchState matchState) {
long creds = (long) (QuestPreferences.getMatchRewardBase()
+ (QuestPreferences.getMatchRewardTotalWins() * win));
boolean hasNeverLost = true;
for (GameSummary game : matchState.getGamesPlayed()) {
if (game.isAIWinner()) {
hasNeverLost = true;
continue; // no rewards for losing a game
}
GamePlayerRating aiRating = game.getPlayerRating(PlayerIndex.AI);
GamePlayerRating humanRating = game.getPlayerRating(PlayerIndex.HUMAN);
GameLossReason whyAiLost = aiRating.getLossReason();
creds += getCreditsRewardForAltWin(whyAiLost);
creds += getCreditsRewardForWinByTurn(game.getTurnGameEnded());
int cntCardsHumanStartedWith = humanRating.getOpeningHandSize();
if (0 == cntCardsHumanStartedWith) {
creds += QuestPreferences.getMatchMullToZero();
}
}
if (hasNeverLost) {
creds += QuestPreferences.getMatchRewardNoLosses();
}
switch(inventory.getItemLevel("Estates")) {
case 1: creds *= 1.1; break;
case 2: creds *= 1.15; break;
case 3: creds *= 1.2; break;
default: break;
}
return creds;
}
//gets all of the cards that are in the cardpool
/**
* <p>getTotalNumberOfGames.</p>
*
* @param difficulty a int.
* @return a int.
*/
public int getTotalNumberOfGames(int difficulty) {
//-2 because you start a level 1, and the last level is secret
int numberLevels = rankArray.length - 2;
int nMatches = QuestPreferences.getWinsForRankIncrease(difficulty);
return numberLevels * nMatches;
}
//this changes getRank()
/**
* <p>addWin.</p>
*/
public void addWin() {
win++; win++;
if (win % QuestPreferences.getWinsForRankIncrease(diffIndex) == 0) { int winsToLvlUp = QuestPreferences.getWinsForRankIncrease(diffIndex);
rankIndex++; if (win % winsToLvlUp == 0) { rankIndex++; }
}
} }
/** // Life (only fantasy)
* <p>addLost.</p> public int getLife() { return isFantasy() ? life : 20; }
*/ public void addLife(final int n) { life += n; }
public void addLost() {
lost++;
}
/** // Credits
* <p>Getter for the field <code>win</code>.</p> public void addCredits(final long c) { credits += c; }
* public void subtractCredits(final long c) { credits = credits > c ? credits - c : 0; }
* @return a int. public long getCredits() { return credits; }
*/
public int getWin() {
return win;
}
/** // Quest mode
* <p>Getter for the field <code>lost</code>.</p> public boolean isFantasy() { return mode.equals(FANTASY); }
* public String getMode() { return mode == null ? "" : mode; }
* @return a int.
*/
public int getLost() {
return lost;
}
//********************FANTASY STUFF START*********************** // Difficulty
public String getDifficulty() { return difficulty; }
public int getDifficultyIndex() { return diffIndex; }
/** public void setDifficulty(final int i) {
* <p>Setter for the field <code>life</code>.</p>
*
* @param n a int.
*/
public void setLife(int n) {
life = n;
}
/**
* <p>Getter for the field <code>life</code>.</p>
*
* @return a int.
*/
public int getLife() {
return life;
}
/**
* <p>addLife.</p>
*
* @param n a int.
*/
public void addLife(int n) {
life += n;
}
/**
* <p>Getter for the field <code>questsPlayed</code>.</p>
*
* @return a int.
*/
public int getQuestsPlayed() {
return questsPlayed;
}
/**
* <p>addQuestsPlayed.</p>
*/
public void addQuestsPlayed() {
questsPlayed++;
}
//********************FANTASY STUFF END***********************
/**
* <p>addCredits.</p>
*
* @param c a long.
*/
public void addCredits(long c) {
credits += c;
}
/**
* <p>subtractCredits.</p>
*
* @param c a long.
*/
public void subtractCredits(long c) {
credits -= c;
if (credits < 0) {
credits = 0;
}
}
/**
* <p>Getter for the field <code>credits</code>.</p>
*
* @return a long.
*/
public long getCredits() {
return credits;
}
/**
* <p>Getter for the field <code>mode</code>.</p>
*
* @return a {@link java.lang.String} object.
*/
public String getMode() {
if (mode == null) {
return "";
}
return mode;
}
public double getSellMutliplier() {
double multi = 0.20 + (0.001 * getWin());
if (multi > 0.6)
multi = 0.6;
if (getMode().equals(forge.quest.data.QuestData.FANTASY)) {
if (getInventory().getItemLevel("Estates") == 1)
multi += 0.01;
else if (getInventory().getItemLevel("Estates") == 2)
multi += 0.0175;
else if (getInventory().getItemLevel("Estates") >= 3)
multi += 0.025;
}
return multi;
}
public int getSellPriceLimit() {
return getWin() <= 50 ? 1000 : Integer.MAX_VALUE;
}
//should be called first, because the difficultly won't change
/**
* <p>Getter for the field <code>difficulty</code>.</p>
*
* @return a {@link java.lang.String} object.
*/
public String getDifficulty() {
return difficulty;
}
/**
* <p>getDifficultyIndex.</p>
*
* @return a int.
*/
public int getDifficultyIndex() {
return diffIndex;
}
/**
* <p>Setter for the field <code>difficulty</code>.</p>
*
* @param i a int.
*/
public void setDifficulty(int i) {
diffIndex = i; diffIndex = i;
difficulty = QuestPreferences.getDifficulty(i); difficulty = QuestPreferences.getDifficulty(i);
} }
/** public void guessDifficultyIndex() {
* <p>setDifficultyIndex.</p>
*/
public void setDifficultyIndex() {
String[] diffStr = QuestPreferences.getDifficulty(); String[] diffStr = QuestPreferences.getDifficulty();
for (int i = 0; i < diffStr.length; i++) { for (int i = 0; i < diffStr.length; i++) {
if (difficulty.equals(diffStr[i])) { if (difficulty.equals(diffStr[i])) {
@@ -678,139 +185,56 @@ public final class QuestData {
} }
} }
/** // Level, read-only ( note: it increments in addWin() )
* <p>getDifficultyChoices.</p> public int getLevel() { return rankIndex; }
*
* @return an array of {@link java.lang.String} objects.
*/
public String[] getDifficultyChoices() {
return QuestPreferences.getDifficulty();
}
/**
* <p>getRank.</p>
*
* @return a {@link java.lang.String} object.
*/
public String getRank() { public String getRank() {
//is rankIndex too big? if (rankIndex >= RANK_TITLES.length) { rankIndex = RANK_TITLES.length - 1; }
if (rankIndex >= rankArray.length) { return RANK_TITLES[rankIndex];
rankIndex = rankArray.length - 1;
} }
return rankArray[rankIndex]; // decks management
} public List<String> getDeckNames() { return new ArrayList<String>(myDecks.keySet()); }
public void removeDeck(final String deckName) { myDecks.remove(deckName); }
public void addDeck(final Deck d) { myDecks.put(d.getName(), d); }
/** /**
* <p>getLevel.</p> * <p>getDeck.</p>
* *
* @return a int. * @param deckName a {@link java.lang.String} object.
* @since 1.0.15 * @return a {@link forge.deck.Deck} object.
*/ */
public int getLevel() { public Deck getDeck(final String deckName) {
return rankIndex; if (!myDecks.containsKey(deckName)) {
ErrorViewer.showError(new Exception(),
"QuestData : getDeckFromMap(String deckName) error, deck name not found - %s", deckName);
}
Deck d = myDecks.get(deckName);
d.clearSideboard();
return d;
} }
//add cards after a certain number of wins or losses // randomizer - related
public long getRandomSeed() { return randomSeed; }
/** /**
* <p>shouldAddCards.</p> * This method should be called whenever the opponents should change.
*
* @param didWin a boolean.
* @return a boolean.
*/ */
public boolean shouldAddCards(boolean didWin) { public void randomizeOpponents() {
int n = QuestPreferences.getWinsForBooster(diffIndex); randomSeed = MyRandom.random.nextLong();
if (didWin) {
return getWin() % n == 0;
} else {
return getLost() % n == 0;
}
} }
/** // SERIALIZATION - relared things
* <p>shouldAddAdditionalCards.</p>
*
* @param didWin a boolean.
* @return a boolean.
*/
public boolean shouldAddAdditionalCards(boolean didWin) {
float chance = 0.5f;
if (inventory.getItemLevel("Lucky Coin") == 1) {
chance = 0.65f;
}
float r = MyRandom.random.nextFloat(); // This must be called by XML-serializer via reflection
if (didWin) {
return r <= chance;
} else {
return false;
}
}
/**
* <p>hasSaveFile.</p>
*
* @return a boolean.
*/
public boolean hasSaveFile() {
return ForgeProps.getFile(NewConstants.QUEST.DATA).exists() ||
ForgeProps.getFile(NewConstants.QUEST.XMLDATA).exists();
}
/**
* <p>Getter for the field <code>petManager</code>.</p>
*
* @return a {@link forge.quest.data.pet.QuestPetManager} object.
*/
public QuestPetManager getPetManager() {
return petManager;
}
//get new cards that were added to your card pool by addCards()
/**
* <p>readResolve.</p>
*
* @return a {@link java.lang.Object} object.
*/
public Object readResolve() { public Object readResolve() {
initTransients(); initTransients();
return this; return this;
} }
/** public boolean hasSaveFile() {
* <p>Getter for the field <code>inventory</code>.</p> return ForgeProps.getFile(NewConstants.QUEST.DATA).exists() ||
* ForgeProps.getFile(NewConstants.QUEST.XMLDATA).exists();
* @return a {@link forge.quest.data.item.QuestInventory} object.
*/
public QuestInventory getInventory() {
return inventory;
} }
/** public void saveData() { QuestDataIO.saveData(this); }
* <p>Getter for the field <code>randomSeed</code>.</p>
*
* @return a long.
*/
public long getRandomSeed() {
return randomSeed;
}
public void buyCard(final CardPrinted card, final int value) {
if (credits >= value) {
credits -= value;
getCardpool().add(card);
shopList.remove(card);
}
}
public void sellCard(final CardPrinted card, final int price) {
if (price > 0) { credits += price; }
getCardpool().remove(card);
// remove from decks right here
}
} }

View File

@@ -0,0 +1,152 @@
package forge.quest.data;
import java.util.ArrayList;
import java.util.List;
import net.slightlymagic.maxmtg.Predicate;
import forge.ReadBoosterPack;
import forge.card.CardDb;
import forge.card.CardPool;
import forge.card.CardPoolView;
import forge.card.CardPrinted;
import forge.card.CardRarity;
import forge.deck.Deck;
/**
* This is a helper class to execute operations on QuestData.
* It has been created to decrease complexity of questData class
*/
public final class QuestUtilCards {
private QuestData q;
public QuestUtilCards(final QuestData qd) { q = qd; }
public void generateBasicLands(int nBasic, int nSnow)
{
CardDb db = CardDb.instance();
q.cardPool.add(db.getCard("Forest", "M10"), nBasic);
q.cardPool.add(db.getCard("Mountain", "M10"), nBasic);
q.cardPool.add(db.getCard("Swamp", "M10"), nBasic);
q.cardPool.add(db.getCard("Island", "M10"), nBasic);
q.cardPool.add(db.getCard("Plains", "M10"), nBasic);
q.cardPool.add(db.getCard("Snow-Covered Forest", "ICE"), nSnow);
q.cardPool.add(db.getCard("Snow-Covered Mountain", "ICE"), nSnow);
q.cardPool.add(db.getCard("Snow-Covered Swamp", "ICE"), nSnow);
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)
/**
* <p>addCards.</p>
*/
public ArrayList<CardPrinted> addCards(final List<String> setsFilter) {
int nCommon = QuestPreferences.getNumCommon();
int nUncommon = QuestPreferences.getNumUncommon();
int nRare = QuestPreferences.getNumRare();
Predicate<CardPrinted> fSets = CardPrinted.Predicates.printedInSets(setsFilter, true);
ArrayList<CardPrinted> newCards = new ArrayList<CardPrinted>();
newCards.addAll(QuestBoosterPack.generateCards(fSets, nCommon, CardRarity.Common, null));
newCards.addAll(QuestBoosterPack.generateCards(fSets, nUncommon, CardRarity.Uncommon, null));
newCards.addAll(QuestBoosterPack.generateCards(fSets, nRare, CardRarity.Rare, null));
addAllCards(newCards);
return newCards;
}
public void addAllCards(final Iterable<CardPrinted> newCards) {
for (CardPrinted card : newCards) {
q.cardPool.add(card);
}
}
public CardPrinted addRandomRare() { return addRandomRare(1).get(0); }
public List<CardPrinted> addRandomRare(final int n) {
List<CardPrinted> newCards = CardPrinted.Predicates.Presets.isRareOrMythic.random(CardDb.instance().getAllCards(), n);
addAllCards(newCards);
return newCards;
}
public void setupNewGameCardPool(Predicate<CardPrinted> filter, 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);
}
}
public void sellCard(final CardPrinted card, final int price) {
if (price > 0) { q.credits += price; }
q.cardPool.remove(card);
q.shopList.add(card);
// remove card being sold from all decks
int leftInPool = q.cardPool.count(card);
// remove sold cards from all decks:
for (Deck deck : q.myDecks.values()) {
deck.removeMain(card, deck.getMain().count(card) - leftInPool);
}
}
public void clearShopList() {
if (null != q.shopList) { q.shopList.clear(); }
}
public double getSellMutliplier() {
double multi = 0.20 + (0.001 * q.getWin());
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;
}
return multi;
}
public int getSellPriceLimit() {
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;
}
public CardPoolView getShopList() {
if (q.shopList.isEmpty()) {
generateCardsInShop();
}
return q.shopList;
}
}

View File

@@ -0,0 +1,96 @@
package forge.quest.data;
import forge.MyRandom;
import forge.game.GameLossReason;
import forge.game.GamePlayerRating;
import forge.game.GameSummary;
import forge.game.PlayerIndex;
/**
* Helper class to deal with rewards given in quest.
*/
public class QuestUtilRewards {
private QuestData q;
public QuestUtilRewards(final QuestData qd) { q = qd; }
public int getCreditsRewardForAltWin(final GameLossReason whyAiLost) {
int rewardAltWinCondition = 0;
switch (whyAiLost) {
case LifeReachedZero: return 0; // nothing special here, ordinary kill
case Milled: return QuestPreferences.getMatchRewardMilledWinBonus();
case Poisoned: return QuestPreferences.getMatchRewardPoisonWinBonus();
case DidNotLoseYet: return QuestPreferences.getMatchRewardAltWinBonus(); // felidar, helix pinnacle and like this
case SpellEffect: return QuestPreferences.getMatchRewardAltWinBonus(); // Door to Nothingness or something like this
default: // this .checkstyle forces us to write some idiotic code
rewardAltWinCondition = 0;
}
return rewardAltWinCondition;
}
public int getCreditsRewardForWinByTurn(final int iTurn) {
if (iTurn == 1) { return QuestPreferences.getMatchRewardWinFirst();
} else if (iTurn <= 5) { return QuestPreferences.getMatchRewardWinByFifth();
} else if (iTurn <= 10) { return QuestPreferences.getMatchRewardWinByTen();
} else if (iTurn <= 15) { return QuestPreferences.getMatchRewardWinByFifteen();
}
return 0;
}
/**
* <p>getCreditsToAdd.</p>
*
* @param matchState a {@link forge.quest.data.QuestMatchState} object.
* @return a long.
*/
public long getCreditsToAdd(final QuestMatchState matchState) {
long creds = (long) (QuestPreferences.getMatchRewardBase()
+ (QuestPreferences.getMatchRewardTotalWins() * q.getWin()));
boolean hasNeverLost = true;
for (GameSummary game : matchState.getGamesPlayed()) {
if (game.isAIWinner()) {
hasNeverLost = true;
continue; // no rewards for losing a game
}
GamePlayerRating aiRating = game.getPlayerRating(PlayerIndex.AI);
GamePlayerRating humanRating = game.getPlayerRating(PlayerIndex.HUMAN);
GameLossReason whyAiLost = aiRating.getLossReason();
creds += getCreditsRewardForAltWin(whyAiLost);
creds += getCreditsRewardForWinByTurn(game.getTurnGameEnded());
int cntCardsHumanStartedWith = humanRating.getOpeningHandSize();
if (0 == cntCardsHumanStartedWith) {
creds += QuestPreferences.getMatchMullToZero();
}
}
if (hasNeverLost) {
creds += QuestPreferences.getMatchRewardNoLosses();
}
switch(q.inventory.getItemLevel("Estates")) {
case 1: creds *= 1.1; break;
case 2: creds *= 1.15; break;
case 3: creds *= 1.2; break;
default: break;
}
return creds;
}
//add cards after a certain number of wins or losses
public boolean willGiveBooster(final boolean didWin) {
int cntOutcomes = didWin ? q.getWin() : q.getLost();
return cntOutcomes % QuestPreferences.getWinsForBooster(q.getDifficultyIndex()) == 0;
}
// this is a chance check, but used for random rare only by now
public boolean getLuckyCoinResult() {
boolean hasCoin = q.inventory.getItemLevel("Lucky Coin") >= 1;
return MyRandom.random.nextFloat() <= (hasCoin ? 0.65f : 0.5f);
}
}

View File

@@ -1,15 +1,16 @@
package forge; package forge.quest.gui;
import forge.AllZone;
import forge.error.ErrorViewer; import forge.error.ErrorViewer;
import forge.gui.GuiUtils; import forge.gui.GuiUtils;
import forge.quest.data.QuestData;
import forge.quest.data.QuestDataIO; import forge.quest.data.QuestDataIO;
import forge.quest.gui.QuestFrame; import forge.quest.data.QuestPreferences;
import forge.view.swing.OldGuiNewGame; import forge.view.swing.OldGuiNewGame;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.border.TitledBorder; import javax.swing.border.TitledBorder;
import java.awt.Color;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
@@ -21,11 +22,11 @@ import java.awt.event.WindowEvent;
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public class Gui_QuestOptions extends JFrame { public class QuestOptions extends JFrame {
/** Constant <code>serialVersionUID=2018518804206822235L</code> */ /** Constant <code>serialVersionUID=2018518804206822235L</code> */
private static final long serialVersionUID = 2018518804206822235L; private static final long serialVersionUID = 2018518804206822235L;
private forge.quest.data.QuestData questData = new forge.quest.data.QuestData(); private QuestData questData = new QuestData();
private JLabel jLabel1 = new JLabel(); private JLabel jLabel1 = new JLabel();
private JButton continueQuestButton = new JButton(); private JButton continueQuestButton = new JButton();
@@ -52,7 +53,7 @@ public class Gui_QuestOptions extends JFrame {
/** /**
* <p>Constructor for Gui_QuestOptions.</p> * <p>Constructor for Gui_QuestOptions.</p>
*/ */
public Gui_QuestOptions() { public QuestOptions() {
try { try {
jbInit(); jbInit();
} catch (Exception ex) { } catch (Exception ex) {
@@ -79,7 +80,7 @@ public class Gui_QuestOptions extends JFrame {
this.addWindowListener(new WindowAdapter() { this.addWindowListener(new WindowAdapter() {
@Override @Override
public void windowClosing(WindowEvent ev) { public void windowClosing(WindowEvent ev) {
Gui_QuestOptions.this.dispose(); QuestOptions.this.dispose();
new OldGuiNewGame(); new OldGuiNewGame();
} }
}); });
@@ -93,11 +94,15 @@ public class Gui_QuestOptions extends JFrame {
* <p>setupRadioButtonText.</p> * <p>setupRadioButtonText.</p>
*/ */
private void setupRadioButtonText() { private void setupRadioButtonText() {
String[] diff = questData.getDifficultyChoices(); String[] diff = QuestPreferences.getDifficulty();
JRadioButton[] b = {easyRadio, mediumRadio, hardRadio, veryHardRadio}; JRadioButton[] b = {easyRadio, mediumRadio, hardRadio, veryHardRadio};
for (int i = 0; i < diff.length; i++) { for (int i = 0; i < diff.length; i++) {
b[i].setText(diff[i] + " - " + questData.getTotalNumberOfGames(i)); //-2 because you start a level 1, and the last level is secret
int numberLevels = QuestData.RANK_TITLES.length - 2;
int numGames = numberLevels * QuestPreferences.getWinsForRankIncrease(i);
b[i].setText(String.format("%s - %d", diff[i], numGames));
} }
}//setupRadioButtonText() }//setupRadioButtonText()
@@ -215,7 +220,7 @@ public class Gui_QuestOptions extends JFrame {
void continueQuestButton_actionPerformed(ActionEvent e) { void continueQuestButton_actionPerformed(ActionEvent e) {
//set global variable //set global variable
AllZone.setQuestData(QuestDataIO.loadData()); AllZone.setQuestData(QuestDataIO.loadData());
AllZone.getQuestData().setDifficultyIndex(); AllZone.getQuestData().guessDifficultyIndex();
dispose(); dispose();
new QuestFrame(); new QuestFrame();

View File

@@ -20,6 +20,7 @@ import forge.properties.ForgeProps;
import forge.properties.NewConstants; import forge.properties.NewConstants;
import forge.properties.NewConstants.LANG.OldGuiNewGame.MENU_BAR.MENU; import forge.properties.NewConstants.LANG.OldGuiNewGame.MENU_BAR.MENU;
import forge.properties.NewConstants.LANG.OldGuiNewGame.MENU_BAR.OPTIONS; import forge.properties.NewConstants.LANG.OldGuiNewGame.MENU_BAR.OPTIONS;
import forge.quest.gui.QuestOptions;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import javax.swing.*; import javax.swing.*;
@@ -277,7 +278,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants.
// ActionListener // ActionListener
OldGuiNewGame.this.dispose(); OldGuiNewGame.this.dispose();
new Gui_QuestOptions(); new QuestOptions();
} }
}); });
} // addListeners() } // addListeners()

View File

@@ -174,7 +174,11 @@ public abstract class Predicate<T> {
return new Node<T>(operand1, operator, operand2); return new Node<T>(operand1, operator, operand2);
} }
// Predefined operators: and, or // Predefined operators: and, or
public static <T> Predicate<T> and(final Predicate<T> operand1, final Predicate<T> operand2) { return new NodeAnd<T>(operand1, operand2); } public static <T> Predicate<T> and(final Predicate<T> operand1, final Predicate<T> operand2) {
if (operand1.is1()) { return operand2; }
if (operand2.is1()) { return operand1; }
return new NodeAnd<T>(operand1, operand2);
}
public static <T> Predicate<T> and(final Iterable<Predicate<T>> operand) { return new MultiNodeAnd<T>(operand); } public static <T> Predicate<T> and(final Iterable<Predicate<T>> operand) { return new MultiNodeAnd<T>(operand); }
public static <T, U> Predicate<T> and(final Predicate<T> operand1, final Predicate<U> operand2, Lambda1<U, T> bridge) { return new NodeAndBridged<T, U>(operand1, operand2, bridge); } public static <T, U> Predicate<T> and(final Predicate<T> operand1, final Predicate<U> operand2, Lambda1<U, T> bridge) { return new NodeAndBridged<T, U>(operand1, operand2, bridge); }