checkstyle and refactor

This commit is contained in:
jendave
2011-11-01 17:51:10 +00:00
parent c011b284e7
commit 4d25421af8
9 changed files with 452 additions and 352 deletions

View File

@@ -144,8 +144,8 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
PresetColumns.FN_RARITY_GET)); PresetColumns.FN_RARITY_GET));
columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.FN_SET_COMPARE, columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.FN_SET_COMPARE,
PresetColumns.FN_SET_GET)); PresetColumns.FN_SET_GET));
columns.add(new TableColumnInfo<InventoryItem>("New", 30, this.questData.getCards().fnNewCompare, columns.add(new TableColumnInfo<InventoryItem>("New", 30, this.questData.getCards().getFnNewCompare(),
this.questData.getCards().fnNewGet)); this.questData.getCards().getFnNewGet()));
columns.get(2).setCellRenderer(new ManaCostRenderer()); columns.get(2).setCellRenderer(new ManaCostRenderer());

View File

@@ -163,8 +163,8 @@ public final class DeckEditorShop extends DeckEditorBase {
this.getTopTableWithCards().setup(columns, this.getCardView()); this.getTopTableWithCards().setup(columns, this.getCardView());
columnsBelow.add(new TableColumnInfo<InventoryItem>("Dks", 30, this.fnDeckCompare, this.fnDeckGet)); columnsBelow.add(new TableColumnInfo<InventoryItem>("Dks", 30, this.fnDeckCompare, this.fnDeckGet));
columnsBelow.add(new TableColumnInfo<InventoryItem>("New", 35, this.questData.getCards().fnNewCompare, columnsBelow.add(new TableColumnInfo<InventoryItem>("New", 35, this.questData.getCards().getFnNewCompare(),
this.questData.getCards().fnNewGet)); this.questData.getCards().getFnNewGet()));
columnsBelow.add(new TableColumnInfo<InventoryItem>("Price", 36, this.fnPriceCompare, this.fnPriceSellGet)); columnsBelow.add(new TableColumnInfo<InventoryItem>("Price", 36, this.fnPriceCompare, this.fnPriceSellGet));
this.getBottomTableWithCards().setup(columnsBelow, this.getCardView()); this.getBottomTableWithCards().setup(columnsBelow, this.getCardView());

View File

@@ -40,40 +40,40 @@ public final class QuestData {
// but only when the object is created through the constructor // but only when the object is created through the constructor
// DO NOT RENAME THIS FIELD // DO NOT RENAME THIS FIELD
/** The version number. */ /** The version number. */
int versionNumber = CURRENT_VERSION_NUMBER; private int versionNumber = QuestData.CURRENT_VERSION_NUMBER;
/** The rank index. */ /** The rank index. */
int rankIndex; // level private int rankIndex; // level
/** The win. */ /** The win. */
int win; // number of wins private int win; // number of wins
/** The lost. */ /** The lost. */
int lost; private int lost;
/** The credits. */ /** The credits. */
long credits; // this money is good for all modes private long credits; // this money is good for all modes
/** The life. */ /** The life. */
int life; // for fantasy mode, how much life bought at shop to start game private int life; // for fantasy mode, how much life bought at shop to start game
// with // with
/** The inventory. */ /** The inventory. */
QuestInventory inventory = new QuestInventory(); // different gadgets private QuestInventory inventory = new QuestInventory(); // different gadgets
/** The pet manager. */ /** The pet manager. */
QuestPetManager petManager = new QuestPetManager(); // pets that start match private QuestPetManager petManager = new QuestPetManager(); // pets that start match
// with you // with you
// Diffuculty - they store both index and title // Diffuculty - they store both index and title
/** The diff index. */ /** The diff index. */
int diffIndex; private int diffIndex;
/** The difficulty. */ /** The difficulty. */
String difficulty; private String difficulty;
// Quest mode - there should be an enum :( // Quest mode - there should be an enum :(
/** The mode. */ /** The mode. */
String mode = ""; private String mode = "";
/** The Constant FANTASY. */ /** The Constant FANTASY. */
public static final String FANTASY = "Fantasy"; public static final String FANTASY = "Fantasy";
@@ -83,19 +83,19 @@ public final class QuestData {
// Decks collected by player // Decks collected by player
/** The my decks. */ /** The my decks. */
Map<String, Deck> myDecks = new HashMap<String, Deck>(); private Map<String, Deck> myDecks = new HashMap<String, Deck>();
// Cards associated with quest // Cards associated with quest
/** The card pool. */ /** The card pool. */
ItemPool<InventoryItem> cardPool = new ItemPool<InventoryItem>(InventoryItem.class); // player's private ItemPool<InventoryItem> cardPool = new ItemPool<InventoryItem>(InventoryItem.class); // player's
// belonging // belonging
/** The shop list. */ /** The shop list. */
ItemPool<InventoryItem> shopList = new ItemPool<InventoryItem>(InventoryItem.class); // the private ItemPool<InventoryItem> shopList = new ItemPool<InventoryItem>(InventoryItem.class); // the
// current // current
// shop // shop
// list // list
/** The new card list. */ /** The new card list. */
ItemPool<InventoryItem> newCardList = new ItemPool<InventoryItem>(InventoryItem.class); // cards private ItemPool<InventoryItem> newCardList = new ItemPool<InventoryItem>(InventoryItem.class); // cards
// acquired // acquired
// since // since
// last // last
@@ -103,13 +103,13 @@ public final class QuestData {
// Challenge history // Challenge history
/** The challenges played. */ /** The challenges played. */
int challengesPlayed = 0; private int challengesPlayed = 0;
/** The available challenges. */ /** The available challenges. */
List<Integer> availableChallenges = new ArrayList<Integer>(); private List<Integer> availableChallenges = new ArrayList<Integer>();
/** The completed challenges. */ /** The completed challenges. */
List<Integer> completedChallenges = new ArrayList<Integer>(); private List<Integer> completedChallenges = new ArrayList<Integer>();
// Challenges used to be called quests. During the renaming, // Challenges used to be called quests. During the renaming,
// files could be corrupted. These fields ensure old files still work. // files could be corrupted. These fields ensure old files still work.
@@ -117,13 +117,13 @@ public final class QuestData {
// The old files, if played once, are updated automatically to the new // The old files, if played once, are updated automatically to the new
// system. // system.
/** The quests played. */ /** The quests played. */
int questsPlayed = -1; private int questsPlayed = -1;
/** The available quests. */ /** The available quests. */
List<Integer> availableQuests = null; private List<Integer> availableQuests = null;
/** The completed quests. */ /** The completed quests. */
List<Integer> completedQuests = null; private List<Integer> completedQuests = null;
// own randomizer seed // own randomizer seed
private long randomSeed = 0; private long randomSeed = 0;
@@ -151,21 +151,22 @@ public final class QuestData {
* </p> * </p>
*/ */
public QuestData() { public QuestData() {
initTransients(); this.initTransients();
myCards.addBasicLands(cardPool, QuestPreferences.getStartingBasic(), QuestPreferences.getStartingSnowBasic()); this.myCards.addBasicLands(this.getCardPool(), QuestPreferences.getStartingBasic(),
randomizeOpponents(); QuestPreferences.getStartingSnowBasic());
this.randomizeOpponents();
} }
private void initTransients() { private void initTransients() {
// These are helper classes that hold no data. // These are helper classes that hold no data.
myCards = new QuestUtilCards(this); this.myCards = new QuestUtilCards(this);
// to avoid NPE some pools will be created here if they are null // to avoid NPE some pools will be created here if they are null
if (null == newCardList) { if (null == this.getNewCardList()) {
newCardList = new ItemPool<InventoryItem>(InventoryItem.class); this.setNewCardList(new ItemPool<InventoryItem>(InventoryItem.class));
} }
if (null == shopList) { if (null == this.getShopList()) {
shopList = new ItemPool<InventoryItem>(InventoryItem.class); this.setShopList(new ItemPool<InventoryItem>(InventoryItem.class));
} }
} }
@@ -181,16 +182,16 @@ public final class QuestData {
* the standard start * the standard start
*/ */
public void newGame(final int diff, final String m0de, final boolean standardStart) { public void newGame(final int diff, final String m0de, final boolean standardStart) {
setDifficulty(diff); this.setDifficulty(diff);
Predicate<CardPrinted> filter = Predicate.and(standardStart ? SetUtils.getStandard().getFilterPrinted() final Predicate<CardPrinted> filter = Predicate.and(standardStart ? SetUtils.getStandard().getFilterPrinted()
: CardPrinted.Predicates.Presets.IS_TRUE, CardPrinted.Predicates.Presets.NON_ALTERNATE); : CardPrinted.Predicates.Presets.IS_TRUE, CardPrinted.Predicates.Presets.NON_ALTERNATE);
myCards.setupNewGameCardPool(filter, diff); this.myCards.setupNewGameCardPool(filter, diff);
credits = QuestPreferences.getStartingCredits(); this.setCredits(QuestPreferences.getStartingCredits());
mode = m0de; this.mode = m0de;
life = mode.equals(FANTASY) ? 15 : 20; this.life = this.mode.equals(QuestData.FANTASY) ? 15 : 20;
} }
// All belongings // All belongings
@@ -200,7 +201,7 @@ public final class QuestData {
* @return the inventory * @return the inventory
*/ */
public QuestInventory getInventory() { public QuestInventory getInventory() {
return inventory; return this.inventory;
} }
/** /**
@@ -209,7 +210,7 @@ public final class QuestData {
* @return the pet manager * @return the pet manager
*/ */
public QuestPetManager getPetManager() { public QuestPetManager getPetManager() {
return petManager; return this.petManager;
} }
// Cards - class uses data from here // Cards - class uses data from here
@@ -219,7 +220,7 @@ public final class QuestData {
* @return the cards * @return the cards
*/ */
public QuestUtilCards getCards() { public QuestUtilCards getCards() {
return myCards; return this.myCards;
} }
// Challenge performance // Challenge performance
@@ -231,19 +232,19 @@ public final class QuestData {
public int getChallengesPlayed() { public int getChallengesPlayed() {
// This should be phased out after a while, when // This should be phased out after a while, when
// old quest decks have been updated. (changes made 19-9-11) // old quest decks have been updated. (changes made 19-9-11)
if (questsPlayed != -1) { if (this.questsPlayed != -1) {
challengesPlayed = questsPlayed; this.challengesPlayed = this.questsPlayed;
questsPlayed = -1; this.questsPlayed = -1;
} }
return challengesPlayed; return this.challengesPlayed;
} }
/** /**
* Adds the challenges played. * Adds the challenges played.
*/ */
public void addChallengesPlayed() { public void addChallengesPlayed() {
challengesPlayed++; this.challengesPlayed++;
} }
/** /**
@@ -254,12 +255,12 @@ public final class QuestData {
public List<Integer> getAvailableChallenges() { public List<Integer> getAvailableChallenges() {
// This should be phased out after a while, when // This should be phased out after a while, when
// old quest decks have been updated. (changes made 19-9-11) // old quest decks have been updated. (changes made 19-9-11)
if (availableQuests != null) { if (this.availableQuests != null) {
availableChallenges = availableQuests; this.availableChallenges = this.availableQuests;
availableQuests = null; this.availableQuests = null;
} }
return availableChallenges != null ? new ArrayList<Integer>(availableChallenges) : null; return this.availableChallenges != null ? new ArrayList<Integer>(this.availableChallenges) : null;
} }
/** /**
@@ -269,14 +270,14 @@ public final class QuestData {
* the new available challenges * the new available challenges
*/ */
public void setAvailableChallenges(final List<Integer> list) { public void setAvailableChallenges(final List<Integer> list) {
availableChallenges = list; this.availableChallenges = list;
} }
/** /**
* Clear available challenges. * Clear available challenges.
*/ */
public void clearAvailableChallenges() { public void clearAvailableChallenges() {
availableChallenges.clear(); this.availableChallenges.clear();
} }
/** /**
@@ -292,12 +293,12 @@ public final class QuestData {
// old quest decks have been updated. (changes made 19-9-11) // old quest decks have been updated. (changes made 19-9-11)
// Also, poorly named - this should be "getLockedChalleneges" or // Also, poorly named - this should be "getLockedChalleneges" or
// similar. // similar.
if (completedQuests != null) { if (this.completedQuests != null) {
completedChallenges = completedQuests; this.completedChallenges = this.completedQuests;
completedQuests = null; this.completedQuests = null;
} }
return completedChallenges != null ? new ArrayList<Integer>(completedChallenges) : null; return this.completedChallenges != null ? new ArrayList<Integer>(this.completedChallenges) : null;
} }
/** /**
@@ -312,7 +313,7 @@ public final class QuestData {
// Poorly named - this should be "setLockedChalleneges" or similar. // Poorly named - this should be "setLockedChalleneges" or similar.
public void addCompletedChallenge(final int i) { public void addCompletedChallenge(final int i) {
completedChallenges.add(i); this.completedChallenges.add(i);
} }
// Wins & Losses // Wins & Losses
@@ -322,14 +323,14 @@ public final class QuestData {
* @return the lost * @return the lost
*/ */
public int getLost() { public int getLost() {
return lost; return this.lost;
} }
/** /**
* Adds the lost. * Adds the lost.
*/ */
public void addLost() { public void addLost() {
lost++; this.lost++;
} }
/** /**
@@ -338,18 +339,18 @@ public final class QuestData {
* @return the win * @return the win
*/ */
public int getWin() { public int getWin() {
return win; return this.win;
} }
/** /**
* Adds the win. * Adds the win.
*/ */
public void addWin() { // changes getRank() public void addWin() { // changes getRank()
win++; this.win++;
int winsToLvlUp = QuestPreferences.getWinsForRankIncrease(diffIndex); final int winsToLvlUp = QuestPreferences.getWinsForRankIncrease(this.diffIndex);
if (win % winsToLvlUp == 0) { if ((this.win % winsToLvlUp) == 0) {
rankIndex++; this.rankIndex++;
} }
} }
@@ -360,7 +361,7 @@ public final class QuestData {
* @return the life * @return the life
*/ */
public int getLife() { public int getLife() {
return isFantasy() ? life : 20; return this.isFantasy() ? this.life : 20;
} }
/** /**
@@ -370,7 +371,7 @@ public final class QuestData {
* the n * the n
*/ */
public void addLife(final int n) { public void addLife(final int n) {
life += n; this.life += n;
} }
// Credits // Credits
@@ -381,7 +382,7 @@ public final class QuestData {
* the c * the c
*/ */
public void addCredits(final long c) { public void addCredits(final long c) {
credits += c; this.setCredits(this.getCredits() + c);
} }
/** /**
@@ -391,7 +392,7 @@ public final class QuestData {
* the c * the c
*/ */
public void subtractCredits(final long c) { public void subtractCredits(final long c) {
credits = credits > c ? credits - c : 0; this.setCredits(this.getCredits() > c ? this.getCredits() - c : 0);
} }
/** /**
@@ -400,7 +401,7 @@ public final class QuestData {
* @return the credits * @return the credits
*/ */
public long getCredits() { public long getCredits() {
return credits; return this.credits;
} }
// Quest mode // Quest mode
@@ -410,7 +411,7 @@ public final class QuestData {
* @return true, if is fantasy * @return true, if is fantasy
*/ */
public boolean isFantasy() { public boolean isFantasy() {
return mode.equals(FANTASY); return this.mode.equals(QuestData.FANTASY);
} }
/** /**
@@ -419,7 +420,7 @@ public final class QuestData {
* @return the mode * @return the mode
*/ */
public String getMode() { public String getMode() {
return mode == null ? "" : mode; return this.mode == null ? "" : this.mode;
} }
// Difficulty // Difficulty
@@ -429,7 +430,7 @@ public final class QuestData {
* @return the difficulty * @return the difficulty
*/ */
public String getDifficulty() { public String getDifficulty() {
return difficulty; return this.difficulty;
} }
/** /**
@@ -438,7 +439,7 @@ public final class QuestData {
* @return the difficulty index * @return the difficulty index
*/ */
public int getDifficultyIndex() { public int getDifficultyIndex() {
return diffIndex; return this.diffIndex;
} }
/** /**
@@ -448,18 +449,18 @@ public final class QuestData {
* the new difficulty * the new difficulty
*/ */
public void setDifficulty(final int i) { public void setDifficulty(final int i) {
diffIndex = i; this.diffIndex = i;
difficulty = QuestPreferences.getDifficulty(i); this.difficulty = QuestPreferences.getDifficulty(i);
} }
/** /**
* Guess difficulty index. * Guess difficulty index.
*/ */
public void guessDifficultyIndex() { public void guessDifficultyIndex() {
String[] diffStr = QuestPreferences.getDifficulty(); final 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 (this.difficulty.equals(diffStr[i])) {
diffIndex = i; this.diffIndex = i;
} }
} }
} }
@@ -471,7 +472,7 @@ public final class QuestData {
* @return the level * @return the level
*/ */
public int getLevel() { public int getLevel() {
return rankIndex; return this.rankIndex;
} }
/** /**
@@ -480,10 +481,10 @@ public final class QuestData {
* @return the rank * @return the rank
*/ */
public String getRank() { public String getRank() {
if (rankIndex >= RANK_TITLES.length) { if (this.rankIndex >= QuestData.RANK_TITLES.length) {
rankIndex = RANK_TITLES.length - 1; this.rankIndex = QuestData.RANK_TITLES.length - 1;
} }
return RANK_TITLES[rankIndex]; return QuestData.RANK_TITLES[this.rankIndex];
} }
// decks management // decks management
@@ -493,7 +494,7 @@ public final class QuestData {
* @return the deck names * @return the deck names
*/ */
public List<String> getDeckNames() { public List<String> getDeckNames() {
return new ArrayList<String>(myDecks.keySet()); return new ArrayList<String>(this.getMyDecks().keySet());
} }
/** /**
@@ -503,7 +504,7 @@ public final class QuestData {
* the deck name * the deck name
*/ */
public void removeDeck(final String deckName) { public void removeDeck(final String deckName) {
myDecks.remove(deckName); this.getMyDecks().remove(deckName);
} }
/** /**
@@ -513,7 +514,7 @@ public final class QuestData {
* the d * the d
*/ */
public void addDeck(final Deck d) { public void addDeck(final Deck d) {
myDecks.put(d.getName(), d); this.getMyDecks().put(d.getName(), d);
} }
/** /**
@@ -526,11 +527,11 @@ public final class QuestData {
* @return a {@link forge.deck.Deck} object. * @return a {@link forge.deck.Deck} object.
*/ */
public Deck getDeck(final String deckName) { public Deck getDeck(final String deckName) {
if (!myDecks.containsKey(deckName)) { if (!this.getMyDecks().containsKey(deckName)) {
ErrorViewer.showError(new Exception(), ErrorViewer.showError(new Exception(),
"QuestData : getDeckFromMap(String deckName) error, deck name not found - %s", deckName); "QuestData : getDeckFromMap(String deckName) error, deck name not found - %s", deckName);
} }
Deck d = myDecks.get(deckName); final Deck d = this.getMyDecks().get(deckName);
d.clearSideboard(); d.clearSideboard();
return d; return d;
} }
@@ -542,14 +543,14 @@ public final class QuestData {
* @return the random seed * @return the random seed
*/ */
public long getRandomSeed() { public long getRandomSeed() {
return randomSeed; return this.randomSeed;
} }
/** /**
* This method should be called whenever the opponents should change. * This method should be called whenever the opponents should change.
*/ */
public void randomizeOpponents() { public void randomizeOpponents() {
randomSeed = MyRandom.getRandom().nextLong(); this.randomSeed = MyRandom.getRandom().nextLong();
} }
// SERIALIZATION - related things // SERIALIZATION - related things
@@ -561,7 +562,7 @@ public final class QuestData {
* @return the object * @return the object
*/ */
public Object readResolve() { public Object readResolve() {
initTransients(); this.initTransients();
return this; return this;
} }
@@ -581,4 +582,88 @@ public final class QuestData {
public void saveData() { public void saveData() {
QuestDataIO.saveData(this); QuestDataIO.saveData(this);
} }
/**
* @return the cardPool
*/
public ItemPool<InventoryItem> getCardPool() {
return cardPool;
}
/**
* @param cardPool the cardPool to set
*/
public void setCardPool(ItemPool<InventoryItem> cardPool) {
this.cardPool = cardPool; // TODO: Add 0 to parameter's name.
}
/**
* @return the shopList
*/
public ItemPool<InventoryItem> getShopList() {
return shopList;
}
/**
* @param shopList the shopList to set
*/
public void setShopList(ItemPool<InventoryItem> shopList) {
this.shopList = shopList; // TODO: Add 0 to parameter's name.
}
/**
* @return the newCardList
*/
public ItemPool<InventoryItem> getNewCardList() {
return newCardList;
}
/**
* @param newCardList the newCardList to set
*/
public void setNewCardList(ItemPool<InventoryItem> newCardList) {
this.newCardList = newCardList; // TODO: Add 0 to parameter's name.
}
/**
* @return the myDecks
*/
public Map<String, Deck> getMyDecks() {
return myDecks;
}
/**
* @param myDecks the myDecks to set
*/
public void setMyDecks(Map<String, Deck> myDecks) {
this.myDecks = myDecks; // TODO: Add 0 to parameter's name.
}
/**
* @param inventory the inventory to set
*/
public void setInventory(QuestInventory inventory) {
this.inventory = inventory; // TODO: Add 0 to parameter's name.
}
/**
* @param credits the credits to set
*/
public void setCredits(long credits) {
this.credits = credits; // TODO: Add 0 to parameter's name.
}
/**
* @return the versionNumber
*/
public int getVersionNumber() {
return versionNumber;
}
/**
* @param versionNumber the versionNumber to set
*/
public void setVersionNumber(int versionNumber) {
this.versionNumber = versionNumber; // TODO: Add 0 to parameter's name.
}
} }

View File

@@ -68,35 +68,35 @@ public class QuestDataIO {
// read file "questData" // read file "questData"
QuestData data = null; QuestData data = null;
File xmlSaveFile = ForgeProps.getFile(NewConstants.Quest.XMLDATA); final File xmlSaveFile = ForgeProps.getFile(NewConstants.Quest.XMLDATA);
GZIPInputStream zin = new GZIPInputStream(new FileInputStream(xmlSaveFile)); final GZIPInputStream zin = new GZIPInputStream(new FileInputStream(xmlSaveFile));
StringBuilder xml = new StringBuilder(); final StringBuilder xml = new StringBuilder();
char[] buf = new char[1024]; final char[] buf = new char[1024];
InputStreamReader reader = new InputStreamReader(zin); final InputStreamReader reader = new InputStreamReader(zin);
while (reader.ready()) { while (reader.ready()) {
int len = reader.read(buf); final int len = reader.read(buf);
if (len == -1) { if (len == -1) {
break; break;
} // when end of stream was reached } // when end of stream was reached
xml.append(buf, 0, len); xml.append(buf, 0, len);
} }
IgnoringXStream xStream = new IgnoringXStream(); final IgnoringXStream xStream = new IgnoringXStream();
xStream.registerConverter(new CardPoolToXml()); xStream.registerConverter(new CardPoolToXml());
xStream.registerConverter(new GameTypeToXml()); xStream.registerConverter(new GameTypeToXml());
xStream.alias("CardPool", ItemPool.class); xStream.alias("CardPool", ItemPool.class);
data = (QuestData) xStream.fromXML(xml.toString()); data = (QuestData) xStream.fromXML(xml.toString());
if (data.versionNumber != QuestData.CURRENT_VERSION_NUMBER) { if (data.getVersionNumber() != QuestData.CURRENT_VERSION_NUMBER) {
updateSaveFile(data, xml.toString()); QuestDataIO.updateSaveFile(data, xml.toString());
} }
zin.close(); zin.close();
return data; return data;
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex, "Error loading Quest Data"); ErrorViewer.showError(ex, "Error loading Quest Data");
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
@@ -114,18 +114,18 @@ public class QuestDataIO {
*/ */
private static void updateSaveFile(final QuestData newData, final String input) { private static void updateSaveFile(final QuestData newData, final String input) {
try { try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource is = new InputSource(); final InputSource is = new InputSource();
is.setCharacterStream(new StringReader(input)); is.setCharacterStream(new StringReader(input));
Document document = builder.parse(is); final Document document = builder.parse(is);
switch (newData.versionNumber) { switch (newData.getVersionNumber()) {
// There should be a fall-through b/w the cases so that each // There should be a fall-through b/w the cases so that each
// version's changes get applied progressively // version's changes get applied progressively
case 0: case 0:
// First beta release with new file format, // First beta release with new file format,
// inventory needs to be migrated // inventory needs to be migrated
newData.inventory = new QuestInventory(); newData.setInventory(new QuestInventory());
NodeList elements = document.getElementsByTagName("estatesLevel"); NodeList elements = document.getElementsByTagName("estatesLevel");
newData.getInventory().setItemLevel("Estates", Integer.parseInt(elements.item(0).getTextContent())); newData.getInventory().setItemLevel("Estates", Integer.parseInt(elements.item(0).getTextContent()));
elements = document.getElementsByTagName("luckyCoinLevel"); elements = document.getElementsByTagName("luckyCoinLevel");
@@ -134,12 +134,12 @@ public class QuestDataIO {
newData.getInventory().setItemLevel("Sleight", Integer.parseInt(elements.item(0).getTextContent())); newData.getInventory().setItemLevel("Sleight", Integer.parseInt(elements.item(0).getTextContent()));
elements = document.getElementsByTagName("gearLevel"); elements = document.getElementsByTagName("gearLevel");
int gearLevel = Integer.parseInt(elements.item(0).getTextContent()); final int gearLevel = Integer.parseInt(elements.item(0).getTextContent());
if (gearLevel >= 1) { if (gearLevel >= 1) {
newData.inventory.setItemLevel("Map", 1); newData.getInventory().setItemLevel("Map", 1);
} }
if (gearLevel == 2) { if (gearLevel == 2) {
newData.inventory.setItemLevel("Zeppelin", 1); newData.getInventory().setItemLevel("Zeppelin", 1);
} }
// fall-through // fall-through
case 1: case 1:
@@ -151,9 +151,9 @@ public class QuestDataIO {
} }
// mark the QD as the latest version // mark the QD as the latest version
newData.versionNumber = QuestData.CURRENT_VERSION_NUMBER; newData.setVersionNumber(QuestData.CURRENT_VERSION_NUMBER);
} catch (Exception e) { } catch (final Exception e) {
forge.error.ErrorViewer.showError(e); forge.error.ErrorViewer.showError(e);
} }
} }
@@ -168,13 +168,13 @@ public class QuestDataIO {
*/ */
public static void saveData(final QuestData qd) { public static void saveData(final QuestData qd) {
try { try {
XStream xStream = new XStream(); final XStream xStream = new XStream();
xStream.registerConverter(new CardPoolToXml()); xStream.registerConverter(new CardPoolToXml());
xStream.alias("CardPool", ItemPool.class); xStream.alias("CardPool", ItemPool.class);
File f = ForgeProps.getFile(NewConstants.Quest.XMLDATA); final File f = ForgeProps.getFile(NewConstants.Quest.XMLDATA);
BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(f)); final BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(f));
GZIPOutputStream zout = new GZIPOutputStream(bout); final GZIPOutputStream zout = new GZIPOutputStream(bout);
xStream.toXML(qd, zout); xStream.toXML(qd, zout);
zout.flush(); zout.flush();
zout.close(); zout.close();
@@ -185,7 +185,7 @@ public class QuestDataIO {
// boutUnp.flush(); // boutUnp.flush();
// boutUnp.close(); // boutUnp.close();
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex, "Error saving Quest Data."); ErrorViewer.showError(ex, "Error saving Quest Data.");
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
@@ -197,15 +197,16 @@ public class QuestDataIO {
* (but are there any fields?) * (but are there any fields?)
*/ */
private static class IgnoringXStream extends XStream { private static class IgnoringXStream extends XStream {
List<String> ignoredFields = new ArrayList<String>(); private List<String> ignoredFields = new ArrayList<String>();
@Override @Override
protected MapperWrapper wrapMapper(MapperWrapper next) { protected MapperWrapper wrapMapper(final MapperWrapper next) {
return new MapperWrapper(next) { return new MapperWrapper(next) {
@Override @Override
public boolean shouldSerializeMember(@SuppressWarnings("rawtypes") Class definedIn, String fieldName) { public boolean shouldSerializeMember(@SuppressWarnings("rawtypes") final Class definedIn,
final String fieldName) {
if (definedIn == Object.class) { if (definedIn == Object.class) {
ignoredFields.add(fieldName); IgnoringXStream.this.ignoredFields.add(fieldName);
return false; return false;
} }
return super.shouldSerializeMember(definedIn, fieldName); return super.shouldSerializeMember(definedIn, fieldName);
@@ -217,18 +218,18 @@ public class QuestDataIO {
private static class GameTypeToXml implements Converter { private static class GameTypeToXml implements Converter {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
public boolean canConvert(Class clasz) { public boolean canConvert(final Class clasz) {
return clasz.equals(GameType.class); return clasz.equals(GameType.class);
} }
@Override @Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
// not used // not used
} }
@Override @Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
String value = reader.getValue(); final String value = reader.getValue();
return GameType.smartValueOf(value); return GameType.smartValueOf(value);
} }
@@ -237,11 +238,11 @@ public class QuestDataIO {
private static class CardPoolToXml implements Converter { private static class CardPoolToXml implements Converter {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
public boolean canConvert(Class clasz) { public boolean canConvert(final Class clasz) {
return clasz.equals(ItemPool.class); return clasz.equals(ItemPool.class);
} }
private void write(CardPrinted cref, Integer count, HierarchicalStreamWriter writer) { private void write(final CardPrinted cref, final Integer count, final HierarchicalStreamWriter writer) {
writer.startNode("card"); writer.startNode("card");
writer.addAttribute("c", cref.getName()); writer.addAttribute("c", cref.getName());
writer.addAttribute("s", cref.getSet()); writer.addAttribute("s", cref.getSet());
@@ -255,7 +256,7 @@ public class QuestDataIO {
writer.endNode(); writer.endNode();
} }
private void write(BoosterPack booster, Integer count, HierarchicalStreamWriter writer) { private void write(final BoosterPack booster, final Integer count, final HierarchicalStreamWriter writer) {
writer.startNode("booster"); writer.startNode("booster");
writer.addAttribute("s", booster.getSet()); writer.addAttribute("s", booster.getSet());
writer.addAttribute("n", count.toString()); writer.addAttribute("n", count.toString());
@@ -263,16 +264,16 @@ public class QuestDataIO {
} }
@Override @Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ItemPool<InventoryItem> pool = (ItemPool<InventoryItem>) source; final ItemPool<InventoryItem> pool = (ItemPool<InventoryItem>) source;
for (Entry<InventoryItem, Integer> e : pool) { for (final Entry<InventoryItem, Integer> e : pool) {
InventoryItem item = e.getKey(); final InventoryItem item = e.getKey();
Integer count = e.getValue(); final Integer count = e.getValue();
if (item instanceof CardPrinted) { if (item instanceof CardPrinted) {
write((CardPrinted) item, count, writer); this.write((CardPrinted) item, count, writer);
} else if (item instanceof BoosterPack) { } else if (item instanceof BoosterPack) {
write((BoosterPack) item, count, writer); this.write((BoosterPack) item, count, writer);
} }
} }
@@ -280,19 +281,19 @@ public class QuestDataIO {
@Override @Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
ItemPool<InventoryItem> result = new ItemPool<InventoryItem>(InventoryItem.class); final ItemPool<InventoryItem> result = new ItemPool<InventoryItem>(InventoryItem.class);
while (reader.hasMoreChildren()) { while (reader.hasMoreChildren()) {
reader.moveDown(); reader.moveDown();
String sCnt = reader.getAttribute("n"); final String sCnt = reader.getAttribute("n");
int cnt = StringUtils.isNumeric(sCnt) ? Integer.parseInt(sCnt) : 1; final int cnt = StringUtils.isNumeric(sCnt) ? Integer.parseInt(sCnt) : 1;
String nodename = reader.getNodeName(); final String nodename = reader.getNodeName();
if ("string".equals(nodename)) { if ("string".equals(nodename)) {
result.add(CardDb.instance().getCard(reader.getValue())); result.add(CardDb.instance().getCard(reader.getValue()));
} else if ("card".equals(nodename)) { // new format } else if ("card".equals(nodename)) { // new format
result.add(readCardPrinted(reader), cnt); result.add(this.readCardPrinted(reader), cnt);
} else if ("booster".equals(nodename)) { } else if ("booster".equals(nodename)) {
result.add(readBooster(reader), cnt); result.add(this.readBooster(reader), cnt);
} }
reader.moveUp(); reader.moveUp();
} }
@@ -300,17 +301,17 @@ public class QuestDataIO {
} }
private BoosterPack readBooster(final HierarchicalStreamReader reader) { private BoosterPack readBooster(final HierarchicalStreamReader reader) {
String set = reader.getAttribute("s"); final String set = reader.getAttribute("s");
return new BoosterPack(set); return new BoosterPack(set);
} }
private CardPrinted readCardPrinted(final HierarchicalStreamReader reader) { private CardPrinted readCardPrinted(final HierarchicalStreamReader reader) {
String name = reader.getAttribute("c"); final String name = reader.getAttribute("c");
String set = reader.getAttribute("s"); final String set = reader.getAttribute("s");
String sIndex = reader.getAttribute("i"); final String sIndex = reader.getAttribute("i");
short index = StringUtils.isNumeric(sIndex) ? Short.parseShort(sIndex) : 0; final short index = StringUtils.isNumeric(sIndex) ? Short.parseShort(sIndex) : 0;
boolean foil = "1".equals(reader.getAttribute("foil")); final boolean foil = "1".equals(reader.getAttribute("foil"));
CardPrinted card = CardDb.instance().getCard(name, set, index); final CardPrinted card = CardDb.instance().getCard(name, set, index);
return foil ? CardPrinted.makeFoiled(card) : card; return foil ? CardPrinted.makeFoiled(card) : card;
} }
} }

View File

@@ -24,7 +24,7 @@ public class QuestMatchState {
/** The Constant MIN_GAMES_TO_WIN_MATCH. */ /** The Constant MIN_GAMES_TO_WIN_MATCH. */
public static final int MIN_GAMES_TO_WIN_MATCH = 2; public static final int MIN_GAMES_TO_WIN_MATCH = 2;
private List<GameSummary> gamesPlayed = new ArrayList<GameSummary>(); private final List<GameSummary> gamesPlayed = new ArrayList<GameSummary>();
// ArrayList<GameSpecialConditions> // ArrayList<GameSpecialConditions>
@@ -35,7 +35,7 @@ public class QuestMatchState {
* the completed game * the completed game
*/ */
public final void addGamePlayed(final GameSummary completedGame) { public final void addGamePlayed(final GameSummary completedGame) {
gamesPlayed.add(completedGame); this.gamesPlayed.add(completedGame);
} }
/** /**
@@ -44,7 +44,7 @@ public class QuestMatchState {
* @return the games played * @return the games played
*/ */
public final GameSummary[] getGamesPlayed() { public final GameSummary[] getGamesPlayed() {
return gamesPlayed.toArray(new GameSummary[gamesPlayed.size()]); return this.gamesPlayed.toArray(new GameSummary[this.gamesPlayed.size()]);
} }
/** /**
@@ -53,7 +53,7 @@ public class QuestMatchState {
* @return the games played count * @return the games played count
*/ */
public final int getGamesPlayedCount() { public final int getGamesPlayedCount() {
return gamesPlayed.size(); return this.gamesPlayed.size();
} }
/** /**
@@ -64,8 +64,8 @@ public class QuestMatchState {
* @return true, if successful * @return true, if successful
*/ */
public final boolean hasWonLastGame(final String playerName) { public final boolean hasWonLastGame(final String playerName) {
int iLastGame = gamesPlayed.size() - 1; final int iLastGame = this.gamesPlayed.size() - 1;
return iLastGame >= 0 ? gamesPlayed.get(iLastGame).isWinner(playerName) : false; return iLastGame >= 0 ? this.gamesPlayed.get(iLastGame).isWinner(playerName) : false;
} }
/** /**
@@ -76,21 +76,21 @@ public class QuestMatchState {
public final boolean isMatchOver() { public final boolean isMatchOver() {
int totalGames = 0; int totalGames = 0;
Map<String, Integer> winsCount = new HashMap<String, Integer>(); final Map<String, Integer> winsCount = new HashMap<String, Integer>();
for (GameSummary game : gamesPlayed) { for (final GameSummary game : this.gamesPlayed) {
String winner = game.getWinner(); final String winner = game.getWinner();
Integer boxedWins = winsCount.get(winner); final Integer boxedWins = winsCount.get(winner);
int wins = boxedWins == null ? 0 : boxedWins.intValue(); final int wins = boxedWins == null ? 0 : boxedWins.intValue();
winsCount.put(winner, wins + 1); winsCount.put(winner, wins + 1);
totalGames++; totalGames++;
} }
int maxWins = 0; int maxWins = 0;
for (Integer win : winsCount.values()) { for (final Integer win : winsCount.values()) {
maxWins = Math.max(maxWins, win); maxWins = Math.max(maxWins, win);
} }
return maxWins >= MIN_GAMES_TO_WIN_MATCH || totalGames >= GAMES_PER_MATCH; return (maxWins >= QuestMatchState.MIN_GAMES_TO_WIN_MATCH) || (totalGames >= QuestMatchState.GAMES_PER_MATCH);
} }
/** /**
@@ -100,9 +100,9 @@ public class QuestMatchState {
* the name * the name
* @return the int * @return the int
*/ */
public final int countGamesWonBy(String name) { public final int countGamesWonBy(final String name) {
int wins = 0; int wins = 0;
for (GameSummary game : gamesPlayed) { for (final GameSummary game : this.gamesPlayed) {
if (game.isWinner(name)) { if (game.isWinner(name)) {
wins++; wins++;
} }
@@ -117,15 +117,15 @@ public class QuestMatchState {
* the name * the name
* @return true, if is match won by * @return true, if is match won by
*/ */
public final boolean isMatchWonBy(String name) { public final boolean isMatchWonBy(final String name) {
return countGamesWonBy(name) >= MIN_GAMES_TO_WIN_MATCH; return this.countGamesWonBy(name) >= QuestMatchState.MIN_GAMES_TO_WIN_MATCH;
} }
/** /**
* Reset. * Reset.
*/ */
public final void reset() { public final void reset() {
gamesPlayed.clear(); this.gamesPlayed.clear();
} }
} }

View File

@@ -89,7 +89,7 @@ public class QuestPreferences implements Serializable {
static { static {
// if quest.prefs exists // if quest.prefs exists
grabPrefsFromFile(); QuestPreferences.grabPrefsFromFile();
} }
/** /**
@@ -99,67 +99,67 @@ public class QuestPreferences implements Serializable {
*/ */
public static void grabPrefsFromFile() { public static void grabPrefsFromFile() {
try { try {
BufferedReader input = new BufferedReader(new FileReader(ForgeProps.getFile(Quest.PREFS))); final BufferedReader input = new BufferedReader(new FileReader(ForgeProps.getFile(Quest.PREFS)));
String line = null; String line = null;
while ((line = input.readLine()) != null) { while ((line = input.readLine()) != null) {
if (line.startsWith("#") || line.length() == 0) { if (line.startsWith("#") || (line.length() == 0)) {
continue; continue;
} }
String[] split = line.split("="); final String[] split = line.split("=");
if (split[0].equals("difficultyString")) { if (split[0].equals("difficultyString")) {
setDifficulty(split[1]); QuestPreferences.setDifficulty(split[1]);
} else if (split[0].equals("winsForBooster")) { } else if (split[0].equals("winsForBooster")) {
setWinsForBooster(split[1]); QuestPreferences.setWinsForBooster(split[1]);
} else if (split[0].equals("winsForRankIncrease")) { } else if (split[0].equals("winsForRankIncrease")) {
setWinsForRank(split[1]); QuestPreferences.setWinsForRank(split[1]);
} else if (split[0].equals("winsForMediumAI")) { } else if (split[0].equals("winsForMediumAI")) {
setWinsForMediumAI(split[1]); QuestPreferences.setWinsForMediumAI(split[1]);
} else if (split[0].equals("winsForHardAI")) { } else if (split[0].equals("winsForHardAI")) {
setWinsForHardAI(split[1]); QuestPreferences.setWinsForHardAI(split[1]);
} else if (split[0].equals("startingBasicLand")) { } else if (split[0].equals("startingBasicLand")) {
setStartingBasic(split[1]); QuestPreferences.setStartingBasic(split[1]);
} else if (split[0].equals("startingSnowBasicLand")) { } else if (split[0].equals("startingSnowBasicLand")) {
setStartingSnowBasic(split[1]); QuestPreferences.setStartingSnowBasic(split[1]);
} else if (split[0].equals("startingCommons")) { } else if (split[0].equals("startingCommons")) {
setStartingCommons(split[1]); QuestPreferences.setStartingCommons(split[1]);
} else if (split[0].equals("startingUncommons")) { } else if (split[0].equals("startingUncommons")) {
setStartingUncommons(split[1]); QuestPreferences.setStartingUncommons(split[1]);
} else if (split[0].equals("startingRares")) { } else if (split[0].equals("startingRares")) {
setStartingRares(split[1]); QuestPreferences.setStartingRares(split[1]);
} else if (split[0].equals("startingCredits")) { } else if (split[0].equals("startingCredits")) {
setStartingCredits(split[1]); QuestPreferences.setStartingCredits(split[1]);
} else if (split[0].equals("boosterPackCommon")) { } else if (split[0].equals("boosterPackCommon")) {
setNumCommon(split[1]); QuestPreferences.setNumCommon(split[1]);
} else if (split[0].equals("boosterPackUncommon")) { } else if (split[0].equals("boosterPackUncommon")) {
setNumUncommon(split[1]); QuestPreferences.setNumUncommon(split[1]);
} else if (split[0].equals("boosterPackRare")) { } else if (split[0].equals("boosterPackRare")) {
setNumRares(split[1]); QuestPreferences.setNumRares(split[1]);
} else if (split[0].equals("matchRewardBase")) { } else if (split[0].equals("matchRewardBase")) {
setMatchRewardBase(split[1]); QuestPreferences.setMatchRewardBase(split[1]);
} else if (split[0].equals("matchRewardTotalWins")) { } else if (split[0].equals("matchRewardTotalWins")) {
setMatchRewardTotalWins(split[1]); QuestPreferences.setMatchRewardTotalWins(split[1]);
} else if (split[0].equals("matchRewardNoLosses")) { } else if (split[0].equals("matchRewardNoLosses")) {
setMatchRewardNoLosses(split[1]); QuestPreferences.setMatchRewardNoLosses(split[1]);
} else if (split[0].equals("matchRewardMilledWinBonus")) { } else if (split[0].equals("matchRewardMilledWinBonus")) {
setMatchRewardMilledWinBonus(split[1]); QuestPreferences.setMatchRewardMilledWinBonus(split[1]);
} else if (split[0].equals("matchRewardPoisonWinBonus")) { } else if (split[0].equals("matchRewardPoisonWinBonus")) {
setMatchRewardPoisonWinBonus(split[1]); QuestPreferences.setMatchRewardPoisonWinBonus(split[1]);
} else if (split[0].equals("matchRewardAltWinBonus")) { } else if (split[0].equals("matchRewardAltWinBonus")) {
setMatchRewardAltWinBonus(split[1]); QuestPreferences.setMatchRewardAltWinBonus(split[1]);
} else if (split[0].equals("matchRewardWinOnFirstTurn")) { } else if (split[0].equals("matchRewardWinOnFirstTurn")) {
setMatchRewardWinFirst(split[1]); QuestPreferences.setMatchRewardWinFirst(split[1]);
} else if (split[0].equals("matchRewardWinByTurnFive")) { } else if (split[0].equals("matchRewardWinByTurnFive")) {
setMatchRewardWinByFifth(split[1]); QuestPreferences.setMatchRewardWinByFifth(split[1]);
} else if (split[0].equals("matchRewardWinByTurnTen")) { } else if (split[0].equals("matchRewardWinByTurnTen")) {
setMatchRewardWinByTen(split[1]); QuestPreferences.setMatchRewardWinByTen(split[1]);
} else if (split[0].equals("matchRewardWinByTurnFifteen")) { } else if (split[0].equals("matchRewardWinByTurnFifteen")) {
setMatchRewardWinByFifteen(split[1]); QuestPreferences.setMatchRewardWinByFifteen(split[1]);
} else if (split[0].equals("matchRewardMullToZero")) { } else if (split[0].equals("matchRewardMullToZero")) {
setMatchMullToZero(split[1]); QuestPreferences.setMatchMullToZero(split[1]);
} }
} }
} catch (Exception e) { } catch (final Exception e) {
System.out.println("Trouble grabbing quest data preferences. Using default values."); System.out.println("Trouble grabbing quest data preferences. Using default values.");
} }
} }
@@ -172,7 +172,7 @@ public class QuestPreferences implements Serializable {
* @return an array of {@link java.lang.String} objects. * @return an array of {@link java.lang.String} objects.
*/ */
public static String[] getDifficulty() { public static String[] getDifficulty() {
return sDifficulty; return QuestPreferences.sDifficulty;
} }
/** /**
@@ -185,7 +185,7 @@ public class QuestPreferences implements Serializable {
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
public static String getDifficulty(final int index) { public static String getDifficulty(final int index) {
return sDifficulty[index]; return QuestPreferences.sDifficulty[index];
} }
/** /**
@@ -198,7 +198,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getWinsForBooster(final int index) { public static int getWinsForBooster(final int index) {
return winsForBooster[index]; return QuestPreferences.winsForBooster[index];
} }
/** /**
@@ -211,7 +211,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getWinsForRankIncrease(final int index) { public static int getWinsForRankIncrease(final int index) {
return winsForRankIncrease[index]; return QuestPreferences.winsForRankIncrease[index];
} }
/** /**
@@ -224,7 +224,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getWinsForMediumAI(final int index) { public static int getWinsForMediumAI(final int index) {
return winsForMediumAI[index]; return QuestPreferences.winsForMediumAI[index];
} }
/** /**
@@ -237,7 +237,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getWinsForHardAI(final int index) { public static int getWinsForHardAI(final int index) {
return winsForHardAI[index]; return QuestPreferences.winsForHardAI[index];
} }
/** /**
@@ -250,7 +250,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getWinsForVeryHardAI(final int index) { public static int getWinsForVeryHardAI(final int index) {
return winsForVeryHardAI[index]; return QuestPreferences.winsForVeryHardAI[index];
} }
/** /**
@@ -261,7 +261,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getStartingBasic() { public static int getStartingBasic() {
return startingBasicLand; return QuestPreferences.startingBasicLand;
} }
/** /**
@@ -272,7 +272,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getStartingSnowBasic() { public static int getStartingSnowBasic() {
return startingSnowBasicLand; return QuestPreferences.startingSnowBasicLand;
} }
/** /**
@@ -285,7 +285,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getStartingCommons(final int index) { public static int getStartingCommons(final int index) {
return startingCommons[index]; return QuestPreferences.startingCommons[index];
} }
/** /**
@@ -298,7 +298,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getStartingUncommons(final int index) { public static int getStartingUncommons(final int index) {
return startingUncommons[index]; return QuestPreferences.startingUncommons[index];
} }
/** /**
@@ -311,7 +311,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getStartingRares(final int index) { public static int getStartingRares(final int index) {
return startingRares[index]; return QuestPreferences.startingRares[index];
} }
/** /**
@@ -322,7 +322,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getStartingCredits() { public static int getStartingCredits() {
return startingCredits; return QuestPreferences.startingCredits;
} }
/** /**
@@ -333,7 +333,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getNumCommon() { public static int getNumCommon() {
return boosterPackCommon; return QuestPreferences.boosterPackCommon;
} }
/** /**
@@ -344,7 +344,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getNumUncommon() { public static int getNumUncommon() {
return boosterPackUncommon; return QuestPreferences.boosterPackUncommon;
} }
/** /**
@@ -355,7 +355,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getNumRare() { public static int getNumRare() {
return boosterPackRare; return QuestPreferences.boosterPackRare;
} }
/** /**
@@ -366,7 +366,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getMatchRewardBase() { public static int getMatchRewardBase() {
return matchRewardBase; return QuestPreferences.matchRewardBase;
} }
/** /**
@@ -377,7 +377,7 @@ public class QuestPreferences implements Serializable {
* @return a double. * @return a double.
*/ */
public static double getMatchRewardTotalWins() { public static double getMatchRewardTotalWins() {
return matchRewardTotalWins; return QuestPreferences.matchRewardTotalWins;
} }
/** /**
@@ -388,7 +388,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getMatchRewardNoLosses() { public static int getMatchRewardNoLosses() {
return matchRewardNoLosses; return QuestPreferences.matchRewardNoLosses;
} }
/** /**
@@ -399,7 +399,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getMatchRewardPoisonWinBonus() { public static int getMatchRewardPoisonWinBonus() {
return matchRewardPoisonWinBonus; return QuestPreferences.matchRewardPoisonWinBonus;
} }
/** /**
@@ -410,7 +410,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getMatchRewardMilledWinBonus() { public static int getMatchRewardMilledWinBonus() {
return matchRewardMilledWinBonus; return QuestPreferences.matchRewardMilledWinBonus;
} }
/** /**
@@ -421,7 +421,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getMatchRewardAltWinBonus() { public static int getMatchRewardAltWinBonus() {
return matchRewardAltWinBonus; return QuestPreferences.matchRewardAltWinBonus;
} }
/** /**
@@ -432,7 +432,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getMatchRewardWinFirst() { public static int getMatchRewardWinFirst() {
return matchRewardWinOnFirstTurn; return QuestPreferences.matchRewardWinOnFirstTurn;
} }
/** /**
@@ -443,7 +443,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getMatchRewardWinByFifth() { public static int getMatchRewardWinByFifth() {
return matchRewardWinByTurnFive; return QuestPreferences.matchRewardWinByTurnFive;
} }
/** /**
@@ -454,7 +454,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getMatchRewardWinByTen() { public static int getMatchRewardWinByTen() {
return matchRewardWinByTurnTen; return QuestPreferences.matchRewardWinByTurnTen;
} }
/** /**
@@ -465,7 +465,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getMatchRewardWinByFifteen() { public static int getMatchRewardWinByFifteen() {
return matchRewardWinByTurnFifteen; return QuestPreferences.matchRewardWinByTurnFifteen;
} }
/** /**
@@ -476,7 +476,7 @@ public class QuestPreferences implements Serializable {
* @return a int. * @return a int.
*/ */
public static int getMatchMullToZero() { public static int getMatchMullToZero() {
return matchRewardMullToZero; return QuestPreferences.matchRewardMullToZero;
} }
// setters // setters
@@ -489,7 +489,7 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setDifficulty(final String diff) { public static void setDifficulty(final String diff) {
sDifficulty = diff.split(","); QuestPreferences.sDifficulty = diff.split(",");
} }
/** /**
@@ -501,10 +501,10 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setWinsForBooster(final String wins) { public static void setWinsForBooster(final String wins) {
String[] winsStr = wins.split(","); final String[] winsStr = wins.split(",");
for (int i = 0; i < numDiff; i++) { for (int i = 0; i < QuestPreferences.numDiff; i++) {
winsForBooster[i] = Integer.parseInt(winsStr[i]); QuestPreferences.winsForBooster[i] = Integer.parseInt(winsStr[i]);
} }
} }
@@ -517,10 +517,10 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setWinsForRank(final String wins) { public static void setWinsForRank(final String wins) {
String[] winsStr = wins.split(","); final String[] winsStr = wins.split(",");
for (int i = 0; i < numDiff; i++) { for (int i = 0; i < QuestPreferences.numDiff; i++) {
winsForRankIncrease[i] = Integer.parseInt(winsStr[i]); QuestPreferences.winsForRankIncrease[i] = Integer.parseInt(winsStr[i]);
} }
} }
@@ -533,10 +533,10 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setWinsForMediumAI(final String wins) { public static void setWinsForMediumAI(final String wins) {
String[] winsStr = wins.split(","); final String[] winsStr = wins.split(",");
for (int i = 0; i < numDiff; i++) { for (int i = 0; i < QuestPreferences.numDiff; i++) {
winsForMediumAI[i] = Integer.parseInt(winsStr[i]); QuestPreferences.winsForMediumAI[i] = Integer.parseInt(winsStr[i]);
} }
} }
@@ -549,10 +549,10 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setWinsForHardAI(final String wins) { public static void setWinsForHardAI(final String wins) {
String[] winsStr = wins.split(","); final String[] winsStr = wins.split(",");
for (int i = 0; i < numDiff; i++) { for (int i = 0; i < QuestPreferences.numDiff; i++) {
winsForHardAI[i] = Integer.parseInt(winsStr[i]); QuestPreferences.winsForHardAI[i] = Integer.parseInt(winsStr[i]);
} }
} }
@@ -565,7 +565,7 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setStartingBasic(final String land) { public static void setStartingBasic(final String land) {
startingBasicLand = Integer.parseInt(land); QuestPreferences.startingBasicLand = Integer.parseInt(land);
} }
/** /**
@@ -577,7 +577,7 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setStartingSnowBasic(final String land) { public static void setStartingSnowBasic(final String land) {
startingSnowBasicLand = Integer.parseInt(land); QuestPreferences.startingSnowBasicLand = Integer.parseInt(land);
} }
/** /**
@@ -589,10 +589,10 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setStartingCommons(final String rarity) { public static void setStartingCommons(final String rarity) {
String[] splitStr = rarity.split(","); final String[] splitStr = rarity.split(",");
for (int i = 0; i < numDiff; i++) { for (int i = 0; i < QuestPreferences.numDiff; i++) {
startingCommons[i] = Integer.parseInt(splitStr[i]); QuestPreferences.startingCommons[i] = Integer.parseInt(splitStr[i]);
} }
} }
@@ -605,10 +605,10 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setStartingUncommons(final String rarity) { public static void setStartingUncommons(final String rarity) {
String[] splitStr = rarity.split(","); final String[] splitStr = rarity.split(",");
for (int i = 0; i < numDiff; i++) { for (int i = 0; i < QuestPreferences.numDiff; i++) {
startingUncommons[i] = Integer.parseInt(splitStr[i]); QuestPreferences.startingUncommons[i] = Integer.parseInt(splitStr[i]);
} }
} }
@@ -621,10 +621,10 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setStartingRares(final String rarity) { public static void setStartingRares(final String rarity) {
String[] splitStr = rarity.split(","); final String[] splitStr = rarity.split(",");
for (int i = 0; i < numDiff; i++) { for (int i = 0; i < QuestPreferences.numDiff; i++) {
startingRares[i] = Integer.parseInt(splitStr[i]); QuestPreferences.startingRares[i] = Integer.parseInt(splitStr[i]);
} }
} }
@@ -637,7 +637,7 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setStartingCredits(final String credits) { public static void setStartingCredits(final String credits) {
startingCredits = Integer.parseInt(credits); QuestPreferences.startingCredits = Integer.parseInt(credits);
} }
/** /**
@@ -649,7 +649,7 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setNumCommon(final String pack) { public static void setNumCommon(final String pack) {
boosterPackCommon = Integer.parseInt(pack); QuestPreferences.boosterPackCommon = Integer.parseInt(pack);
} }
/** /**
@@ -661,7 +661,7 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setNumUncommon(final String pack) { public static void setNumUncommon(final String pack) {
boosterPackUncommon = Integer.parseInt(pack); QuestPreferences.boosterPackUncommon = Integer.parseInt(pack);
} }
/** /**
@@ -673,7 +673,7 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setNumRares(final String pack) { public static void setNumRares(final String pack) {
boosterPackRare = Integer.parseInt(pack); QuestPreferences.boosterPackRare = Integer.parseInt(pack);
} }
/** /**
@@ -685,7 +685,7 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setMatchRewardBase(final String match) { public static void setMatchRewardBase(final String match) {
matchRewardBase = Integer.parseInt(match); QuestPreferences.matchRewardBase = Integer.parseInt(match);
} }
/** /**
@@ -697,7 +697,7 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setMatchRewardTotalWins(final String match) { public static void setMatchRewardTotalWins(final String match) {
matchRewardTotalWins = Double.parseDouble(match); QuestPreferences.matchRewardTotalWins = Double.parseDouble(match);
} }
/** /**
@@ -709,7 +709,7 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setMatchRewardNoLosses(final String match) { public static void setMatchRewardNoLosses(final String match) {
matchRewardNoLosses = Integer.parseInt(match); QuestPreferences.matchRewardNoLosses = Integer.parseInt(match);
} }
/** /**
@@ -721,7 +721,7 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setMatchRewardPoisonWinBonus(final String match) { public static void setMatchRewardPoisonWinBonus(final String match) {
matchRewardPoisonWinBonus = Integer.parseInt(match); QuestPreferences.matchRewardPoisonWinBonus = Integer.parseInt(match);
} }
/** /**
@@ -733,7 +733,7 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setMatchRewardMilledWinBonus(final String match) { public static void setMatchRewardMilledWinBonus(final String match) {
matchRewardMilledWinBonus = Integer.parseInt(match); QuestPreferences.matchRewardMilledWinBonus = Integer.parseInt(match);
} }
/** /**
@@ -745,7 +745,7 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setMatchRewardAltWinBonus(final String match) { public static void setMatchRewardAltWinBonus(final String match) {
matchRewardAltWinBonus = Integer.parseInt(match); QuestPreferences.matchRewardAltWinBonus = Integer.parseInt(match);
} }
/** /**
@@ -757,7 +757,7 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setMatchRewardWinFirst(final String match) { public static void setMatchRewardWinFirst(final String match) {
matchRewardWinOnFirstTurn = Integer.parseInt(match); QuestPreferences.matchRewardWinOnFirstTurn = Integer.parseInt(match);
} }
/** /**
@@ -769,7 +769,7 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setMatchRewardWinByFifth(final String match) { public static void setMatchRewardWinByFifth(final String match) {
matchRewardWinByTurnFive = Integer.parseInt(match); QuestPreferences.matchRewardWinByTurnFive = Integer.parseInt(match);
} }
/** /**
@@ -781,7 +781,7 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setMatchRewardWinByTen(final String match) { public static void setMatchRewardWinByTen(final String match) {
matchRewardWinByTurnTen = Integer.parseInt(match); QuestPreferences.matchRewardWinByTurnTen = Integer.parseInt(match);
} }
/** /**
@@ -793,7 +793,7 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setMatchRewardWinByFifteen(final String match) { public static void setMatchRewardWinByFifteen(final String match) {
matchRewardWinByTurnFifteen = Integer.parseInt(match); QuestPreferences.matchRewardWinByTurnFifteen = Integer.parseInt(match);
} }
/** /**
@@ -805,6 +805,6 @@ public class QuestPreferences implements Serializable {
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
*/ */
public static void setMatchMullToZero(final String match) { public static void setMatchMullToZero(final String match) {
matchRewardMullToZero = Integer.parseInt(match); QuestPreferences.matchRewardMullToZero = Integer.parseInt(match);
} }
} }

View File

@@ -50,13 +50,13 @@ public class QuestUtil {
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public static CardList getComputerStartingCards(final QuestData qd, final QuestEvent qe) { public static CardList getComputerStartingCards(final QuestData qd, final QuestEvent qe) {
CardList list = new CardList(); final CardList list = new CardList();
if (qe.getEventType().equals("challenge")) { if (qe.getEventType().equals("challenge")) {
List<String> extras = ((QuestChallenge) qe).getAIExtraCards(); final List<String> extras = ((QuestChallenge) qe).getAIExtraCards();
for (String s : extras) { for (final String s : extras) {
list.add(readExtraCard(s, AllZone.getComputerPlayer())); list.add(QuestUtil.readExtraCard(s, AllZone.getComputerPlayer()));
} }
} }
@@ -74,7 +74,7 @@ public class QuestUtil {
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public static CardList getHumanStartingCards(final QuestData qd) { public static CardList getHumanStartingCards(final QuestData qd) {
CardList list = new CardList(); final CardList list = new CardList();
if (qd.getPetManager().shouldPetBeUsed()) { if (qd.getPetManager().shouldPetBeUsed()) {
list.add(qd.getPetManager().getSelectedPet().getPetCard()); list.add(qd.getPetManager().getSelectedPet().getPetCard());
@@ -101,13 +101,13 @@ public class QuestUtil {
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public static CardList getHumanStartingCards(final QuestData qd, final QuestEvent qe) { public static CardList getHumanStartingCards(final QuestData qd, final QuestEvent qe) {
CardList list = getHumanStartingCards(qd); final CardList list = QuestUtil.getHumanStartingCards(qd);
if (qe.getEventType().equals("challenge")) { if (qe.getEventType().equals("challenge")) {
List<String> extras = ((QuestChallenge) qe).getHumanExtraCards(); final List<String> extras = ((QuestChallenge) qe).getHumanExtraCards();
for (String s : extras) { for (final String s : extras) {
list.add(readExtraCard(s, AllZone.getHumanPlayer())); list.add(QuestUtil.readExtraCard(s, AllZone.getHumanPlayer()));
} }
} }
@@ -126,8 +126,8 @@ public class QuestUtil {
* @return token Card * @return token Card
*/ */
public static Card createToken(final String s) { public static Card createToken(final String s) {
String[] properties = s.split(";"); final String[] properties = s.split(";");
Card c = new Card(); final Card c = new Card();
c.setToken(true); c.setToken(true);
// c.setManaCost(properties[1]); // c.setManaCost(properties[1]);
@@ -157,9 +157,9 @@ public class QuestUtil {
* @return CardList * @return CardList
*/ */
public static List<CardPrinted> generateCardRewardList(final String s) { public static List<CardPrinted> generateCardRewardList(final String s) {
String[] temp = s.split(" "); final String[] temp = s.split(" ");
int qty = Integer.parseInt(temp[0]); final int qty = Integer.parseInt(temp[0]);
// Determine rarity // Determine rarity
CardRarity rar = CardRarity.Uncommon; CardRarity rar = CardRarity.Uncommon;
if (temp[2].equalsIgnoreCase("rare") || temp[2].equalsIgnoreCase("rares")) { if (temp[2].equalsIgnoreCase("rare") || temp[2].equalsIgnoreCase("rares")) {

View File

@@ -25,7 +25,7 @@ import forge.item.ItemPoolView;
* created to decrease complexity of questData class * created to decrease complexity of questData class
*/ */
public final class QuestUtilCards { public final class QuestUtilCards {
private QuestData q; private final QuestData q;
/** /**
* Instantiates a new quest util cards. * Instantiates a new quest util cards.
@@ -34,7 +34,7 @@ public final class QuestUtilCards {
* the qd * the qd
*/ */
public QuestUtilCards(final QuestData qd) { public QuestUtilCards(final QuestData qd) {
q = qd; this.q = qd;
} }
/** /**
@@ -48,7 +48,7 @@ public final class QuestUtilCards {
* the n snow * the n snow
*/ */
public void addBasicLands(final ItemPool<InventoryItem> pool, final int nBasic, final int nSnow) { public void addBasicLands(final ItemPool<InventoryItem> pool, final int nBasic, final int nSnow) {
CardDb db = CardDb.instance(); final CardDb db = CardDb.instance();
pool.add(db.getCard("Forest", "M10"), nBasic); pool.add(db.getCard("Forest", "M10"), nBasic);
pool.add(db.getCard("Mountain", "M10"), nBasic); pool.add(db.getCard("Mountain", "M10"), nBasic);
pool.add(db.getCard("Swamp", "M10"), nBasic); pool.add(db.getCard("Swamp", "M10"), nBasic);
@@ -75,16 +75,16 @@ public final class QuestUtilCards {
* @return the array list * @return the array list
*/ */
public ArrayList<CardPrinted> addCards(final Predicate<CardPrinted> fSets) { public ArrayList<CardPrinted> addCards(final Predicate<CardPrinted> fSets) {
int nCommon = QuestPreferences.getNumCommon(); final int nCommon = QuestPreferences.getNumCommon();
int nUncommon = QuestPreferences.getNumUncommon(); final int nUncommon = QuestPreferences.getNumUncommon();
int nRare = QuestPreferences.getNumRare(); final int nRare = QuestPreferences.getNumRare();
ArrayList<CardPrinted> newCards = new ArrayList<CardPrinted>(); final ArrayList<CardPrinted> newCards = new ArrayList<CardPrinted>();
newCards.addAll(BoosterUtils.generateCards(fSets, nCommon, CardRarity.Common, null)); newCards.addAll(BoosterUtils.generateCards(fSets, nCommon, CardRarity.Common, null));
newCards.addAll(BoosterUtils.generateCards(fSets, nUncommon, CardRarity.Uncommon, null)); newCards.addAll(BoosterUtils.generateCards(fSets, nUncommon, CardRarity.Uncommon, null));
newCards.addAll(BoosterUtils.generateCards(fSets, nRare, CardRarity.Rare, null)); newCards.addAll(BoosterUtils.generateCards(fSets, nRare, CardRarity.Rare, null));
addAllCards(newCards); this.addAllCards(newCards);
return newCards; return newCards;
} }
@@ -95,8 +95,8 @@ public final class QuestUtilCards {
* the new cards * the new cards
*/ */
public void addAllCards(final Iterable<CardPrinted> newCards) { public void addAllCards(final Iterable<CardPrinted> newCards) {
for (CardPrinted card : newCards) { for (final CardPrinted card : newCards) {
addSingleCard(card); this.addSingleCard(card);
} }
} }
@@ -107,13 +107,13 @@ public final class QuestUtilCards {
* the card * the card
*/ */
public void addSingleCard(final CardPrinted card) { public void addSingleCard(final CardPrinted card) {
q.cardPool.add(card); this.q.getCardPool().add(card);
// register card into that list so that it would appear as a new one. // register card into that list so that it would appear as a new one.
q.newCardList.add(card); this.q.getNewCardList().add(card);
} }
private static final Predicate<CardPrinted> rarePredicate = CardPrinted.Predicates.Presets.IS_RARE_OR_MYTHIC; private static final Predicate<CardPrinted> RARE_PREDICATE = CardPrinted.Predicates.Presets.IS_RARE_OR_MYTHIC;
/** /**
* Adds the random rare. * Adds the random rare.
@@ -121,8 +121,8 @@ public final class QuestUtilCards {
* @return the card printed * @return the card printed
*/ */
public CardPrinted addRandomRare() { public CardPrinted addRandomRare() {
CardPrinted card = rarePredicate.random(CardDb.instance().getAllCards()); final CardPrinted card = QuestUtilCards.RARE_PREDICATE.random(CardDb.instance().getAllCards());
addSingleCard(card); this.addSingleCard(card);
return card; return card;
} }
@@ -134,8 +134,8 @@ public final class QuestUtilCards {
* @return the list * @return the list
*/ */
public List<CardPrinted> addRandomRare(final int n) { public List<CardPrinted> addRandomRare(final int n) {
List<CardPrinted> newCards = rarePredicate.random(CardDb.instance().getAllCards(), n); final List<CardPrinted> newCards = QuestUtilCards.RARE_PREDICATE.random(CardDb.instance().getAllCards(), n);
addAllCards(newCards); this.addAllCards(newCards);
return newCards; return newCards;
} }
@@ -148,11 +148,11 @@ public final class QuestUtilCards {
* the idx difficulty * the idx difficulty
*/ */
public void setupNewGameCardPool(final Predicate<CardPrinted> filter, final int idxDifficulty) { public void setupNewGameCardPool(final Predicate<CardPrinted> filter, final int idxDifficulty) {
int nC = QuestPreferences.getStartingCommons(idxDifficulty); final int nC = QuestPreferences.getStartingCommons(idxDifficulty);
int nU = QuestPreferences.getStartingUncommons(idxDifficulty); final int nU = QuestPreferences.getStartingUncommons(idxDifficulty);
int nR = QuestPreferences.getStartingRares(idxDifficulty); final int nR = QuestPreferences.getStartingRares(idxDifficulty);
addAllCards(BoosterUtils.getQuestStarterDeck(filter, nC, nU, nR)); this.addAllCards(BoosterUtils.getQuestStarterDeck(filter, nC, nU, nR));
} }
/** /**
@@ -164,10 +164,10 @@ public final class QuestUtilCards {
* the value * the value
*/ */
public void buyCard(final CardPrinted card, final int value) { public void buyCard(final CardPrinted card, final int value) {
if (q.credits >= value) { if (this.q.getCredits() >= value) {
q.credits -= value; this.q.setCredits(this.q.getCredits() - value);
q.shopList.remove(card); this.q.getShopList().remove(card);
addSingleCard(card); this.addSingleCard(card);
} }
} }
@@ -180,10 +180,10 @@ public final class QuestUtilCards {
* the value * the value
*/ */
public void buyBooster(final BoosterPack booster, final int value) { public void buyBooster(final BoosterPack booster, final int value) {
if (q.credits >= value) { if (this.q.getCredits() >= value) {
q.credits -= value; this.q.setCredits(this.q.getCredits() - value);
q.shopList.remove(booster); this.q.getShopList().remove(booster);
addAllCards(booster.getCards()); this.addAllCards(booster.getCards());
} }
} }
@@ -197,15 +197,15 @@ public final class QuestUtilCards {
*/ */
public void sellCard(final CardPrinted card, final int price) { public void sellCard(final CardPrinted card, final int price) {
if (price > 0) { if (price > 0) {
q.credits += price; this.q.setCredits(this.q.getCredits() + price);
} }
q.cardPool.remove(card); this.q.getCardPool().remove(card);
q.shopList.add(card); this.q.getShopList().add(card);
// remove card being sold from all decks // remove card being sold from all decks
int leftInPool = q.cardPool.count(card); final int leftInPool = this.q.getCardPool().count(card);
// remove sold cards from all decks: // remove sold cards from all decks:
for (Deck deck : q.myDecks.values()) { for (final Deck deck : this.q.getMyDecks().values()) {
deck.removeMain(card, deck.getMain().count(card) - leftInPool); deck.removeMain(card, deck.getMain().count(card) - leftInPool);
} }
} }
@@ -214,8 +214,8 @@ public final class QuestUtilCards {
* Clear shop list. * Clear shop list.
*/ */
public void clearShopList() { public void clearShopList() {
if (null != q.shopList) { if (null != this.q.getShopList()) {
q.shopList.clear(); this.q.getShopList().clear();
} }
} }
@@ -225,12 +225,12 @@ public final class QuestUtilCards {
* @return the sell mutliplier * @return the sell mutliplier
*/ */
public double getSellMutliplier() { public double getSellMutliplier() {
double multi = 0.20 + (0.001 * q.getWin()); double multi = 0.20 + (0.001 * this.q.getWin());
if (multi > 0.6) { if (multi > 0.6) {
multi = 0.6; multi = 0.6;
} }
int lvlEstates = q.isFantasy() ? q.inventory.getItemLevel("Estates") : 0; final int lvlEstates = this.q.isFantasy() ? this.q.getInventory().getItemLevel("Estates") : 0;
switch (lvlEstates) { switch (lvlEstates) {
case 1: case 1:
multi += 0.01; multi += 0.01;
@@ -254,18 +254,18 @@ public final class QuestUtilCards {
* @return the sell price limit * @return the sell price limit
*/ */
public int getSellPriceLimit() { public int getSellPriceLimit() {
return q.getWin() <= 50 ? 1000 : Integer.MAX_VALUE; return this.q.getWin() <= 50 ? 1000 : Integer.MAX_VALUE;
} }
/** /**
* Generate cards in shop. * Generate cards in shop.
*/ */
public void generateCardsInShop() { public void generateCardsInShop() {
BoosterGenerator pack = new BoosterGenerator(CardDb.instance().getAllCards()); final BoosterGenerator pack = new BoosterGenerator(CardDb.instance().getAllCards());
int levelPacks = q.getLevel() > 0 ? 4 / q.getLevel() : 4; final int levelPacks = this.q.getLevel() > 0 ? 4 / this.q.getLevel() : 4;
int winPacks = q.getWin() / 10; final int winPacks = this.q.getWin() / 10;
int totalPacks = Math.min(levelPacks + winPacks, 6); final int totalPacks = Math.min(levelPacks + winPacks, 6);
final Predicate<CardSet> filterExt = CardSet.Predicates.Presets.SETS_IN_EXT; final Predicate<CardSet> filterExt = CardSet.Predicates.Presets.SETS_IN_EXT;
final Predicate<CardSet> filterT2booster = Predicate.and(CardSet.Predicates.CAN_MAKE_BOOSTER, final Predicate<CardSet> filterT2booster = Predicate.and(CardSet.Predicates.CAN_MAKE_BOOSTER,
@@ -275,18 +275,18 @@ public final class QuestUtilCards {
final Predicate<CardSet> filterNotExt = Predicate.and(CardSet.Predicates.CAN_MAKE_BOOSTER, final Predicate<CardSet> filterNotExt = Predicate.and(CardSet.Predicates.CAN_MAKE_BOOSTER,
Predicate.not(filterExt)); Predicate.not(filterExt));
q.shopList.clear(); this.q.getShopList().clear();
for (int i = 0; i < totalPacks; i++) { for (int i = 0; i < totalPacks; i++) {
q.shopList.addAllCards(pack.getBoosterPack(7, 3, 1, 0, 0, 0, 0, 0, 0)); this.q.getShopList().addAllCards(pack.getBoosterPack(7, 3, 1, 0, 0, 0, 0, 0, 0));
// add some boosters // add some boosters
int rollD100 = MyRandom.getRandom().nextInt(100); final int rollD100 = MyRandom.getRandom().nextInt(100);
Predicate<CardSet> filter = rollD100 < 40 ? filterT2booster : (rollD100 < 75 ? filterExtButT2 final Predicate<CardSet> filter = rollD100 < 40 ? filterT2booster : (rollD100 < 75 ? filterExtButT2
: filterNotExt); : filterNotExt);
q.shopList.addAllCards(filter.random(SetUtils.getAllSets(), 1, BoosterPack.FN_FROM_SET)); this.q.getShopList().addAllCards(filter.random(SetUtils.getAllSets(), 1, BoosterPack.FN_FROM_SET));
} }
addBasicLands(q.shopList, 10, 5); this.addBasicLands(this.q.getShopList(), 10, 5);
} }
/** /**
@@ -295,7 +295,7 @@ public final class QuestUtilCards {
* @return the cardpool * @return the cardpool
*/ */
public ItemPool<InventoryItem> getCardpool() { public ItemPool<InventoryItem> getCardpool() {
return q.cardPool; return this.q.getCardPool();
} }
/** /**
@@ -304,10 +304,10 @@ public final class QuestUtilCards {
* @return the shop list * @return the shop list
*/ */
public ItemPoolView<InventoryItem> getShopList() { public ItemPoolView<InventoryItem> getShopList() {
if (q.shopList.isEmpty()) { if (this.q.getShopList().isEmpty()) {
generateCardsInShop(); this.generateCardsInShop();
} }
return q.shopList; return this.q.getShopList();
} }
/** /**
@@ -316,14 +316,28 @@ public final class QuestUtilCards {
* @return the new cards * @return the new cards
*/ */
public ItemPoolView<InventoryItem> getNewCards() { public ItemPoolView<InventoryItem> getNewCards() {
return q.newCardList; return this.q.getNewCardList();
} }
/** /**
* Reset new list. * Reset new list.
*/ */
public void resetNewList() { public void resetNewList() {
q.newCardList.clear(); this.q.getNewCardList().clear();
}
/**
* @return the fnNewCompare
*/
public Lambda1<Comparable, Entry<InventoryItem, Integer>> getFnNewCompare() {
return fnNewCompare;
}
/**
* @return the fnNewGet
*/
public Lambda1<Object, Entry<InventoryItem, Integer>> getFnNewGet() {
return fnNewGet;
} }
// These functions provide a way to sort and compare cards in a table // These functions provide a way to sort and compare cards in a table
@@ -333,18 +347,18 @@ public final class QuestUtilCards {
// Maybe we should consider doing so later // Maybe we should consider doing so later
/** The fn new compare. */ /** The fn new compare. */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnNewCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnNewCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
@Override @Override
public Comparable apply(final Entry<InventoryItem, Integer> from) { public Comparable apply(final Entry<InventoryItem, Integer> from) {
return q.newCardList.contains(from.getKey()) ? Integer.valueOf(1) : Integer.valueOf(0); return QuestUtilCards.this.q.getNewCardList().contains(from.getKey()) ? Integer.valueOf(1) : Integer.valueOf(0);
} }
}; };
/** The fn new get. */ /** The fn new get. */
public final Lambda1<Object, Entry<InventoryItem, Integer>> fnNewGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() { private final Lambda1<Object, Entry<InventoryItem, Integer>> fnNewGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
@Override @Override
public Object apply(final Entry<InventoryItem, Integer> from) { public Object apply(final Entry<InventoryItem, Integer> from) {
return q.newCardList.contains(from.getKey()) ? "NEW" : ""; return QuestUtilCards.this.q.getNewCardList().contains(from.getKey()) ? "NEW" : "";
} }
}; };
} }

View File

@@ -35,7 +35,7 @@ public class ReadPriceList implements NewConstants {
* </p> * </p>
*/ */
public ReadPriceList() { public ReadPriceList() {
setup(); this.setup();
} }
/** /**
@@ -44,8 +44,8 @@ public class ReadPriceList implements NewConstants {
* </p> * </p>
*/ */
private void setup() { private void setup() {
priceMap = readFile(ForgeProps.getFile(Quest.PRICE)); this.priceMap = this.readFile(ForgeProps.getFile(Quest.PRICE));
priceMap.putAll(readFile(ForgeProps.getFile(Quest.BOOSTER_PRICE))); this.priceMap.putAll(this.readFile(ForgeProps.getFile(Quest.BOOSTER_PRICE)));
} // setup() } // setup()
@@ -60,19 +60,19 @@ public class ReadPriceList implements NewConstants {
*/ */
private HashMap<String, Integer> readFile(final File file) { private HashMap<String, Integer> readFile(final File file) {
BufferedReader in; BufferedReader in;
HashMap<String, Integer> map = new HashMap<String, Integer>(); final HashMap<String, Integer> map = new HashMap<String, Integer>();
Random r = MyRandom.getRandom(); final Random r = MyRandom.getRandom();
try { try {
in = new BufferedReader(new FileReader(file)); in = new BufferedReader(new FileReader(file));
String line = in.readLine(); String line = in.readLine();
// stop reading if end of file or blank line is read // stop reading if end of file or blank line is read
while (line != null && (line.trim().length() != 0)) { while ((line != null) && (line.trim().length() != 0)) {
if (!line.startsWith(comment)) { if (!line.startsWith(ReadPriceList.comment)) {
String[] s = line.split("="); final String[] s = line.split("=");
String name = s[0].trim(); final String name = s[0].trim();
String price = s[1].trim(); final String price = s[1].trim();
// System.out.println("Name: " + name + ", Price: " + // System.out.println("Name: " + name + ", Price: " +
// price); // price);
@@ -87,29 +87,29 @@ public class ReadPriceList implements NewConstants {
.equals("Snow-Covered Forest"))) { .equals("Snow-Covered Forest"))) {
float ff = 0; float ff = 0;
if (r.nextInt(100) < 90) { if (r.nextInt(100) < 90) {
ff = (float) r.nextInt(10) * (float) .01; ff = r.nextInt(10) * (float) .01;
} else { } else {
// +/- 50% // +/- 50%
ff = (float) r.nextInt(50) * (float) .01; ff = r.nextInt(50) * (float) .01;
} }
if (r.nextInt(100) < 50) { if (r.nextInt(100) < 50) {
val = (int) ((float) val * ((float) 1 - ff)); val = (int) (val * (1 - ff));
} else { } else {
// +ff% // +ff%
val = (int) ((float) val * ((float) 1 + ff)); val = (int) (val * (1 + ff));
} }
} }
map.put(name, val); map.put(name, val);
} catch (NumberFormatException nfe) { } catch (final NumberFormatException nfe) {
Log.warn("NumberFormatException: " + nfe.getMessage()); Log.warn("NumberFormatException: " + nfe.getMessage());
} }
} }
line = in.readLine(); line = in.readLine();
} // if } // if
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("ReadPriceList : readFile error, " + ex); throw new RuntimeException("ReadPriceList : readFile error, " + ex);
} }
@@ -125,6 +125,6 @@ public class ReadPriceList implements NewConstants {
* @return a {@link java.util.Map} object. * @return a {@link java.util.Map} object.
*/ */
public final Map<String, Integer> getPriceList() { public final Map<String, Integer> getPriceList() {
return priceMap; return this.priceMap;
} }
} }