Added option to start quests with a precon deck

This commit is contained in:
Fnoed
2012-03-04 03:39:31 +00:00
parent 1a7dce2204
commit 2fe2dad81f
6 changed files with 965 additions and 911 deletions

1
.gitattributes vendored
View File

@@ -11529,6 +11529,7 @@ src/main/java/forge/quest/data/QuestDuel.java svneol=native#text/plain
src/main/java/forge/quest/data/QuestEvent.java -text src/main/java/forge/quest/data/QuestEvent.java -text
src/main/java/forge/quest/data/QuestEventManager.java svneol=native#text/plain src/main/java/forge/quest/data/QuestEventManager.java svneol=native#text/plain
src/main/java/forge/quest/data/QuestPreferences.java svneol=native#text/plain src/main/java/forge/quest/data/QuestPreferences.java svneol=native#text/plain
src/main/java/forge/quest/data/QuestStartPool.java -text
src/main/java/forge/quest/data/QuestUtil.java svneol=native#text/plain src/main/java/forge/quest/data/QuestUtil.java svneol=native#text/plain
src/main/java/forge/quest/data/QuestUtilCards.java -text src/main/java/forge/quest/data/QuestUtilCards.java -text
src/main/java/forge/quest/data/bazaar/QuestStallDefinition.java svneol=native#text/plain src/main/java/forge/quest/data/bazaar/QuestStallDefinition.java svneol=native#text/plain

View File

