mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
Added option to start quests with a precon deck
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -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/QuestEventManager.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/QuestUtilCards.java -text
|
||||
src/main/java/forge/quest/data/bazaar/QuestStallDefinition.java svneol=native#text/plain
|
||||
|
||||
@@ -1,186 +1,198 @@
|
||||
package forge.gui.home.quest;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.Command;
|
||||
import forge.Singletons;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.home.ICSubmenu;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.quest.data.QuestData;
|
||||
import forge.quest.data.QuestDataIO;
|
||||
import forge.quest.data.QuestPreferences.QPref;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public enum CSubmenuQuestData implements ICSubmenu {
|
||||
/** */
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
private final Map<String, QuestData> arrQuests = new HashMap<String, QuestData>();
|
||||
|
||||
private final Command cmdQuestSelect = new Command() { @Override
|
||||
public void execute() { changeQuest(); } };
|
||||
|
||||
private final Command cmdQuestDelete = new Command() { @Override
|
||||
public void execute() { update(); } };
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#update()
|
||||
*/
|
||||
@Override
|
||||
public void initialize() {
|
||||
VSubmenuQuestData.SINGLETON_INSTANCE.populate();
|
||||
CSubmenuQuestData.SINGLETON_INSTANCE.update();
|
||||
|
||||
VSubmenuQuestData.SINGLETON_INSTANCE.getBtnEmbark().setCommand(
|
||||
new Command() { @Override public void execute() { newQuest(); } });
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#getCommand()
|
||||
*/
|
||||
@Override
|
||||
public Command getMenuCommand() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#update()
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
final VSubmenuQuestData view = VSubmenuQuestData.SINGLETON_INSTANCE;
|
||||
final File dirQuests = ForgeProps.getFile(NewConstants.Quest.DATA_DIR);
|
||||
|
||||
// Temporary transition code between v1.2.2 and v1.2.3.
|
||||
// Can be safely deleted after release of 1.2.3.
|
||||
if (!dirQuests.exists()) {
|
||||
dirQuests.mkdirs();
|
||||
}
|
||||
File olddata = new File("res/quest/questData.dat");
|
||||
File newpath = new File(dirQuests.getPath() + "/questData.dat");
|
||||
|
||||
if (olddata.exists()) { olddata.renameTo(newpath); }
|
||||
// end block which can be deleted
|
||||
|
||||
// Iterate over files and load quest datas for each.
|
||||
FilenameFilter takeDatFiles = new FilenameFilter() {
|
||||
@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) {
|
||||
arrQuests.put(f.getName(), QuestDataIO.loadData(f));
|
||||
}
|
||||
|
||||
// Populate list with available quest datas.
|
||||
view.getLstQuests().setQuests(arrQuests.values().toArray(new QuestData[0]));
|
||||
|
||||
// If there are quests available, force select.
|
||||
if (arrQuests.size() > 0) {
|
||||
final String questname = Singletons.getModel().getQuestPreferences()
|
||||
.getPreference(QPref.CURRENT_QUEST);
|
||||
|
||||
// Attempt to select previous quest.
|
||||
if (arrQuests.get(questname) != null) {
|
||||
view.getLstQuests().setSelectedQuestData(arrQuests.get(questname));
|
||||
}
|
||||
else {
|
||||
view.getLstQuests().setSelectedIndex(0);
|
||||
}
|
||||
|
||||
// Drop into AllZone.
|
||||
AllZone.setQuestData(view.getLstQuests().getSelectedQuest());
|
||||
}
|
||||
else {
|
||||
AllZone.setQuestData(null);
|
||||
}
|
||||
|
||||
view.getLstQuests().setSelectCommand(cmdQuestSelect);
|
||||
view.getLstQuests().setDeleteCommand(cmdQuestDelete);
|
||||
}
|
||||
|
||||
/**
|
||||
* The actuator for new quests.
|
||||
*/
|
||||
private void newQuest() {
|
||||
final VSubmenuQuestData view = VSubmenuQuestData.SINGLETON_INSTANCE;
|
||||
int difficulty = 0;
|
||||
QuestData newdata = new QuestData();
|
||||
|
||||
final String mode = view.getRadFantasy().isSelected()
|
||||
? forge.quest.data.QuestData.FANTASY
|
||||
: forge.quest.data.QuestData.CLASSIC;
|
||||
|
||||
if (view.getRadEasy().isSelected()) {
|
||||
difficulty = 0;
|
||||
} else if (view.getRadMedium().isSelected()) {
|
||||
difficulty = 1;
|
||||
} else if (view.getRadHard().isSelected()) {
|
||||
difficulty = 2;
|
||||
} else if (view.getRadExpert().isSelected()) {
|
||||
difficulty = 3;
|
||||
} 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 String questName = GuiUtils.cleanString(o.toString());
|
||||
|
||||
if (getAllQuests().get(questName) != null || questName.equals("")) {
|
||||
JOptionPane.showMessageDialog(null, "Please pick another quest name, a quest already has that name.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Give the user a few cards to build a deck
|
||||
newdata.newGame(difficulty, mode, view.getCbStandardStart().isSelected());
|
||||
newdata.setName(questName);
|
||||
newdata.saveData();
|
||||
|
||||
// Save in preferences.
|
||||
Singletons.getModel().getQuestPreferences().setPreference(QPref.CURRENT_QUEST, questName + ".dat");
|
||||
Singletons.getModel().getQuestPreferences().save();
|
||||
|
||||
update();
|
||||
} // New Quest
|
||||
|
||||
/** Changes between quest data files. */
|
||||
private void changeQuest() {
|
||||
AllZone.setQuestData(VSubmenuQuestData.SINGLETON_INSTANCE
|
||||
.getLstQuests().getSelectedQuest());
|
||||
|
||||
// Save in preferences.
|
||||
Singletons.getModel().getQuestPreferences().setPreference(QPref.CURRENT_QUEST,
|
||||
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;
|
||||
}
|
||||
}
|
||||
package forge.gui.home.quest;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.Command;
|
||||
import forge.Singletons;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.home.ICSubmenu;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.quest.data.QuestData;
|
||||
import forge.quest.data.QuestDataIO;
|
||||
import forge.quest.data.QuestPreferences.QPref;
|
||||
import forge.quest.data.QuestStartPool;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static forge.quest.data.QuestStartPool.*;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public enum CSubmenuQuestData implements ICSubmenu {
|
||||
/** */
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
private final Map<String, QuestData> arrQuests = new HashMap<String, QuestData>();
|
||||
|
||||
private final Command cmdQuestSelect = new Command() { @Override
|
||||
public void execute() { changeQuest(); } };
|
||||
|
||||
private final Command cmdQuestDelete = new Command() { @Override
|
||||
public void execute() { update(); } };
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#update()
|
||||
*/
|
||||
@Override
|
||||
public void initialize() {
|
||||
VSubmenuQuestData.SINGLETON_INSTANCE.populate();
|
||||
CSubmenuQuestData.SINGLETON_INSTANCE.update();
|
||||
|
||||
VSubmenuQuestData.SINGLETON_INSTANCE.getBtnEmbark().setCommand(
|
||||
new Command() { @Override public void execute() { newQuest(); } });
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#getCommand()
|
||||
*/
|
||||
@Override
|
||||
public Command getMenuCommand() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#update()
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
final VSubmenuQuestData view = VSubmenuQuestData.SINGLETON_INSTANCE;
|
||||
final File dirQuests = ForgeProps.getFile(NewConstants.Quest.DATA_DIR);
|
||||
|
||||
// Temporary transition code between v1.2.2 and v1.2.3.
|
||||
// Can be safely deleted after release of 1.2.3.
|
||||
if (!dirQuests.exists()) {
|
||||
dirQuests.mkdirs();
|
||||
}
|
||||
File olddata = new File("res/quest/questData.dat");
|
||||
File newpath = new File(dirQuests.getPath() + "/questData.dat");
|
||||
|
||||
if (olddata.exists()) { olddata.renameTo(newpath); }
|
||||
// end block which can be deleted
|
||||
|
||||
// Iterate over files and load quest datas for each.
|
||||
FilenameFilter takeDatFiles = new FilenameFilter() {
|
||||
@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) {
|
||||
arrQuests.put(f.getName(), QuestDataIO.loadData(f));
|
||||
}
|
||||
|
||||
// Populate list with available quest datas.
|
||||
view.getLstQuests().setQuests(arrQuests.values().toArray(new QuestData[0]));
|
||||
|
||||
// If there are quests available, force select.
|
||||
if (arrQuests.size() > 0) {
|
||||
final String questname = Singletons.getModel().getQuestPreferences()
|
||||
.getPreference(QPref.CURRENT_QUEST);
|
||||
|
||||
// Attempt to select previous quest.
|
||||
if (arrQuests.get(questname) != null) {
|
||||
view.getLstQuests().setSelectedQuestData(arrQuests.get(questname));
|
||||
}
|
||||
else {
|
||||
view.getLstQuests().setSelectedIndex(0);
|
||||
}
|
||||
|
||||
// Drop into AllZone.
|
||||
AllZone.setQuestData(view.getLstQuests().getSelectedQuest());
|
||||
}
|
||||
else {
|
||||
AllZone.setQuestData(null);
|
||||
}
|
||||
|
||||
view.getLstQuests().setSelectCommand(cmdQuestSelect);
|
||||
view.getLstQuests().setDeleteCommand(cmdQuestDelete);
|
||||
}
|
||||
|
||||
/**
|
||||
* The actuator for new quests.
|
||||
*/
|
||||
private void newQuest() {
|
||||
final VSubmenuQuestData view = VSubmenuQuestData.SINGLETON_INSTANCE;
|
||||
int difficulty = 0;
|
||||
QuestData newdata = new QuestData();
|
||||
|
||||
final String mode = view.getRadFantasy().isSelected()
|
||||
? forge.quest.data.QuestData.FANTASY
|
||||
: forge.quest.data.QuestData.CLASSIC;
|
||||
|
||||
if (view.getRadEasy().isSelected()) {
|
||||
difficulty = 0;
|
||||
} else if (view.getRadMedium().isSelected()) {
|
||||
difficulty = 1;
|
||||
} else if (view.getRadHard().isSelected()) {
|
||||
difficulty = 2;
|
||||
} else if (view.getRadExpert().isSelected()) {
|
||||
difficulty = 3;
|
||||
} else {
|
||||
throw new IllegalStateException(
|
||||
"ControlQuest() > newQuest(): Error starting new quest!");
|
||||
}
|
||||
|
||||
final QuestStartPool startPool;
|
||||
final String startPrecon = view.getPrecon();
|
||||
if (view.getRadCompleteStart().isSelected()) {
|
||||
startPool = COMPLETE;
|
||||
} else if (view.getRadStandardStart().isSelected()) {
|
||||
startPool = STANDARD;
|
||||
} else {
|
||||
startPool = PRECON;
|
||||
}
|
||||
|
||||
final Object o = JOptionPane.showInputDialog(null, "Poets will remember your quest as:", "Quest Name", JOptionPane.OK_CANCEL_OPTION);
|
||||
|
||||
if (o == null) { return; }
|
||||
|
||||
final String questName = GuiUtils.cleanString(o.toString());
|
||||
|
||||
if (getAllQuests().get(questName) != null || questName.equals("")) {
|
||||
JOptionPane.showMessageDialog(null, "Please pick another quest name, a quest already has that name.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Give the user a few cards to build a deck
|
||||
newdata.newGame(difficulty, mode, startPool, startPrecon);
|
||||
newdata.setName(questName);
|
||||
newdata.saveData();
|
||||
|
||||
// Save in preferences.
|
||||
Singletons.getModel().getQuestPreferences().setPreference(QPref.CURRENT_QUEST, questName + ".dat");
|
||||
Singletons.getModel().getQuestPreferences().save();
|
||||
|
||||
update();
|
||||
} // New Quest
|
||||
|
||||
/** Changes between quest data files. */
|
||||
private void changeQuest() {
|
||||
AllZone.setQuestData(VSubmenuQuestData.SINGLETON_INSTANCE
|
||||
.getLstQuests().getSelectedQuest());
|
||||
|
||||
// Save in preferences.
|
||||
Singletons.getModel().getQuestPreferences().setPreference(QPref.CURRENT_QUEST,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,204 +1,238 @@
|
||||
package forge.gui.home.quest;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import forge.gui.home.EMenuGroup;
|
||||
import forge.gui.home.EMenuItem;
|
||||
import forge.gui.home.ICSubmenu;
|
||||
import forge.gui.home.IVSubmenu;
|
||||
import forge.gui.toolbox.FCheckBox;
|
||||
import forge.gui.toolbox.FLabel;
|
||||
import forge.gui.toolbox.FPanel;
|
||||
import forge.gui.toolbox.FRadioButton;
|
||||
import forge.gui.toolbox.FScrollPane;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
|
||||
/**
|
||||
* Singleton instance of "Colors" submenu in "Constructed" group.
|
||||
*
|
||||
*/
|
||||
public enum VSubmenuQuestData implements IVSubmenu {
|
||||
/** */
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
/** */
|
||||
private final JPanel pnl = new JPanel();
|
||||
private final JPanel pnlViewport = new JPanel();
|
||||
private final QuestFileLister lstQuests = new QuestFileLister();
|
||||
|
||||
private final JRadioButton radEasy = new FRadioButton("Easy");
|
||||
private final JRadioButton radMedium = new FRadioButton("Medium");
|
||||
private final JRadioButton radHard = new FRadioButton("Hard");
|
||||
private final JRadioButton radExpert = new FRadioButton("Expert");
|
||||
private final JRadioButton radFantasy = new FRadioButton("Fantasy");
|
||||
private final JRadioButton radClassic = new FRadioButton("Classic");
|
||||
|
||||
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();
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.view.home.IViewSubmenu#populate()
|
||||
*/
|
||||
@Override
|
||||
public void populate() {
|
||||
pnl.removeAll();
|
||||
pnl.setOpaque(false);
|
||||
pnl.setLayout(new MigLayout("insets 0, gap 0"));
|
||||
|
||||
// Load quest
|
||||
final FPanel pnlTitleLoad = new FPanel();
|
||||
pnlTitleLoad.setLayout(new MigLayout("insets 0, align center"));
|
||||
pnlTitleLoad.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
||||
pnlTitleLoad.add(new FLabel.Builder().text("Load a previous Quest")
|
||||
.fontScaleAuto(false).fontSize(16).build(), "h 95%!, gap 0 0 2.5% 0");
|
||||
|
||||
final FScrollPane scr = new FScrollPane(lstQuests);
|
||||
scr.setBorder(null);
|
||||
scr.getViewport().setBorder(null);
|
||||
|
||||
// New quest
|
||||
final FPanel pnlTitleNew = new FPanel();
|
||||
pnlTitleNew.setLayout(new MigLayout("insets 0, align center"));
|
||||
pnlTitleNew.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
||||
pnlTitleNew.add(new FLabel.Builder().text("Start a new Quest")
|
||||
.fontScaleAuto(false).fontSize(16).build(), "h 95%!, gap 0 0 2.5% 0");
|
||||
|
||||
final ButtonGroup group1 = new ButtonGroup();
|
||||
group1.add(radEasy);
|
||||
group1.add(radMedium);
|
||||
group1.add(radHard);
|
||||
group1.add(radExpert);
|
||||
|
||||
radEasy.setSelected(true);
|
||||
radClassic.setSelected(true);
|
||||
|
||||
final ButtonGroup group2 = new ButtonGroup();
|
||||
group2.add(radFantasy);
|
||||
group2.add(radClassic);
|
||||
|
||||
final JPanel pnlOptions = new JPanel();
|
||||
pnlOptions.setOpaque(false);
|
||||
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");
|
||||
pnlOptions.add(radFantasy, constraints + ", wrap");
|
||||
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");
|
||||
pnlOptions.add(cbStandardStart, constraints + ", wrap");
|
||||
pnlOptions.add(radExpert, constraints + ", gap 7.5% 2.5% 0 0, wrap");
|
||||
|
||||
pnlOptions.add(btnEmbark, "w 40%!, h 30px!, gap 30% 0 20px 0, span 3 1");
|
||||
|
||||
// Final layout
|
||||
pnlViewport.removeAll();
|
||||
pnlViewport.setOpaque(false);
|
||||
pnlViewport.setLayout(new MigLayout("insets 0, gap 0, wrap"));
|
||||
|
||||
pnlViewport.add(pnlTitleLoad, "w 96%, h 36px!, gap 2% 0 20px 10px");
|
||||
|
||||
pnlViewport.add(new FLabel.Builder().text("Old quest data? Put into "
|
||||
+ "res/quest/data, and restart Forge.")
|
||||
.fontAlign(SwingConstants.CENTER).fontScaleAuto(false).fontSize(12)
|
||||
.build(), "w 96%!, h 18px!, gap 2% 0 0 4px");
|
||||
|
||||
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 200px!, gap 2% 0 0 20px");
|
||||
|
||||
pnl.add(new FScrollPane(pnlViewport), "w 100%!, h 100%!");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.view.home.IViewSubmenu#getGroup()
|
||||
*/
|
||||
@Override
|
||||
public EMenuGroup getGroupEnum() {
|
||||
return EMenuGroup.QUEST;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.view.home.IViewSubmenu#getPanel()
|
||||
*/
|
||||
@Override
|
||||
public JPanel getPanel() {
|
||||
return pnl;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.home.IVSubmenu#getMenuTitle()
|
||||
*/
|
||||
@Override
|
||||
public String getMenuTitle() {
|
||||
return "New / Load Quest";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.home.IVSubmenu#getMenuName()
|
||||
*/
|
||||
@Override
|
||||
public String getItemEnum() {
|
||||
return EMenuItem.QUEST_DATA.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.home.IVSubmenu#getControl()
|
||||
*/
|
||||
@Override
|
||||
public ICSubmenu getControl() {
|
||||
return CSubmenuQuestData.SINGLETON_INSTANCE;
|
||||
}
|
||||
|
||||
/** @return {@link forge.gui.home.quest.QuestFileLister} */
|
||||
public QuestFileLister getLstQuests() {
|
||||
return this.lstQuests;
|
||||
}
|
||||
|
||||
/** @return {@link javax.swing.JRadioButton} */
|
||||
public JRadioButton getRadEasy() {
|
||||
return radEasy;
|
||||
}
|
||||
|
||||
/** @return {@link javax.swing.JRadioButton} */
|
||||
public JRadioButton getRadMedium() {
|
||||
return radMedium;
|
||||
}
|
||||
|
||||
/** @return {@link javax.swing.JRadioButton} */
|
||||
public JRadioButton getRadHard() {
|
||||
return radHard;
|
||||
}
|
||||
|
||||
/** @return {@link javax.swing.JRadioButton} */
|
||||
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;
|
||||
}
|
||||
|
||||
/** @return {@link javax.swing.JCheckBox} */
|
||||
public JCheckBox getCbStandardStart() {
|
||||
return cbStandardStart;
|
||||
}
|
||||
|
||||
/** @return {@link forge.gui.toolbox.FLabel} */
|
||||
public FLabel getBtnEmbark() {
|
||||
return btnEmbark;
|
||||
}
|
||||
}
|
||||
package forge.gui.home.quest;
|
||||
|
||||
import forge.gui.home.EMenuGroup;
|
||||
import forge.gui.home.EMenuItem;
|
||||
import forge.gui.home.ICSubmenu;
|
||||
import forge.gui.home.IVSubmenu;
|
||||
import forge.gui.toolbox.*;
|
||||
import forge.quest.data.QuestData;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* Singleton instance of "Colors" submenu in "Constructed" group.
|
||||
*
|
||||
*/
|
||||
public enum VSubmenuQuestData implements IVSubmenu {
|
||||
/** */
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
/** */
|
||||
private final JPanel pnl = new JPanel();
|
||||
private final JPanel pnlViewport = new JPanel();
|
||||
private final QuestFileLister lstQuests = new QuestFileLister();
|
||||
|
||||
private final JRadioButton radEasy = new FRadioButton("Easy");
|
||||
private final JRadioButton radMedium = new FRadioButton("Medium");
|
||||
private final JRadioButton radHard = new FRadioButton("Hard");
|
||||
private final JRadioButton radExpert = new FRadioButton("Expert");
|
||||
|
||||
private final JRadioButton radFantasy = new FRadioButton("Fantasy");
|
||||
private final JRadioButton radClassic = new FRadioButton("Classic");
|
||||
|
||||
private final JRadioButton radCompleteStart = new FRadioButton("Unrestricted Starting Pool");
|
||||
private final JRadioButton radStandardStart = new FRadioButton("Standard (Type 2) Starting Pool");
|
||||
private final JRadioButton radPreconStart = new FRadioButton("Preconstructed Deck: ");
|
||||
private final JComboBox cbxPrecon = new JComboBox();
|
||||
|
||||
private final FLabel btnEmbark = new FLabel.Builder().opaque(true).hoverable(true).text("Embark!").build();
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.view.home.IViewSubmenu#populate()
|
||||
*/
|
||||
@Override
|
||||
public void populate() {
|
||||
pnl.removeAll();
|
||||
pnl.setOpaque(false);
|
||||
pnl.setLayout(new MigLayout("insets 0, gap 0"));
|
||||
|
||||
// Load quest
|
||||
final FPanel pnlTitleLoad = new FPanel();
|
||||
pnlTitleLoad.setLayout(new MigLayout("insets 0, align center"));
|
||||
pnlTitleLoad.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
||||
pnlTitleLoad.add(new FLabel.Builder().text("Load a previous Quest")
|
||||
.fontScaleAuto(false).fontSize(16).build(), "h 95%!, gap 0 0 2.5% 0");
|
||||
|
||||
final FScrollPane scr = new FScrollPane(lstQuests);
|
||||
scr.setBorder(null);
|
||||
scr.getViewport().setBorder(null);
|
||||
|
||||
// New quest
|
||||
final FPanel pnlTitleNew = new FPanel();
|
||||
pnlTitleNew.setLayout(new MigLayout("insets 0, align center"));
|
||||
pnlTitleNew.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
||||
pnlTitleNew.add(new FLabel.Builder().text("Start a new Quest")
|
||||
.fontScaleAuto(false).fontSize(16).build(), "h 95%!, gap 0 0 2.5% 0");
|
||||
|
||||
final ButtonGroup group1 = new ButtonGroup();
|
||||
group1.add(radEasy);
|
||||
group1.add(radMedium);
|
||||
group1.add(radHard);
|
||||
group1.add(radExpert);
|
||||
radEasy.setSelected(true);
|
||||
|
||||
final ButtonGroup group2 = new ButtonGroup();
|
||||
group2.add(radFantasy);
|
||||
group2.add(radClassic);
|
||||
radClassic.setSelected(true);
|
||||
|
||||
final ActionListener preconListener = new ActionListener() {
|
||||
@Override public void actionPerformed(ActionEvent actionEvent) {
|
||||
cbxPrecon.setEnabled(radPreconStart.isSelected());
|
||||
}
|
||||
};
|
||||
|
||||
for (String preconDeck : QuestData.getPrecons().getNames()) {
|
||||
cbxPrecon.addItem(preconDeck);
|
||||
}
|
||||
|
||||
final ButtonGroup group3 = new ButtonGroup();
|
||||
group3.add(radCompleteStart);
|
||||
radCompleteStart.addActionListener(preconListener);
|
||||
group3.add(radStandardStart);
|
||||
radStandardStart.addActionListener(preconListener);
|
||||
group3.add(radPreconStart);
|
||||
radPreconStart.addActionListener(preconListener);
|
||||
radCompleteStart.setSelected(true);
|
||||
cbxPrecon.setEnabled(false);
|
||||
final JPanel pnlOptions = new JPanel();
|
||||
pnlOptions.setOpaque(false);
|
||||
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");
|
||||
pnlOptions.add(radFantasy, constraints + ", wrap");
|
||||
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");
|
||||
pnlOptions.add(radCompleteStart, constraints + ", wrap");
|
||||
pnlOptions.add(radExpert, constraints + ", gap 7.5% 2.5% 0 0 ");
|
||||
pnlOptions.add(radStandardStart, constraints + ", wrap");
|
||||
pnlOptions.add(radPreconStart, constraints + ", wrap, skip");
|
||||
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");
|
||||
|
||||
// Final layout
|
||||
pnlViewport.removeAll();
|
||||
pnlViewport.setOpaque(false);
|
||||
pnlViewport.setLayout(new MigLayout("insets 0, gap 0, wrap"));
|
||||
|
||||
pnlViewport.add(pnlTitleLoad, "w 96%, h 36px!, gap 2% 0 20px 10px");
|
||||
|
||||
pnlViewport.add(new FLabel.Builder().text("Old quest data? Put into "
|
||||
+ "res/quest/data, and restart Forge.")
|
||||
.fontAlign(SwingConstants.CENTER).fontScaleAuto(false).fontSize(12)
|
||||
.build(), "w 96%!, h 18px!, gap 2% 0 0 4px");
|
||||
|
||||
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");
|
||||
|
||||
pnl.add(new FScrollPane(pnlViewport), "w 100%!, h 100%!");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.view.home.IViewSubmenu#getGroup()
|
||||
*/
|
||||
@Override
|
||||
public EMenuGroup getGroupEnum() {
|
||||
return EMenuGroup.QUEST;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.view.home.IViewSubmenu#getPanel()
|
||||
*/
|
||||
@Override
|
||||
public JPanel getPanel() {
|
||||
return pnl;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.home.IVSubmenu#getMenuTitle()
|
||||
*/
|
||||
@Override
|
||||
public String getMenuTitle() {
|
||||
return "New / Load Quest";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.home.IVSubmenu#getMenuName()
|
||||
*/
|
||||
@Override
|
||||
public String getItemEnum() {
|
||||
return EMenuItem.QUEST_DATA.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.home.IVSubmenu#getControl()
|
||||
*/
|
||||
@Override
|
||||
public ICSubmenu getControl() {
|
||||
return CSubmenuQuestData.SINGLETON_INSTANCE;
|
||||
}
|
||||
|
||||
/** @return {@link forge.gui.home.quest.QuestFileLister} */
|
||||
public QuestFileLister getLstQuests() {
|
||||
return this.lstQuests;
|
||||
}
|
||||
|
||||
/** @return {@link javax.swing.JRadioButton} */
|
||||
public JRadioButton getRadEasy() {
|
||||
return radEasy;
|
||||
}
|
||||
|
||||
/** @return {@link javax.swing.JRadioButton} */
|
||||
public JRadioButton getRadMedium() {
|
||||
return radMedium;
|
||||
}
|
||||
|
||||
/** @return {@link javax.swing.JRadioButton} */
|
||||
public JRadioButton getRadHard() {
|
||||
return radHard;
|
||||
}
|
||||
|
||||
/** @return {@link javax.swing.JRadioButton} */
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,28 +17,19 @@
|
||||
*/
|
||||
package forge.quest.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.deck.Deck;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.item.PreconDeck;
|
||||
import forge.item.*;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.quest.data.QuestPreferences.QPref;
|
||||
import forge.quest.data.item.QuestInventory;
|
||||
import forge.quest.data.pet.QuestPetManager;
|
||||
import forge.util.Predicate;
|
||||
import forge.util.StorageView;
|
||||
import forge.util.IStorage;
|
||||
import forge.util.IStorageView;
|
||||
import forge.util.MyRandom;
|
||||
import forge.util.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
//when you create QuestDataOld and AFTER you copy the AI decks over
|
||||
//you have to call one of these two methods below
|
||||
@@ -172,8 +163,8 @@ public final class QuestData {
|
||||
private transient QuestEvent currentEvent;
|
||||
|
||||
// This is used by shop. Had no idea where else to place this
|
||||
private static transient IStorageView<PreconDeck> preconManager = new StorageView<PreconDeck>(new PreconReader(
|
||||
ForgeProps.getFile(NewConstants.Quest.PRECONS)));
|
||||
private static transient IStorageView<PreconDeck> preconManager =
|
||||
new StorageView<PreconDeck>(new PreconReader(ForgeProps.getFile(NewConstants.Quest.PRECONS)));
|
||||
|
||||
/** The Constant RANK_TITLES. */
|
||||
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
|
||||
* the diff
|
||||
* @param m0de
|
||||
* the m0de
|
||||
* @param standardStart
|
||||
* the standard start
|
||||
* @param mode
|
||||
* the mode
|
||||
* @param startPool
|
||||
* 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);
|
||||
|
||||
final Predicate<CardPrinted> filter = standardStart ? Singletons.getModel().getFormats().getStandard()
|
||||
.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.mode = mode;
|
||||
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
|
||||
|
||||
7
src/main/java/forge/quest/data/QuestStartPool.java
Normal file
7
src/main/java/forge/quest/data/QuestStartPool.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package forge.quest.data;
|
||||
|
||||
public enum QuestStartPool {
|
||||
COMPLETE,
|
||||
STANDARD,
|
||||
PRECON
|
||||
}
|
||||
@@ -1,492 +1,489 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.quest.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.slightlymagic.braids.util.lambda.Lambda1;
|
||||
import forge.Singletons;
|
||||
import forge.card.BoosterGenerator;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.FormatCollection;
|
||||
import forge.deck.Deck;
|
||||
import forge.item.BoosterPack;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.FatPack;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.item.OpenablePack;
|
||||
import forge.item.PreconDeck;
|
||||
import forge.item.TournamentPack;
|
||||
import forge.quest.BoosterUtils;
|
||||
import forge.quest.data.QuestPreferences.QPref;
|
||||
import forge.util.MyRandom;
|
||||
import forge.util.Predicate;
|
||||
|
||||
/**
|
||||
* This is a helper class to execute operations on QuestData. It has been
|
||||
* created to decrease complexity of questData class
|
||||
*/
|
||||
public final class QuestUtilCards {
|
||||
private final QuestData q;
|
||||
private final QuestPreferences qpref;
|
||||
|
||||
/**
|
||||
* Instantiates a new quest util cards.
|
||||
*
|
||||
* @param qd
|
||||
* the qd
|
||||
*/
|
||||
public QuestUtilCards(final QuestData qd) {
|
||||
this.q = qd;
|
||||
this.qpref = Singletons.getModel().getQuestPreferences();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the basic lands.
|
||||
*
|
||||
* @param nBasic the n basic
|
||||
* @param nSnow the n snow
|
||||
* @return the item pool view
|
||||
*/
|
||||
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);
|
||||
pool.add(db.getCard("Forest", "M10"), nBasic);
|
||||
pool.add(db.getCard("Mountain", "M10"), nBasic);
|
||||
pool.add(db.getCard("Swamp", "M10"), nBasic);
|
||||
pool.add(db.getCard("Island", "M10"), nBasic);
|
||||
pool.add(db.getCard("Plains", "M10"), nBasic);
|
||||
|
||||
pool.add(db.getCard("Snow-Covered Forest", "ICE"), nSnow);
|
||||
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);
|
||||
pool.add(db.getCard("Snow-Covered Plains", "ICE"), nSnow);
|
||||
return pool;
|
||||
}
|
||||
|
||||
// adds 11 cards, to the current card pool
|
||||
// (I chose 11 cards instead of 15 in order to make things more challenging)
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* addCards.
|
||||
* </p>
|
||||
*
|
||||
* @param fSets
|
||||
* the f sets
|
||||
* @return the array list
|
||||
*/
|
||||
public ArrayList<CardPrinted> addCards(final Predicate<CardPrinted> fSets) {
|
||||
final int nCommon = this.qpref.getPreferenceInt(QPref.BOOSTER_COMMONS);
|
||||
final int nUncommon = this.qpref.getPreferenceInt(QPref.BOOSTER_UNCOMMONS);
|
||||
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));
|
||||
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));
|
||||
|
||||
this.addAllCards(newCards);
|
||||
return newCards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the all cards.
|
||||
*
|
||||
* @param newCards
|
||||
* the new cards
|
||||
*/
|
||||
public void addAllCards(final Iterable<CardPrinted> newCards) {
|
||||
for (final CardPrinted card : newCards) {
|
||||
this.addSingleCard(card);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the single card.
|
||||
*
|
||||
* @param card
|
||||
* the 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.
|
||||
this.q.getNewCardList().add(card);
|
||||
}
|
||||
|
||||
private static final Predicate<CardPrinted> RARE_PREDICATE = CardPrinted.Predicates.Presets.IS_RARE_OR_MYTHIC;
|
||||
|
||||
/**
|
||||
* Adds the random rare.
|
||||
*
|
||||
* @return the card printed
|
||||
*/
|
||||
public CardPrinted addRandomRare() {
|
||||
final CardPrinted card = QuestUtilCards.RARE_PREDICATE.random(CardDb.instance().getAllCards());
|
||||
this.addSingleCard(card);
|
||||
return card;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the random rare.
|
||||
*
|
||||
* @param n
|
||||
* the n
|
||||
* @return the list
|
||||
*/
|
||||
public List<CardPrinted> addRandomRare(final int n) {
|
||||
final List<CardPrinted> newCards = QuestUtilCards.RARE_PREDICATE.random(CardDb.instance().getAllCards(), n);
|
||||
this.addAllCards(newCards);
|
||||
return newCards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup new game card pool.
|
||||
*
|
||||
* @param filter
|
||||
* the filter
|
||||
* @param idxDifficulty
|
||||
* the idx difficulty
|
||||
*/
|
||||
public void setupNewGameCardPool(final Predicate<CardPrinted> filter, final int idxDifficulty) {
|
||||
final int nC = this.qpref.getPreferenceInt(QPref.STARTING_COMMONS, idxDifficulty);
|
||||
final int nU = this.qpref.getPreferenceInt(QPref.STARTING_UNCOMMONS, idxDifficulty);
|
||||
final int nR = this.qpref.getPreferenceInt(QPref.STARTING_RARES, idxDifficulty);
|
||||
|
||||
this.addAllCards(BoosterUtils.getQuestStarterDeck(filter, nC, nU, nR));
|
||||
}
|
||||
|
||||
/**
|
||||
* Buy card.
|
||||
*
|
||||
* @param card
|
||||
* the card
|
||||
* @param value
|
||||
* the value
|
||||
*/
|
||||
public void buyCard(final CardPrinted card, final int value) {
|
||||
if (this.q.getCredits() >= value) {
|
||||
this.q.setCredits(this.q.getCredits() - value);
|
||||
this.q.getShopList().remove(card);
|
||||
this.addSingleCard(card);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Buy booster.
|
||||
*
|
||||
* @param booster
|
||||
* the booster
|
||||
* @param value
|
||||
* the value
|
||||
*/
|
||||
public void buyPack(final OpenablePack booster, final int value) {
|
||||
if (this.q.getCredits() >= value) {
|
||||
this.q.setCredits(this.q.getCredits() - value);
|
||||
this.q.getShopList().remove(booster);
|
||||
this.addAllCards(booster.getCards());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Buy precon deck.
|
||||
*
|
||||
* @param precon
|
||||
* the precon
|
||||
* @param value
|
||||
* the value
|
||||
*/
|
||||
public void buyPreconDeck(final PreconDeck precon, final int value) {
|
||||
if (this.q.getCredits() >= value) {
|
||||
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
|
||||
* the price
|
||||
*/
|
||||
public void sellCard(final CardPrinted card, final int price) {
|
||||
this.sellCard(card, price, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sell card.
|
||||
*
|
||||
* @param card
|
||||
* the card
|
||||
* @param price
|
||||
* the price
|
||||
* @param addToShop
|
||||
* true if this card should be added to the shop, false otherwise
|
||||
*/
|
||||
public void sellCard(final CardPrinted card, final int price, final boolean addToShop) {
|
||||
if (price > 0) {
|
||||
this.q.setCredits(this.q.getCredits() + price);
|
||||
}
|
||||
this.q.getCardPool().remove(card);
|
||||
if (addToShop) {
|
||||
this.q.getShopList().add(card);
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sell mutliplier.
|
||||
*
|
||||
* @return the sell mutliplier
|
||||
*/
|
||||
public double getSellMutliplier() {
|
||||
double multi = 0.20 + (0.001 * this.q.getWin());
|
||||
if (multi > 0.6) {
|
||||
multi = 0.6;
|
||||
}
|
||||
|
||||
final int lvlEstates = this.q.isFantasy() ? this.q.getInventory().getItemLevel("Estates") : 0;
|
||||
switch (lvlEstates) {
|
||||
case 1:
|
||||
multi += 0.01;
|
||||
break;
|
||||
case 2:
|
||||
multi += 0.0175;
|
||||
break;
|
||||
case 3:
|
||||
multi += 0.025;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return multi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sell price limit.
|
||||
*
|
||||
* @return the sell price limit
|
||||
*/
|
||||
public int getSellPriceLimit() {
|
||||
return this.q.getWin() <= 50 ? 1000 : Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate cards in shop.
|
||||
*/
|
||||
private final FormatCollection formats = Singletons.getModel().getFormats();
|
||||
private final Predicate<CardEdition> filterExt = CardEdition.Predicates.isLegalInFormat(this.formats.getExtended());
|
||||
|
||||
/** The filter t2booster. */
|
||||
private final Predicate<CardEdition> filterT2booster = Predicate.and(CardEdition.Predicates.CAN_MAKE_BOOSTER,
|
||||
CardEdition.Predicates.isLegalInFormat(this.formats.getStandard()));
|
||||
|
||||
/** The filter ext but t2. */
|
||||
private final Predicate<CardEdition> filterExtButT2 = Predicate.and(
|
||||
CardEdition.Predicates.CAN_MAKE_BOOSTER,
|
||||
Predicate.and(this.filterExt,
|
||||
Predicate.not(CardEdition.Predicates.isLegalInFormat(this.formats.getStandard()))));
|
||||
|
||||
/** The filter not ext. */
|
||||
private final Predicate<CardEdition> filterNotExt = Predicate.and(CardEdition.Predicates.CAN_MAKE_BOOSTER,
|
||||
Predicate.not(this.filterExt));
|
||||
|
||||
/**
|
||||
* Generate boosters in shop.
|
||||
*
|
||||
* @param count
|
||||
* the count
|
||||
*/
|
||||
public void generateBoostersInShop(final int count) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
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
|
||||
*/
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate precons in shop.
|
||||
*
|
||||
* @param count
|
||||
* the count
|
||||
*/
|
||||
public void generatePreconsInShop(final int count) {
|
||||
final List<PreconDeck> meetRequirements = new ArrayList<PreconDeck>();
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate cards in shop.
|
||||
*/
|
||||
public void generateCardsInShop() {
|
||||
final BoosterGenerator pack = new BoosterGenerator(CardDb.instance().getAllCards());
|
||||
|
||||
// Preferences
|
||||
final int startPacks = this.qpref.getPreferenceInt(QPref.SHOP_STARTING_PACKS);
|
||||
final int winsForPack = this.qpref.getPreferenceInt(QPref.SHOP_WINS_FOR_ADDITIONAL_PACK);
|
||||
final int maxPacks = this.qpref.getPreferenceInt(QPref.SHOP_MAX_PACKS);
|
||||
final int common = this.qpref.getPreferenceInt(QPref.SHOP_SINGLES_COMMON);
|
||||
final int uncommon = this.qpref.getPreferenceInt(QPref.SHOP_SINGLES_UNCOMMON);
|
||||
final int rare = this.qpref.getPreferenceInt(QPref.SHOP_SINGLES_RARE);
|
||||
|
||||
final int levelPacks = this.q.getLevel() > 0 ? startPacks / this.q.getLevel() : startPacks;
|
||||
final int winPacks = this.q.getWin() / winsForPack;
|
||||
final int totalPacks = Math.min(levelPacks + winPacks, maxPacks);
|
||||
|
||||
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.generateFatPacksInShop(totalPacks);
|
||||
this.q.getShopList().addAll(QuestUtilCards.generateBasicLands(10, 5));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cardpool.
|
||||
*
|
||||
* @return the cardpool
|
||||
*/
|
||||
public ItemPool<CardPrinted> getCardpool() {
|
||||
return this.q.getCardPool();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the shop list.
|
||||
*
|
||||
* @return the shop list
|
||||
*/
|
||||
public ItemPoolView<InventoryItem> getShopList() {
|
||||
if (this.q.getShopList().isEmpty()) {
|
||||
this.generateCardsInShop();
|
||||
}
|
||||
return this.q.getShopList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the new cards.
|
||||
*
|
||||
* @return the new cards
|
||||
*/
|
||||
public ItemPoolView<InventoryItem> getNewCards() {
|
||||
return this.q.getNewCardList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset new list.
|
||||
*/
|
||||
public void resetNewList() {
|
||||
this.q.getNewCardList().clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fn new compare.
|
||||
*
|
||||
* @return the fnNewCompare
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Lambda1<Comparable, Entry<InventoryItem, Integer>> getFnNewCompare() {
|
||||
return this.fnNewCompare;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fn new get.
|
||||
*
|
||||
* @return the 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
|
||||
// deck editors
|
||||
// Maybe we should consider doing so later
|
||||
/** The fn new compare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnNewCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
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
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return QuestUtilCards.this.q.getNewCardList().contains(from.getKey()) ? "NEW" : "";
|
||||
}
|
||||
};
|
||||
}
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.quest.data;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.card.BoosterGenerator;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.FormatCollection;
|
||||
import forge.deck.Deck;
|
||||
import forge.item.*;
|
||||
import forge.quest.BoosterUtils;
|
||||
import forge.quest.data.QuestPreferences.QPref;
|
||||
import forge.util.MyRandom;
|
||||
import forge.util.Predicate;
|
||||
import net.slightlymagic.braids.util.lambda.Lambda1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* This is a helper class to execute operations on QuestData. It has been
|
||||
* created to decrease complexity of questData class
|
||||
*/
|
||||
public final class QuestUtilCards {
|
||||
private final QuestData q;
|
||||
private final QuestPreferences qpref;
|
||||
|
||||
/**
|
||||
* Instantiates a new quest util cards.
|
||||
*
|
||||
* @param qd
|
||||
* the qd
|
||||
*/
|
||||
public QuestUtilCards(final QuestData qd) {
|
||||
this.q = qd;
|
||||
this.qpref = Singletons.getModel().getQuestPreferences();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the basic lands.
|
||||
*
|
||||
* @param nBasic the n basic
|
||||
* @param nSnow the n snow
|
||||
* @return the item pool view
|
||||
*/
|
||||
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);
|
||||
pool.add(db.getCard("Forest", "M10"), nBasic);
|
||||
pool.add(db.getCard("Mountain", "M10"), nBasic);
|
||||
pool.add(db.getCard("Swamp", "M10"), nBasic);
|
||||
pool.add(db.getCard("Island", "M10"), nBasic);
|
||||
pool.add(db.getCard("Plains", "M10"), nBasic);
|
||||
|
||||
pool.add(db.getCard("Snow-Covered Forest", "ICE"), nSnow);
|
||||
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);
|
||||
pool.add(db.getCard("Snow-Covered Plains", "ICE"), nSnow);
|
||||
return pool;
|
||||
}
|
||||
|
||||
// adds 11 cards, to the current card pool
|
||||
// (I chose 11 cards instead of 15 in order to make things more challenging)
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* addCards.
|
||||
* </p>
|
||||
*
|
||||
* @param fSets
|
||||
* the f sets
|
||||
* @return the array list
|
||||
*/
|
||||
public ArrayList<CardPrinted> addCards(final Predicate<CardPrinted> fSets) {
|
||||
final int nCommon = this.qpref.getPreferenceInt(QPref.BOOSTER_COMMONS);
|
||||
final int nUncommon = this.qpref.getPreferenceInt(QPref.BOOSTER_UNCOMMONS);
|
||||
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));
|
||||
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));
|
||||
|
||||
this.addAllCards(newCards);
|
||||
return newCards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the all cards.
|
||||
*
|
||||
* @param newCards
|
||||
* the new cards
|
||||
*/
|
||||
public void addAllCards(final Iterable<CardPrinted> newCards) {
|
||||
for (final CardPrinted card : newCards) {
|
||||
this.addSingleCard(card);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the single card.
|
||||
*
|
||||
* @param card
|
||||
* the 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.
|
||||
this.q.getNewCardList().add(card);
|
||||
}
|
||||
|
||||
private static final Predicate<CardPrinted> RARE_PREDICATE = CardPrinted.Predicates.Presets.IS_RARE_OR_MYTHIC;
|
||||
|
||||
/**
|
||||
* Adds the random rare.
|
||||
*
|
||||
* @return the card printed
|
||||
*/
|
||||
public CardPrinted addRandomRare() {
|
||||
final CardPrinted card = QuestUtilCards.RARE_PREDICATE.random(CardDb.instance().getAllCards());
|
||||
this.addSingleCard(card);
|
||||
return card;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the random rare.
|
||||
*
|
||||
* @param n
|
||||
* the n
|
||||
* @return the list
|
||||
*/
|
||||
public List<CardPrinted> addRandomRare(final int n) {
|
||||
final List<CardPrinted> newCards = QuestUtilCards.RARE_PREDICATE.random(CardDb.instance().getAllCards(), n);
|
||||
this.addAllCards(newCards);
|
||||
return newCards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup new game card pool.
|
||||
*
|
||||
* @param filter
|
||||
* the filter
|
||||
* @param idxDifficulty
|
||||
* the idx difficulty
|
||||
*/
|
||||
public void setupNewGameCardPool(final Predicate<CardPrinted> filter, final int idxDifficulty) {
|
||||
final int nC = this.qpref.getPreferenceInt(QPref.STARTING_COMMONS, idxDifficulty);
|
||||
final int nU = this.qpref.getPreferenceInt(QPref.STARTING_UNCOMMONS, idxDifficulty);
|
||||
final int nR = this.qpref.getPreferenceInt(QPref.STARTING_RARES, idxDifficulty);
|
||||
|
||||
this.addAllCards(BoosterUtils.getQuestStarterDeck(filter, nC, nU, nR));
|
||||
}
|
||||
|
||||
/**
|
||||
* Buy card.
|
||||
*
|
||||
* @param card
|
||||
* the card
|
||||
* @param value
|
||||
* the value
|
||||
*/
|
||||
public void buyCard(final CardPrinted card, final int value) {
|
||||
if (this.q.getCredits() >= value) {
|
||||
this.q.setCredits(this.q.getCredits() - value);
|
||||
this.q.getShopList().remove(card);
|
||||
this.addSingleCard(card);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Buy booster.
|
||||
*
|
||||
* @param booster
|
||||
* the booster
|
||||
* @param value
|
||||
* the value
|
||||
*/
|
||||
public void buyPack(final OpenablePack booster, final int value) {
|
||||
if (this.q.getCredits() >= value) {
|
||||
this.q.setCredits(this.q.getCredits() - value);
|
||||
this.q.getShopList().remove(booster);
|
||||
this.addAllCards(booster.getCards());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Buy precon deck.
|
||||
*
|
||||
* @param precon
|
||||
* the precon
|
||||
* @param value
|
||||
* the value
|
||||
*/
|
||||
public void buyPreconDeck(final PreconDeck precon, final int value) {
|
||||
if (this.q.getCredits() >= value) {
|
||||
this.q.setCredits(this.q.getCredits() - value);
|
||||
this.q.getShopList().remove(precon);
|
||||
addPreconDeck(precon);
|
||||
}
|
||||
}
|
||||
|
||||
void addPreconDeck(PreconDeck precon) {
|
||||
this.q.getMyDecks().add(precon.getDeck());
|
||||
this.addAllCards(precon.getDeck().getMain().toFlatList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sell card.
|
||||
*
|
||||
* @param card
|
||||
* the card
|
||||
* @param price
|
||||
* the price
|
||||
*/
|
||||
public void sellCard(final CardPrinted card, final int price) {
|
||||
this.sellCard(card, price, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sell card.
|
||||
*
|
||||
* @param card
|
||||
* the card
|
||||
* @param price
|
||||
* the price
|
||||
* @param addToShop
|
||||
* true if this card should be added to the shop, false otherwise
|
||||
*/
|
||||
public void sellCard(final CardPrinted card, final int price, final boolean addToShop) {
|
||||
if (price > 0) {
|
||||
this.q.setCredits(this.q.getCredits() + price);
|
||||
}
|
||||
this.q.getCardPool().remove(card);
|
||||
if (addToShop) {
|
||||
this.q.getShopList().add(card);
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sell mutliplier.
|
||||
*
|
||||
* @return the sell mutliplier
|
||||
*/
|
||||
public double getSellMutliplier() {
|
||||
double multi = 0.20 + (0.001 * this.q.getWin());
|
||||
if (multi > 0.6) {
|
||||
multi = 0.6;
|
||||
}
|
||||
|
||||
final int lvlEstates = this.q.isFantasy() ? this.q.getInventory().getItemLevel("Estates") : 0;
|
||||
switch (lvlEstates) {
|
||||
case 1:
|
||||
multi += 0.01;
|
||||
break;
|
||||
case 2:
|
||||
multi += 0.0175;
|
||||
break;
|
||||
case 3:
|
||||
multi += 0.025;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return multi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sell price limit.
|
||||
*
|
||||
* @return the sell price limit
|
||||
*/
|
||||
public int getSellPriceLimit() {
|
||||
return this.q.getWin() <= 50 ? 1000 : Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate cards in shop.
|
||||
*/
|
||||
private final FormatCollection formats = Singletons.getModel().getFormats();
|
||||
private final Predicate<CardEdition> filterExt = CardEdition.Predicates.isLegalInFormat(this.formats.getExtended());
|
||||
|
||||
/** The filter t2booster. */
|
||||
private final Predicate<CardEdition> filterT2booster = Predicate.and(CardEdition.Predicates.CAN_MAKE_BOOSTER,
|
||||
CardEdition.Predicates.isLegalInFormat(this.formats.getStandard()));
|
||||
|
||||
/** The filter ext but t2. */
|
||||
private final Predicate<CardEdition> filterExtButT2 = Predicate.and(
|
||||
CardEdition.Predicates.CAN_MAKE_BOOSTER,
|
||||
Predicate.and(this.filterExt,
|
||||
Predicate.not(CardEdition.Predicates.isLegalInFormat(this.formats.getStandard()))));
|
||||
|
||||
/** The filter not ext. */
|
||||
private final Predicate<CardEdition> filterNotExt = Predicate.and(CardEdition.Predicates.CAN_MAKE_BOOSTER,
|
||||
Predicate.not(this.filterExt));
|
||||
|
||||
/**
|
||||
* Generate boosters in shop.
|
||||
*
|
||||
* @param count
|
||||
* the count
|
||||
*/
|
||||
public void generateBoostersInShop(final int count) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
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
|
||||
*/
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate precons in shop.
|
||||
*
|
||||
* @param count
|
||||
* the count
|
||||
*/
|
||||
public void generatePreconsInShop(final int count) {
|
||||
final List<PreconDeck> meetRequirements = new ArrayList<PreconDeck>();
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate cards in shop.
|
||||
*/
|
||||
public void generateCardsInShop() {
|
||||
final BoosterGenerator pack = new BoosterGenerator(CardDb.instance().getAllCards());
|
||||
|
||||
// Preferences
|
||||
final int startPacks = this.qpref.getPreferenceInt(QPref.SHOP_STARTING_PACKS);
|
||||
final int winsForPack = this.qpref.getPreferenceInt(QPref.SHOP_WINS_FOR_ADDITIONAL_PACK);
|
||||
final int maxPacks = this.qpref.getPreferenceInt(QPref.SHOP_MAX_PACKS);
|
||||
final int common = this.qpref.getPreferenceInt(QPref.SHOP_SINGLES_COMMON);
|
||||
final int uncommon = this.qpref.getPreferenceInt(QPref.SHOP_SINGLES_UNCOMMON);
|
||||
final int rare = this.qpref.getPreferenceInt(QPref.SHOP_SINGLES_RARE);
|
||||
|
||||
final int levelPacks = this.q.getLevel() > 0 ? startPacks / this.q.getLevel() : startPacks;
|
||||
final int winPacks = this.q.getWin() / winsForPack;
|
||||
final int totalPacks = Math.min(levelPacks + winPacks, maxPacks);
|
||||
|
||||
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.generateFatPacksInShop(totalPacks);
|
||||
this.q.getShopList().addAll(QuestUtilCards.generateBasicLands(10, 5));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cardpool.
|
||||
*
|
||||
* @return the cardpool
|
||||
*/
|
||||
public ItemPool<CardPrinted> getCardpool() {
|
||||
return this.q.getCardPool();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the shop list.
|
||||
*
|
||||
* @return the shop list
|
||||
*/
|
||||
public ItemPoolView<InventoryItem> getShopList() {
|
||||
if (this.q.getShopList().isEmpty()) {
|
||||
this.generateCardsInShop();
|
||||
}
|
||||
return this.q.getShopList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the new cards.
|
||||
*
|
||||
* @return the new cards
|
||||
*/
|
||||
public ItemPoolView<InventoryItem> getNewCards() {
|
||||
return this.q.getNewCardList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset new list.
|
||||
*/
|
||||
public void resetNewList() {
|
||||
this.q.getNewCardList().clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fn new compare.
|
||||
*
|
||||
* @return the fnNewCompare
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Lambda1<Comparable, Entry<InventoryItem, Integer>> getFnNewCompare() {
|
||||
return this.fnNewCompare;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fn new get.
|
||||
*
|
||||
* @return the 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
|
||||
// deck editors
|
||||
// Maybe we should consider doing so later
|
||||
/** The fn new compare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnNewCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
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
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return QuestUtilCards.this.q.getNewCardList().contains(from.getKey()) ? "NEW" : "";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user