Finally, all quest and duel decks fully encapsulated with acceptable format.

Helper files completely removed (easy.txt, quests.txt, etc.) and hard-coded quest properties are a thing of the past.

Model and view fully separated for main panel in quest GUI.

Critical file: QuestEventManager can handle instantiation of all decks, once (ideally).
This commit is contained in:
Doublestrike
2011-09-17 09:21:43 +00:00
parent 3e26b4b262
commit 6545bbf276
28 changed files with 1544 additions and 2478 deletions

View File

@@ -17,6 +17,7 @@ import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import forge.quest.data.QuestMatchState;
import forge.quest.data.QuestData;
import forge.quest.gui.main.QuestQuest;
/**
* Please use public getters and setters instead of direct field access.
@@ -42,7 +43,7 @@ public final class AllZone implements NewConstants {
private static forge.quest.data.QuestData questData = null;
/** Global <code>QuestAssignment</code>. */
private static Quest_Assignment questAssignment = null;
private static QuestQuest questquest = null;
/** Constant <code>NAME_CHANGER</code>. */
private static final NameChanger NAME_CHANGER = new NameChanger();
@@ -136,8 +137,8 @@ public final class AllZone implements NewConstants {
* @return a {@link forge.Quest_Assignment} object.
* @since 1.0.15
*/
public static Quest_Assignment getQuestAssignment() {
return questAssignment;
public static QuestQuest getQuestQuest() {
return questquest;
}
/**
@@ -146,8 +147,8 @@ public final class AllZone implements NewConstants {
* @param assignment a {@link forge.Quest_Assignment} object.
* @since 1.0.15
*/
public static void setQuestAssignment(final Quest_Assignment assignment) {
questAssignment = assignment;
public static void setQuestQuest(final QuestQuest q) {
questquest = q;
}
/**

View File

@@ -29,6 +29,7 @@ import forge.gui.input.Input_PayManaCost_Ability;
import forge.item.CardPrinted;
import forge.properties.ForgeProps;
import forge.properties.NewConstants.LANG.GameAction.GAMEACTION_TEXT;
import forge.quest.gui.main.QuestQuest;
import java.util.ArrayList;
import java.util.Comparator;
@@ -653,7 +654,7 @@ public class GameAction {
AllZone.getDisplay().savePrefs();
frame.setEnabled(false);
//frame.dispose();
Gui_WinLose gwl = new Gui_WinLose(AllZone.getMatchState(), AllZone.getQuestData(), AllZone.getQuestAssignment());
Gui_WinLose gwl = new Gui_WinLose(AllZone.getMatchState(), AllZone.getQuestData(), AllZone.getQuestQuest());
//gwl.setAlwaysOnTop(true);
gwl.toFront();
canShowWinLose = false;
@@ -1074,15 +1075,15 @@ public class GameAction {
* @param computer a {@link forge.CardList} object.
*/
public final void newGame(final Deck humanDeck, final Deck computerDeck, final CardList human,
final CardList computer, final int humanLife, final int computerLife, final Quest_Assignment qa)
final CardList computer, final int humanLife, final int computerLife, final QuestQuest qq)
{
this.newGame(humanDeck, computerDeck);
AllZone.getComputerPlayer().setLife(computerLife, null);
AllZone.getHumanPlayer().setLife(humanLife, null);
if (qa != null) {
computer.addAll(forge.quest.data.QuestUtil.getComputerStartingCards(AllZone.getQuestData(), AllZone.getQuestAssignment()));
if (qq != null) {
computer.addAll(forge.quest.data.QuestUtil.getComputerStartingCards(AllZone.getQuestData(), AllZone.getQuestQuest()));
}
for (Card c : human) {

View File

@@ -17,6 +17,7 @@ import forge.quest.data.QuestData;
import forge.quest.data.QuestMatchState;
import forge.quest.data.QuestPreferences;
import forge.quest.gui.QuestFrame;
import forge.quest.gui.main.QuestQuest;
import forge.view.swing.OldGuiNewGame;
import net.miginfocom.swing.MigLayout;
@@ -65,7 +66,7 @@ public class Gui_WinLose extends JFrame implements NewConstants {
private class WinLoseModel {
public QuestMatchState match;
public QuestData quest;
public Quest_Assignment qa;
public QuestQuest qq;
}
private WinLoseModel model;
@@ -77,11 +78,11 @@ public class Gui_WinLose extends JFrame implements NewConstants {
* @param quest a QuestData object
* @param qa a Quest_Assignment object
*/
public Gui_WinLose(final QuestMatchState matchState, final QuestData quest, final Quest_Assignment qa) {
public Gui_WinLose(final QuestMatchState matchState, final QuestData quest, final QuestQuest qq) {
model = new WinLoseModel();
model.match = matchState;
model.quest = quest;
model.qa = qa;
model.qq = qq;
try {
jbInit();
@@ -186,25 +187,25 @@ public class Gui_WinLose extends JFrame implements NewConstants {
void prepareForNextRound() {
if (Constant.Quest.fantasyQuest[0]) {
int extraLife = 0;
if (model.qa != null) {
if (model.qq != null) {
if (model.quest.getInventory().hasItem("Zeppelin")) {
extraLife = 3;
}
}
//AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0],
//humanList, computerList, humanLife, computerLife);
CardList humanList = forge.quest.data.QuestUtil.getHumanStartingCards(model.quest, model.qa);
CardList humanList = forge.quest.data.QuestUtil.getHumanStartingCards(model.quest, model.qq);
CardList computerList = new CardList();
int humanLife = model.quest.getLife() + extraLife;
int computerLife = 20;
if (model.qa != null) {
computerLife = model.qa.getComputerLife();
if (model.qq != null) {
computerLife = model.qq.getAILife();
}
AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0],
humanList, computerList, humanLife, computerLife, model.qa);
humanList, computerList, humanLife, computerLife, model.qq);
} else {
AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0]);
}
@@ -362,7 +363,7 @@ public class Gui_WinLose extends JFrame implements NewConstants {
giveQuestRewards(wonMatch);
model.match.reset();
AllZone.setQuestAssignment(null);
AllZone.setQuestQuest(null);
model.quest.saveData();
@@ -440,11 +441,11 @@ public class Gui_WinLose extends JFrame implements NewConstants {
}
// Rewards from QuestAssignment
if (wonMatch && model.qa != null) {
if (wonMatch && model.qq != null) {
model.quest.addQuestsPlayed();
List<CardPrinted> questRewardCards = model.qa.getCardRewardList();
long questRewardCredits = model.qa.getCreditsReward();
List<CardPrinted> questRewardCards = model.qq.getCardRewardList();
long questRewardCredits = model.qq.getCreditsReward();
StringBuilder sb = new StringBuilder();
sb.append("Quest Completed - \r\n");
@@ -465,7 +466,7 @@ public class Gui_WinLose extends JFrame implements NewConstants {
String fileName = "BoxIcon.png";
ImageIcon icon = getIcon(fileName);
String title = "Quest Rewards for " + model.qa.getName();
String title = "Quest Rewards for " + model.qq.getTitle();
JOptionPane.showMessageDialog(null, sb.toString(), title, JOptionPane.INFORMATION_MESSAGE, icon);
}
/*

View File

@@ -1,289 +0,0 @@
package forge;
import java.util.ArrayList;
import java.util.List;
import forge.item.CardPrinted;
/**
* <p>Quest_Assignment class.</p>
* An instance of a single quest assignment. Holds values that aren't defined in
* Deck class, such as credit reward.
*
* @author Forge
* @version $Id$
*/
public class Quest_Assignment {
// ID (default -1, should be explicitly set at later time.)
private int id = -1;
// Default vals if none provided for this ID in quests.txt.
private int requiredNumberWins = 20;
private int computerLife = 25;
private long creditsReward = 100;
private String name = "Mystery Quest";
private String desc = "";
private String difficulty = "Medium";
private String cardReward = "1 colorless rare";
private String iconName = "Unknown.jpg";
private boolean repeatable = false;
// Other cards used in assignment: starting, and reward.
private CardList humanExtraCards = new CardList();
private CardList aiExtraCards = new CardList();
private List<CardPrinted> cardRewardList = new ArrayList<CardPrinted>();
// No constructor required; fields are set dynamically.
// Setters and getters, in alphabetical order.
/**
* <p>Setter for the field <code>aiExtraCards</code>.</p>
* Sets list of cards automatically played at start of match.
*
* @param s a CardList object.
*/
public final void setAIExtraCards(final CardList cl) {
this.aiExtraCards = cl;
}
/**
* <p>Getter for the field <code>aiExtraCards</code>.</p>
* Gets list of cards automatically played at start of match.
*
* @return a {@link java.util.ArrayList} object.
*/
public final CardList getAIExtraCards() {
return aiExtraCards;
}
/**
* <p>Setter for the field <code>cardReward</code>.</p>
* Sets string notated card reward received if match is won.
*
* @param cardRewardIn a {@link java.lang.String} object.
*/
public final void setCardReward(final String cardRewardIn) {
this.cardReward = cardRewardIn;
}
/**
* <p>Getter for the field <code>cardReward</code>.</p>
* Gets string notated card reward received if match is won.
*
* @return a {@link java.lang.String} object.
*/
public final String getCardReward() {
return cardReward;
}
/**
* <p>Setter for the field <code>cardRewardList</code>.</p>
* Sets card reward list for cards received if match is won.
*
* @return a {@link java.util.ArrayList} object.
*/
public void setCardRewardList(final List<CardPrinted> cp) {
this.cardRewardList = cp;
}
/**
* <p>Getter for the field <code>cardRewardList</code>.</p>
* Gets card reward list for cards received if match is won.
*
* @return a {@link java.util.ArrayList} object.
*/
public final List<CardPrinted> getCardRewardList() {
return cardRewardList;
}
/**
* <p>Setter for the field <code>computerLife</code>.</p>
* Sets computer life at start of match.
*
* @param computerLifeIn a int.
*/
public final void setComputerLife(final int computerLifeIn) {
this.computerLife = computerLifeIn;
}
/**
* <p>Getter for the field <code>computerLife</code>.</p>
* Gets computer life at start of match.
*
* @return a int.
*/
public final int getComputerLife() {
return computerLife;
}
/**
* <p>Setter for the field <code>creditsReward</code>.</p>
* Sets credit reward received if match is won.
*
* @param creditsRewardIn a long.
*/
public final void setCreditsReward(final long creditsRewardIn) {
this.creditsReward = creditsRewardIn;
}
/**
* <p>Getter for the field <code>creditsReward</code>.</p>
* Gets credit reward received if match is won.
*
* @return a long.
*/
public final long getCreditsReward() {
return creditsReward;
}
/**
* <p>Setter for the field <code>desc</code>.</p>
*
* @param descIn a {@link java.lang.String} object.
*/
public final void setDesc(final String descIn) {
this.desc = descIn;
}
/**
* <p>Getter for the field <code>desc</code>.</p>
*
* @return a {@link java.lang.String} object.
*/
public final String getDesc() {
return desc;
}
/**
* <p>Setter for the field <code>difficulty</code>.</p>
*
* @param difficultyIn a {@link java.lang.String} object.
*/
public final void setDifficulty(final String difficultyIn) {
this.difficulty = difficultyIn;
}
/**
* <p>Setter for the field <code>humanExtraCards</code>.</p>
* Sets list of cards automatically played at start of match.
*
* @param s a CardList object.
*/
public final void setHumanExtraCards(final CardList cl) {
this.humanExtraCards = cl;
}
/**
* <p>Getter for the field <code>humanExtraCards</code>.</p>
* Gets list of cards automatically played at start of match.
*
* @return a {@link forge.CardList} object.
*/
public final CardList getHumanExtraCards() {
return humanExtraCards;
}
/**
* <p>Getter for the field <code>difficulty</code>.</p>
*
* @return a {@link java.lang.String} object.
*/
public final String getDifficulty() {
return difficulty;
}
/**
* <p>Setter for the field <code>id</code>.</p>
*
* @param idIn a int.
*/
public final void setId(final int idIn) {
this.id = idIn;
}
/**
* <p>Getter for the field <code>id</code>.</p>
*
* @return a int.
*/
public final int getId() {
return id;
}
/**
* <p>Setter for the field <code>iconName</code>.</p>
* Sets filename of icon used when displaying this quest.
*
* @param s a {@link java.lang.String} object.
*/
public final void setIconName(final String s) {
iconName = s;
}
/**
* <p>Getter for the field <code>iconName</code>.</p>
* Gets filename of icon used when displaying this quest.
*
* @return a {@link java.lang.String} object.
*/
public final String getIconName() {
return iconName;
}
/**
* <p>Setter for the field <code>name</code>.</p>
*
* @param nameIn a {@link java.lang.String} object.
*/
public final void setName(final String nameIn) {
this.name = nameIn;
}
/**
* <p>Getter for the field <code>name</code>.</p>
*
* @return a {@link java.lang.String} object.
*/
public final String getName() {
return name;
}
/**
* <p>Setter for the field <code>repeatable</code>.</p>
*
* @param repeatableIn a boolean.
*/
public final void setRepeatable(final boolean repeatableIn) {
this.repeatable = repeatableIn;
}
/**
* <p>isRepeatable.</p>
*
* @return a boolean.
*/
public final boolean isRepeatable() {
return repeatable;
}
/**
* <p>Setter for the field <code>requiredNumberWins</code>.</p>
* Sets number of wins required to unlock this quest.
*
* @param requiredNumberWinsIn a int.
*/
public final void setRequiredNumberWins(final int requiredNumberWinsIn) {
this.requiredNumberWins = requiredNumberWinsIn;
}
/**
* <p>Getter for the field <code>requiredNumberWins</code>.</p>
* Gets number of wins required to unlock this quest.
*
* @return a int.
*/
public final int getRequiredNumberWins() {
return requiredNumberWins;
}
}

View File

@@ -1,278 +0,0 @@
package forge;
import forge.error.ErrorViewer;
import forge.properties.NewConstants;
import forge.quest.data.QuestUtil;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* <p>ReadQuest_Assignment class.</p>
*
* @author Forge
* @version $Id$
*/
public class ReadQuest_Assignment implements Runnable, NewConstants {
ArrayList<Quest_Assignment> allQuests = new ArrayList<Quest_Assignment>();
private ArrayList<Integer> ids = new ArrayList<Integer>();
private BufferedReader br;
private int totalWins;
private List<Integer> completedQuests = new ArrayList<Integer>();
// Constants, tied to properties in the quests.txt file.
private static final String ID = "id";
private static final String ICON = "Icon";
private static final String TITLE = "Title";
private static final String DESC = "Desc";
private static final String DIFF = "Diff";
private static final String AILIFE = "AILife";
private static final String REPEAT = "Repeat";
private static final String WINS = "Wins";
private static final String CARDS = "Card Reward";
private static final String CREDITS = "Credit Reward";
private static final String HUMANEXTRAS = "HumanExtras";
private static final String AIEXTRAS = "AIExtras";
/**
* <p>Constructor for ReadQuest_Assignment.</p>
* Sets parameters for available quests and prepares buffered reader for quests.txt.
*
* @param filename a {@link java.lang.String} object.
* @param questData a {@link forge.quest.data.QuestData} object.
*/
public ReadQuest_Assignment(String filename, forge.quest.data.QuestData questData) {
this(new File(filename), questData);
}
/**
* <p>Constructor for ReadQuest_Assignment.</p>
* Sets parameters for available quests and prepares buffered reader for quests.txt.
*
* @param file a {@link java.io.File} object.
* @param questData a {@link forge.quest.data.QuestData} object.
*/
public ReadQuest_Assignment(File file, forge.quest.data.QuestData questData) {
if (questData != null) {
totalWins = questData.getWin();
if (questData.getCompletedQuests() != null) {
completedQuests = questData.getCompletedQuests();
}
else {
completedQuests = new ArrayList<Integer>();
}
}
try {
br = new BufferedReader(new FileReader(file));
} catch (Exception ex) {
ErrorViewer.showError(ex, "File \"%s\" not found", file.getAbsolutePath());
throw new RuntimeException("ReadQuest_Assignment > constructor error: "+
"BufferedReader failed, '"+file.getAbsolutePath()+"' not found.");
}
} // ReadQuest_Assignment()
/**
* <p>getAvailableQuests.</p>
* Returns list of currently available quest objects.
*
* @return a {@link java.util.List} object.
*/
public List<Quest_Assignment> getAvailableQuests() {
ArrayList<Quest_Assignment> availableQuests = new ArrayList<Quest_Assignment>();
for(Quest_Assignment qa : allQuests) {
if (qa.getRequiredNumberWins() <= totalWins && !completedQuests.contains(qa.getId())) {
availableQuests.add(qa);
}
}
return availableQuests;
}
/**
* <p>getQuests.</p>
* Returns complete list of all quest objects.
*
* @return a {@link java.util.List} object.
*/
public List<Quest_Assignment> getAllQuests() {
return allQuests;
}
/**
* <p>getQuestsByIds.</p>
*
* @param availableQuestIds a {@link java.util.List} object.
* @return a {@link java.util.List} object.
*/
public List<Quest_Assignment> getQuestsByIds(List<Integer> availableQuestIds) {
List<Quest_Assignment> q = new ArrayList<Quest_Assignment>();
for (Quest_Assignment qa : allQuests) {
if (availableQuestIds.contains(qa.getId())) {
q.add(qa);
}
}
return q;
}
/**
* <p>getQuestById.</p>
*
* @param i a int.
* @return a {@link forge.Quest_Assignment} object.
*/
public Quest_Assignment getQuestById(int id) {
// Error handling for OOB ID?
return allQuests.get(id);
}
/**
* <p>run.</p>
* Assembles Quest_Assignment instances into allQuests.
*/
public void run() {
Quest_Assignment qa = null;
String line;
int i;
String[] linedata;
try {
while ((line = br.readLine()) != null) {
if(line.equals("[quest]")) {
qa = new Quest_Assignment();
allQuests.add(qa);
}
else if(!line.equals("") && qa != null) {
linedata = line.split("=", 2);
linedata[1] = linedata[1].trim();
// If empty data, ignore the line (assignment will use default).
if(linedata[1].equals("")) {
continue;
}
// Data OK.
if(linedata[0].equals(ID)) {
i = Integer.parseInt(linedata[1]);
// Duplicate ID check
if(ids.contains(i)) {
throw new RuntimeException("ReadQuest_Assignment > run() error: duplicate quest ID ("+i+")");
}
// Non-sequential ID check
else if(i != allQuests.size()) {
throw new RuntimeException("ReadQuest_Assignment > run() error: non-sequential quest ID ("+i+")");
}
// ID OK.
else {
ids.add(i);
qa.setId(i);
}
}
else if(linedata[0].equals(ICON)) {
qa.setIconName(linedata[1]);
}
else if(linedata[0].equals(TITLE)) {
qa.setName(linedata[1]);
}
else if(linedata[0].equals(DESC)) {
qa.setDesc(linedata[1]);
}
else if(linedata[0].equals(DIFF)) {
qa.setDifficulty(linedata[1]);
}
else if(linedata[0].equals(REPEAT)) {
qa.setRepeatable(Boolean.parseBoolean(linedata[1]));
}
else if(linedata[0].equals(AILIFE)) {
qa.setComputerLife(Integer.parseInt(linedata[1]));
}
else if(linedata[0].equals(WINS)) {
qa.setRequiredNumberWins(Integer.parseInt(linedata[1]));
}
else if(linedata[0].equals(CREDITS)) {
qa.setCreditsReward(Integer.parseInt(linedata[1]));
}
// Card reward list assembled here.
else if(linedata[0].equals(CARDS)) {
qa.setCardReward(linedata[1]);
qa.setCardRewardList(QuestUtil.generateCardRewardList(linedata[1]));
}
// Human extra card list assembled here.
else if(linedata[0].equals(HUMANEXTRAS)) {
String[] names = linedata[1].split("\\|");
CardList templist = new CardList();
Card tempcard;
for(String s : names) {
// Token card creation
if(s.substring(0,5).equals("TOKEN")) {
tempcard = QuestUtil.createToken(s);
tempcard.addController(AllZone.getHumanPlayer());
tempcard.setOwner(AllZone.getHumanPlayer());
templist.add(tempcard);
}
// Standard card creation
else {
tempcard = AllZone.getCardFactory().getCard(s, AllZone.getHumanPlayer());
tempcard.setCurSetCode(tempcard.getMostRecentSet());
tempcard.setImageFilename(CardUtil.buildFilename(tempcard));
templist.add(tempcard);
}
}
qa.setHumanExtraCards(templist);
}
// AI extra card list assembled here.
else if(linedata[0].equals(AIEXTRAS)) {
String[] names = linedata[1].split("\\|");
CardList templist = new CardList();
Card tempcard;
for(String s : names) {
// Token card creation
if(s.substring(0,5).equals("TOKEN")) {
tempcard = QuestUtil.createToken(s);
tempcard.addController(AllZone.getComputerPlayer());
tempcard.setOwner(AllZone.getComputerPlayer());
templist.add(tempcard);
}
// Standard card creation
else {
tempcard = AllZone.getCardFactory().getCard(s, AllZone.getComputerPlayer());
tempcard.setCurSetCode(tempcard.getMostRecentSet());
tempcard.setImageFilename(CardUtil.buildFilename(tempcard));
templist.add(tempcard);
}
}
qa.setAIExtraCards(templist);
}
} // else if()
} // while()
br.close();
}
catch (IOException e) {
e.printStackTrace();
}
// Confirm that all quests have IDs.
for(Quest_Assignment q : allQuests) {
if(q.getId()==-1) {
throw new RuntimeException("ReadQuest_Assignment > getQuests() error: "+
"Quest ID missing for '"+q.getName()+"'.");
}
}
} // run()
}

View File

@@ -53,7 +53,7 @@ public final class BoosterUtils {
int nRares = numRare, nMythics = 0;
Predicate<CardPrinted> filterMythics = Predicate.and(filter, CardPrinted.Predicates.Presets.isMythicRare);
boolean haveMythics = filterMythics.any(cardpool);
boolean haveMythics = false;//filterMythics.any(cardpool);
for(int iSlot = 0; haveMythics && iSlot < numRare; iSlot++) {
if (MyRandom.random.nextInt(7) < 1) { // a bit higher chance to get a mythic
nRares--;

View File

@@ -1,2 +1,2 @@
/** Forge Card Game */
package forge.game.limited;
/** Forge Card Game */
package forge.game.limited;

View File

@@ -1,194 +0,0 @@
package forge.quest.data;
import forge.AllZone;
import forge.FileUtil;
import forge.deck.Deck;
import forge.deck.DeckManager;
import forge.error.ErrorViewer;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import java.io.File;
import java.util.*;
import org.apache.commons.lang3.StringUtils;
/**
* <p>QuestBattleManager class.</p>
*
* @author Forge
* @version $Id$
*/
public class QuestBattleManager {
/** Constant <code>easyAIDecks</code> */
private static transient List<String> easyAIDecks;
/** Constant <code>mediumAIDecks</code> */
private static transient List<String> mediumAIDecks;
/** Constant <code>hardAIDecks</code> */
private static transient List<String> hardAIDecks;
/** Constant <code>veryHardAIDecks</code> */
private static transient List<String> veryHardAIDecks;
static {
easyAIDecks = readFile(ForgeProps.getFile(NewConstants.QUEST.EASY));
mediumAIDecks = readFile(ForgeProps.getFile(NewConstants.QUEST.MEDIUM));
hardAIDecks = readFile(ForgeProps.getFile(NewConstants.QUEST.HARD));
veryHardAIDecks = readFile(ForgeProps.getFile(NewConstants.QUEST.VERYHARD));
}
/**
* <p>getOpponent.</p>
*
* Badly named; AllZoneUtil already has a method called getOpponents.
* ?????
*
* @param aiDeck a {@link java.util.List} object.
* @param number a int.
* @return a {@link java.lang.String} object.
*/
public static String getOpponent(List<String> aiDeck, int number) {
//This is to make sure that the opponents do not change when the deck editor is launched.
List<String> deckListCopy = new ArrayList<String>(aiDeck);
Collections.shuffle(deckListCopy, new Random(AllZone.getQuestData().getRandomSeed()));
return deckListCopy.get(number);
}
/**
* <p>generateBattles.</p>
* Generates an array of new opponents based on current win conditions.
*
* @return an array of {@link java.lang.String} objects.
*/
public static String[] generateBattles() {
int index = AllZone.getQuestData().getDifficultyIndex();
if (AllZone.getQuestData().getWin() < QuestPreferences.getWinsForMediumAI(index)) {
return new String[]{
getOpponent(easyAIDecks, 0),
getOpponent(easyAIDecks, 1),
getOpponent(easyAIDecks, 2)};
}
if (AllZone.getQuestData().getWin() == QuestPreferences.getWinsForMediumAI(index)) {
return new String[]{
getOpponent(easyAIDecks, 0),
getOpponent(mediumAIDecks, 0),
getOpponent(mediumAIDecks, 1)};
}
if (AllZone.getQuestData().getWin() < QuestPreferences.getWinsForHardAI(index)) {
return new String[]{
getOpponent(mediumAIDecks, 0),
getOpponent(mediumAIDecks, 1),
getOpponent(mediumAIDecks, 2)};
}
if (AllZone.getQuestData().getWin() == QuestPreferences.getWinsForHardAI(index)) {
return new String[]{
getOpponent(mediumAIDecks, 0),
getOpponent(hardAIDecks, 0),
getOpponent(hardAIDecks, 1)};
}
if (AllZone.getQuestData().getWin() >= QuestPreferences.getWinsForVeryHardAI(index)) {
return new String[]{
getOpponent(hardAIDecks, 0),
getOpponent(hardAIDecks, 1),
getOpponent(veryHardAIDecks, 0)};
}
return new String[]{
getOpponent(hardAIDecks, 0),
getOpponent(hardAIDecks, 1),
getOpponent(hardAIDecks, 2)};
}
/**
* <p>getDeckFromFile.</p>
* Returns a deck object built from a file name.
*
* @param deckName a {@link java.lang.String} object.
* @return a {@link forge.deck.Deck} object.
*/
public static Deck getAIDeckFromFile(String deckName) {
final File file = ForgeProps.getFile(NewConstants.QUEST.DECKS);
final DeckManager manager = new DeckManager(file);
return manager.getDeck(deckName);
}
/**
* <p>getQuestEventFromFile.</p>
* Returns QuestEvent data for the challenge stored in that file name.
*
* @param deckName a {@link java.lang.String} object.
* @return a {@link forge.deck.Deck} object.
*/
public static QuestEvent getQuestEventFromFile(String deckName) {
final File deckPath = ForgeProps.getFile(NewConstants.QUEST.DECKS);
File deckFile = new File(deckPath, deckName + ".dck");
QuestEvent result = readQuestBattleMetadataFromDeckFile(deckFile);
return result;
}
/**
* <p>readFile.</p>
* A reader util for accessing the AI deck list text files.
*
* @param file a {@link java.io.File} object.
* @param aiDecks a {@link java.util.List} object.
* @return a {@link java.util.List} object.
*/
private static List<String> readFile(File file) {
ArrayList<String> list = FileUtil.readFile(file);
//remove any blank lines
ArrayList<String> noBlankLines = new ArrayList<String>();
String s;
for (String aList : list) {
s = aList.trim();
if (!s.equals("")) {
noBlankLines.add(s);
}
}
list = noBlankLines;
if (list.size() < 3) {
ErrorViewer.showError(new Exception(),
"QuestData : readFile() error, file %s is too short, it must contain at least 3 ai deck names",
file);
}
return list;
}
private static QuestEvent readQuestBattleMetadataFromDeckFile(final File f) {
QuestEvent out = new QuestEvent();
List<String> contents = FileUtil.readFile(f);
for (String s : contents) {
if ("[main]".equals(s)) { break; }
if (StringUtils.isBlank(s) || s.charAt(0) == '[') { continue; }
int eqPos = s.indexOf('=');
if (eqPos < 0) { continue; } // no equals sign here
String key = s.substring(0, eqPos);
String value = s.substring(eqPos + 1);
if ("DisplayName".equalsIgnoreCase(key)) {
out.displayName = value;
} else if ("Difficulty".equalsIgnoreCase(key)) {
out.difficulty = value;
} else if ("Description".equalsIgnoreCase(key)) {
out.description = value;
} else if ("Icon".equalsIgnoreCase(key)) {
out.icon = value;
}
}
return out;
}
}

View File

@@ -1,17 +0,0 @@
package forge.quest.data;
/**
* TODO: Write javadoc for this type.
*
*/
public class QuestEvent {
String displayName;
String difficulty;
String description;
String icon;
public final String getDisplayName() { return displayName; }
public final String getDifficulty() { return difficulty; }
public final String getDescription() { return description; }
public final String getIcon() { return icon; }
}

View File

@@ -3,21 +3,21 @@ package forge.quest.data;
import forge.Card;
import forge.CardList;
import forge.Constant;
import forge.Quest_Assignment;
import forge.card.CardRarity;
import forge.card.BoosterUtils;
import forge.item.CardPrinted;
import forge.quest.gui.main.QuestQuest;
import java.util.List;
/**
* <p>QuestUtil class.</p>
* MODEL - Static utility methods to help with minor tasks around Quest.
*
* @author Forge
* @version $Id$
*/
public class QuestUtil {
/**
* <p>getComputerStartingCards.</p>
*
@@ -36,11 +36,11 @@ public class QuestUtil {
* @param qa a {@link forge.Quest_Assignment} object.
* @return a {@link forge.CardList} object.
*/
public static CardList getComputerStartingCards(final QuestData qd, Quest_Assignment qa) {
public static CardList getComputerStartingCards(final QuestData qd, QuestQuest qq) {
CardList list = new CardList();
if (qa != null) {
list.addAll(qa.getAIExtraCards());
if (qq != null) {
list.addAll(qq.getAIExtraCards());
}
return list;
}
@@ -75,11 +75,11 @@ public class QuestUtil {
* @param qa a {@link forge.Quest_Assignment} object.
* @return a {@link forge.CardList} object.
*/
public static CardList getHumanStartingCards(final QuestData qd, Quest_Assignment qa) {
public static CardList getHumanStartingCards(final QuestData qd, QuestQuest qq) {
CardList list = getHumanStartingCards(qd);
if (qa != null) {
list.addAll(qa.getHumanExtraCards());
if (qq != null) {
list.addAll(qq.getHumanExtraCards());
}
return list;
@@ -163,17 +163,5 @@ public class QuestUtil {
return BoosterUtils.generateCards(qty, rar, col);
}
/**
* <p>setupQuest.</p>
* Assembled hard-coded quest options.
* All non-deck-specific handling now takes place in quests.txt.
*
* @deprecated
* @param qa
*/
public static void setupQuest(Quest_Assignment qa) {
}
} //QuestUtil

View File

@@ -3,7 +3,7 @@ package forge.quest.gui;
import forge.AllZone;
import forge.gui.GuiUtils;
import forge.quest.gui.bazaar.QuestBazaarPanel;
import forge.quest.gui.main.QuestMainPanel;
import forge.quest.gui.main.QuestEventManager;
import forge.view.swing.OldGuiNewGame;
import javax.swing.*;
@@ -24,6 +24,7 @@ public class QuestFrame extends JFrame {
JPanel visiblePanel;
CardLayout questLayout;
QuestEventManager qem = new QuestEventManager();
/** Constant <code>MAIN_PANEL="Main"</code> */
public static final String MAIN_PANEL = "Main";
@@ -39,7 +40,14 @@ public class QuestFrame extends JFrame {
*/
public QuestFrame() throws HeadlessException {
this.setTitle("Quest Mode");
// DOUBLESTRIKE SEZ - this assembles all events, once.
// Unfortunately, QuestFrame is called several times.
// This is THE WRONG PLACE for this method, feel free to move,
// I'll do it very soon anyways, this is only a temporary thing.
if(qem.getAllDuels()==null) {
qem.assembleAllEvents();
}
visiblePanel = new JPanel(new BorderLayout());
visiblePanel.setBorder(new EmptyBorder(2, 2, 2, 2));
questLayout = new CardLayout();
@@ -53,7 +61,6 @@ public class QuestFrame extends JFrame {
visiblePanel.add(newPanel, BAZAAR_PANEL);
subPanelMap.put(BAZAAR_PANEL, newPanel);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(visiblePanel, BorderLayout.CENTER);
this.setPreferredSize(new Dimension(1024, 768));

View File

@@ -1,90 +0,0 @@
package forge.quest.gui.main;
import forge.gui.GuiUtils;
import forge.quest.data.QuestBattleManager;
import forge.quest.data.QuestEvent;
import javax.swing.*;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
/**
* <p>QuestBattle class.</p>
* Manages QuestSelectablePanel instances for "battle" style matches.
*
* @author Forge
* @version $Id$
*/
public class QuestBattle extends QuestSelectablePanel {
/** Constant <code>serialVersionUID=3112668476017792084L</code> */
private static final long serialVersionUID = 3112668476017792084L;
private String deckName;
/**
* <p>Constructor for QuestBattle.</p>
*
* @param name a {@link java.lang.String}, stores display name of opponent.
* @param diff a {@link java.lang.String} stores difficulty of opponent.
* @param description a {@link java.lang.String} stores description of opponent's deck.
* @param icon a {@link javax.swing.ImageIcon} stores opponent's icon.
*/
private QuestBattle(String name, String deck, String diff, String desc, ImageIcon icon) {
super(name, diff, desc, icon);
this.deckName = deck;
}
/**
* <p>getBattles.</p>
*
* Returns list of QuestBattle objects storing data
* of the battles currently available.
*
* @return a {@link java.util.List} object.
*/
// There's got to be a better place for this method.
public static List<QuestSelectablePanel> getBattles() {
List<QuestSelectablePanel> opponentList = new ArrayList<QuestSelectablePanel>();
String[] oppDecks = QuestBattleManager.generateBattles();
for (String oppDeckName : oppDecks) {
// Get deck object and properties for this opponent.
QuestEvent event1 = QuestBattleManager.getQuestEventFromFile(oppDeckName);
String oppName = event1.getDisplayName();
String oppDiff = event1.getDifficulty();
String oppDesc = event1.getDescription();
String oppIconAddress = event1.getIcon();
ImageIcon icon;
// If non-default icon defined, use it
if (StringUtils.isBlank(oppIconAddress)) {
icon = GuiUtils.getIconFromFile(oppName + ".jpg");
}
else
icon = GuiUtils.getIconFromFile(oppIconAddress + ".jpg");
// Add to list of current quest opponents.
opponentList.add(
new QuestBattle(oppName, oppDeckName, oppDiff, oppDesc, icon)
);
}
return opponentList;
}
/** {@inheritDoc} */
@Override
public String getName() {
// Called by ???? to get deck name for image icon generation.
// Exception should be thrown somewhere if image can't be found.
return deckName;
}
}

View File

@@ -0,0 +1,12 @@
package forge.quest.gui.main;
/**
* <p>QuestDuel class.</p>
* MODEL - A single duel event data instance, including meta and deck.
*
*/
public class QuestDuel extends QuestEvent {
// [QuestDuel has no unique properties yet.]
}

View File

@@ -0,0 +1,20 @@
package forge.quest.gui.main;
/**
* <p>QuestDuelPanel.</p>
* VIEW - Creates a QuestSelectablePanel instance for a "battle" style event.
*/
@SuppressWarnings("serial")
public class QuestDuelPanel extends QuestSelectablePanel {
/** <p>QuestDuelPanel.</p>
* Constructor, using duel data instance.
*
* @param {@link forge.quest.gui.main.QuestDuel}
*/
public QuestDuelPanel(QuestDuel d) {
super(d);
}
}

View File

@@ -0,0 +1,73 @@
package forge.quest.gui.main;
import forge.deck.Deck;
/**
* <p>QuestEvent.</p>
*
* MODEL - A basic event instance in Quest mode. Can be extended for use in
* unique event types: battles, quests, and others.
*/
public class QuestEvent {
// Default vals if none provided in the event file.
public Deck eventDeck = null;
public String title = "Mystery Event";
public String description = "";
public String difficulty = "Medium";
public String icon = "Unknown.jpg";
public String name = "Noname";
/**
* <p>getTitle.</p>
*
* @return a {@link java.lang.String}.
*/
public final String getTitle() {
return title;
}
/**
* <p>getDifficulty.</p>
*
* @return a {@link java.lang.String}.
*/
public final String getDifficulty() {
return difficulty;
}
/**
* <p>getDescription.</p>
*
* @return a {@link java.lang.String}.
*/
public final String getDescription() {
return description;
}
/**
* <p>getEventDeck.</p>
*
* @return {@link forge.deck.Deck}
*/
public final Deck getEventDeck() {
return eventDeck;
}
/**
* <p>getIcon.</p>
*
* @return a {@link java.lang.String}.
*/
public final String getIcon() {
return icon;
}
/**
* <p>getName.</p>
*
* @return a {@link java.lang.String}.
*/
public final String getName() {
return name;
}
}

View File

@@ -0,0 +1,406 @@
package forge.quest.gui.main;
import forge.AllZone;
import forge.Card;
import forge.CardList;
import forge.CardUtil;
import forge.FileUtil;
import forge.deck.DeckManager;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import forge.quest.data.QuestPreferences;
import forge.quest.data.QuestUtil;
import java.io.File;
import java.util.*;
/**
* <p>QuestEventManager.</p>
* MODEL - Manages collections of quest events (duelsquests, etc.)
*
* @author Forge
* @version $Id$
*/
public class QuestEventManager {
public List<QuestDuel> easyAIduels = null;
public List<QuestDuel> mediumAIduels = null;
public List<QuestDuel> hardAIduels = null;
public List<QuestDuel> veryHardAIduels = null;
public List<QuestDuel> allDuels = null;
public List<QuestQuest> allQuests = null;
/**<p>assembleAllEvents.</p> *
* Reads all quest and battle files to extract quest data.
* Instantiates all duel and quest events, and difficulty lists accordingly.
* Should be used sparingly.
*/
public void assembleAllEvents() {
this.allDuels = new ArrayList<QuestDuel>();
this.allQuests = new ArrayList<QuestQuest>();
List<String> contents;
QuestEvent tempEvent;
File file = ForgeProps.getFile(NewConstants.QUEST.DECKS);
DeckManager manager = new DeckManager(file);
File[] allFiles = ForgeProps.getFile(NewConstants.QUEST.DECKS).listFiles();
for(File f : allFiles) {
contents = FileUtil.readFile(f);
if(contents.get(0).trim().equals("[quest]")) {
tempEvent = new QuestQuest();
assembleQuestUniquedata(contents,(QuestQuest)tempEvent);
allQuests.add((QuestQuest)tempEvent);
} // End if([quest])
else {
tempEvent = new QuestDuel();
assembleDuelUniquedata(contents,(QuestDuel)tempEvent);
allDuels.add((QuestDuel)tempEvent);
}
// Assemble metadata (may not be necessary later) and deck object.
assembleEventMetadata(contents,tempEvent);
tempEvent.eventDeck = manager.getDeck(tempEvent.getName());
} // End for(allFiles)
assembleDuelDifficultyLists();
} // End assembleAllEvents()
/**
* <p>assembleDuelUniqueData.</p>
* Handler for any unique data contained in duel files.
*
* @param contents
* @param qd
*/
private void assembleDuelUniquedata(List<String> contents, QuestDuel qd) {
int eqpos;
String key, value;
for(String s : contents) {
if (s.equals("[metadata]")) { break; }
if (s.equals("[duel]")) { continue; }
if (s.equals("")) { continue; }
eqpos = s.indexOf('=');
key = s.substring(0, eqpos);
value = s.substring(eqpos + 1);
if (key.equalsIgnoreCase("Name")) {
qd.name = value;
}
}
}
/**
* <p>assembleQuestUniquedata.</p>
* Handler for any unique data contained in quest files.
*
* @param contents
* @param qq
*/
private void assembleQuestUniquedata(List<String> contents, QuestQuest qq) {
int eqpos;
String key, value;
// Unique properties
for(String s : contents) {
if (s.equals("[metadata]")) { break; }
if (s.equals("[quest]")) { continue; }
if (s.equals("")) { continue; }
eqpos = s.indexOf('=');
key = s.substring(0, eqpos);
value = s.substring(eqpos + 1).trim();
if (key.equalsIgnoreCase("ID")) {
qq.id = Integer.parseInt(value);
}
else if (key.equalsIgnoreCase("Repeat")) {
qq.repeatable = Boolean.parseBoolean(value);
}
else if (key.equalsIgnoreCase("AILife")) {
qq.aiLife = Integer.parseInt(value);
}
else if (key.equalsIgnoreCase("Wins")) {
qq.winsReqd = Integer.parseInt(value);
}
else if (key.equalsIgnoreCase("Credit Reward")) {
qq.creditsReward = Integer.parseInt(value);
}
else if (key.equalsIgnoreCase("Card Reward")) {
qq.cardReward = value;
qq.cardRewardList = QuestUtil.generateCardRewardList(value);
}
// Human extra card list assembled here.
else if(key.equalsIgnoreCase("HumanExtras") && !value.equals("")) {
String[] names = value.split("\\|");
CardList templist = new CardList();
Card tempcard;
for(String n : names) {
// Token card creation
if(n.substring(0,5).equals("TOKEN")) {
tempcard = QuestUtil.createToken(n);
tempcard.addController(AllZone.getHumanPlayer());
tempcard.setOwner(AllZone.getHumanPlayer());
templist.add(tempcard);
}
// Standard card creation
else {
tempcard = AllZone.getCardFactory().getCard(n, AllZone.getHumanPlayer());
tempcard.setCurSetCode(tempcard.getMostRecentSet());
tempcard.setImageFilename(CardUtil.buildFilename(tempcard));
templist.add(tempcard);
}
}
qq.humanExtraCards = templist;
}
// AI extra card list assembled here.
else if(key.equalsIgnoreCase("AIExtras") && !value.equals("")) {
String[] names = value.split("\\|");
CardList templist = new CardList();
Card tempcard;
for(String n : names) {
// Token card creation
if(n.substring(0,5).equals("TOKEN")) {
tempcard = QuestUtil.createToken(n);
tempcard.addController(AllZone.getComputerPlayer());
tempcard.setOwner(AllZone.getComputerPlayer());
templist.add(tempcard);
}
// Standard card creation
else {
tempcard = AllZone.getCardFactory().getCard(n, AllZone.getComputerPlayer());
tempcard.setCurSetCode(tempcard.getMostRecentSet());
tempcard.setImageFilename(CardUtil.buildFilename(tempcard));
templist.add(tempcard);
}
}
qq.aiExtraCards = templist;
}
// Card reward list assembled here.
else if(key.equalsIgnoreCase("Card Reward")) {
qq.cardReward = value;
qq.cardRewardList = QuestUtil.generateCardRewardList(value);
}
}
}
/**
* <p>assembleEventMetadata.</p>
* Handler for metadata contained in event files.
*
* @param contents
* @param qe
*/
private void assembleEventMetadata(List<String> contents, QuestEvent qe) {
int eqpos;
String key, value;
for(String s : contents) {
s = s.trim();
eqpos = s.indexOf('=');
if (s.equals("[main]")) { break; }
if (s.equals("[metadata]")) { continue; }
if (s.equals("")) { continue; }
if (eqpos==-1) { continue; }
key = s.substring(0, eqpos);
value = s.substring(eqpos + 1);
if (key.equalsIgnoreCase("Name")) {
qe.name = value;
}
else if (key.equalsIgnoreCase("Title")) {
qe.title = value;
}
else if (key.equalsIgnoreCase("Difficulty")) {
qe.difficulty = value;
}
else if (key.equalsIgnoreCase("Description")) {
qe.description = value;
}
else if (key.equalsIgnoreCase("Icon")) {
qe.icon = value;
}
}
}
/**
* <p>getAllDuels.</p>
* Returns complete list of all duel objects.
*
* @return a {@link java.util.List} object.
*/
public List<QuestDuel> getAllDuels() {
return this.allDuels;
}
/**
* <p>getAllQuests.</p>
* Returns complete list of all quest objects.
*
* @return a {@link java.util.List} object.
*/
public List<QuestQuest> getAllQuests() {
return this.allQuests;
}
/**
* <p>assembleDuelDifficultyLists.</p>
* Assemble duel deck difficulty lists
*/
private void assembleDuelDifficultyLists() {
easyAIduels = new ArrayList<QuestDuel>();
mediumAIduels = new ArrayList<QuestDuel>();
hardAIduels = new ArrayList<QuestDuel>();
veryHardAIduels = new ArrayList<QuestDuel>();
String s;
for(QuestDuel qd : allDuels) {
s = qd.getDifficulty();
if(s.equalsIgnoreCase("easy")) {
easyAIduels.add(qd);
}
else if(s.equalsIgnoreCase("medium")) {
mediumAIduels.add(qd);
}
else if(s.equalsIgnoreCase("hard")) {
hardAIduels.add(qd);
}
else if(s.equalsIgnoreCase("very hard")) {
veryHardAIduels.add(qd);
}
}
}
/**
* <p>getDuelOpponent.</p>
* Returns specific duel opponent from current shuffle of available duels.
* This is to make sure that the opponents do not change
* when the deck editor is launched.
*
* @param aiDeck a {@link java.util.List} object.
* @param number a int.
* @return a {@link java.lang.String} object.
*/
private static QuestDuel getDuelOpponentByNumber(List<QuestDuel> aiDeck, int n) {
List<QuestDuel> deckListCopy = new ArrayList<QuestDuel>(aiDeck);
Collections.shuffle(deckListCopy, new Random(AllZone.getQuestData().getRandomSeed()));
return deckListCopy.get(n);
}
private QuestQuest getQuestOpponentByNumber(int n) {
for(QuestQuest qq : allQuests) {
if(qq.getId()==n) {
return qq;
}
}
return null;
}
/**
* <p>generateDuels.</p>
* Generates an array of new duel opponents based on current win conditions.
*
* @return an array of {@link java.lang.String} objects.
*/
public List<QuestDuel> generateDuels() {
int index = AllZone.getQuestData().getDifficultyIndex();
List<QuestDuel> duelOpponents = new ArrayList<QuestDuel>();
if (AllZone.getQuestData().getWin() < QuestPreferences.getWinsForMediumAI(index)) {
duelOpponents.add(getDuelOpponentByNumber(easyAIduels, 0));
duelOpponents.add(getDuelOpponentByNumber(easyAIduels, 1));
duelOpponents.add(getDuelOpponentByNumber(easyAIduels, 2));
}
else if (AllZone.getQuestData().getWin() == QuestPreferences.getWinsForMediumAI(index)) {
duelOpponents.add(getDuelOpponentByNumber(easyAIduels, 0));
duelOpponents.add(getDuelOpponentByNumber(mediumAIduels, 0));
duelOpponents.add(getDuelOpponentByNumber(mediumAIduels, 1));
}
else if (AllZone.getQuestData().getWin() < QuestPreferences.getWinsForHardAI(index)) {
duelOpponents.add(getDuelOpponentByNumber(mediumAIduels, 0));
duelOpponents.add(getDuelOpponentByNumber(mediumAIduels, 1));
duelOpponents.add(getDuelOpponentByNumber(mediumAIduels, 2));
}
else if (AllZone.getQuestData().getWin() == QuestPreferences.getWinsForHardAI(index)) {
duelOpponents.add( getDuelOpponentByNumber(mediumAIduels, 0));
duelOpponents.add(getDuelOpponentByNumber(hardAIduels, 0));
duelOpponents.add(getDuelOpponentByNumber(hardAIduels, 1));
}
else if (AllZone.getQuestData().getWin() >= QuestPreferences.getWinsForVeryHardAI(index)) {
duelOpponents.add(getDuelOpponentByNumber(hardAIduels, 0));
duelOpponents.add(getDuelOpponentByNumber(hardAIduels, 1));
duelOpponents.add(getDuelOpponentByNumber(veryHardAIduels, 0));
}
else {
duelOpponents.add(getDuelOpponentByNumber(veryHardAIduels, 0));
duelOpponents.add(getDuelOpponentByNumber(veryHardAIduels, 1));
duelOpponents.add(getDuelOpponentByNumber(veryHardAIduels, 2));
}
return duelOpponents;
}
/**
* <p>generateQuests.</p>
* Generates an array of new quest opponents based on current win conditions.
*
* @return a {@link java.util.List} object.
*/
public List<QuestQuest> generateQuests() {
forge.quest.data.QuestData questData = AllZone.getQuestData();
List<QuestQuest> questOpponents = new ArrayList<QuestQuest>();
// If no quests available right now, generate new IDs.
if (questData.getAvailableQuests() == null || questData.getAvailableQuests().size() == 0) {
// Assemble full list of currently available IDs.
List<Integer> availableQuestIds = new ArrayList<Integer>();
for(QuestQuest qq : allQuests) {
if (qq.getWinsReqd() <= questData.getWin() &&
!questData.getCompletedQuests().contains(qq.getId())) {
availableQuestIds.add(qq.getId());
}
}
// Filter that list as needed.
int maxQuests = questData.getWin() / 10;
if (maxQuests > 5) {
maxQuests = 5;
}
Collections.shuffle(availableQuestIds);
for (int i = 0; i < maxQuests; i++) {
availableQuestIds.add(i);
}
questData.setAvailableQuests(availableQuestIds);
questData.saveData();
} //
// Finally, pull quest events from available IDs and return.
for(int i : questData.getAvailableQuests()) {
questOpponents.add(getQuestOpponentByNumber(i));
}
return questOpponents;
}
}

View File

@@ -1,116 +1,114 @@
package forge.quest.gui.main;
import forge.AllZone;
import forge.Quest_Assignment;
import forge.ReadQuest_Assignment;
import forge.gui.GuiUtils;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import forge.CardList;
import forge.item.CardPrinted;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* <p>QuestQuest class.</p>
*
* Manages QuestSelectablePanel instances for "quest" style matches.
*
* @author Forge
* @version $Id$
* MODEL - A single quest event data instance, including meta,
* deck, and quest-specific properties.
*
*/
public class QuestQuest extends QuestSelectablePanel {
/** Constant <code>serialVersionUID=-162817410327650160L</code> */
private static final long serialVersionUID = -162817410327650160L;
public class QuestQuest extends QuestEvent {
// ID (default -1, should be explicitly set at later time.)
public int id = -1;
// Default vals if none provided for this ID
public int aiLife = 25;
public int creditsReward = 100;
public String cardReward = "1 colorless rare";
public boolean repeatable = false;
public int winsReqd = 20;
Quest_Assignment assignment;
// Other cards used in assignment: starting, and reward.
public CardList humanExtraCards = new CardList();
public CardList aiExtraCards = new CardList();
public List<CardPrinted> cardRewardList = new ArrayList<CardPrinted>();
/**
* <p>Constructor for QuestQuest.</p>
* <p>getAILife.</p>
*
* @param assignment a {@link forge.Quest_Assignment} object.
* @return {@link java.lang.Integer}.
*/
public QuestQuest(Quest_Assignment assignment) {
super(assignment.getName(), assignment.getDifficulty(), assignment.getDesc(), GuiUtils.getIconFromFile(assignment.getIconName()));
this.assignment = assignment;
JLabel repeatabilityLabel;
if (assignment.isRepeatable()) {
repeatabilityLabel = new JLabel("This quest is repeatable");
} else {
repeatabilityLabel = new JLabel("This quest is not repeatable");
}
GuiUtils.addGap(centerPanel);
this.centerPanel.add(repeatabilityLabel);
public final int getAILife() {
return aiLife;
}
/**
* <p>getQuests.</p>
* <p>getCardReward.</p>
*
* @return a {@link java.util.List} object.
* @return {@link java.lang.String}.
*/
public static List<QuestQuest> getQuests() {
List<QuestQuest> quests = new ArrayList<QuestQuest>();
List<Quest_Assignment> questList = readQuests();
for (Quest_Assignment assignment : questList) {
quests.add(new QuestQuest(assignment));
}
return quests;
public final String getCardReward() {
return cardReward;
}
/**
* <p>readQuests.</p>
* <p>getCreditsReward.</p>
*
* @return a {@link java.util.List} object.
* @return {@link java.lang.Integer}.
*/
private static List<Quest_Assignment> readQuests() {
forge.quest.data.QuestData questData = AllZone.getQuestData();
ReadQuest_Assignment read = new ReadQuest_Assignment(ForgeProps.getFile(NewConstants.QUEST.QUESTS), questData);
read.run();
List<Quest_Assignment> questsToDisplay = new ArrayList<Quest_Assignment>();
if (questData.getAvailableQuests() != null && questData.getAvailableQuests().size() > 0) {
List<Quest_Assignment> availableQuests = read.getQuestsByIds(questData.getAvailableQuests());
questsToDisplay = availableQuests;
} else {
List<Quest_Assignment> allAvailableQuests = read.getAvailableQuests();
List<Integer> availableInts = new ArrayList<Integer>();
int maxQuests = questData.getWin() / 10;
if (maxQuests > 5) {
maxQuests = 5;
}
if (allAvailableQuests.size() < maxQuests) {
maxQuests = allAvailableQuests.size();
}
Collections.shuffle(allAvailableQuests);
for (int i = 0; i < maxQuests; i++) {
Quest_Assignment qa = allAvailableQuests.get(i);
availableInts.add(qa.getId());
questsToDisplay.add(qa);
}
questData.setAvailableQuests(availableInts);
questData.saveData();
}//else
return questsToDisplay;
public final int getCreditsReward() {
return creditsReward;
}
/**
* <p>getQuestAssignment.</p>
* <p>getId.</p>
*
* @return a {@link forge.Quest_Assignment} object.
* @return {@link java.lang.Integer}.
*/
public Quest_Assignment getQuestAssignment() {
return assignment;
public final int getId() {
return id;
}
/**
* <p>getRepeatable.</p>
*
* @return {@link java.lang.Boolean}.
*/
public final boolean getRepeatable() {
return repeatable;
}
/**
* <p>getWinsReqd.</p>
*
* @return {@link java.lang.Integer}.
*/
public final int getWinsReqd() {
return winsReqd;
}
/**
* <p>getAIExtraCards.</p>
* Retrieves list of cards AI has in play at the beginning of this quest.
*
* @return
*/
public final CardList getAIExtraCards() {
return aiExtraCards;
}
/**
* <p>getHumanExtraCards.</p>
* Retrieves list of cards human has in play at the beginning of this quest.
*
* @return
*/
public final CardList getHumanExtraCards() {
return humanExtraCards;
}
/**
* <p>getCardRewardList.</p>
*
* @return
*/
public final List<CardPrinted> getCardRewardList() {
return cardRewardList;
}
}

View File

@@ -0,0 +1,35 @@
package forge.quest.gui.main;
//import javax.swing.JLabel;
/**
* <p>QuestQuestPanel.</p>
* VIEW - Creates a QuestSelectablePanel instance for a "quest" style event.
*/
@SuppressWarnings("serial")
public class QuestQuestPanel extends QuestSelectablePanel {
//private JLabel repeatabilityLabel;
/** <p>QuestQuestPanel.</p>
* Constructor, using quest data instance.
*
* @param {@link forge.quest.gui.main.QuestDuel}
*/
public QuestQuestPanel(QuestQuest q) {
super(q);
// Repeatability is currently meaningless.
// Can be added here later if necessary.
/*
* if (q.getRepeatable()) {
repeatabilityLabel = new JLabel("This quest is repeatable");
} else {
repeatabilityLabel = new JLabel("This quest is not repeatable");
}
super.rootPanel.add(repeatabilityLabel);
*/
}
}

View File

@@ -1,15 +1,19 @@
package forge.quest.gui.main;
import forge.gui.GuiUtils;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import javax.swing.*;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.io.File;
/**
* <p>QuestSelectablePanel class.</p>
* VIEW - Creates a selectable panel, used for picking events.
*
* @author Forge
* @version $Id$
@@ -20,35 +24,38 @@ public class QuestSelectablePanel extends JPanel {
protected Color backgroundColor;
private boolean selected;
ImageIcon icon;
String name;
String description;
String difficulty;
JPanel centerPanel = new JPanel();
private QuestEvent event;
private String iconfilename;
public JPanel rootPanel = new JPanel();
/**
* <p>Constructor for QuestSelectablePanel.</p>
* VIEW - A JPanel for selecting quest events.
*
* @param name a {@link java.lang.String} object.
* @param difficulty a {@link java.lang.String} object.
* @param description a {@link java.lang.String} object.
* @param icon a {@link javax.swing.ImageIcon} object.
*/
public QuestSelectablePanel(String name, String difficulty, String description, ImageIcon icon) {
public QuestSelectablePanel(QuestEvent qe) {
this.event = qe;
this.iconfilename = qe.icon;
File base = ForgeProps.getFile(NewConstants.IMAGE_ICON);
File file = new File(base, iconfilename);
if(!file.exists()) {
file = new File(base,"Unknown.jpg");
this.iconfilename = "Unknown.jpg";
}
ImageIcon icon = new ImageIcon(file.toString());
this.backgroundColor = getBackground();
this.name = name;
this.difficulty = difficulty;
this.description = description;
this.icon = icon;
this.setLayout(new BorderLayout(5, 5));
JLabel iconLabel;
if (icon == null) {
if (icon.getIconHeight() == -1) {
iconLabel = new JLabel(GuiUtils.getEmptyIcon(40, 40));
} else {
iconLabel = new JLabel(GuiUtils.getResizedIcon(icon, 40, 40));
@@ -62,32 +69,32 @@ public class QuestSelectablePanel extends JPanel {
iconPanel.add(iconLabel, BorderLayout.NORTH);
this.add(iconPanel, BorderLayout.WEST);
centerPanel.setOpaque(false);
centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));
this.add(centerPanel, BorderLayout.CENTER);
rootPanel.setOpaque(false);
rootPanel.setLayout(new BoxLayout(rootPanel, BoxLayout.Y_AXIS));
this.add(rootPanel, BorderLayout.CENTER);
JPanel centerTopPanel = new JPanel();
centerTopPanel.setOpaque(false);
centerTopPanel.setAlignmentX(LEFT_ALIGNMENT);
centerTopPanel.setLayout(new BoxLayout(centerTopPanel, BoxLayout.X_AXIS));
JLabel nameLabel = new JLabel(this.name);
JLabel nameLabel = new JLabel(qe.getTitle());
GuiUtils.setFontSize(nameLabel, 20);
nameLabel.setAlignmentY(BOTTOM_ALIGNMENT);
centerTopPanel.add(nameLabel);
GuiUtils.addExpandingHorizontalSpace(centerTopPanel);
JLabel difficultyLabel = new JLabel(this.difficulty);
JLabel difficultyLabel = new JLabel(qe.getDifficulty());
difficultyLabel.setAlignmentY(BOTTOM_ALIGNMENT);
centerTopPanel.add(difficultyLabel);
centerPanel.add(centerTopPanel);
rootPanel.add(centerTopPanel);
GuiUtils.addGap(centerPanel);
GuiUtils.addGap(rootPanel);
JLabel descriptionLabel = new JLabel(description);
JLabel descriptionLabel = new JLabel(qe.getDescription());
descriptionLabel.setAlignmentX(LEFT_ALIGNMENT);
centerPanel.add(descriptionLabel);
rootPanel.add(descriptionLabel);
this.setMaximumSize(new Dimension(Integer.MAX_VALUE, 80));
this.setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder(5, 5, 5, 5)));
@@ -117,9 +124,21 @@ public class QuestSelectablePanel extends JPanel {
this.selected = selected;
}
/** {@inheritDoc} */
@Override
public String getName() {
return name;
/**
* <p>getIconFilename.</p>
*
* @return String
*/
public String getIconFilename() {
return this.iconfilename;
}
/**
* <p>getEvent.</p>
*
* @return QuestEvent
*/
public QuestEvent getEvent() {
return this.event;
}
}