@@ -1,186 +1,198 @@
package forge.gui.home.quest; package forge.gui.home.quest;
import java.io.File; import forge.AllZone;
import java.io.FilenameFilter; import forge.Command;
import java.util.HashMap; import forge.Singletons;
import java.util.Map; import forge.gui.GuiUtils;
import forge.gui.home.ICSubmenu;
import javax.swing.JOptionPane; import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import forge.AllZone; import forge.quest.data.QuestData;
import forge.Command; import forge.quest.data.QuestDataIO;
import forge.Singletons; import forge.quest.data.QuestPreferences.QPref;
import forge.gui.GuiUtils; import forge.quest.data.QuestStartPool;
import forge.gui.home.ICSubmenu;
import forge.properties.ForgeProps; import javax.swing.*;
import forge.properties.NewConstants; import java.io.File;
import forge.quest.data.QuestData; import java.io.FilenameFilter;
import forge.quest.data.QuestDataIO; import java.util.HashMap;
import forge.quest.data.QuestPreferences.QPref; import java.util.Map;
/** import static forge.quest.data.QuestStartPool.*;
* TODO: Write javadoc for this type.
* /**
*/ * TODO: Write javadoc for this type.
@SuppressWarnings("serial") *
public enum CSubmenuQuestData implements ICSubmenu { */
/** */ @SuppressWarnings("serial")
SINGLETON_INSTANCE; public enum CSubmenuQuestData implements ICSubmenu {
/** */
private final Map<String, QuestData> arrQuests = new HashMap<String, QuestData>(); SINGLETON_INSTANCE;
private final Command cmdQuestSelect = new Command() { @Override private final Map<String, QuestData> arrQuests = new HashMap<String, QuestData>();
public void execute() { changeQuest(); } };
private final Command cmdQuestSelect = new Command() { @Override
private final Command cmdQuestDelete = new Command() { @Override public void execute() { changeQuest(); } };
public void execute() { update(); } };
private final Command cmdQuestDelete = new Command() { @Override
/* (non-Javadoc) public void execute() { update(); } };
* @see forge.control.home.IControlSubmenu#update()
*/ /* (non-Javadoc)
@Override * @see forge.control.home.IControlSubmenu#update()
public void initialize() { */
VSubmenuQuestData.SINGLETON_INSTANCE.populate(); @Override
CSubmenuQuestData.SINGLETON_INSTANCE.update(); public void initialize() {
VSubmenuQuestData.SINGLETON_INSTANCE.populate();
VSubmenuQuestData.SINGLETON_INSTANCE.getBtnEmbark().setCommand( CSubmenuQuestData.SINGLETON_INSTANCE.update();
new Command() { @Override public void execute() { newQuest(); } });
} VSubmenuQuestData.SINGLETON_INSTANCE.getBtnEmbark().setCommand(
new Command() { @Override public void execute() { newQuest(); } });
/* (non-Javadoc) }
* @see forge.control.home.IControlSubmenu#getCommand()
*/ /* (non-Javadoc)
@Override * @see forge.control.home.IControlSubmenu#getCommand()
public Command getMenuCommand() { */
return null; @Override
} public Command getMenuCommand() {
return null;
/* (non-Javadoc) }
* @see forge.control.home.IControlSubmenu#update()
*/ /* (non-Javadoc)
@Override * @see forge.control.home.IControlSubmenu#update()
public void update() { */
final VSubmenuQuestData view = VSubmenuQuestData.SINGLETON_INSTANCE; @Override
final File dirQuests = ForgeProps.getFile(NewConstants.Quest.DATA_DIR); public void update() {
final VSubmenuQuestData view = VSubmenuQuestData.SINGLETON_INSTANCE;
// Temporary transition code between v1.2.2 and v1.2.3. final File dirQuests = ForgeProps.getFile(NewConstants.Quest.DATA_DIR);
// Can be safely deleted after release of 1.2.3.
if (!dirQuests.exists()) { // Temporary transition code between v1.2.2 and v1.2.3.
dirQuests.mkdirs(); // Can be safely deleted after release of 1.2.3.
} if (!dirQuests.exists()) {
File olddata = new File("res/quest/questData.dat"); dirQuests.mkdirs();
File newpath = new File(dirQuests.getPath() + "/questData.dat"); }
File olddata = new File("res/quest/questData.dat");
if (olddata.exists()) { olddata.renameTo(newpath); } File newpath = new File(dirQuests.getPath() + "/questData.dat");
// end block which can be deleted
if (olddata.exists()) { olddata.renameTo(newpath); }
// Iterate over files and load quest datas for each. // end block which can be deleted
FilenameFilter takeDatFiles = new FilenameFilter() {
@Override // Iterate over files and load quest datas for each.
public boolean accept(final File dir, final String name) { FilenameFilter takeDatFiles = new FilenameFilter() {
return name.endsWith(".dat"); @Override
} public boolean accept(final File dir, final String name) {
}; return name.endsWith(".dat");
File[] arrFiles = dirQuests.listFiles(takeDatFiles); }
arrQuests.clear(); };
for (File f : arrFiles) { File[] arrFiles = dirQuests.listFiles(takeDatFiles);
arrQuests.put(f.getName(), QuestDataIO.loadData(f)); arrQuests.clear();
} for (File f : arrFiles) {
arrQuests.put(f.getName(), QuestDataIO.loadData(f));
// Populate list with available quest datas. }
view.getLstQuests().setQuests(arrQuests.values().toArray(new QuestData[0]));
// Populate list with available quest datas.
// If there are quests available, force select. view.getLstQuests().setQuests(arrQuests.values().toArray(new QuestData[0]));
if (arrQuests.size() > 0) {
final String questname = Singletons.getModel().getQuestPreferences() // If there are quests available, force select.
.getPreference(QPref.CURRENT_QUEST); if (arrQuests.size() > 0) {
final String questname = Singletons.getModel().getQuestPreferences()
// Attempt to select previous quest. .getPreference(QPref.CURRENT_QUEST);
if (arrQuests.get(questname) != null) {
view.getLstQuests().setSelectedQuestData(arrQuests.get(questname)); // Attempt to select previous quest.
} if (arrQuests.get(questname) != null) {
else { view.getLstQuests().setSelectedQuestData(arrQuests.get(questname));
view.getLstQuests().setSelectedIndex(0); }
} else {
view.getLstQuests().setSelectedIndex(0);
// Drop into AllZone. }
AllZone.setQuestData(view.getLstQuests().getSelectedQuest());
} // Drop into AllZone.
else { AllZone.setQuestData(view.getLstQuests().getSelectedQuest());
AllZone.setQuestData(null); }
} else {
AllZone.setQuestData(null);
view.getLstQuests().setSelectCommand(cmdQuestSelect); }
view.getLstQuests().setDeleteCommand(cmdQuestDelete);
} view.getLstQuests().setSelectCommand(cmdQuestSelect);
view.getLstQuests().setDeleteCommand(cmdQuestDelete);
/** }
* The actuator for new quests.
*/ /**
private void newQuest() { * The actuator for new quests.
final VSubmenuQuestData view = VSubmenuQuestData.SINGLETON_INSTANCE; */
int difficulty = 0; private void newQuest() {
QuestData newdata = new QuestData(); final VSubmenuQuestData view = VSubmenuQuestData.SINGLETON_INSTANCE;
int difficulty = 0;
final String mode = view.getRadFantasy().isSelected() QuestData newdata = new QuestData();
? forge.quest.data.QuestData.FANTASY
: forge.quest.data.QuestData.CLASSIC; final String mode = view.getRadFantasy().isSelected()
? forge.quest.data.QuestData.FANTASY
if (view.getRadEasy().isSelected()) { : forge.quest.data.QuestData.CLASSIC;
difficulty = 0;
} else if (view.getRadMedium().isSelected()) { if (view.getRadEasy().isSelected()) {
difficulty = 1; difficulty = 0;
} else if (view.getRadHard().isSelected()) { } else if (view.getRadMedium().isSelected()) {
difficulty = 2; difficulty = 1;
} else if (view.getRadExpert().isSelected()) { } else if (view.getRadHard().isSelected()) {
difficulty = 3; difficulty = 2;
} else { } else if (view.getRadExpert().isSelected()) {
throw new IllegalStateException( difficulty = 3;
"ControlQuest() > newQuest(): Error starting new quest!"); } else {
} throw new IllegalStateException(
"ControlQuest() > newQuest(): Error starting new quest!");
final Object o = JOptionPane.showInputDialog(null, "Poets will remember your quest as:", "Quest Name", JOptionPane.OK_CANCEL_OPTION); }
if (o == null) { return; } final QuestStartPool startPool;
final String startPrecon = view.getPrecon();
final String questName = GuiUtils.cleanString(o.toString()); if (view.getRadCompleteStart().isSelected()) {
startPool = COMPLETE;
if (getAllQuests().get(questName) != null || questName.equals("")) { } else if (view.getRadStandardStart().isSelected()) {
JOptionPane.showMessageDialog(null, "Please pick another quest name, a quest already has that name."); startPool = STANDARD;
return; } else {
} startPool = PRECON;
}
// Give the user a few cards to build a deck
newdata.newGame(difficulty, mode, view.getCbStandardStart().isSelected()); final Object o = JOptionPane.showInputDialog(null, "Poets will remember your quest as:", "Quest Name", JOptionPane.OK_CANCEL_OPTION);
newdata.setName(questName);
newdata.saveData(); if (o == null) { return; }
// Save in preferences. final String questName = GuiUtils.cleanString(o.toString());
Singletons.getModel().getQuestPreferences().setPreference(QPref.CURRENT_QUEST, questName + ".dat");
Singletons.getModel().getQuestPreferences().save(); if (getAllQuests().get(questName) != null || questName.equals("")) {
JOptionPane.showMessageDialog(null, "Please pick another quest name, a quest already has that name.");
update(); return;
} // New Quest }
/** Changes between quest data files. */ // Give the user a few cards to build a deck
private void changeQuest() { newdata.newGame(difficulty, mode, startPool, startPrecon);
AllZone.setQuestData(VSubmenuQuestData.SINGLETON_INSTANCE newdata.setName(questName);
.getLstQuests().getSelectedQuest()); newdata.saveData();
// Save in preferences. // Save in preferences.
Singletons.getModel().getQuestPreferences().setPreference(QPref.CURRENT_QUEST, Singletons.getModel().getQuestPreferences().setPreference(QPref.CURRENT_QUEST, questName + ".dat");
AllZone.getQuestData().getName() + ".dat"); Singletons.getModel().getQuestPreferences().save();
Singletons.getModel().getQuestPreferences().save();
update();
SubmenuQuestUtil.updateStatsAndPet(); } // New Quest
CSubmenuDuels.SINGLETON_INSTANCE.update(); /** Changes between quest data files. */
CSubmenuChallenges.SINGLETON_INSTANCE.update(); private void changeQuest() {
CSubmenuQuestDecks.SINGLETON_INSTANCE.update(); AllZone.setQuestData(VSubmenuQuestData.SINGLETON_INSTANCE
} .getLstQuests().getSelectedQuest());
/** @return */ // Save in preferences.
private Map<String, QuestData> getAllQuests() { Singletons.getModel().getQuestPreferences().setPreference(QPref.CURRENT_QUEST,
return arrQuests; AllZone.getQuestData().getName() + ".dat");
} Singletons.getModel().getQuestPreferences().save();
}
SubmenuQuestUtil.updateStatsAndPet();
CSubmenuDuels.SINGLETON_INSTANCE.update();
CSubmenuChallenges.SINGLETON_INSTANCE.update();
CSubmenuQuestDecks.SINGLETON_INSTANCE.update();
}
/** @return */
private Map<String, QuestData> getAllQuests() {
return arrQuests;
}
}

View File

@@ -1,204 +1,238 @@
package forge.gui.home.quest; package forge.gui.home.quest;
import javax.swing.ButtonGroup; import forge.gui.home.EMenuGroup;
import javax.swing.JCheckBox; import forge.gui.home.EMenuItem;
import javax.swing.JPanel; import forge.gui.home.ICSubmenu;
import javax.swing.JRadioButton; import forge.gui.home.IVSubmenu;
import javax.swing.SwingConstants; import forge.gui.toolbox.*;
import forge.quest.data.QuestData;
import net.miginfocom.swing.MigLayout;
import forge.gui.home.EMenuGroup; import net.miginfocom.swing.MigLayout;
import forge.gui.home.EMenuItem;
import forge.gui.home.ICSubmenu; import javax.swing.*;
import forge.gui.home.IVSubmenu; import java.awt.event.ActionEvent;
import forge.gui.toolbox.FCheckBox; import java.awt.event.ActionListener;
import forge.gui.toolbox.FLabel;
import forge.gui.toolbox.FPanel; /**
import forge.gui.toolbox.FRadioButton; * Singleton instance of "Colors" submenu in "Constructed" group.
import forge.gui.toolbox.FScrollPane; *
import forge.gui.toolbox.FSkin; */
public enum VSubmenuQuestData implements IVSubmenu {
/** /** */
* Singleton instance of "Colors" submenu in "Constructed" group. SINGLETON_INSTANCE;
*
*/ /** */
public enum VSubmenuQuestData implements IVSubmenu { private final JPanel pnl = new JPanel();
/** */ private final JPanel pnlViewport = new JPanel();
SINGLETON_INSTANCE; private final QuestFileLister lstQuests = new QuestFileLister();
/** */ private final JRadioButton radEasy = new FRadioButton("Easy");
private final JPanel pnl = new JPanel(); private final JRadioButton radMedium = new FRadioButton("Medium");
private final JPanel pnlViewport = new JPanel(); private final JRadioButton radHard = new FRadioButton("Hard");
private final QuestFileLister lstQuests = new QuestFileLister(); private final JRadioButton radExpert = new FRadioButton("Expert");
private final JRadioButton radEasy = new FRadioButton("Easy"); private final JRadioButton radFantasy = new FRadioButton("Fantasy");
private final JRadioButton radMedium = new FRadioButton("Medium"); private final JRadioButton radClassic = new FRadioButton("Classic");
private final JRadioButton radHard = new FRadioButton("Hard");
private final JRadioButton radExpert = new FRadioButton("Expert"); private final JRadioButton radCompleteStart = new FRadioButton("Unrestricted Starting Pool");
private final JRadioButton radFantasy = new FRadioButton("Fantasy"); private final JRadioButton radStandardStart = new FRadioButton("Standard (Type 2) Starting Pool");
private final JRadioButton radClassic = new FRadioButton("Classic"); private final JRadioButton radPreconStart = new FRadioButton("Preconstructed Deck: ");
private final JComboBox cbxPrecon = new JComboBox();
private final JCheckBox cbStandardStart = new FCheckBox("Standard (Type 2) Starting Pool");
private final FLabel btnEmbark = new FLabel.Builder().opaque(true).hoverable(true).text("Embark!").build(); private final FLabel btnEmbark = new FLabel.Builder().opaque(true).hoverable(true).text("Embark!").build();
/* (non-Javadoc) /* (non-Javadoc)
* @see forge.view.home.IViewSubmenu#populate() * @see forge.view.home.IViewSubmenu#populate()
*/ */
@Override @Override
public void populate() { public void populate() {
pnl.removeAll(); pnl.removeAll();
pnl.setOpaque(false); pnl.setOpaque(false);
pnl.setLayout(new MigLayout("insets 0, gap 0")); pnl.setLayout(new MigLayout("insets 0, gap 0"));
// Load quest // Load quest
final FPanel pnlTitleLoad = new FPanel(); final FPanel pnlTitleLoad = new FPanel();
pnlTitleLoad.setLayout(new MigLayout("insets 0, align center")); pnlTitleLoad.setLayout(new MigLayout("insets 0, align center"));
pnlTitleLoad.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); pnlTitleLoad.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
pnlTitleLoad.add(new FLabel.Builder().text("Load a previous Quest") pnlTitleLoad.add(new FLabel.Builder().text("Load a previous Quest")
.fontScaleAuto(false).fontSize(16).build(), "h 95%!, gap 0 0 2.5% 0"); .fontScaleAuto(false).fontSize(16).build(), "h 95%!, gap 0 0 2.5% 0");
final FScrollPane scr = new FScrollPane(lstQuests); final FScrollPane scr = new FScrollPane(lstQuests);
scr.setBorder(null); scr.setBorder(null);
scr.getViewport().setBorder(null); scr.getViewport().setBorder(null);
// New quest // New quest
final FPanel pnlTitleNew = new FPanel(); final FPanel pnlTitleNew = new FPanel();
pnlTitleNew.setLayout(new MigLayout("insets 0, align center")); pnlTitleNew.setLayout(new MigLayout("insets 0, align center"));
pnlTitleNew.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); pnlTitleNew.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
pnlTitleNew.add(new FLabel.Builder().text("Start a new Quest") pnlTitleNew.add(new FLabel.Builder().text("Start a new Quest")
.fontScaleAuto(false).fontSize(16).build(), "h 95%!, gap 0 0 2.5% 0"); .fontScaleAuto(false).fontSize(16).build(), "h 95%!, gap 0 0 2.5% 0");
final ButtonGroup group1 = new ButtonGroup(); final ButtonGroup group1 = new ButtonGroup();
group1.add(radEasy); group1.add(radEasy);
group1.add(radMedium); group1.add(radMedium);
group1.add(radHard); group1.add(radHard);
group1.add(radExpert); group1.add(radExpert);
radEasy.setSelected(true);
radEasy.setSelected(true);
radClassic.setSelected(true); final ButtonGroup group2 = new ButtonGroup();
group2.add(radFantasy);
final ButtonGroup group2 = new ButtonGroup(); group2.add(radClassic);
group2.add(radFantasy); radClassic.setSelected(true);
group2.add(radClassic);
final ActionListener preconListener = new ActionListener() {
final JPanel pnlOptions = new JPanel(); @Override public void actionPerformed(ActionEvent actionEvent) {
pnlOptions.setOpaque(false); cbxPrecon.setEnabled(radPreconStart.isSelected());
pnlOptions.setLayout(new MigLayout("insets 0, gap 0")); }
};
final String constraints = "w 40%!, h 30px!";
pnlOptions.add(radEasy, constraints + ", gap 7.5% 2.5% 0 0"); for (String preconDeck : QuestData.getPrecons().getNames()) {
pnlOptions.add(radFantasy, constraints + ", wrap"); cbxPrecon.addItem(preconDeck);
pnlOptions.add(radMedium, constraints + ", gap 7.5% 2.5% 0 0"); }
pnlOptions.add(radClassic, constraints + ", wrap");
pnlOptions.add(radHard, constraints + ", gap 7.5% 2.5% 0 0"); final ButtonGroup group3 = new ButtonGroup();
pnlOptions.add(cbStandardStart, constraints + ", wrap"); group3.add(radCompleteStart);
pnlOptions.add(radExpert, constraints + ", gap 7.5% 2.5% 0 0, wrap"); radCompleteStart.addActionListener(preconListener);
group3.add(radStandardStart);
pnlOptions.add(btnEmbark, "w 40%!, h 30px!, gap 30% 0 20px 0, span 3 1"); radStandardStart.addActionListener(preconListener);
group3.add(radPreconStart);
// Final layout radPreconStart.addActionListener(preconListener);
pnlViewport.removeAll(); radCompleteStart.setSelected(true);
pnlViewport.setOpaque(false); cbxPrecon.setEnabled(false);
pnlViewport.setLayout(new MigLayout("insets 0, gap 0, wrap")); final JPanel pnlOptions = new JPanel();
pnlOptions.setOpaque(false);
pnlViewport.add(pnlTitleLoad, "w 96%, h 36px!, gap 2% 0 20px 10px"); pnlOptions.setLayout(new MigLayout("insets 0, gap 0"));
pnlViewport.add(new FLabel.Builder().text("Old quest data? Put into " final String constraints = "w 40%!, h 30px!";
+ "res/quest/data, and restart Forge.") pnlOptions.add(radEasy, constraints + ", gap 7.5% 2.5% 0 0");
.fontAlign(SwingConstants.CENTER).fontScaleAuto(false).fontSize(12) pnlOptions.add(radFantasy, constraints + ", wrap");
.build(), "w 96%!, h 18px!, gap 2% 0 0 4px"); pnlOptions.add(radMedium, constraints + ", gap 7.5% 2.5% 0 0");
pnlOptions.add(radClassic, constraints + ", wrap");
pnlViewport.add(scr, "w 96%!, pushy, growy, gap 2% 0 0 30px"); pnlOptions.add(radHard, constraints + ", gap 7.5% 2.5% 0 0");
pnlOptions.add(radCompleteStart, constraints + ", wrap");
pnlViewport.add(pnlTitleNew, "w 96%, h 36px!, gap 2% 0 0 10px"); pnlOptions.add(radExpert, constraints + ", gap 7.5% 2.5% 0 0 ");
pnlViewport.add(pnlOptions, "w 96%!, h 200px!, gap 2% 0 0 20px"); pnlOptions.add(radStandardStart, constraints + ", wrap");
pnlOptions.add(radPreconStart, constraints + ", wrap, skip");
pnl.add(new FScrollPane(pnlViewport), "w 100%!, h 100%!"); pnlOptions.add(cbxPrecon, "gap 20 0, w 30%!, h 35px!, wrap, skip");
}
pnlOptions.add(btnEmbark, "w 40%!, h 30px!, gap 30% 0 20px 0, span 3 1");
/* (non-Javadoc)
* @see forge.view.home.IViewSubmenu#getGroup() // Final layout
*/ pnlViewport.removeAll();
@Override pnlViewport.setOpaque(false);
public EMenuGroup getGroupEnum() { pnlViewport.setLayout(new MigLayout("insets 0, gap 0, wrap"));
return EMenuGroup.QUEST;
} pnlViewport.add(pnlTitleLoad, "w 96%, h 36px!, gap 2% 0 20px 10px");
/* (non-Javadoc) pnlViewport.add(new FLabel.Builder().text("Old quest data? Put into "
* @see forge.view.home.IViewSubmenu#getPanel() + "res/quest/data, and restart Forge.")
*/ .fontAlign(SwingConstants.CENTER).fontScaleAuto(false).fontSize(12)
@Override .build(), "w 96%!, h 18px!, gap 2% 0 0 4px");
public JPanel getPanel() {
return pnl; pnlViewport.add(scr, "w 96%!, pushy, growy, gap 2% 0 0 30px");
}
pnlViewport.add(pnlTitleNew, "w 96%, h 36px!, gap 2% 0 0 10px");
pnlViewport.add(pnlOptions, "w 96%!, h 250px!, gap 2% 0 0 20px");
/* (non-Javadoc)
* @see forge.gui.home.IVSubmenu#getMenuTitle() pnl.add(new FScrollPane(pnlViewport), "w 100%!, h 100%!");
*/ }
@Override
public String getMenuTitle() { /* (non-Javadoc)
return "New / Load Quest"; * @see forge.view.home.IViewSubmenu#getGroup()
} */
@Override
/* (non-Javadoc) public EMenuGroup getGroupEnum() {
* @see forge.gui.home.IVSubmenu#getMenuName() return EMenuGroup.QUEST;
*/ }
@Override
public String getItemEnum() { /* (non-Javadoc)
return EMenuItem.QUEST_DATA.toString(); * @see forge.view.home.IViewSubmenu#getPanel()
} */
@Override
/* (non-Javadoc) public JPanel getPanel() {
* @see forge.gui.home.IVSubmenu#getControl() return pnl;
*/ }
@Override
public ICSubmenu getControl() {
return CSubmenuQuestData.SINGLETON_INSTANCE; /* (non-Javadoc)
} * @see forge.gui.home.IVSubmenu#getMenuTitle()
*/
/** @return {@link forge.gui.home.quest.QuestFileLister} */ @Override
public QuestFileLister getLstQuests() { public String getMenuTitle() {
return this.lstQuests; return "New / Load Quest";
} }
/** @return {@link javax.swing.JRadioButton} */ /* (non-Javadoc)
public JRadioButton getRadEasy() { * @see forge.gui.home.IVSubmenu#getMenuName()
return radEasy; */
} @Override
public String getItemEnum() {
/** @return {@link javax.swing.JRadioButton} */ return EMenuItem.QUEST_DATA.toString();
public JRadioButton getRadMedium() { }
return radMedium;
} /* (non-Javadoc)
* @see forge.gui.home.IVSubmenu#getControl()
/** @return {@link javax.swing.JRadioButton} */ */
public JRadioButton getRadHard() { @Override
return radHard; public ICSubmenu getControl() {
} return CSubmenuQuestData.SINGLETON_INSTANCE;
}
/** @return {@link javax.swing.JRadioButton} */
public JRadioButton getRadExpert() { /** @return {@link forge.gui.home.quest.QuestFileLister} */
return radExpert; public QuestFileLister getLstQuests() {
} return this.lstQuests;
}
/** @return {@link javax.swing.JRadioButton} */
public JRadioButton getRadFantasy() { /** @return {@link javax.swing.JRadioButton} */
return radFantasy; public JRadioButton getRadEasy() {
} return radEasy;
}
/** @return {@link javax.swing.JRadioButton} */
public JRadioButton getRadClassic() { /** @return {@link javax.swing.JRadioButton} */
return radClassic; public JRadioButton getRadMedium() {
} return radMedium;
}
/** @return {@link javax.swing.JCheckBox} */
public JCheckBox getCbStandardStart() { /** @return {@link javax.swing.JRadioButton} */
return cbStandardStart; public JRadioButton getRadHard() {
} return radHard;
}
/** @return {@link forge.gui.toolbox.FLabel} */
public FLabel getBtnEmbark() { /** @return {@link javax.swing.JRadioButton} */
return btnEmbark; public JRadioButton getRadExpert() {
} return radExpert;
} }
/** @return {@link javax.swing.JRadioButton} */
public JRadioButton getRadFantasy() {
return radFantasy;
}
/** @return {@link javax.swing.JRadioButton} */
public JRadioButton getRadClassic() {
return radClassic;
}
public JRadioButton getRadCompleteStart() {
return radCompleteStart;
}
/** @return {@link javax.swing.JCheckBox} */
public JRadioButton getRadStandardStart() {
return radStandardStart;
}
public JRadioButton getRadPreconStart() {
return radPreconStart;
}
public String getPrecon() {
return (String) cbxPrecon.getSelectedItem();
}
/** @return {@link forge.gui.toolbox.FLabel} */
public FLabel getBtnEmbark() {
return btnEmbark;
}
}

View File

@@ -17,28 +17,19 @@
*/ */
package forge.quest.data; package forge.quest.data;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import forge.Singletons; import forge.Singletons;
import forge.deck.Deck; import forge.deck.Deck;
import forge.item.CardPrinted; import forge.item.*;
import forge.item.InventoryItem;
import forge.item.ItemPool;
import forge.item.ItemPoolView;
import forge.item.PreconDeck;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
import forge.properties.NewConstants; import forge.properties.NewConstants;
import forge.quest.data.QuestPreferences.QPref; import forge.quest.data.QuestPreferences.QPref;
import forge.quest.data.item.QuestInventory; import forge.quest.data.item.QuestInventory;
import forge.quest.data.pet.QuestPetManager; import forge.quest.data.pet.QuestPetManager;
import forge.util.Predicate; import forge.util.*;
import forge.util.StorageView;
import forge.util.IStorage; import java.util.ArrayList;
import forge.util.IStorageView; import java.util.HashMap;
import forge.util.MyRandom; import java.util.List;
//when you create QuestDataOld and AFTER you copy the AI decks over //when you create QuestDataOld and AFTER you copy the AI decks over
//you have to call one of these two methods below //you have to call one of these two methods below
@@ -172,8 +163,8 @@ public final class QuestData {
private transient QuestEvent currentEvent; private transient QuestEvent currentEvent;
// This is used by shop. Had no idea where else to place this // This is used by shop. Had no idea where else to place this
private static transient IStorageView<PreconDeck> preconManager = new StorageView<PreconDeck>(new PreconReader( private static transient IStorageView<PreconDeck> preconManager =
ForgeProps.getFile(NewConstants.Quest.PRECONS))); new StorageView<PreconDeck>(new PreconReader(ForgeProps.getFile(NewConstants.Quest.PRECONS)));
/** The Constant RANK_TITLES. */ /** The Constant RANK_TITLES. */
public static final String[] RANK_TITLES = new String[] { "Level 0 - Confused Wizard", "Level 1 - Mana Mage", public static final String[] RANK_TITLES = new String[] { "Level 0 - Confused Wizard", "Level 1 - Mana Mage",
@@ -235,22 +226,34 @@ public final class QuestData {
* *
* @param diff * @param diff
* the diff * the diff
* @param m0de * @param mode
* the m0de * the mode
* @param standardStart * @param startPool
* the standard start * the start type
*/ */
public void newGame(final int diff, final String m0de, final boolean standardStart) { public void newGame(final int diff, final String mode, final QuestStartPool startPool, final String preconName) {
this.setDifficulty(diff); this.setDifficulty(diff);
final Predicate<CardPrinted> filter = standardStart ? Singletons.getModel().getFormats().getStandard() this.mode = mode;
.getFilterPrinted() : CardPrinted.Predicates.Presets.IS_TRUE;
this.myCards.setupNewGameCardPool(filter, diff);
this.setCredits(Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.STARTING_CREDITS, diff));
this.mode = m0de;
this.life = this.mode.equals(QuestData.FANTASY) ? 15 : 20; this.life = this.mode.equals(QuestData.FANTASY) ? 15 : 20;
final Predicate<CardPrinted> filter;
switch (startPool) {
case PRECON:
myCards.addPreconDeck(preconManager.get(preconName));
return;
case STANDARD:
filter = Singletons.getModel().getFormats().getStandard().getFilterPrinted();
break;
default: //Unrestricted
filter = CardPrinted.Predicates.Presets.IS_TRUE;
break;
}
this.setCredits(Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.STARTING_CREDITS, diff));
this.myCards.setupNewGameCardPool(filter, diff);
} }
// All belongings // All belongings

View File

@@ -0,0 +1,7 @@
package forge.quest.data;
public enum QuestStartPool {
COMPLETE,
STANDARD,
PRECON
}

View File

@@ -1,492 +1,489 @@
/* /*
* Forge: Play Magic: the Gathering. * Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team * Copyright (C) 2011 Forge Team
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package forge.quest.data; package forge.quest.data;
import java.util.ArrayList; import forge.Singletons;
import java.util.List; import forge.card.BoosterGenerator;
import java.util.Map.Entry; import forge.card.CardEdition;
import forge.card.FormatCollection;
import net.slightlymagic.braids.util.lambda.Lambda1; import forge.deck.Deck;
import forge.Singletons; import forge.item.*;
import forge.card.BoosterGenerator; import forge.quest.BoosterUtils;
import forge.card.CardEdition; import forge.quest.data.QuestPreferences.QPref;
import forge.card.FormatCollection; import forge.util.MyRandom;
import forge.deck.Deck; import forge.util.Predicate;
import forge.item.BoosterPack; import net.slightlymagic.braids.util.lambda.Lambda1;
import forge.item.CardDb;
import forge.item.CardPrinted; import java.util.ArrayList;
import forge.item.FatPack; import java.util.List;
import forge.item.InventoryItem; import java.util.Map.Entry;
import forge.item.ItemPool;
import forge.item.ItemPoolView; /**
import forge.item.OpenablePack; * This is a helper class to execute operations on QuestData. It has been
import forge.item.PreconDeck; * created to decrease complexity of questData class
import forge.item.TournamentPack; */
import forge.quest.BoosterUtils; public final class QuestUtilCards {
import forge.quest.data.QuestPreferences.QPref; private final QuestData q;
import forge.util.MyRandom; private final QuestPreferences qpref;
import forge.util.Predicate;
/**
/** * Instantiates a new quest util cards.
* This is a helper class to execute operations on QuestData. It has been *
* created to decrease complexity of questData class * @param qd
*/ * the qd
public final class QuestUtilCards { */
private final QuestData q; public QuestUtilCards(final QuestData qd) {
private final QuestPreferences qpref; this.q = qd;
this.qpref = Singletons.getModel().getQuestPreferences();
/** }
* Instantiates a new quest util cards.
* /**
* @param qd * Adds the basic lands.
* the qd *
*/ * @param nBasic the n basic
public QuestUtilCards(final QuestData qd) { * @param nSnow the n snow
this.q = qd; * @return the item pool view
this.qpref = Singletons.getModel().getQuestPreferences(); */
} public static ItemPoolView<CardPrinted> generateBasicLands(final int nBasic, final int nSnow) {
final CardDb db = CardDb.instance();
/** final ItemPool<CardPrinted> pool = new ItemPool<CardPrinted>(CardPrinted.class);
* Adds the basic lands. pool.add(db.getCard("Forest", "M10"), nBasic);
* pool.add(db.getCard("Mountain", "M10"), nBasic);
* @param nBasic the n basic pool.add(db.getCard("Swamp", "M10"), nBasic);
* @param nSnow the n snow pool.add(db.getCard("Island", "M10"), nBasic);
* @return the item pool view pool.add(db.getCard("Plains", "M10"), nBasic);
*/
public static ItemPoolView<CardPrinted> generateBasicLands(final int nBasic, final int nSnow) { pool.add(db.getCard("Snow-Covered Forest", "ICE"), nSnow);
final CardDb db = CardDb.instance(); pool.add(db.getCard("Snow-Covered Mountain", "ICE"), nSnow);
final ItemPool<CardPrinted> pool = new ItemPool<CardPrinted>(CardPrinted.class); pool.add(db.getCard("Snow-Covered Swamp", "ICE"), nSnow);
pool.add(db.getCard("Forest", "M10"), nBasic); pool.add(db.getCard("Snow-Covered Island", "ICE"), nSnow);
pool.add(db.getCard("Mountain", "M10"), nBasic); pool.add(db.getCard("Snow-Covered Plains", "ICE"), nSnow);
pool.add(db.getCard("Swamp", "M10"), nBasic); return pool;
pool.add(db.getCard("Island", "M10"), nBasic); }
pool.add(db.getCard("Plains", "M10"), nBasic);
// adds 11 cards, to the current card pool
pool.add(db.getCard("Snow-Covered Forest", "ICE"), nSnow); // (I chose 11 cards instead of 15 in order to make things more challenging)
pool.add(db.getCard("Snow-Covered Mountain", "ICE"), nSnow);
pool.add(db.getCard("Snow-Covered Swamp", "ICE"), nSnow); /**
pool.add(db.getCard("Snow-Covered Island", "ICE"), nSnow); * <p>
pool.add(db.getCard("Snow-Covered Plains", "ICE"), nSnow); * addCards.
return pool; * </p>
} *
* @param fSets
// adds 11 cards, to the current card pool * the f sets
// (I chose 11 cards instead of 15 in order to make things more challenging) * @return the array list
*/
/** public ArrayList<CardPrinted> addCards(final Predicate<CardPrinted> fSets) {
* <p> final int nCommon = this.qpref.getPreferenceInt(QPref.BOOSTER_COMMONS);
* addCards. final int nUncommon = this.qpref.getPreferenceInt(QPref.BOOSTER_UNCOMMONS);
* </p> final int nRare = this.qpref.getPreferenceInt(QPref.BOOSTER_RARES);
*
* @param fSets final ArrayList<CardPrinted> newCards = new ArrayList<CardPrinted>();
* the f sets newCards.addAll(BoosterUtils.generateDistinctCards(Predicate.and(fSets, CardPrinted.Predicates.Presets.IS_COMMON), nCommon));
* @return the array list newCards.addAll(BoosterUtils.generateDistinctCards(Predicate.and(fSets, CardPrinted.Predicates.Presets.IS_UNCOMMON), nUncommon));
*/ newCards.addAll(BoosterUtils.generateDistinctCards(Predicate.and(fSets, CardPrinted.Predicates.Presets.IS_RARE_OR_MYTHIC), nRare));
public ArrayList<CardPrinted> addCards(final Predicate<CardPrinted> fSets) {
final int nCommon = this.qpref.getPreferenceInt(QPref.BOOSTER_COMMONS); this.addAllCards(newCards);
final int nUncommon = this.qpref.getPreferenceInt(QPref.BOOSTER_UNCOMMONS); return newCards;
final int nRare = this.qpref.getPreferenceInt(QPref.BOOSTER_RARES); }
final ArrayList<CardPrinted> newCards = new ArrayList<CardPrinted>(); /**
newCards.addAll(BoosterUtils.generateDistinctCards(Predicate.and(fSets, CardPrinted.Predicates.Presets.IS_COMMON), nCommon)); * Adds the all cards.
newCards.addAll(BoosterUtils.generateDistinctCards(Predicate.and(fSets, CardPrinted.Predicates.Presets.IS_UNCOMMON), nUncommon)); *
newCards.addAll(BoosterUtils.generateDistinctCards(Predicate.and(fSets, CardPrinted.Predicates.Presets.IS_RARE_OR_MYTHIC), nRare)); * @param newCards
* the new cards
this.addAllCards(newCards); */
return newCards; public void addAllCards(final Iterable<CardPrinted> newCards) {
} for (final CardPrinted card : newCards) {
this.addSingleCard(card);
/** }
* Adds the all cards. }
*
* @param newCards /**
* the new cards * Adds the single card.
*/ *
public void addAllCards(final Iterable<CardPrinted> newCards) { * @param card
for (final CardPrinted card : newCards) { * the card
this.addSingleCard(card); */
} public void addSingleCard(final CardPrinted card) {
} this.q.getCardPool().add(card);
/** // register card into that list so that it would appear as a new one.
* Adds the single card. this.q.getNewCardList().add(card);
* }
* @param card
* the card private static final Predicate<CardPrinted> RARE_PREDICATE = CardPrinted.Predicates.Presets.IS_RARE_OR_MYTHIC;
*/
public void addSingleCard(final CardPrinted card) { /**
this.q.getCardPool().add(card); * Adds the random rare.
*
// register card into that list so that it would appear as a new one. * @return the card printed
this.q.getNewCardList().add(card); */
} public CardPrinted addRandomRare() {
final CardPrinted card = QuestUtilCards.RARE_PREDICATE.random(CardDb.instance().getAllCards());
private static final Predicate<CardPrinted> RARE_PREDICATE = CardPrinted.Predicates.Presets.IS_RARE_OR_MYTHIC; this.addSingleCard(card);
return card;
/** }
* Adds the random rare.
* /**
* @return the card printed * Adds the random rare.
*/ *
public CardPrinted addRandomRare() { * @param n
final CardPrinted card = QuestUtilCards.RARE_PREDICATE.random(CardDb.instance().getAllCards()); * the n
this.addSingleCard(card); * @return the list
return card; */
} public List<CardPrinted> addRandomRare(final int n) {
final List<CardPrinted> newCards = QuestUtilCards.RARE_PREDICATE.random(CardDb.instance().getAllCards(), n);
/** this.addAllCards(newCards);
* Adds the random rare. return newCards;
* }
* @param n
* the n /**
* @return the list * Setup new game card pool.
*/ *
public List<CardPrinted> addRandomRare(final int n) { * @param filter
final List<CardPrinted> newCards = QuestUtilCards.RARE_PREDICATE.random(CardDb.instance().getAllCards(), n); * the filter
this.addAllCards(newCards); * @param idxDifficulty
return newCards; * the idx difficulty
} */
public void setupNewGameCardPool(final Predicate<CardPrinted> filter, final int idxDifficulty) {
/** final int nC = this.qpref.getPreferenceInt(QPref.STARTING_COMMONS, idxDifficulty);
* Setup new game card pool. final int nU = this.qpref.getPreferenceInt(QPref.STARTING_UNCOMMONS, idxDifficulty);
* final int nR = this.qpref.getPreferenceInt(QPref.STARTING_RARES, idxDifficulty);
* @param filter
* the filter this.addAllCards(BoosterUtils.getQuestStarterDeck(filter, nC, nU, nR));
* @param idxDifficulty }
* the idx difficulty
*/ /**
public void setupNewGameCardPool(final Predicate<CardPrinted> filter, final int idxDifficulty) { * Buy card.
final int nC = this.qpref.getPreferenceInt(QPref.STARTING_COMMONS, idxDifficulty); *
final int nU = this.qpref.getPreferenceInt(QPref.STARTING_UNCOMMONS, idxDifficulty); * @param card
final int nR = this.qpref.getPreferenceInt(QPref.STARTING_RARES, idxDifficulty); * the card
* @param value
this.addAllCards(BoosterUtils.getQuestStarterDeck(filter, nC, nU, nR)); * the value
} */
public void buyCard(final CardPrinted card, final int value) {
/** if (this.q.getCredits() >= value) {
* Buy card. this.q.setCredits(this.q.getCredits() - value);
* this.q.getShopList().remove(card);
* @param card this.addSingleCard(card);
* the card }
* @param value }
* the value
*/ /**
public void buyCard(final CardPrinted card, final int value) { * Buy booster.
if (this.q.getCredits() >= value) { *
this.q.setCredits(this.q.getCredits() - value); * @param booster
this.q.getShopList().remove(card); * the booster
this.addSingleCard(card); * @param value
} * the value
} */
public void buyPack(final OpenablePack booster, final int value) {
/** if (this.q.getCredits() >= value) {
* Buy booster. this.q.setCredits(this.q.getCredits() - value);
* this.q.getShopList().remove(booster);
* @param booster this.addAllCards(booster.getCards());
* the booster }
* @param value }
* the value
*/ /**
public void buyPack(final OpenablePack booster, final int value) { * Buy precon deck.
if (this.q.getCredits() >= value) { *
this.q.setCredits(this.q.getCredits() - value); * @param precon
this.q.getShopList().remove(booster); * the precon
this.addAllCards(booster.getCards()); * @param value
} * the value
} */
public void buyPreconDeck(final PreconDeck precon, final int value) {
/** if (this.q.getCredits() >= value) {
* Buy precon deck. this.q.setCredits(this.q.getCredits() - value);
* this.q.getShopList().remove(precon);
* @param precon addPreconDeck(precon);
* the precon }
* @param value }
* the value
*/ void addPreconDeck(PreconDeck precon) {
public void buyPreconDeck(final PreconDeck precon, final int value) { this.q.getMyDecks().add(precon.getDeck());
if (this.q.getCredits() >= value) { this.addAllCards(precon.getDeck().getMain().toFlatList());
this.q.setCredits(this.q.getCredits() - value); }
this.q.getShopList().remove(precon);
this.q.getMyDecks().add(precon.getDeck()); /**
this.addAllCards(precon.getDeck().getMain().toFlatList()); * Sell card.
} *
} * @param card
* the card
/** * @param price
* Sell card. * the price
* */
* @param card public void sellCard(final CardPrinted card, final int price) {
* the card this.sellCard(card, price, true);
* @param price }
* the price
*/ /**
public void sellCard(final CardPrinted card, final int price) { * Sell card.
this.sellCard(card, price, true); *
} * @param card
* the card
/** * @param price
* Sell card. * the price
* * @param addToShop
* @param card * true if this card should be added to the shop, false otherwise
* the card */
* @param price public void sellCard(final CardPrinted card, final int price, final boolean addToShop) {
* the price if (price > 0) {
* @param addToShop this.q.setCredits(this.q.getCredits() + price);
* true if this card should be added to the shop, false otherwise }
*/ this.q.getCardPool().remove(card);
public void sellCard(final CardPrinted card, final int price, final boolean addToShop) { if (addToShop) {
if (price > 0) { this.q.getShopList().add(card);
this.q.setCredits(this.q.getCredits() + price); }
}
this.q.getCardPool().remove(card); // remove card being sold from all decks
if (addToShop) { final int leftInPool = this.q.getCardPool().count(card);
this.q.getShopList().add(card); // remove sold cards from all decks:
} for (final Deck deck : this.q.getMyDecks()) {
deck.getMain().remove(card, deck.getMain().count(card) - leftInPool);
// remove card being sold from all decks }
final int leftInPool = this.q.getCardPool().count(card); }
// remove sold cards from all decks:
for (final Deck deck : this.q.getMyDecks()) { /**
deck.getMain().remove(card, deck.getMain().count(card) - leftInPool); * Clear shop list.
} */
} public void clearShopList() {
if (null != this.q.getShopList()) {
/** this.q.getShopList().clear();
* Clear shop list. }
*/ }
public void clearShopList() {
if (null != this.q.getShopList()) { /**
this.q.getShopList().clear(); * Gets the sell mutliplier.
} *
} * @return the sell mutliplier
*/
/** public double getSellMutliplier() {
* Gets the sell mutliplier. double multi = 0.20 + (0.001 * this.q.getWin());
* if (multi > 0.6) {
* @return the sell mutliplier multi = 0.6;
*/ }
public double getSellMutliplier() {
double multi = 0.20 + (0.001 * this.q.getWin()); final int lvlEstates = this.q.isFantasy() ? this.q.getInventory().getItemLevel("Estates") : 0;
if (multi > 0.6) { switch (lvlEstates) {
multi = 0.6; case 1:
} multi += 0.01;
break;
final int lvlEstates = this.q.isFantasy() ? this.q.getInventory().getItemLevel("Estates") : 0; case 2:
switch (lvlEstates) { multi += 0.0175;
case 1: break;
multi += 0.01; case 3:
break; multi += 0.025;
case 2: break;
multi += 0.0175; default:
break; break;
case 3: }
multi += 0.025;
break; return multi;
default: }
break;
} /**
* Gets the sell price limit.
return multi; *
} * @return the sell price limit
*/
/** public int getSellPriceLimit() {
* Gets the sell price limit. return this.q.getWin() <= 50 ? 1000 : Integer.MAX_VALUE;
* }
* @return the sell price limit
*/ /**
public int getSellPriceLimit() { * Generate cards in shop.
return this.q.getWin() <= 50 ? 1000 : Integer.MAX_VALUE; */
} private final FormatCollection formats = Singletons.getModel().getFormats();
private final Predicate<CardEdition> filterExt = CardEdition.Predicates.isLegalInFormat(this.formats.getExtended());
/**
* Generate cards in shop. /** The filter t2booster. */
*/ private final Predicate<CardEdition> filterT2booster = Predicate.and(CardEdition.Predicates.CAN_MAKE_BOOSTER,
private final FormatCollection formats = Singletons.getModel().getFormats(); CardEdition.Predicates.isLegalInFormat(this.formats.getStandard()));
private final Predicate<CardEdition> filterExt = CardEdition.Predicates.isLegalInFormat(this.formats.getExtended());
/** The filter ext but t2. */
/** The filter t2booster. */ private final Predicate<CardEdition> filterExtButT2 = Predicate.and(
private final Predicate<CardEdition> filterT2booster = Predicate.and(CardEdition.Predicates.CAN_MAKE_BOOSTER, CardEdition.Predicates.CAN_MAKE_BOOSTER,
CardEdition.Predicates.isLegalInFormat(this.formats.getStandard())); Predicate.and(this.filterExt,
Predicate.not(CardEdition.Predicates.isLegalInFormat(this.formats.getStandard()))));
/** The filter ext but t2. */
private final Predicate<CardEdition> filterExtButT2 = Predicate.and( /** The filter not ext. */
CardEdition.Predicates.CAN_MAKE_BOOSTER, private final Predicate<CardEdition> filterNotExt = Predicate.and(CardEdition.Predicates.CAN_MAKE_BOOSTER,
Predicate.and(this.filterExt, Predicate.not(this.filterExt));
Predicate.not(CardEdition.Predicates.isLegalInFormat(this.formats.getStandard()))));
/**
/** The filter not ext. */ * Generate boosters in shop.
private final Predicate<CardEdition> filterNotExt = Predicate.and(CardEdition.Predicates.CAN_MAKE_BOOSTER, *
Predicate.not(this.filterExt)); * @param count
* the count
/** */
* Generate boosters in shop. public void generateBoostersInShop(final int count) {
* for (int i = 0; i < count; i++) {
* @param count final int rollD100 = MyRandom.getRandom().nextInt(100);
* the count final Predicate<CardEdition> filter = rollD100 < 40 ? this.filterT2booster
*/ : (rollD100 < 75 ? this.filterExtButT2 : this.filterNotExt);
public void generateBoostersInShop(final int count) { this.q.getShopList().addAllFlat(
for (int i = 0; i < count; i++) { filter.random(Singletons.getModel().getEditions(), 1, BoosterPack.FN_FROM_SET));
final int rollD100 = MyRandom.getRandom().nextInt(100); }
final Predicate<CardEdition> filter = rollD100 < 40 ? this.filterT2booster }
: (rollD100 < 75 ? this.filterExtButT2 : this.filterNotExt);
this.q.getShopList().addAllFlat( /**
filter.random(Singletons.getModel().getEditions(), 1, BoosterPack.FN_FROM_SET)); * Generate precons in shop.
} *
} * @param count
* the count
/** */
* Generate precons in shop. public void generateTournamentsInShop(final int count) {
* Predicate<CardEdition> hasTournament = CardEdition.Predicates.HAS_TOURNAMENT_PACK;
* @param count this.q.getShopList().addAllFlat(hasTournament.random(Singletons.getModel().getEditions(),
* the count count,
*/ TournamentPack.FN_FROM_SET));
public void generateTournamentsInShop(final int count) { }
Predicate<CardEdition> hasTournament = CardEdition.Predicates.HAS_TOURNAMENT_PACK;
this.q.getShopList().addAllFlat(hasTournament.random(Singletons.getModel().getEditions(), count, TournamentPack.FN_FROM_SET)); public void generateFatPacksInShop(final int count) {
} Predicate<CardEdition> hasPack = CardEdition.Predicates.HAS_FAT_PACK;
this.q.getShopList().addAllFlat(hasPack.random(Singletons.getModel().getEditions(), count, FatPack.FN_FROM_SET));
public void generateFatPacksInShop(final int count) { }
Predicate<CardEdition> hasPack = CardEdition.Predicates.HAS_FAT_PACK;
this.q.getShopList().addAllFlat(hasPack.random(Singletons.getModel().getEditions(), count, FatPack.FN_FROM_SET)); /**
} * Generate precons in shop.
*
/** * @param count
* Generate precons in shop. * the count
* */
* @param count public void generatePreconsInShop(final int count) {
* the count final List<PreconDeck> meetRequirements = new ArrayList<PreconDeck>();
*/ for (final PreconDeck deck : QuestData.getPrecons()) {
public void generatePreconsInShop(final int count) { if (deck.getRecommendedDeals().meetsRequiremnts(this.q)) {
final List<PreconDeck> meetRequirements = new ArrayList<PreconDeck>(); meetRequirements.add(deck);
for (final PreconDeck deck : QuestData.getPrecons()) { }
if (deck.getRecommendedDeals().meetsRequiremnts(this.q)) { }
meetRequirements.add(deck); this.q.getShopList().addAllFlat(Predicate.getTrue(PreconDeck.class).random(meetRequirements, count));
} }
}
this.q.getShopList().addAllFlat(Predicate.getTrue(PreconDeck.class).random(meetRequirements, count)); /**
} * Generate cards in shop.
*/
/** public void generateCardsInShop() {
* Generate cards in shop. final BoosterGenerator pack = new BoosterGenerator(CardDb.instance().getAllCards());
*/
public void generateCardsInShop() { // Preferences
final BoosterGenerator pack = new BoosterGenerator(CardDb.instance().getAllCards()); final int startPacks = this.qpref.getPreferenceInt(QPref.SHOP_STARTING_PACKS);
final int winsForPack = this.qpref.getPreferenceInt(QPref.SHOP_WINS_FOR_ADDITIONAL_PACK);
// Preferences final int maxPacks = this.qpref.getPreferenceInt(QPref.SHOP_MAX_PACKS);
final int startPacks = this.qpref.getPreferenceInt(QPref.SHOP_STARTING_PACKS); final int common = this.qpref.getPreferenceInt(QPref.SHOP_SINGLES_COMMON);
final int winsForPack = this.qpref.getPreferenceInt(QPref.SHOP_WINS_FOR_ADDITIONAL_PACK); final int uncommon = this.qpref.getPreferenceInt(QPref.SHOP_SINGLES_UNCOMMON);
final int maxPacks = this.qpref.getPreferenceInt(QPref.SHOP_MAX_PACKS); final int rare = this.qpref.getPreferenceInt(QPref.SHOP_SINGLES_RARE);
final int common = this.qpref.getPreferenceInt(QPref.SHOP_SINGLES_COMMON);
final int uncommon = this.qpref.getPreferenceInt(QPref.SHOP_SINGLES_UNCOMMON); final int levelPacks = this.q.getLevel() > 0 ? startPacks / this.q.getLevel() : startPacks;
final int rare = this.qpref.getPreferenceInt(QPref.SHOP_SINGLES_RARE); final int winPacks = this.q.getWin() / winsForPack;
final int totalPacks = Math.min(levelPacks + winPacks, maxPacks);
final int levelPacks = this.q.getLevel() > 0 ? startPacks / this.q.getLevel() : startPacks;
final int winPacks = this.q.getWin() / winsForPack; this.q.getShopList().clear();
final int totalPacks = Math.min(levelPacks + winPacks, maxPacks); for (int i = 0; i < totalPacks; i++) {
this.q.getShopList().addAllFlat(pack.getBoosterPack(common, uncommon, rare, 0, 0, 0, 0, 0, 0));
this.q.getShopList().clear(); }
for (int i = 0; i < totalPacks; i++) {
this.q.getShopList().addAllFlat(pack.getBoosterPack(common, uncommon, rare, 0, 0, 0, 0, 0, 0)); this.generateBoostersInShop(totalPacks);
} this.generatePreconsInShop(totalPacks);
this.generateTournamentsInShop(totalPacks);
this.generateBoostersInShop(totalPacks); this.generateFatPacksInShop(totalPacks);
this.generatePreconsInShop(totalPacks); this.q.getShopList().addAll(QuestUtilCards.generateBasicLands(10, 5));
this.generateTournamentsInShop(totalPacks); }
this.generateFatPacksInShop(totalPacks);
this.q.getShopList().addAll(QuestUtilCards.generateBasicLands(10, 5)); /**
} * Gets the cardpool.
*
/** * @return the cardpool
* Gets the cardpool. */
* public ItemPool<CardPrinted> getCardpool() {
* @return the cardpool return this.q.getCardPool();
*/ }
public ItemPool<CardPrinted> getCardpool() {
return this.q.getCardPool(); /**
} * Gets the shop list.
*
/** * @return the shop list
* Gets the shop list. */
* public ItemPoolView<InventoryItem> getShopList() {
* @return the shop list if (this.q.getShopList().isEmpty()) {
*/ this.generateCardsInShop();
public ItemPoolView<InventoryItem> getShopList() { }
if (this.q.getShopList().isEmpty()) { return this.q.getShopList();
this.generateCardsInShop(); }
}
return this.q.getShopList(); /**
} * Gets the new cards.
*
/** * @return the new cards
* Gets the new cards. */
* public ItemPoolView<InventoryItem> getNewCards() {
* @return the new cards return this.q.getNewCardList();
*/ }
public ItemPoolView<InventoryItem> getNewCards() {
return this.q.getNewCardList(); /**
} * Reset new list.
*/
/** public void resetNewList() {
* Reset new list. this.q.getNewCardList().clear();
*/ }
public void resetNewList() {
this.q.getNewCardList().clear(); /**
} * Gets the fn new compare.
*
/** * @return the fnNewCompare
* Gets the fn new compare. */
* @SuppressWarnings("rawtypes")
* @return the fnNewCompare public Lambda1<Comparable, Entry<InventoryItem, Integer>> getFnNewCompare() {
*/ return this.fnNewCompare;
@SuppressWarnings("rawtypes") }
public Lambda1<Comparable, Entry<InventoryItem, Integer>> getFnNewCompare() {
return this.fnNewCompare; /**
} * Gets the fn new get.
*
/** * @return the fnNewGet
* Gets the fn new get. */
* public Lambda1<Object, Entry<InventoryItem, Integer>> getFnNewGet() {
* @return the fnNewGet return this.fnNewGet;
*/ }
public Lambda1<Object, Entry<InventoryItem, Integer>> getFnNewGet() {
return this.fnNewGet; // These functions provide a way to sort and compare cards in a table
} // according to their new-ness
// It might be a good idea to store them in a base class for both quest-mode
// These functions provide a way to sort and compare cards in a table // deck editors
// according to their new-ness // Maybe we should consider doing so later
// It might be a good idea to store them in a base class for both quest-mode /** The fn new compare. */
// deck editors @SuppressWarnings("rawtypes")
// Maybe we should consider doing so later private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnNewCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
/** The fn new compare. */ @Override
@SuppressWarnings("rawtypes") public Comparable apply(final Entry<InventoryItem, Integer> from) {
private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnNewCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { return QuestUtilCards.this.q.getNewCardList().contains(from.getKey()) ? Integer.valueOf(1) : Integer
@Override .valueOf(0);
public Comparable apply(final Entry<InventoryItem, Integer> from) { }
return QuestUtilCards.this.q.getNewCardList().contains(from.getKey()) ? Integer.valueOf(1) : Integer };
.valueOf(0);
} /** The fn new get. */
}; private final Lambda1<Object, Entry<InventoryItem, Integer>> fnNewGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
@Override
/** The fn new get. */ public Object apply(final Entry<InventoryItem, Integer> from) {
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnNewGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() { return QuestUtilCards.this.q.getNewCardList().contains(from.getKey()) ? "NEW" : "";
@Override }
public Object apply(final Entry<InventoryItem, Integer> from) { };
return QuestUtilCards.this.q.getNewCardList().contains(from.getKey()) ? "NEW" : ""; }
}
};
}