mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
Quest duels and challenges stored in separate arrays.
When you chose a quest challenge from Home screen, you also get all extra creatures on battlefield Deck generation now able to correctly generate decks of definite + random color MyRandom uses SecureRandom
This commit is contained in:
4
.gitattributes
vendored
4
.gitattributes
vendored
@@ -14540,7 +14540,7 @@ src/main/java/forge/quest/QuestEvent.java -text
|
|||||||
src/main/java/forge/quest/QuestEventChallenge.java svneol=native#text/plain
|
src/main/java/forge/quest/QuestEventChallenge.java svneol=native#text/plain
|
||||||
src/main/java/forge/quest/QuestEventDifficulty.java -text
|
src/main/java/forge/quest/QuestEventDifficulty.java -text
|
||||||
src/main/java/forge/quest/QuestEventDuel.java svneol=native#text/plain
|
src/main/java/forge/quest/QuestEventDuel.java svneol=native#text/plain
|
||||||
src/main/java/forge/quest/QuestEventManager.java svneol=native#text/plain
|
src/main/java/forge/quest/QuestEventDuelManager.java -text
|
||||||
src/main/java/forge/quest/QuestMode.java -text
|
src/main/java/forge/quest/QuestMode.java -text
|
||||||
src/main/java/forge/quest/QuestRewardCard.java -text
|
src/main/java/forge/quest/QuestRewardCard.java -text
|
||||||
src/main/java/forge/quest/QuestRewardCardDuplicate.java -text
|
src/main/java/forge/quest/QuestRewardCardDuplicate.java -text
|
||||||
@@ -14572,7 +14572,9 @@ src/main/java/forge/quest/data/QuestItemCondition.java -text
|
|||||||
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/package-info.java svneol=native#text/plain
|
src/main/java/forge/quest/data/package-info.java svneol=native#text/plain
|
||||||
src/main/java/forge/quest/io/PreconReader.java -text
|
src/main/java/forge/quest/io/PreconReader.java -text
|
||||||
|
src/main/java/forge/quest/io/QuestChallengeReader.java -text
|
||||||
src/main/java/forge/quest/io/QuestDataIO.java svneol=native#text/plain
|
src/main/java/forge/quest/io/QuestDataIO.java svneol=native#text/plain
|
||||||
|
src/main/java/forge/quest/io/QuestDuelReader.java -text
|
||||||
src/main/java/forge/quest/io/ReadPriceList.java svneol=native#text/plain
|
src/main/java/forge/quest/io/ReadPriceList.java svneol=native#text/plain
|
||||||
src/main/java/forge/quest/io/package-info.java svneol=native#text/plain
|
src/main/java/forge/quest/io/package-info.java svneol=native#text/plain
|
||||||
src/main/java/forge/quest/package-info.java svneol=native#text/plain
|
src/main/java/forge/quest/package-info.java svneol=native#text/plain
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package forge.deck;
|
package forge.deck;
|
||||||
|
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.datatransfer.StringSelection;
|
import java.awt.datatransfer.StringSelection;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@@ -15,6 +13,9 @@ import javax.swing.JOptionPane;
|
|||||||
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.deck.generate.Generate2ColorDeck;
|
import forge.deck.generate.Generate2ColorDeck;
|
||||||
import forge.deck.generate.Generate3ColorDeck;
|
import forge.deck.generate.Generate3ColorDeck;
|
||||||
@@ -26,9 +27,12 @@ import forge.game.player.PlayerType;
|
|||||||
import forge.item.CardDb;
|
import forge.item.CardDb;
|
||||||
import forge.item.CardPrinted;
|
import forge.item.CardPrinted;
|
||||||
import forge.item.ItemPoolView;
|
import forge.item.ItemPoolView;
|
||||||
|
import forge.quest.QuestController;
|
||||||
import forge.quest.QuestEvent;
|
import forge.quest.QuestEvent;
|
||||||
import forge.quest.QuestEventManager;
|
import forge.quest.QuestEventChallenge;
|
||||||
|
import forge.quest.QuestEventDuel;
|
||||||
import forge.util.Aggregates;
|
import forge.util.Aggregates;
|
||||||
|
import forge.util.Lang;
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
import forge.util.storage.IStorage;
|
import forge.util.storage.IStorage;
|
||||||
|
|
||||||
@@ -42,21 +46,6 @@ import forge.util.storage.IStorage;
|
|||||||
// TODO This class can be used for home menu constructed deck generation as well.
|
// TODO This class can be used for home menu constructed deck generation as well.
|
||||||
public class DeckgenUtil {
|
public class DeckgenUtil {
|
||||||
/** */
|
/** */
|
||||||
public static final Map<String, String> COLOR_VALS = new HashMap<String, String>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
COLOR_VALS.clear();
|
|
||||||
COLOR_VALS.put("Random 1", "AI");
|
|
||||||
COLOR_VALS.put("Random 2", "AI");
|
|
||||||
COLOR_VALS.put("Random 3", "AI");
|
|
||||||
COLOR_VALS.put("Random 4", "AI");
|
|
||||||
COLOR_VALS.put("Black", "black");
|
|
||||||
COLOR_VALS.put("Blue", "blue");
|
|
||||||
COLOR_VALS.put("Green", "green");
|
|
||||||
COLOR_VALS.put("Red", "red");
|
|
||||||
COLOR_VALS.put("White", "white");
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum DeckTypes {
|
public enum DeckTypes {
|
||||||
COLORS,
|
COLORS,
|
||||||
THEMES,
|
THEMES,
|
||||||
@@ -71,11 +60,7 @@ public class DeckgenUtil {
|
|||||||
public static Deck buildColorDeck(final String[] selection, PlayerType pt) {
|
public static Deck buildColorDeck(final String[] selection, PlayerType pt) {
|
||||||
|
|
||||||
final Deck deck;
|
final Deck deck;
|
||||||
|
String deckName = null;
|
||||||
// Replace "random" with "AI" for deck generation code
|
|
||||||
for (int i = 0; i < selection.length; i++) {
|
|
||||||
selection[i] = COLOR_VALS.get(selection[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
GenerateColoredDeckBase gen = null;
|
GenerateColoredDeckBase gen = null;
|
||||||
|
|
||||||
@@ -87,12 +72,16 @@ public class DeckgenUtil {
|
|||||||
gen = new Generate3ColorDeck(selection[0], selection[1], selection[2]);
|
gen = new Generate3ColorDeck(selection[0], selection[1], selection[2]);
|
||||||
} else {
|
} else {
|
||||||
gen = new Generate5ColorDeck();
|
gen = new Generate5ColorDeck();
|
||||||
|
deckName = "5 colors";
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemPoolView<CardPrinted> cards = gen == null ? null : gen.getDeck(60, pt);
|
ItemPoolView<CardPrinted> cards = gen == null ? null : gen.getDeck(60, pt);
|
||||||
|
|
||||||
|
if(null == deckName)
|
||||||
|
deckName = Lang.joinHomogenous(Arrays.asList(selection));
|
||||||
|
|
||||||
// After generating card lists, build deck.
|
// After generating card lists, build deck.
|
||||||
deck = new Deck();
|
deck = new Deck("Random deck : " + deckName);
|
||||||
deck.getMain().addAll(cards);
|
deck.getMain().addAll(cards);
|
||||||
|
|
||||||
return deck;
|
return deck;
|
||||||
@@ -127,7 +116,18 @@ public class DeckgenUtil {
|
|||||||
* @return {@link forge.deck.Deck}
|
* @return {@link forge.deck.Deck}
|
||||||
*/
|
*/
|
||||||
public static Deck buildQuestDeck(final String[] selection) {
|
public static Deck buildQuestDeck(final String[] selection) {
|
||||||
return Singletons.getModel().getQuest().getDuelsManager().getEvent(selection[0]).getEventDeck();
|
return getQuestEvent(selection[0]).getEventDeck();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static QuestEvent getQuestEvent(final String name) {
|
||||||
|
QuestController qCtrl = Singletons.getModel().getQuest();
|
||||||
|
QuestEventChallenge challenge = qCtrl.getChallenges().get(name);
|
||||||
|
if( null != challenge ) return challenge;
|
||||||
|
|
||||||
|
QuestEventDuel duel = Iterables.find(qCtrl.getDuelsManager().getAllDuels(), new Predicate<QuestEventDuel>() {
|
||||||
|
@Override public boolean apply(QuestEventDuel in) { return in.getName().equals(name); }
|
||||||
|
});
|
||||||
|
return duel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return {@link forge.deck.Deck} */
|
/** @return {@link forge.deck.Deck} */
|
||||||
@@ -161,13 +161,14 @@ public class DeckgenUtil {
|
|||||||
/** @return {@link forge.deck.Deck} */
|
/** @return {@link forge.deck.Deck} */
|
||||||
public static Deck getRandomQuestDeck() {
|
public static Deck getRandomQuestDeck() {
|
||||||
final List<Deck> allQuestDecks = new ArrayList<Deck>();
|
final List<Deck> allQuestDecks = new ArrayList<Deck>();
|
||||||
final QuestEventManager manager = Singletons.getModel().getQuest().getDuelsManager();
|
QuestController qCtrl = Singletons.getModel().getQuest();
|
||||||
|
|
||||||
for (final QuestEvent e : manager.getAllDuels()) {
|
|
||||||
|
for (final QuestEvent e : qCtrl.getDuelsManager().getAllDuels()) {
|
||||||
allQuestDecks.add(e.getEventDeck());
|
allQuestDecks.add(e.getEventDeck());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final QuestEvent e : manager.getAllChallenges()) {
|
for (final QuestEvent e : qCtrl.getChallenges()) {
|
||||||
allQuestDecks.add(e.getEventDeck());
|
allQuestDecks.add(e.getEventDeck());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,10 +228,8 @@ public class DeckgenUtil {
|
|||||||
// Retrieve from custom or quest deck maps
|
// Retrieve from custom or quest deck maps
|
||||||
if (lst0.getName().equals(DeckTypes.CUSTOM.toString())) {
|
if (lst0.getName().equals(DeckTypes.CUSTOM.toString())) {
|
||||||
deck = Singletons.getModel().getDecks().getConstructed().get(deckName);
|
deck = Singletons.getModel().getDecks().getConstructed().get(deckName);
|
||||||
}
|
} else
|
||||||
else {
|
deck = getQuestEvent(deckName).getEventDeck();
|
||||||
deck = Singletons.getModel().getQuest().getDuelsManager().getEvent(deckName).getEventDeck();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dump into map and display.
|
// Dump into map and display.
|
||||||
final String nl = System.getProperty("line.separator");
|
final String nl = System.getProperty("line.separator");
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package forge.deck.generate;
|
package forge.deck.generate;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||||
@@ -68,13 +69,20 @@ public class Generate2ColorDeck extends GenerateColoredDeckBase {
|
|||||||
* a {@link java.lang.String} object.
|
* a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public Generate2ColorDeck(final String clr1, final String clr2) {
|
public Generate2ColorDeck(final String clr1, final String clr2) {
|
||||||
|
int c1 = MagicColor.fromName(clr1);
|
||||||
|
int c2 = MagicColor.fromName(clr2);
|
||||||
|
|
||||||
if (clr1.equals("AI")) {
|
if( c1 == 0 && c2 == 0) {
|
||||||
int color1 = r.nextInt(5);
|
int color1 = r.nextInt(5);
|
||||||
int color2 = (color1 + 1 + r.nextInt(4)) % 5;
|
int color2 = (color1 + 1 + r.nextInt(4)) % 5;
|
||||||
colors = ColorSet.fromMask(MagicColor.WHITE << color1 | MagicColor.WHITE << color2);
|
colors = ColorSet.fromMask(MagicColor.WHITE << color1 | MagicColor.WHITE << color2);
|
||||||
|
} else if ( c1 == 0 || c2 == 0 ) {
|
||||||
|
byte knownColor = (byte) (c1 | c2);
|
||||||
|
int color1 = Arrays.binarySearch(MagicColor.WUBRG, knownColor);
|
||||||
|
int color2 = (color1 + 1 + r.nextInt(4)) % 5;
|
||||||
|
colors = ColorSet.fromMask(MagicColor.WHITE << color1 | MagicColor.WHITE << color2);
|
||||||
} else {
|
} else {
|
||||||
colors = ColorSet.fromNames(clr1, clr2);
|
colors = ColorSet.fromMask(c1 | c2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import forge.deck.generate.GenerateDeckUtil.FilterCMC;
|
|||||||
import forge.game.player.PlayerType;
|
import forge.game.player.PlayerType;
|
||||||
import forge.item.CardPrinted;
|
import forge.item.CardPrinted;
|
||||||
import forge.item.ItemPoolView;
|
import forge.item.ItemPoolView;
|
||||||
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -59,13 +60,40 @@ public class Generate3ColorDeck extends GenerateColoredDeckBase {
|
|||||||
* a {@link java.lang.String} object.
|
* a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public Generate3ColorDeck(final String clr1, final String clr2, final String clr3) {
|
public Generate3ColorDeck(final String clr1, final String clr2, final String clr3) {
|
||||||
if (clr1.equals("AI")) {
|
int c1 = MagicColor.fromName(clr1);
|
||||||
int color1 = r.nextInt(5);
|
int c2 = MagicColor.fromName(clr2);
|
||||||
int color2 = (color1 + 1 + r.nextInt(4)) % 5;
|
int c3 = MagicColor.fromName(clr3);
|
||||||
colors = ColorSet.fromMask(MagicColor.WHITE << color1 | MagicColor.WHITE << color2).inverse();
|
|
||||||
} else {
|
int rc = 0;
|
||||||
colors = ColorSet.fromNames(clr1, clr2, clr3);
|
int combo = c1 | c2 | c3;
|
||||||
|
|
||||||
|
ColorSet param = ColorSet.fromMask(combo);
|
||||||
|
switch(param.countColors()) {
|
||||||
|
case 3:
|
||||||
|
colors = param;
|
||||||
|
return;
|
||||||
|
|
||||||
|
case 0:
|
||||||
|
int color1 = r.nextInt(5);
|
||||||
|
int color2 = (color1 + 1 + r.nextInt(4)) % 5;
|
||||||
|
colors = ColorSet.fromMask(MagicColor.WHITE << color1 | MagicColor.WHITE << color2).inverse();
|
||||||
|
return;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
do {
|
||||||
|
rc = MagicColor.WHITE << MyRandom.getRandom().nextInt(5);
|
||||||
|
} while ( rc == combo );
|
||||||
|
combo |= rc;
|
||||||
|
// fall-through
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
do {
|
||||||
|
rc = MagicColor.WHITE << MyRandom.getRandom().nextInt(5);
|
||||||
|
} while ( (rc & combo) != 0 );
|
||||||
|
combo |= rc;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
colors = ColorSet.fromMask(combo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -69,8 +69,7 @@ public class GenerateMonoColorDeck extends GenerateColoredDeckBase {
|
|||||||
* a {@link java.lang.String} object.
|
* a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public GenerateMonoColorDeck(final String clr1) {
|
public GenerateMonoColorDeck(final String clr1) {
|
||||||
|
if (MagicColor.fromName(clr1) == 0) {
|
||||||
if (clr1.equals("AI")) {
|
|
||||||
int color1 = r.nextInt(5);
|
int color1 = r.nextInt(5);
|
||||||
colors = ColorSet.fromMask(MagicColor.WHITE << color1);
|
colors = ColorSet.fromMask(MagicColor.WHITE << color1);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -106,11 +106,11 @@ public enum CDeckgen implements ICDoc {
|
|||||||
switch (colorCount0) {
|
switch (colorCount0) {
|
||||||
case 2:
|
case 2:
|
||||||
genConstructed.getMain().addAll(
|
genConstructed.getMain().addAll(
|
||||||
(new Generate2ColorDeck("AI", "AI")).getDeck(60, PlayerType.HUMAN));
|
(new Generate2ColorDeck(null, null)).getDeck(60, PlayerType.HUMAN));
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
genConstructed.getMain().addAll(
|
genConstructed.getMain().addAll(
|
||||||
(new Generate3ColorDeck("AI", "AI", "AI")).getDeck(60, PlayerType.HUMAN));
|
(new Generate3ColorDeck(null, null, null)).getDeck(60, PlayerType.HUMAN));
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
genConstructed.getMain().addAll(
|
genConstructed.getMain().addAll(
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
package forge.gui.home.gauntlet;
|
package forge.gui.home.gauntlet;
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.MouseAdapter;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
import javax.swing.JList;
|
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.ListSelectionModel;
|
import javax.swing.ListSelectionModel;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
@@ -19,19 +13,11 @@ import javax.swing.filechooser.FileFilter;
|
|||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
|
||||||
import forge.Command;
|
import forge.Command;
|
||||||
import forge.Singletons;
|
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.deck.DeckgenUtil;
|
|
||||||
import forge.deck.DeckgenUtil.DeckTypes;
|
|
||||||
import forge.deck.generate.GenerateThemeDeck;
|
|
||||||
import forge.game.player.PlayerType;
|
|
||||||
import forge.gauntlet.GauntletData;
|
import forge.gauntlet.GauntletData;
|
||||||
import forge.gauntlet.GauntletIO;
|
import forge.gauntlet.GauntletIO;
|
||||||
import forge.gui.framework.ICDoc;
|
import forge.gui.framework.ICDoc;
|
||||||
import forge.properties.NewConstants;
|
import forge.properties.NewConstants;
|
||||||
import forge.quest.QuestController;
|
|
||||||
import forge.quest.QuestEvent;
|
|
||||||
import forge.util.storage.IStorage;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls the "build gauntlet" submenu in the home UI.
|
* Controls the "build gauntlet" submenu in the home UI.
|
||||||
@@ -65,17 +51,6 @@ public enum CSubmenuGauntletBuild implements ICDoc {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final MouseAdapter madDecklist = new MouseAdapter() {
|
|
||||||
@Override
|
|
||||||
public void mouseClicked(final MouseEvent e) {
|
|
||||||
if (e.getClickCount() == 2) {
|
|
||||||
if (view.getRadColorDecks().isSelected()) { return; }
|
|
||||||
if (view.getRadThemeDecks().isSelected()) { return; }
|
|
||||||
|
|
||||||
DeckgenUtil.showDecklist(((JList) e.getSource())); }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//private final KeyAdapter kadSearch = new KeyAdapter() { @Override
|
//private final KeyAdapter kadSearch = new KeyAdapter() { @Override
|
||||||
//public void keyPressed(final KeyEvent e) { search(); } };
|
//public void keyPressed(final KeyEvent e) { search(); } };
|
||||||
|
|
||||||
@@ -115,22 +90,7 @@ public enum CSubmenuGauntletBuild implements ICDoc {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
final ActionListener deckUpdate = new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(final ActionEvent arg0) {
|
|
||||||
updateDecks(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
view.getLstRight().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
view.getLstRight().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||||
view.getLstLeft().addMouseListener(madDecklist);
|
|
||||||
|
|
||||||
// Deck list and radio button event handling
|
|
||||||
view.getRadUserDecks().setSelected(true);
|
|
||||||
|
|
||||||
view.getRadQuestDecks().addActionListener(deckUpdate);
|
|
||||||
view.getRadColorDecks().addActionListener(deckUpdate);
|
|
||||||
view.getRadThemeDecks().addActionListener(deckUpdate);
|
|
||||||
view.getRadUserDecks().addActionListener(deckUpdate);
|
|
||||||
|
|
||||||
view.getBtnRight().setCommand(cmdAddDeck);
|
view.getBtnRight().setCommand(cmdAddDeck);
|
||||||
view.getBtnLeft().setCommand(cmdRemoveDeck);
|
view.getBtnLeft().setCommand(cmdRemoveDeck);
|
||||||
@@ -140,7 +100,9 @@ public enum CSubmenuGauntletBuild implements ICDoc {
|
|||||||
view.getBtnSave().setCommand(cmdSave);
|
view.getBtnSave().setCommand(cmdSave);
|
||||||
view.getBtnOpen().setCommand(cmdOpen);
|
view.getBtnOpen().setCommand(cmdOpen);
|
||||||
view.getBtnNew().setCommand(cmdNew);
|
view.getBtnNew().setCommand(cmdNew);
|
||||||
updateDecks();
|
|
||||||
|
view.getLstLeft().initialize();
|
||||||
|
// updateDecks();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -151,103 +113,11 @@ public enum CSubmenuGauntletBuild implements ICDoc {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Handles all control for "custom" radio button click. */
|
|
||||||
private void updateDecks() {
|
|
||||||
if (view.getRadUserDecks().isSelected()) {
|
|
||||||
updateUserDecks();
|
|
||||||
}
|
|
||||||
else if (view.getRadQuestDecks().isSelected()) {
|
|
||||||
updateQuestDecks();
|
|
||||||
}
|
|
||||||
else if (view.getRadThemeDecks().isSelected()) {
|
|
||||||
updateThemeDecks();
|
|
||||||
}
|
|
||||||
else if (view.getRadColorDecks().isSelected()) {
|
|
||||||
updateColorDecks();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateUserDecks() {
|
|
||||||
final List<String> customNames = new ArrayList<String>();
|
|
||||||
final IStorage<Deck> allDecks = Singletons.getModel().getDecks().getConstructed();
|
|
||||||
for (final Deck d : allDecks) { customNames.add(d.getName()); }
|
|
||||||
|
|
||||||
view.getLstLeft().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|
||||||
view.getLstLeft().setListData(customNames.toArray(ArrayUtils.EMPTY_STRING_ARRAY));
|
|
||||||
view.getLstLeft().setName(DeckTypes.CUSTOM.toString());
|
|
||||||
|
|
||||||
// Init first in list
|
|
||||||
view.getLstLeft().setSelectedIndex(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Handles all control for "quest event" radio button click. */
|
|
||||||
private void updateQuestDecks() {
|
|
||||||
final List<String> eventNames = new ArrayList<String>();
|
|
||||||
QuestController quest = Singletons.getModel().getQuest();
|
|
||||||
|
|
||||||
for (final QuestEvent e : quest.getDuelsManager().getAllDuels()) {
|
|
||||||
eventNames.add(e.getEventDeck().getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (final QuestEvent e : quest.getChallengesManager().getAllChallenges()) {
|
|
||||||
eventNames.add(e.getEventDeck().getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
view.getLstLeft().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|
||||||
view.getLstLeft().setListData(eventNames.toArray(ArrayUtils.EMPTY_STRING_ARRAY));
|
|
||||||
view.getLstLeft().setName(DeckTypes.QUESTEVENTS.toString());
|
|
||||||
|
|
||||||
// Init first in list
|
|
||||||
view.getLstLeft().setSelectedIndex(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Handles all control for "themes" radio button click. */
|
|
||||||
private void updateThemeDecks() {
|
|
||||||
final List<String> themeNames = new ArrayList<String>();
|
|
||||||
for (final String s : GenerateThemeDeck.getThemeNames()) { themeNames.add(s); }
|
|
||||||
|
|
||||||
view.getLstLeft().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|
||||||
view.getLstLeft().setListData(themeNames.toArray(ArrayUtils.EMPTY_STRING_ARRAY));
|
|
||||||
view.getLstLeft().setName(DeckTypes.THEMES.toString());
|
|
||||||
|
|
||||||
// Init first in list
|
|
||||||
view.getLstLeft().setSelectedIndex(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Handles all control for "colors" radio button click. */
|
|
||||||
private void updateColorDecks() {
|
|
||||||
view.getLstLeft().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
|
||||||
view.getLstLeft().setListData(new String[] {"Random 1", "Random 2", "Random 3",
|
|
||||||
"Random 4", "Black", "Blue", "Green", "Red", "White"});
|
|
||||||
view.getLstLeft().setName(DeckTypes.COLORS.toString());
|
|
||||||
|
|
||||||
// Init basic two color deck
|
|
||||||
view.getLstLeft().setSelectedIndices(new int[]{0, 1});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addDeck() {
|
private void addDeck() {
|
||||||
final Deck deckToAdd;
|
final Deck deckToAdd = view.getLstLeft().getDeck().getOriginalDeck();
|
||||||
final String[] selection = Arrays.asList(
|
if ( null == deckToAdd ) return;
|
||||||
view.getLstLeft().getSelectedValues()).toArray(new String[0]);
|
|
||||||
|
|
||||||
if (selection.length == 0) { return; }
|
|
||||||
|
|
||||||
if (view.getRadColorDecks().isSelected()) {
|
|
||||||
if (!DeckgenUtil.colorCheck(selection)) { return; }
|
|
||||||
deckToAdd = DeckgenUtil.buildColorDeck(selection, PlayerType.HUMAN);
|
|
||||||
}
|
|
||||||
else if (view.getRadQuestDecks().isSelected()) {
|
|
||||||
deckToAdd = DeckgenUtil.buildQuestDeck(selection);
|
|
||||||
}
|
|
||||||
else if (view.getRadThemeDecks().isSelected()) {
|
|
||||||
deckToAdd = DeckgenUtil.buildThemeDeck(selection);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
deckToAdd = DeckgenUtil.getConstructedDeck(selection);
|
|
||||||
}
|
|
||||||
|
|
||||||
workingDecks.add(deckToAdd);
|
workingDecks.add(deckToAdd);
|
||||||
|
|
||||||
view.getLblSave().setVisible(false);
|
view.getLblSave().setVisible(false);
|
||||||
dumpDecksIntoList();
|
dumpDecksIntoList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,34 +6,24 @@ import java.awt.event.MouseAdapter;
|
|||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
import javax.swing.ListSelectionModel;
|
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
|
||||||
|
|
||||||
import forge.Command;
|
import forge.Command;
|
||||||
import forge.FThreads;
|
import forge.FThreads;
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.control.Lobby;
|
import forge.control.Lobby;
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.deck.DeckgenUtil;
|
import forge.deck.DeckgenUtil;
|
||||||
import forge.deck.DeckgenUtil.DeckTypes;
|
|
||||||
import forge.deck.generate.GenerateThemeDeck;
|
|
||||||
import forge.game.GameType;
|
import forge.game.GameType;
|
||||||
import forge.game.MatchController;
|
import forge.game.MatchController;
|
||||||
import forge.game.MatchStartHelper;
|
import forge.game.MatchStartHelper;
|
||||||
import forge.game.player.PlayerType;
|
|
||||||
import forge.gauntlet.GauntletData;
|
import forge.gauntlet.GauntletData;
|
||||||
import forge.gauntlet.GauntletIO;
|
import forge.gauntlet.GauntletIO;
|
||||||
import forge.gui.SOverlayUtils;
|
import forge.gui.SOverlayUtils;
|
||||||
import forge.gui.framework.ICDoc;
|
import forge.gui.framework.ICDoc;
|
||||||
import forge.model.FModel;
|
import forge.model.FModel;
|
||||||
import forge.quest.QuestController;
|
|
||||||
import forge.quest.QuestEvent;
|
|
||||||
import forge.util.storage.IStorage;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls the "gauntlet contests" submenu in the home UI.
|
* Controls the "gauntlet contests" submenu in the home UI.
|
||||||
@@ -64,20 +54,6 @@ public enum CSubmenuGauntletContests implements ICDoc {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Command cmdRandomRegular = new Command() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
DeckgenUtil.randomSelect(view.getLstDecks());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final Command cmdRandomColors = new Command() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
view.getLstDecks().setSelectedIndices(DeckgenUtil.randomSelectColors());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.gui.home.ICSubmenu#initialize()
|
* @see forge.gui.home.ICSubmenu#initialize()
|
||||||
*/
|
*/
|
||||||
@@ -93,48 +69,15 @@ public enum CSubmenuGauntletContests implements ICDoc {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
final ActionListener deckUpdate = new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(final ActionEvent arg0) {
|
|
||||||
updateDecks(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
view.getBtnStart().addActionListener(actStartGame);
|
view.getBtnStart().addActionListener(actStartGame);
|
||||||
view.getLstDecks().addMouseListener(madDecklist);
|
view.getLstDecks().addMouseListener(madDecklist);
|
||||||
|
|
||||||
// Deck list and radio button event handling
|
view.getLstDecks().initialize();
|
||||||
view.getRadUserDecks().setSelected(true);
|
|
||||||
|
|
||||||
view.getRadQuestDecks().addActionListener(deckUpdate);
|
|
||||||
view.getRadColorDecks().addActionListener(deckUpdate);
|
|
||||||
view.getRadThemeDecks().addActionListener(deckUpdate);
|
|
||||||
view.getRadUserDecks().addActionListener(deckUpdate);
|
|
||||||
|
|
||||||
updateDecks();
|
|
||||||
updateData();
|
updateData();
|
||||||
|
|
||||||
view.getGauntletLister().setSelectedIndex(0);
|
view.getGauntletLister().setSelectedIndex(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Handles all control for "custom" radio button click. */
|
|
||||||
private void updateDecks() {
|
|
||||||
if (view.getRadUserDecks().isSelected()) {
|
|
||||||
view.getBtnRandom().setCommand(cmdRandomRegular);
|
|
||||||
updateUserDecks();
|
|
||||||
}
|
|
||||||
else if (view.getRadQuestDecks().isSelected()) {
|
|
||||||
view.getBtnRandom().setCommand(cmdRandomRegular);
|
|
||||||
updateQuestDecks();
|
|
||||||
}
|
|
||||||
else if (view.getRadThemeDecks().isSelected()) {
|
|
||||||
view.getBtnRandom().setCommand(cmdRandomRegular);
|
|
||||||
updateThemeDecks();
|
|
||||||
}
|
|
||||||
else if (view.getRadColorDecks().isSelected()) {
|
|
||||||
view.getBtnRandom().setCommand(cmdRandomColors);
|
|
||||||
updateColorDecks();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateData() {
|
private void updateData() {
|
||||||
final File[] files = GauntletIO.getGauntletFilesLocked();
|
final File[] files = GauntletIO.getGauntletFilesLocked();
|
||||||
@@ -147,64 +90,6 @@ public enum CSubmenuGauntletContests implements ICDoc {
|
|||||||
view.getGauntletLister().setSelectedIndex(0);
|
view.getGauntletLister().setSelectedIndex(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateUserDecks() {
|
|
||||||
final List<String> customNames = new ArrayList<String>();
|
|
||||||
final IStorage<Deck> allDecks = Singletons.getModel().getDecks().getConstructed();
|
|
||||||
for (final Deck d : allDecks) { customNames.add(d.getName()); }
|
|
||||||
|
|
||||||
view.getLstDecks().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|
||||||
view.getLstDecks().setListData(customNames.toArray(ArrayUtils.EMPTY_STRING_ARRAY));
|
|
||||||
view.getLstDecks().setName(DeckTypes.CUSTOM.toString());
|
|
||||||
|
|
||||||
// Init first in list
|
|
||||||
view.getLstDecks().setSelectedIndex(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Handles all control for "quest event" radio button click. */
|
|
||||||
private void updateQuestDecks() {
|
|
||||||
final List<String> eventNames = new ArrayList<String>();
|
|
||||||
QuestController quest = Singletons.getModel().getQuest();
|
|
||||||
|
|
||||||
for (final QuestEvent e : quest.getDuelsManager().getAllDuels()) {
|
|
||||||
eventNames.add(e.getEventDeck().getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (final QuestEvent e : quest.getChallengesManager().getAllChallenges()) {
|
|
||||||
eventNames.add(e.getEventDeck().getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
view.getLstDecks().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|
||||||
view.getLstDecks().setListData(eventNames.toArray(ArrayUtils.EMPTY_STRING_ARRAY));
|
|
||||||
view.getLstDecks().setName(DeckTypes.QUESTEVENTS.toString());
|
|
||||||
|
|
||||||
// Init first in list
|
|
||||||
view.getLstDecks().setSelectedIndex(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Handles all control for "themes" radio button click. */
|
|
||||||
private void updateThemeDecks() {
|
|
||||||
final List<String> themeNames = new ArrayList<String>();
|
|
||||||
for (final String s : GenerateThemeDeck.getThemeNames()) { themeNames.add(s); }
|
|
||||||
|
|
||||||
view.getLstDecks().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|
||||||
view.getLstDecks().setListData(themeNames.toArray(ArrayUtils.EMPTY_STRING_ARRAY));
|
|
||||||
view.getLstDecks().setName(DeckTypes.THEMES.toString());
|
|
||||||
|
|
||||||
// Init first in list
|
|
||||||
view.getLstDecks().setSelectedIndex(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Handles all control for "colors" radio button click. */
|
|
||||||
private void updateColorDecks() {
|
|
||||||
view.getLstDecks().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
|
||||||
view.getLstDecks().setListData(new String[] {"Random 1", "Random 2", "Random 3",
|
|
||||||
"Random 4", "Black", "Blue", "Green", "Red", "White"});
|
|
||||||
view.getLstDecks().setName(DeckTypes.COLORS.toString());
|
|
||||||
|
|
||||||
// Init basic two color deck
|
|
||||||
view.getLstDecks().setSelectedIndices(new int[]{0, 1});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
private void startGame() {
|
private void startGame() {
|
||||||
final GauntletData gd = view.getGauntletLister().getSelectedGauntlet();
|
final GauntletData gd = view.getGauntletLister().getSelectedGauntlet();
|
||||||
@@ -214,22 +99,7 @@ public enum CSubmenuGauntletContests implements ICDoc {
|
|||||||
userDeck = gd.getUserDeck();
|
userDeck = gd.getUserDeck();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final String[] selection = Arrays.asList(
|
userDeck = view.getLstDecks().getDeck().getOriginalDeck();
|
||||||
view.getLstDecks().getSelectedValues()).toArray(new String[0]);
|
|
||||||
|
|
||||||
if (view.getRadColorDecks().isSelected()) {
|
|
||||||
if (!DeckgenUtil.colorCheck(selection)) { return; }
|
|
||||||
userDeck = DeckgenUtil.buildColorDeck(selection, PlayerType.HUMAN);
|
|
||||||
}
|
|
||||||
else if (view.getRadQuestDecks().isSelected()) {
|
|
||||||
userDeck = DeckgenUtil.buildQuestDeck(selection);
|
|
||||||
}
|
|
||||||
else if (view.getRadThemeDecks().isSelected()) {
|
|
||||||
userDeck = DeckgenUtil.buildThemeDeck(selection);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
userDeck = DeckgenUtil.getConstructedDeck(selection);
|
|
||||||
}
|
|
||||||
gd.setUserDeck(userDeck);
|
gd.setUserDeck(userDeck);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ public enum CSubmenuGauntletQuick implements ICDoc {
|
|||||||
eventNames.add(e.getEventDeck().getName());
|
eventNames.add(e.getEventDeck().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final QuestEvent e : quest.getChallengesManager().getAllChallenges()) {
|
for (final QuestEvent e : quest.getChallenges()) {
|
||||||
eventNames.add(e.getEventDeck().getName());
|
eventNames.add(e.getEventDeck().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,18 +279,14 @@ public enum CSubmenuGauntletQuick implements ICDoc {
|
|||||||
lstGauntletDecks.add(tempDeck);
|
lstGauntletDecks.add(tempDeck);
|
||||||
}
|
}
|
||||||
|
|
||||||
FModel.SINGLETON_INSTANCE.getGauntletData()
|
final GauntletData gd = FModel.SINGLETON_INSTANCE.getGauntletData();
|
||||||
.setDecks(lstGauntletDecks);
|
gd.setDecks(lstGauntletDecks);
|
||||||
FModel.SINGLETON_INSTANCE.getGauntletData()
|
gd.setEventNames(lstEventNames);
|
||||||
.setEventNames(lstEventNames);
|
|
||||||
|
|
||||||
// Reset all variable fields to 0, stamps and saves automatically.
|
// Reset all variable fields to 0, stamps and saves automatically.
|
||||||
FModel.SINGLETON_INSTANCE.getGauntletData().reset();
|
gd.reset();
|
||||||
|
gd.setUserDeck(userDeck);
|
||||||
|
|
||||||
FModel.SINGLETON_INSTANCE.getGauntletData().setUserDeck(userDeck);
|
|
||||||
|
|
||||||
|
|
||||||
final GauntletData gd = FModel.SINGLETON_INSTANCE.getGauntletData();
|
|
||||||
final Deck aiDeck = gd.getDecks().get(gd.getCompleted());
|
final Deck aiDeck = gd.getDecks().get(gd.getCompleted());
|
||||||
|
|
||||||
MatchStartHelper starter = new MatchStartHelper();
|
MatchStartHelper starter = new MatchStartHelper();
|
||||||
|
|||||||
@@ -2,18 +2,17 @@ package forge.gui.home.gauntlet;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
||||||
import javax.swing.ButtonGroup;
|
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JRadioButton;
|
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.ScrollPaneConstants;
|
import javax.swing.ScrollPaneConstants;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
import forge.game.player.PlayerType;
|
||||||
import forge.gauntlet.GauntletIO;
|
import forge.gauntlet.GauntletIO;
|
||||||
import forge.gui.framework.DragCell;
|
import forge.gui.framework.DragCell;
|
||||||
import forge.gui.framework.DragTab;
|
import forge.gui.framework.DragTab;
|
||||||
@@ -21,9 +20,9 @@ import forge.gui.framework.EDocID;
|
|||||||
import forge.gui.home.EMenuGroup;
|
import forge.gui.home.EMenuGroup;
|
||||||
import forge.gui.home.IVSubmenu;
|
import forge.gui.home.IVSubmenu;
|
||||||
import forge.gui.home.VHomeUI;
|
import forge.gui.home.VHomeUI;
|
||||||
|
import forge.gui.toolbox.FDeckChooser;
|
||||||
import forge.gui.toolbox.FLabel;
|
import forge.gui.toolbox.FLabel;
|
||||||
import forge.gui.toolbox.FList;
|
import forge.gui.toolbox.FList;
|
||||||
import forge.gui.toolbox.FRadioButton;
|
|
||||||
import forge.gui.toolbox.FScrollPane;
|
import forge.gui.toolbox.FScrollPane;
|
||||||
import forge.gui.toolbox.FSkin;
|
import forge.gui.toolbox.FSkin;
|
||||||
import forge.gui.toolbox.FTextField;
|
import forge.gui.toolbox.FTextField;
|
||||||
@@ -48,30 +47,19 @@ public enum VSubmenuGauntletBuild implements IVSubmenu<CSubmenuGauntletBuild> {
|
|||||||
.opaque(true).fontSize(16).build();
|
.opaque(true).fontSize(16).build();
|
||||||
|
|
||||||
private final JPanel pnlFileHandling = new JPanel(new MigLayout("insets 0, gap 0, align center"));
|
private final JPanel pnlFileHandling = new JPanel(new MigLayout("insets 0, gap 0, align center"));
|
||||||
private final JPanel pnlRadios = new JPanel(new MigLayout("insets 0, gap 0, wrap"));
|
|
||||||
private final JPanel pnlButtons = new JPanel();
|
private final JPanel pnlButtons = new JPanel();
|
||||||
private final JPanel pnlStrut = new JPanel();
|
private final JPanel pnlStrut = new JPanel();
|
||||||
private final JPanel pnlDirections = new JPanel();
|
private final JPanel pnlDirections = new JPanel();
|
||||||
|
|
||||||
private final JRadioButton radUserDecks = new FRadioButton("Custom user decks");
|
private final FDeckChooser lstLeft = new FDeckChooser("Deck", PlayerType.HUMAN);
|
||||||
private final JRadioButton radQuestDecks = new FRadioButton("Quest Decks");
|
|
||||||
private final JRadioButton radColorDecks = new FRadioButton("Fully random color decks");
|
|
||||||
private final JRadioButton radThemeDecks = new FRadioButton("Semi-random theme decks");
|
|
||||||
|
|
||||||
private final JList lstLeft = new FList();
|
|
||||||
private final JList lstRight = new FList();
|
private final JList lstRight = new FList();
|
||||||
|
|
||||||
private final JScrollPane scrLeft = new FScrollPane(lstLeft,
|
|
||||||
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
|
||||||
|
|
||||||
private final JScrollPane scrRight = new FScrollPane(lstRight,
|
private final JScrollPane scrRight = new FScrollPane(lstRight,
|
||||||
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||||
|
|
||||||
private final JTextField txfFilename = new FTextField.Builder().text(GauntletIO.TXF_PROMPT).build();
|
private final JTextField txfFilename = new FTextField.Builder().text(GauntletIO.TXF_PROMPT).build();
|
||||||
|
|
||||||
private final FLabel lblDesc1 = new FLabel.Builder()
|
private final FLabel lblDesc1 = new FLabel.Builder().text("Left/right arrows add or remove decks.").fontSize(12).build();
|
||||||
.text("Left/right arrows add or remove decks.")
|
|
||||||
.fontSize(12).build();
|
|
||||||
|
|
||||||
private final FLabel lblDesc2 = new FLabel.Builder()
|
private final FLabel lblDesc2 = new FLabel.Builder()
|
||||||
.text("Up/down arrows change opponent order.")
|
.text("Up/down arrows change opponent order.")
|
||||||
@@ -131,12 +119,6 @@ public enum VSubmenuGauntletBuild implements IVSubmenu<CSubmenuGauntletBuild> {
|
|||||||
private VSubmenuGauntletBuild() {
|
private VSubmenuGauntletBuild() {
|
||||||
lblTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
lblTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
||||||
|
|
||||||
// Radio button grouping
|
|
||||||
final ButtonGroup grpRadios = new ButtonGroup();
|
|
||||||
grpRadios.add(radUserDecks);
|
|
||||||
grpRadios.add(radQuestDecks);
|
|
||||||
grpRadios.add(radColorDecks);
|
|
||||||
grpRadios.add(radThemeDecks);
|
|
||||||
|
|
||||||
// File handling panel
|
// File handling panel
|
||||||
final FLabel lblFilename = new FLabel.Builder()
|
final FLabel lblFilename = new FLabel.Builder()
|
||||||
@@ -148,13 +130,6 @@ public enum VSubmenuGauntletBuild implements IVSubmenu<CSubmenuGauntletBuild> {
|
|||||||
pnlFileHandling.add(btnNew, "h 30px!, w 30px!, gap 0 5px 0 0");
|
pnlFileHandling.add(btnNew, "h 30px!, w 30px!, gap 0 5px 0 0");
|
||||||
pnlFileHandling.add(btnOpen, "h 30px!, w 30px!, gap 0 5px 0 0");
|
pnlFileHandling.add(btnOpen, "h 30px!, w 30px!, gap 0 5px 0 0");
|
||||||
|
|
||||||
// Radios panel
|
|
||||||
pnlRadios.setOpaque(false);
|
|
||||||
pnlRadios.add(radUserDecks, "h 30px!, gap 0 0 0 5px");
|
|
||||||
pnlRadios.add(radQuestDecks, "h 30px!, gap 0 0 0 5px");
|
|
||||||
pnlRadios.add(radColorDecks, "h 30px!, gap 0 0 0 5px");
|
|
||||||
pnlRadios.add(radThemeDecks, "h 30px!, gap 0 0 0 5px");
|
|
||||||
|
|
||||||
// Directions panel
|
// Directions panel
|
||||||
final JPanel pnlSpacer = new JPanel();
|
final JPanel pnlSpacer = new JPanel();
|
||||||
pnlSpacer.setOpaque(false);
|
pnlSpacer.setOpaque(false);
|
||||||
@@ -211,15 +186,18 @@ public enum VSubmenuGauntletBuild implements IVSubmenu<CSubmenuGauntletBuild> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void populate() {
|
public void populate() {
|
||||||
|
|
||||||
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().removeAll();
|
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().removeAll();
|
||||||
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().setLayout(new MigLayout("insets 0, gap 0, wrap 3"));
|
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().setLayout(new MigLayout("insets 0, gap 0, wrap 3"));
|
||||||
|
|
||||||
|
lstLeft.populate();
|
||||||
|
|
||||||
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(lblTitle, "w 98%!, h 30px!, gap 1% 0 15px 15px, span 3");
|
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(lblTitle, "w 98%!, h 30px!, gap 1% 0 15px 15px, span 3");
|
||||||
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(pnlFileHandling, "w 98%!, gap 1% 0 1% 5px, span 3");
|
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(pnlFileHandling, "w 98%!, gap 1% 0 1% 5px, span 3");
|
||||||
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(pnlRadios, "w 48% - 20px!, gap 1% 0 0 15px");
|
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(lstLeft, "w 48% - 20px!, gap 1% 0 0 25px, spany 2, growy");
|
||||||
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(pnlStrut, "w 40px!, gap 1% 1% 0 15px");
|
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(pnlStrut, "w 40px!, gap 1% 1% 0 15px");
|
||||||
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(pnlDirections, "w 48% - 20px!, gap 0 0 0 15px");
|
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(pnlDirections, "w 48% - 20px!, gap 0 0 0 15px");
|
||||||
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(scrLeft, "w 48% - 20px!, gap 1% 0 0 25px, pushy, growy");
|
// VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(lstLeft, "w 48% - 20px!, gap 1% 0 0 25px, pushy, growy");
|
||||||
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(pnlButtons, "w 40px!, gap 1% 1% 0 25px, pushy, growy");
|
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(pnlButtons, "w 40px!, gap 1% 1% 0 25px, pushy, growy");
|
||||||
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(scrRight, "w 48% - 20px!, gap 0 0 0 25px, pushy, growy");
|
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(scrRight, "w 48% - 20px!, gap 0 0 0 25px, pushy, growy");
|
||||||
|
|
||||||
@@ -228,7 +206,7 @@ public enum VSubmenuGauntletBuild implements IVSubmenu<CSubmenuGauntletBuild> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @return {@link javax.swing.JList} */
|
/** @return {@link javax.swing.JList} */
|
||||||
public JList getLstLeft() {
|
public FDeckChooser getLstLeft() {
|
||||||
return this.lstLeft;
|
return this.lstLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,26 +215,6 @@ public enum VSubmenuGauntletBuild implements IVSubmenu<CSubmenuGauntletBuild> {
|
|||||||
return this.lstRight;
|
return this.lstRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return {@link javax.swing.JRadioButton} */
|
|
||||||
public JRadioButton getRadUserDecks() {
|
|
||||||
return this.radUserDecks;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return {@link javax.swing.JRadioButton} */
|
|
||||||
public JRadioButton getRadQuestDecks() {
|
|
||||||
return this.radQuestDecks;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return {@link javax.swing.JRadioButton} */
|
|
||||||
public JRadioButton getRadColorDecks() {
|
|
||||||
return this.radColorDecks;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return {@link javax.swing.JRadioButton} */
|
|
||||||
public JRadioButton getRadThemeDecks() {
|
|
||||||
return this.radThemeDecks;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return {@link forge.gui.toolbox.FLabel} */
|
/** @return {@link forge.gui.toolbox.FLabel} */
|
||||||
public FLabel getBtnUp() {
|
public FLabel getBtnUp() {
|
||||||
return btnUp;
|
return btnUp;
|
||||||
|
|||||||
@@ -2,17 +2,15 @@ package forge.gui.home.gauntlet;
|
|||||||
|
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
|
||||||
import javax.swing.ButtonGroup;
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JList;
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JRadioButton;
|
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.ScrollPaneConstants;
|
import javax.swing.ScrollPaneConstants;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
import forge.game.player.PlayerType;
|
||||||
import forge.gui.framework.DragCell;
|
import forge.gui.framework.DragCell;
|
||||||
import forge.gui.framework.DragTab;
|
import forge.gui.framework.DragTab;
|
||||||
import forge.gui.framework.EDocID;
|
import forge.gui.framework.EDocID;
|
||||||
@@ -20,9 +18,8 @@ import forge.gui.home.EMenuGroup;
|
|||||||
import forge.gui.home.IVSubmenu;
|
import forge.gui.home.IVSubmenu;
|
||||||
import forge.gui.home.StartButton;
|
import forge.gui.home.StartButton;
|
||||||
import forge.gui.home.VHomeUI;
|
import forge.gui.home.VHomeUI;
|
||||||
|
import forge.gui.toolbox.FDeckChooser;
|
||||||
import forge.gui.toolbox.FLabel;
|
import forge.gui.toolbox.FLabel;
|
||||||
import forge.gui.toolbox.FList;
|
|
||||||
import forge.gui.toolbox.FRadioButton;
|
|
||||||
import forge.gui.toolbox.FScrollPane;
|
import forge.gui.toolbox.FScrollPane;
|
||||||
import forge.gui.toolbox.FSkin;
|
import forge.gui.toolbox.FSkin;
|
||||||
|
|
||||||
@@ -54,18 +51,11 @@ public enum VSubmenuGauntletContests implements IVSubmenu<CSubmenuGauntletContes
|
|||||||
private final JPanel pnlDecks = new JPanel();
|
private final JPanel pnlDecks = new JPanel();
|
||||||
|
|
||||||
private final ContestGauntletLister gauntletList = new ContestGauntletLister();
|
private final ContestGauntletLister gauntletList = new ContestGauntletLister();
|
||||||
private final JList lstDecks = new FList();
|
private final FDeckChooser lstDecks = new FDeckChooser("Deck", PlayerType.HUMAN);
|
||||||
|
|
||||||
private final JScrollPane scrLeft = new FScrollPane(gauntletList,
|
private final JScrollPane scrLeft = new FScrollPane(gauntletList,
|
||||||
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||||
|
|
||||||
private final JScrollPane scrRight = new FScrollPane(lstDecks,
|
|
||||||
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
|
||||||
|
|
||||||
private final JRadioButton radUserDecks = new FRadioButton("Custom user decks");
|
|
||||||
private final JRadioButton radQuestDecks = new FRadioButton("Quest Decks");
|
|
||||||
private final JRadioButton radColorDecks = new FRadioButton("Fully random color decks");
|
|
||||||
private final JRadioButton radThemeDecks = new FRadioButton("Semi-random theme decks");
|
|
||||||
|
|
||||||
private final JLabel lblDeck = new FLabel.Builder().fontSize(16)
|
private final JLabel lblDeck = new FLabel.Builder().fontSize(16)
|
||||||
.fontStyle(Font.BOLD).text("DECK").fontAlign(SwingConstants.CENTER).build();
|
.fontStyle(Font.BOLD).text("DECK").fontAlign(SwingConstants.CENTER).build();
|
||||||
@@ -78,14 +68,7 @@ public enum VSubmenuGauntletContests implements IVSubmenu<CSubmenuGauntletContes
|
|||||||
private VSubmenuGauntletContests() {
|
private VSubmenuGauntletContests() {
|
||||||
lblTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
lblTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
||||||
|
|
||||||
// Radio button grouping
|
|
||||||
final ButtonGroup grpRight = new ButtonGroup();
|
|
||||||
grpRight.add(radUserDecks);
|
|
||||||
grpRight.add(radQuestDecks);
|
|
||||||
grpRight.add(radColorDecks);
|
|
||||||
grpRight.add(radThemeDecks);
|
|
||||||
|
|
||||||
scrLeft.setBorder(null);
|
|
||||||
pnlLoad.setLayout(new MigLayout("insets 0, gap 0, wrap"));
|
pnlLoad.setLayout(new MigLayout("insets 0, gap 0, wrap"));
|
||||||
pnlLoad.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
pnlLoad.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
||||||
pnlLoad.add(lblLoad, "h 30px!, w 94%!, gap 1% 0 0 5px, ax center");
|
pnlLoad.add(lblLoad, "h 30px!, w 94%!, gap 1% 0 0 5px, ax center");
|
||||||
@@ -97,12 +80,8 @@ public enum VSubmenuGauntletContests implements IVSubmenu<CSubmenuGauntletContes
|
|||||||
pnlDecks.setLayout(new MigLayout("insets 0, gap 0, wrap"));
|
pnlDecks.setLayout(new MigLayout("insets 0, gap 0, wrap"));
|
||||||
pnlDecks.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
pnlDecks.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
||||||
pnlDecks.add(lblDeck, "h 30px!, w 94%!, gap 1% 0 0 5px, ax center");
|
pnlDecks.add(lblDeck, "h 30px!, w 94%!, gap 1% 0 0 5px, ax center");
|
||||||
pnlDecks.add(radUserDecks, "w 96%!, h 30px!, gap 2% 0 0 5px");
|
|
||||||
pnlDecks.add(radQuestDecks, "w 96%!, h 30px!, gap 2% 0 0 5px");
|
|
||||||
pnlDecks.add(radColorDecks, "w 96%!, h 30px!, gap 2% 0 0 5px");
|
|
||||||
pnlDecks.add(radThemeDecks, "w 96%!, h 30px!, gap 2% 0 0 5px");
|
|
||||||
pnlDecks.add(btnRandom, "h 30px!, w 200px!, gap 25% 0 0 10px");
|
pnlDecks.add(btnRandom, "h 30px!, w 200px!, gap 25% 0 0 10px");
|
||||||
pnlDecks.add(scrRight, "w 94%!, pushy, growy, gap 3% 0 0 10px");
|
pnlDecks.add(lstDecks, "w 94%!, pushy, growy, gap 3% 0 0 10px");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -164,30 +143,10 @@ public enum VSubmenuGauntletContests implements IVSubmenu<CSubmenuGauntletContes
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @return {@link javax.swing.JList} */
|
/** @return {@link javax.swing.JList} */
|
||||||
public JList getLstDecks() {
|
public FDeckChooser getLstDecks() {
|
||||||
return this.lstDecks;
|
return this.lstDecks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return {@link javax.swing.JRadioButton} */
|
|
||||||
public JRadioButton getRadUserDecks() {
|
|
||||||
return this.radUserDecks;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return {@link javax.swing.JRadioButton} */
|
|
||||||
public JRadioButton getRadQuestDecks() {
|
|
||||||
return this.radQuestDecks;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return {@link javax.swing.JRadioButton} */
|
|
||||||
public JRadioButton getRadColorDecks() {
|
|
||||||
return this.radColorDecks;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return {@link javax.swing.JRadioButton} */
|
|
||||||
public JRadioButton getRadThemeDecks() {
|
|
||||||
return this.radThemeDecks;
|
|
||||||
}
|
|
||||||
|
|
||||||
//========== Overridden from IVDoc
|
//========== Overridden from IVDoc
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.awt.event.KeyAdapter;
|
|||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.JRadioButton;
|
import javax.swing.JRadioButton;
|
||||||
@@ -126,45 +127,54 @@ public enum CSubmenuChallenges implements ICDoc {
|
|||||||
final VSubmenuChallenges view = VSubmenuChallenges.SINGLETON_INSTANCE;
|
final VSubmenuChallenges view = VSubmenuChallenges.SINGLETON_INSTANCE;
|
||||||
final QuestController qCtrl = Singletons.getModel().getQuest();
|
final QuestController qCtrl = Singletons.getModel().getQuest();
|
||||||
|
|
||||||
if (qCtrl.getAchievements() != null) {
|
if (qCtrl.getAchievements() == null) return;
|
||||||
view.getLblTitle().setText("Challenges: " + qCtrl.getRank());
|
|
||||||
|
|
||||||
view.getPnlChallenges().removeAll();
|
view.getLblTitle().setText("Challenges: " + qCtrl.getRank());
|
||||||
final List<QuestEventChallenge> challenges = qCtrl.getChallengesManager().generateChallenges();
|
|
||||||
|
|
||||||
JXButtonPanel grpPanel = new JXButtonPanel();
|
view.getPnlChallenges().removeAll();
|
||||||
|
qCtrl.regenerateChallenges();
|
||||||
for (int i = 0; i < challenges.size(); i++) {
|
final List<String> ids = qCtrl.getAchievements().getCurrentChallenges();
|
||||||
final PnlEvent temp = new PnlEvent(challenges.get(i));
|
final List<QuestEventChallenge> challenges = new ArrayList<QuestEventChallenge>();
|
||||||
final JRadioButton rad = temp.getRad();
|
for(final QuestEventChallenge qc : qCtrl.getChallenges()) {
|
||||||
if (i == 0) {
|
if(ids.contains(qc.getId()))
|
||||||
rad.setSelected(true);
|
challenges.add(qc);
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
|
||||||
@Override public void run() { rad.requestFocusInWindow(); }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
rad.addKeyListener(_startOnEnter);
|
|
||||||
rad.addMouseListener(_startOnDblClick);
|
|
||||||
grpPanel.add(temp, rad, "w 100%!, h 135px!, gap 2% 0 15px 15px");
|
|
||||||
}
|
|
||||||
view.getPnlChallenges().add(grpPanel, "w 96%!");
|
|
||||||
|
|
||||||
if (challenges.size() == 0) {
|
|
||||||
final FLabel lbl = new FLabel.Builder()
|
|
||||||
.text(VSubmenuChallenges.SINGLETON_INSTANCE.getLblNextChallengeInWins().getText())
|
|
||||||
.fontAlign(SwingConstants.CENTER).build();
|
|
||||||
lbl.setForeground(Color.red);
|
|
||||||
lbl.setBackground(Color.white);
|
|
||||||
lbl.setBorder(new EmptyBorder(10, 10, 10, 10));
|
|
||||||
lbl.setOpaque(true);
|
|
||||||
view.getPnlChallenges().add(lbl, "w 50%!, h 30px!, gap 25% 0 50px 0");
|
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
|
||||||
@Override public void run() { view.getBtnTravel().requestFocusInWindow(); }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Singletons.getView().getFrame().validate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JXButtonPanel grpPanel = new JXButtonPanel();
|
||||||
|
|
||||||
|
boolean haveAnyChallenges = true;
|
||||||
|
for (QuestEventChallenge qc : challenges) {
|
||||||
|
final PnlEvent temp = new PnlEvent(qc);
|
||||||
|
final JRadioButton rad = temp.getRad();
|
||||||
|
if (haveAnyChallenges) {
|
||||||
|
rad.setSelected(true);
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override public void run() { rad.requestFocusInWindow(); }
|
||||||
|
});
|
||||||
|
haveAnyChallenges = false;
|
||||||
|
}
|
||||||
|
rad.addKeyListener(_startOnEnter);
|
||||||
|
rad.addMouseListener(_startOnDblClick);
|
||||||
|
grpPanel.add(temp, rad, "w 100%!, h 135px!, gap 2% 0 15px 15px");
|
||||||
|
}
|
||||||
|
view.getPnlChallenges().add(grpPanel, "w 96%!");
|
||||||
|
|
||||||
|
if (!haveAnyChallenges) {
|
||||||
|
final FLabel lbl = new FLabel.Builder()
|
||||||
|
.text(VSubmenuChallenges.SINGLETON_INSTANCE.getLblNextChallengeInWins().getText())
|
||||||
|
.fontAlign(SwingConstants.CENTER).build();
|
||||||
|
lbl.setForeground(Color.red);
|
||||||
|
lbl.setBackground(Color.white);
|
||||||
|
lbl.setBorder(new EmptyBorder(10, 10, 10, 10));
|
||||||
|
lbl.setOpaque(true);
|
||||||
|
view.getPnlChallenges().add(lbl, "w 50%!, h 30px!, gap 25% 0 50px 0");
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override public void run() { view.getBtnTravel().requestFocusInWindow(); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Singletons.getView().getFrame().validate();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class PnlEvent extends JPanel {
|
|||||||
hSrc = img.getHeight(null);
|
hSrc = img.getHeight(null);
|
||||||
|
|
||||||
// Title and description
|
// Title and description
|
||||||
this.rad = new FRadioButton(event.getTitle() + " (" + event.getDifficulty() + ")");
|
this.rad = new FRadioButton(event.getTitle() + " (" + event.getDifficulty().getTitle() + ")");
|
||||||
this.rad.setFont(FSkin.getBoldFont(16));
|
this.rad.setFont(FSkin.getBoldFont(16));
|
||||||
|
|
||||||
final FTextArea tarDesc = new FTextArea();
|
final FTextArea tarDesc = new FTextArea();
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class SSubmenuQuestUtil {
|
|||||||
final int challengesPlayed = qData.getAchievements().getChallengesPlayed();
|
final int challengesPlayed = qData.getAchievements().getChallengesPlayed();
|
||||||
|
|
||||||
final int wins = qData.getAchievements().getWin();
|
final int wins = qData.getAchievements().getWin();
|
||||||
final int turnsToUnlock = Singletons.getModel().getQuest().getChallengesManager().getTurnsToUnlockChallenge();
|
final int turnsToUnlock = Singletons.getModel().getQuest().getTurnsToUnlockChallenge();
|
||||||
final int delta;
|
final int delta;
|
||||||
|
|
||||||
// First challenge unlocks after minimum wins reached.
|
// First challenge unlocks after minimum wins reached.
|
||||||
@@ -341,7 +341,6 @@ public class SSubmenuQuestUtil {
|
|||||||
// (OTOH, you can 'swap' opponents even more easily by simply selecting a different quest data file and
|
// (OTOH, you can 'swap' opponents even more easily by simply selecting a different quest data file and
|
||||||
// then re-selecting your current quest data file.)
|
// then re-selecting your current quest data file.)
|
||||||
qCtrl.getDuelsManager().randomizeOpponents();
|
qCtrl.getDuelsManager().randomizeOpponents();
|
||||||
qCtrl.getChallengesManager().randomizeOpponents();
|
|
||||||
qCtrl.getCards().clearShopList();
|
qCtrl.getCards().clearShopList();
|
||||||
qCtrl.save();
|
qCtrl.save();
|
||||||
}
|
}
|
||||||
@@ -379,8 +378,6 @@ public class SSubmenuQuestUtil {
|
|||||||
final SwingWorker<Object, Void> worker = new SwingWorker<Object, Void>() {
|
final SwingWorker<Object, Void> worker = new SwingWorker<Object, Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Object doInBackground() {
|
public Object doInBackground() {
|
||||||
|
|
||||||
qData.getChallengesManager().randomizeOpponents();
|
|
||||||
qData.getDuelsManager().randomizeOpponents();
|
qData.getDuelsManager().randomizeOpponents();
|
||||||
qData.setCurrentEvent(event);
|
qData.setCurrentEvent(event);
|
||||||
qData.save();
|
qData.save();
|
||||||
@@ -394,8 +391,6 @@ public class SSubmenuQuestUtil {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
worker.execute();
|
worker.execute();
|
||||||
PlayerStartConditions humanStart = new PlayerStartConditions(SSubmenuQuestUtil.getCurrentDeck());
|
|
||||||
PlayerStartConditions aiStart = new PlayerStartConditions(event.getEventDeck());
|
|
||||||
|
|
||||||
int extraLifeHuman = 0;
|
int extraLifeHuman = 0;
|
||||||
int lifeAI = 20;
|
int lifeAI = 20;
|
||||||
@@ -406,10 +401,13 @@ public class SSubmenuQuestUtil {
|
|||||||
extraLifeHuman = 3;
|
extraLifeHuman = 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
humanStart.setStartingLife(qData.getAssets().getLife(qData.getMode()) + extraLifeHuman);
|
|
||||||
aiStart.setStartingLife(lifeAI);
|
|
||||||
|
|
||||||
|
PlayerStartConditions humanStart = new PlayerStartConditions(SSubmenuQuestUtil.getCurrentDeck());
|
||||||
|
humanStart.setStartingLife(qData.getAssets().getLife(qData.getMode()) + extraLifeHuman);
|
||||||
humanStart.setCardsOnBattlefield(QuestUtil.getHumanStartingCards(qData, event));
|
humanStart.setCardsOnBattlefield(QuestUtil.getHumanStartingCards(qData, event));
|
||||||
|
|
||||||
|
PlayerStartConditions aiStart = new PlayerStartConditions(event.getEventDeck());
|
||||||
|
aiStart.setStartingLife(lifeAI);
|
||||||
aiStart.setCardsOnBattlefield(QuestUtil.getComputerStartingCards(event));
|
aiStart.setCardsOnBattlefield(QuestUtil.getComputerStartingCards(event));
|
||||||
|
|
||||||
MatchStartHelper msh = new MatchStartHelper();
|
MatchStartHelper msh = new MatchStartHelper();
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ import forge.item.PreconDeck;
|
|||||||
import forge.quest.QuestController;
|
import forge.quest.QuestController;
|
||||||
import forge.quest.QuestWorld;
|
import forge.quest.QuestWorld;
|
||||||
import forge.quest.StartingPoolType;
|
import forge.quest.StartingPoolType;
|
||||||
import forge.util.storage.IStorage;
|
|
||||||
import forge.util.storage.IStorageView;
|
import forge.util.storage.IStorageView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,6 +117,7 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
|
|||||||
|
|
||||||
/* Listeners */
|
/* Listeners */
|
||||||
private final ActionListener alStartingPool = new ActionListener() {
|
private final ActionListener alStartingPool = new ActionListener() {
|
||||||
|
@SuppressWarnings("incomplete-switch")
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
StartingPoolType newVal = getStartingPoolType();
|
StartingPoolType newVal = getStartingPoolType();
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ import forge.Command;
|
|||||||
import forge.FThreads;
|
import forge.FThreads;
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.control.Lobby;
|
import forge.control.Lobby;
|
||||||
import forge.deck.Deck;
|
|
||||||
import forge.game.GameType;
|
import forge.game.GameType;
|
||||||
import forge.game.MatchController;
|
import forge.game.MatchController;
|
||||||
import forge.game.MatchStartHelper;
|
import forge.game.MatchStartHelper;
|
||||||
|
import forge.game.PlayerStartConditions;
|
||||||
import forge.gui.SOverlayUtils;
|
import forge.gui.SOverlayUtils;
|
||||||
import forge.gui.framework.ICDoc;
|
import forge.gui.framework.ICDoc;
|
||||||
import forge.properties.ForgePreferences;
|
import forge.properties.ForgePreferences;
|
||||||
@@ -96,15 +96,15 @@ public enum CSubmenuConstructed implements ICDoc {
|
|||||||
* @param gameType
|
* @param gameType
|
||||||
*/
|
*/
|
||||||
private void startGame(final GameType gameType) {
|
private void startGame(final GameType gameType) {
|
||||||
Deck humanDeck = VSubmenuConstructed.SINGLETON_INSTANCE.getDcHuman().getDeck();
|
PlayerStartConditions humanPsc = VSubmenuConstructed.SINGLETON_INSTANCE.getDcHuman().getDeck();
|
||||||
String humanDeckErrorMessage = gameType.getDecksFormat().getDeckConformanceProblem(humanDeck);
|
String humanDeckErrorMessage = gameType.getDecksFormat().getDeckConformanceProblem(humanPsc.getOriginalDeck());
|
||||||
if (null != humanDeckErrorMessage) {
|
if (null != humanDeckErrorMessage) {
|
||||||
JOptionPane.showMessageDialog(null, "Your deck " + humanDeckErrorMessage, "Invalid deck", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Your deck " + humanDeckErrorMessage, "Invalid deck", JOptionPane.ERROR_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Deck aiDeck = VSubmenuConstructed.SINGLETON_INSTANCE.getDcAi().getDeck();
|
PlayerStartConditions aiDeck = VSubmenuConstructed.SINGLETON_INSTANCE.getDcAi().getDeck();
|
||||||
String aiDeckErrorMessage = gameType.getDecksFormat().getDeckConformanceProblem(aiDeck);
|
String aiDeckErrorMessage = gameType.getDecksFormat().getDeckConformanceProblem(aiDeck.getOriginalDeck());
|
||||||
if (null != aiDeckErrorMessage) {
|
if (null != aiDeckErrorMessage) {
|
||||||
JOptionPane.showMessageDialog(null, "AI deck " + aiDeckErrorMessage, "Invalid deck", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(null, "AI deck " + aiDeckErrorMessage, "Invalid deck", JOptionPane.ERROR_MESSAGE);
|
||||||
return;
|
return;
|
||||||
@@ -115,7 +115,7 @@ public enum CSubmenuConstructed implements ICDoc {
|
|||||||
|
|
||||||
final MatchStartHelper starter = new MatchStartHelper();
|
final MatchStartHelper starter = new MatchStartHelper();
|
||||||
Lobby lobby = Singletons.getControl().getLobby();
|
Lobby lobby = Singletons.getControl().getLobby();
|
||||||
starter.addPlayer(lobby.getGuiPlayer(), humanDeck);
|
starter.addPlayer(lobby.getGuiPlayer(), humanPsc);
|
||||||
starter.addPlayer(lobby.getAiPlayer(), aiDeck);
|
starter.addPlayer(lobby.getAiPlayer(), aiDeck);
|
||||||
final MatchController mc = new MatchController(gameType, starter.getPlayerMap());
|
final MatchController mc = new MatchController(gameType, starter.getPlayerMap());
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import forge.deck.DeckgenUtil;
|
|||||||
import forge.game.GameType;
|
import forge.game.GameType;
|
||||||
import forge.game.MatchController;
|
import forge.game.MatchController;
|
||||||
import forge.game.MatchStartHelper;
|
import forge.game.MatchStartHelper;
|
||||||
|
import forge.game.PlayerStartConditions;
|
||||||
import forge.game.player.LobbyPlayer;
|
import forge.game.player.LobbyPlayer;
|
||||||
import forge.gui.GuiDialog;
|
import forge.gui.GuiDialog;
|
||||||
import forge.gui.SOverlayUtils;
|
import forge.gui.SOverlayUtils;
|
||||||
@@ -162,14 +163,14 @@ public enum CSubmenuArchenemy implements ICDoc {
|
|||||||
|
|
||||||
List<Deck> playerDecks = new ArrayList<Deck>();
|
List<Deck> playerDecks = new ArrayList<Deck>();
|
||||||
for (int i = 0; i < view.getNumPlayers(); i++) {
|
for (int i = 0; i < view.getNumPlayers(); i++) {
|
||||||
Deck d = view.getDeckChoosers().get(i).getDeck();
|
PlayerStartConditions d = view.getDeckChoosers().get(i).getDeck();
|
||||||
|
|
||||||
if (d == null) {
|
if (d == null) {
|
||||||
//ERROR!
|
//ERROR!
|
||||||
GuiDialog.message("No deck selected for player " + (i + 1));
|
GuiDialog.message("No deck selected for player " + (i + 1));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
playerDecks.add(d);
|
playerDecks.add(d.getOriginalDeck());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<CardPrinted> schemes = null;
|
List<CardPrinted> schemes = null;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import forge.deck.DeckgenUtil;
|
|||||||
import forge.game.GameType;
|
import forge.game.GameType;
|
||||||
import forge.game.MatchController;
|
import forge.game.MatchController;
|
||||||
import forge.game.MatchStartHelper;
|
import forge.game.MatchStartHelper;
|
||||||
|
import forge.game.PlayerStartConditions;
|
||||||
import forge.game.player.LobbyPlayer;
|
import forge.game.player.LobbyPlayer;
|
||||||
import forge.gui.GuiDialog;
|
import forge.gui.GuiDialog;
|
||||||
import forge.gui.SOverlayUtils;
|
import forge.gui.SOverlayUtils;
|
||||||
@@ -152,14 +153,14 @@ public enum CSubmenuPlanechase implements ICDoc {
|
|||||||
MatchStartHelper helper = new MatchStartHelper();
|
MatchStartHelper helper = new MatchStartHelper();
|
||||||
List<Deck> playerDecks = new ArrayList<Deck>();
|
List<Deck> playerDecks = new ArrayList<Deck>();
|
||||||
for (int i = 0; i < view.getNumPlayers(); i++) {
|
for (int i = 0; i < view.getNumPlayers(); i++) {
|
||||||
Deck d = view.getDeckChoosers().get(i).getDeck();
|
PlayerStartConditions d = view.getDeckChoosers().get(i).getDeck();
|
||||||
|
|
||||||
if (d == null) {
|
if (d == null) {
|
||||||
//ERROR!
|
//ERROR!
|
||||||
GuiDialog.message("No deck selected for player " + (i + 1));
|
GuiDialog.message("No deck selected for player " + (i + 1));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
playerDecks.add(d);
|
playerDecks.add(d.getOriginalDeck());
|
||||||
|
|
||||||
|
|
||||||
List<CardPrinted> planes = null;
|
List<CardPrinted> planes = null;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import forge.deck.DeckSection;
|
|||||||
import forge.game.GameType;
|
import forge.game.GameType;
|
||||||
import forge.game.MatchController;
|
import forge.game.MatchController;
|
||||||
import forge.game.MatchStartHelper;
|
import forge.game.MatchStartHelper;
|
||||||
|
import forge.game.PlayerStartConditions;
|
||||||
import forge.game.player.LobbyPlayer;
|
import forge.game.player.LobbyPlayer;
|
||||||
import forge.gui.GuiDialog;
|
import forge.gui.GuiDialog;
|
||||||
import forge.gui.SOverlayUtils;
|
import forge.gui.SOverlayUtils;
|
||||||
@@ -120,14 +121,14 @@ public enum CSubmenuVanguard implements ICDoc {
|
|||||||
|
|
||||||
List<Deck> playerDecks = new ArrayList<Deck>();
|
List<Deck> playerDecks = new ArrayList<Deck>();
|
||||||
for (int i = 0; i < view.getNumPlayers(); i++) {
|
for (int i = 0; i < view.getNumPlayers(); i++) {
|
||||||
Deck d = view.getDeckChoosers().get(i).getDeck();
|
PlayerStartConditions d = view.getDeckChoosers().get(i).getDeck();
|
||||||
|
|
||||||
if (d == null) {
|
if (d == null) {
|
||||||
//ERROR!
|
//ERROR!
|
||||||
GuiDialog.message("No deck selected for player " + (i + 1));
|
GuiDialog.message("No deck selected for player " + (i + 1));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
playerDecks.add(d);
|
playerDecks.add(d.getOriginalDeck());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<CardPrinted> playerAvatars = new ArrayList<CardPrinted>();
|
List<CardPrinted> playerAvatars = new ArrayList<CardPrinted>();
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ import javax.swing.ImageIcon;
|
|||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
import forge.Card;
|
import forge.Card;
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.card.BoosterTemplate;
|
import forge.card.BoosterTemplate;
|
||||||
@@ -63,6 +65,7 @@ import forge.quest.IQuestRewardCard;
|
|||||||
import forge.quest.QuestController;
|
import forge.quest.QuestController;
|
||||||
import forge.quest.QuestEvent;
|
import forge.quest.QuestEvent;
|
||||||
import forge.quest.QuestEventChallenge;
|
import forge.quest.QuestEventChallenge;
|
||||||
|
import forge.quest.QuestEventDifficulty;
|
||||||
import forge.quest.bazaar.QuestItemType;
|
import forge.quest.bazaar.QuestItemType;
|
||||||
import forge.quest.data.QuestPreferences;
|
import forge.quest.data.QuestPreferences;
|
||||||
import forge.quest.data.QuestPreferences.DifficultyPrefs;
|
import forge.quest.data.QuestPreferences.DifficultyPrefs;
|
||||||
@@ -185,7 +188,7 @@ public class QuestWinLose extends ControlWinLose {
|
|||||||
else {
|
else {
|
||||||
awardSpecialReward("Special bonus reward:"); // If any
|
awardSpecialReward("Special bonus reward:"); // If any
|
||||||
// Random rare for winning against a very hard deck
|
// Random rare for winning against a very hard deck
|
||||||
if (qEvent.getDifficulty().toLowerCase().equals("very hard")) {
|
if (qEvent.getDifficulty() == QuestEventDifficulty.EXPERT) {
|
||||||
this.awardRandomRare("You've won a random rare for winning against a very hard deck.");
|
this.awardRandomRare("You've won a random rare for winning against a very hard deck.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -279,18 +282,9 @@ public class QuestWinLose extends ControlWinLose {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (qEvent instanceof QuestEventChallenge) {
|
if (qEvent instanceof QuestEventChallenge) {
|
||||||
final int id = ((QuestEventChallenge) qEvent).getId();
|
final String id = ((QuestEventChallenge) qEvent).getId();
|
||||||
final int size = qData.getAchievements().getCurrentChallenges().size();
|
qData.getAchievements().getCurrentChallenges().remove(id);
|
||||||
for (int i = 0; i < size; i++) {
|
qData.getAchievements().addLockedChallenge(id);
|
||||||
if (qData.getAchievements().getCurrentChallenges().get(i) == id) {
|
|
||||||
qData.getAchievements().getCurrentChallenges().remove(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!((QuestEventChallenge) qEvent).isRepeatable()) {
|
|
||||||
qData.getAchievements().addLockedChallenge(((QuestEventChallenge) qEvent).getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Increment challenge counter to limit challenges available
|
// Increment challenge counter to limit challenges available
|
||||||
qData.getAchievements().addChallengesPlayed();
|
qData.getAchievements().addChallengesPlayed();
|
||||||
@@ -331,23 +325,20 @@ public class QuestWinLose extends ControlWinLose {
|
|||||||
final int base = Singletons.getModel().getQuestPreferences().getPrefInt(QPref.REWARDS_BASE);
|
final int base = Singletons.getModel().getQuestPreferences().getPrefInt(QPref.REWARDS_BASE);
|
||||||
double multiplier = 1;
|
double multiplier = 1;
|
||||||
|
|
||||||
String diff = qEvent.getDifficulty();
|
|
||||||
diff = diff.substring(0, 1).toUpperCase() + diff.substring(1);
|
|
||||||
|
|
||||||
if (diff.equalsIgnoreCase("medium")) {
|
switch(qEvent.getDifficulty()) {
|
||||||
multiplier = 1.5;
|
case EASY: multiplier = 1; break;
|
||||||
} else if (diff.equalsIgnoreCase("hard")) {
|
case MEDIUM: multiplier = 1.5; break;
|
||||||
multiplier = 2;
|
case HARD: multiplier = 2; break;
|
||||||
} else if (diff.equalsIgnoreCase("very hard")) {
|
case EXPERT: multiplier = 3; break;
|
||||||
multiplier = 2.5;
|
|
||||||
} else if (diff.equalsIgnoreCase("expert")) {
|
|
||||||
multiplier = 3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
credBase += (int) ((base * multiplier) + (Double.parseDouble(Singletons.getModel().getQuestPreferences()
|
credBase += (int) ((base * multiplier) + (Double.parseDouble(Singletons.getModel().getQuestPreferences()
|
||||||
.getPref(QPref.REWARDS_WINS_MULTIPLIER)) * qData.getAchievements().getWin()));
|
.getPref(QPref.REWARDS_WINS_MULTIPLIER)) * qData.getAchievements().getWin()));
|
||||||
|
|
||||||
sb.append(diff + " opponent: " + credBase + " credits.<br>");
|
sb.append(StringUtils.capitalize(qEvent.getDifficulty().getTitle()));
|
||||||
|
sb.append(" opponent: ").append(credBase).append(" credits.<br>");
|
||||||
|
|
||||||
// Gameplay bonuses (for each game win)
|
// Gameplay bonuses (for each game win)
|
||||||
boolean hasNeverLost = true;
|
boolean hasNeverLost = true;
|
||||||
|
|
||||||
|
|||||||
@@ -25,9 +25,12 @@ import forge.Singletons;
|
|||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.deck.DeckgenUtil;
|
import forge.deck.DeckgenUtil;
|
||||||
import forge.deck.generate.GenerateThemeDeck;
|
import forge.deck.generate.GenerateThemeDeck;
|
||||||
|
import forge.game.PlayerStartConditions;
|
||||||
import forge.game.player.PlayerType;
|
import forge.game.player.PlayerType;
|
||||||
import forge.quest.QuestController;
|
import forge.quest.QuestController;
|
||||||
import forge.quest.QuestEvent;
|
import forge.quest.QuestEvent;
|
||||||
|
import forge.quest.QuestEventChallenge;
|
||||||
|
import forge.quest.QuestUtil;
|
||||||
import forge.util.storage.IStorage;
|
import forge.util.storage.IStorage;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
@@ -176,11 +179,11 @@ public class FDeckChooser extends JPanel {
|
|||||||
|
|
||||||
QuestController quest = Singletons.getModel().getQuest();
|
QuestController quest = Singletons.getModel().getQuest();
|
||||||
for (QuestEvent e : quest.getDuelsManager().getAllDuels()) {
|
for (QuestEvent e : quest.getDuelsManager().getAllDuels()) {
|
||||||
eventNames.add(e.getEventDeck().getName());
|
eventNames.add(e.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (QuestEvent e : quest.getChallengesManager().getAllChallenges()) {
|
for (QuestEvent e : quest.getChallenges()) {
|
||||||
eventNames.add(e.getEventDeck().getName());
|
eventNames.add(e.getTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
lst.setListData(eventNames.toArray(ArrayUtils.EMPTY_STRING_ARRAY));
|
lst.setListData(eventNames.toArray(ArrayUtils.EMPTY_STRING_ARRAY));
|
||||||
@@ -196,24 +199,35 @@ public class FDeckChooser extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Generates deck from current list selection(s). */
|
/** Generates deck from current list selection(s). */
|
||||||
public Deck getDeck() {
|
public PlayerStartConditions getDeck() {
|
||||||
|
|
||||||
|
|
||||||
JList lst0 = getLstDecks();
|
JList lst0 = getLstDecks();
|
||||||
final String[] selection = Arrays.copyOf(lst0.getSelectedValues(), lst0.getSelectedValues().length, String[].class);
|
final String[] selection = Arrays.copyOf(lst0.getSelectedValues(), lst0.getSelectedValues().length, String[].class);
|
||||||
|
|
||||||
if (selection.length == 0) { return null; }
|
if (selection.length == 0) { return null; }
|
||||||
|
|
||||||
if (lst0.getName().equals(DeckgenUtil.DeckTypes.COLORS.toString()) && DeckgenUtil.colorCheck(selection)) {
|
// Special branch for quest events
|
||||||
return DeckgenUtil.buildColorDeck(selection, getPlayerType());
|
if (lst0.getName().equals(DeckgenUtil.DeckTypes.QUESTEVENTS.toString())) {
|
||||||
} else if (lst0.getName().equals(DeckgenUtil.DeckTypes.THEMES.toString())) {
|
QuestEvent event = DeckgenUtil.getQuestEvent(selection[0]);
|
||||||
return DeckgenUtil.buildThemeDeck(selection);
|
PlayerStartConditions result = new PlayerStartConditions(event.getEventDeck());
|
||||||
} else if (lst0.getName().equals(DeckgenUtil.DeckTypes.QUESTEVENTS.toString())) {
|
if( event instanceof QuestEventChallenge ) {
|
||||||
return DeckgenUtil.buildQuestDeck(selection);
|
result.setStartingLife(((QuestEventChallenge) event).getAiLife());
|
||||||
} else if (lst0.getName().equals(DeckgenUtil.DeckTypes.CUSTOM.toString())) {
|
}
|
||||||
return DeckgenUtil.getConstructedDeck(selection);
|
result.setCardsOnBattlefield(QuestUtil.getComputerStartingCards(event));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Failure, for some reason
|
Deck deck = null;
|
||||||
return null;
|
if (lst0.getName().equals(DeckgenUtil.DeckTypes.COLORS.toString()) && DeckgenUtil.colorCheck(selection)) {
|
||||||
|
deck = DeckgenUtil.buildColorDeck(selection, getPlayerType());
|
||||||
|
} else if (lst0.getName().equals(DeckgenUtil.DeckTypes.THEMES.toString())) {
|
||||||
|
deck = DeckgenUtil.buildThemeDeck(selection);
|
||||||
|
} else if (lst0.getName().equals(DeckgenUtil.DeckTypes.CUSTOM.toString())) {
|
||||||
|
deck = DeckgenUtil.getConstructedDeck(selection);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PlayerStartConditions(deck);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlayerType getPlayerType() {
|
private PlayerType getPlayerType() {
|
||||||
|
|||||||
@@ -37,10 +37,6 @@ public class PreconDeck implements InventoryItemFromSet {
|
|||||||
|
|
||||||
private final Deck deck;
|
private final Deck deck;
|
||||||
private final String imageFilename;
|
private final String imageFilename;
|
||||||
public final String getImageFilename() {
|
|
||||||
return imageFilename;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final String set;
|
private final String set;
|
||||||
private final String description;
|
private final String description;
|
||||||
|
|
||||||
@@ -107,6 +103,10 @@ public class PreconDeck implements InventoryItemFromSet {
|
|||||||
return this.recommendedDeals;
|
return this.recommendedDeals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final String getImageFilename() {
|
||||||
|
return imageFilename;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -18,6 +18,9 @@
|
|||||||
package forge.quest;
|
package forge.quest;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
@@ -40,6 +43,7 @@ import forge.quest.data.QuestAssets;
|
|||||||
import forge.quest.data.QuestData;
|
import forge.quest.data.QuestData;
|
||||||
import forge.quest.data.QuestPreferences.DifficultyPrefs;
|
import forge.quest.data.QuestPreferences.DifficultyPrefs;
|
||||||
import forge.quest.io.PreconReader;
|
import forge.quest.io.PreconReader;
|
||||||
|
import forge.quest.io.QuestChallengeReader;
|
||||||
import forge.util.storage.IStorage;
|
import forge.util.storage.IStorage;
|
||||||
import forge.util.storage.IStorageView;
|
import forge.util.storage.IStorageView;
|
||||||
import forge.util.storage.StorageView;
|
import forge.util.storage.StorageView;
|
||||||
@@ -65,8 +69,8 @@ public class QuestController {
|
|||||||
/** The decks. */
|
/** The decks. */
|
||||||
private transient IStorage<Deck> decks;
|
private transient IStorage<Deck> decks;
|
||||||
|
|
||||||
private QuestEventManager duelManager = null;
|
private QuestEventDuelManager duelManager = null;
|
||||||
private QuestEventManager challengesManager = null;
|
private IStorageView<QuestEventChallenge> allChallenges = null;
|
||||||
|
|
||||||
private QuestBazaarManager bazaar = null;
|
private QuestBazaarManager bazaar = null;
|
||||||
|
|
||||||
@@ -193,7 +197,6 @@ public class QuestController {
|
|||||||
|
|
||||||
this.resetDuelsManager();
|
this.resetDuelsManager();
|
||||||
this.resetChallengesManager();
|
this.resetChallengesManager();
|
||||||
this.getChallengesManager().randomizeOpponents();
|
|
||||||
this.getDuelsManager().randomizeOpponents();
|
this.getDuelsManager().randomizeOpponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,7 +355,7 @@ public class QuestController {
|
|||||||
*
|
*
|
||||||
* @return the event manager
|
* @return the event manager
|
||||||
*/
|
*/
|
||||||
public QuestEventManager getDuelsManager() {
|
public QuestEventDuelManager getDuelsManager() {
|
||||||
if (this.duelManager == null) {
|
if (this.duelManager == null) {
|
||||||
resetDuelsManager();
|
resetDuelsManager();
|
||||||
}
|
}
|
||||||
@@ -364,11 +367,11 @@ public class QuestController {
|
|||||||
* TODO: Write javadoc for this method.
|
* TODO: Write javadoc for this method.
|
||||||
* @return QuestEventManager
|
* @return QuestEventManager
|
||||||
*/
|
*/
|
||||||
public QuestEventManager getChallengesManager() {
|
public IStorageView<QuestEventChallenge> getChallenges() {
|
||||||
if (this.challengesManager == null) {
|
if (this.allChallenges == null) {
|
||||||
resetChallengesManager();
|
resetChallengesManager();
|
||||||
}
|
}
|
||||||
return this.challengesManager;
|
return this.allChallenges;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -376,17 +379,9 @@ public class QuestController {
|
|||||||
* Reset the duels manager.
|
* Reset the duels manager.
|
||||||
*/
|
*/
|
||||||
public void resetDuelsManager() {
|
public void resetDuelsManager() {
|
||||||
if (this.model == null || this.model.getWorldId() == null) {
|
QuestWorld world = getWorld();
|
||||||
this.duelManager = new QuestEventManager(new File(NewConstants.DEFAULT_DUELS_DIR));
|
String path = world == null || world.getDuelsDir() == null ? NewConstants.DEFAULT_DUELS_DIR : "res/quest/world/" + world.getDuelsDir();
|
||||||
} else {
|
this.duelManager = new QuestEventDuelManager(new File(path));
|
||||||
QuestWorld world = Singletons.getModel().getWorlds().get(this.model.getWorldId());
|
|
||||||
|
|
||||||
if (world == null || world.getDuelsDir() == null) {
|
|
||||||
this.duelManager = new QuestEventManager(new File(NewConstants.DEFAULT_DUELS_DIR));
|
|
||||||
} else {
|
|
||||||
this.duelManager = new QuestEventManager(new File("res/quest/world/" + world.getDuelsDir()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -394,18 +389,9 @@ public class QuestController {
|
|||||||
* Reset the challenges manager.
|
* Reset the challenges manager.
|
||||||
*/
|
*/
|
||||||
public void resetChallengesManager() {
|
public void resetChallengesManager() {
|
||||||
if (this.model == null || this.model.getWorldId() == null) {
|
QuestWorld world = getWorld();
|
||||||
this.challengesManager = new QuestEventManager(new File(NewConstants.DEFAULT_CHALLENGES_DIR));
|
String path = world == null || world.getChallengesDir() == null ? NewConstants.DEFAULT_CHALLENGES_DIR : "res/quest/world/" + world.getChallengesDir();
|
||||||
}
|
this.allChallenges = new StorageView<QuestEventChallenge>(new QuestChallengeReader(new File(path)));
|
||||||
else {
|
|
||||||
QuestWorld world = Singletons.getModel().getWorlds().get(this.model.getWorldId());
|
|
||||||
|
|
||||||
if (world == null || world.getChallengesDir() == null) {
|
|
||||||
this.challengesManager = new QuestEventManager(new File(NewConstants.DEFAULT_CHALLENGES_DIR));
|
|
||||||
} else {
|
|
||||||
this.challengesManager = new QuestEventManager(new File("res/quest/world/" + world.getChallengesDir()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -451,4 +437,50 @@ public class QuestController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getTurnsToUnlockChallenge() {
|
||||||
|
if (Singletons.getModel().getQuest().getAssets().hasItem(QuestItemType.ZEPPELIN)) {
|
||||||
|
return 8;
|
||||||
|
}
|
||||||
|
// User may have MAP and ZEPPELIN, so MAP must be tested second.
|
||||||
|
else if (Singletons.getModel().getQuest().getAssets().hasItem(QuestItemType.MAP)) {
|
||||||
|
return 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public final void regenerateChallenges() {
|
||||||
|
final QuestAchievements achievements = model.getAchievements();
|
||||||
|
final List<String> unlockedChallengeIds = new ArrayList<String>();
|
||||||
|
final List<String> availableChallengeIds = achievements.getCurrentChallenges();
|
||||||
|
|
||||||
|
int maxChallenges = achievements.getWin() / getTurnsToUnlockChallenge() - achievements.getChallengesPlayed();
|
||||||
|
if (maxChallenges > 5) {
|
||||||
|
maxChallenges = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate IDs as needed.
|
||||||
|
if (achievements.getCurrentChallenges().size() < maxChallenges) {
|
||||||
|
for (final QuestEventChallenge qc : allChallenges) {
|
||||||
|
if( qc.getWinsReqd() > achievements.getWin()) continue;
|
||||||
|
if( !qc.isRepeatable() && achievements.getLockedChallenges().contains(qc.getId())) continue;
|
||||||
|
if (!availableChallengeIds.contains(qc.getId())) {
|
||||||
|
unlockedChallengeIds.add(qc.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.shuffle(unlockedChallengeIds);
|
||||||
|
|
||||||
|
maxChallenges = Math.min(maxChallenges, unlockedChallengeIds.size());
|
||||||
|
|
||||||
|
for (int i = availableChallengeIds.size(); i < maxChallenges; i++) {
|
||||||
|
availableChallengeIds.add(unlockedChallengeIds.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
achievements.setCurrentChallenges(availableChallengeIds);
|
||||||
|
save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.util.storage.IStorage;
|
import forge.util.storage.IStorage;
|
||||||
|
|
||||||
@@ -125,4 +128,12 @@ public class QuestDeckMap implements IStorage<Deck> {
|
|||||||
return map.size();
|
return map.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see forge.util.storage.IStorageView#find(com.google.common.base.Predicate)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Deck find(Predicate<Deck> condition) {
|
||||||
|
return Iterables.tryFind(map.values(), condition).orNull();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.game.player.IHasIcon;
|
import forge.game.player.IHasIcon;
|
||||||
import forge.item.InventoryItem;
|
import forge.item.InventoryItem;
|
||||||
@@ -38,12 +40,21 @@ public abstract class QuestEvent implements IHasIcon {
|
|||||||
private Deck eventDeck = null;
|
private Deck eventDeck = null;
|
||||||
private String title = "Mystery Event";
|
private String title = "Mystery Event";
|
||||||
private String description = "";
|
private String description = "";
|
||||||
private String difficulty = "Medium";
|
private QuestEventDifficulty difficulty = QuestEventDifficulty.MEDIUM;
|
||||||
private String imageKey = "";
|
private String imageKey = "";
|
||||||
private String name = "Noname";
|
private String name = "Noname";
|
||||||
private String cardReward = null;
|
private String cardReward = null;
|
||||||
private List<InventoryItem> cardRewardList = null;
|
private List<InventoryItem> cardRewardList = null;
|
||||||
|
|
||||||
|
|
||||||
|
public static final Function<QuestEvent, String> FN_GET_NAME = new Function<QuestEvent, String>() {
|
||||||
|
@Override public final String apply(QuestEvent qe) { return qe.name; }
|
||||||
|
};
|
||||||
|
public static final Function<QuestEvent, String> FN_GET_TITLE = new Function<QuestEvent, String>() {
|
||||||
|
@Override public final String apply(QuestEvent qe) { return qe.title; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
public final String getTitle() {
|
public final String getTitle() {
|
||||||
return this.title;
|
return this.title;
|
||||||
}
|
}
|
||||||
@@ -55,7 +66,7 @@ public abstract class QuestEvent implements IHasIcon {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String getDifficulty() {
|
public final QuestEventDifficulty getDifficulty() {
|
||||||
return this.difficulty;
|
return this.difficulty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +95,7 @@ public abstract class QuestEvent implements IHasIcon {
|
|||||||
this.title = title0;
|
this.title = title0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDifficulty(final String difficulty0) {
|
public void setDifficulty(final QuestEventDifficulty difficulty0) {
|
||||||
this.difficulty = difficulty0;
|
this.difficulty = difficulty0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import java.util.List;
|
|||||||
public class QuestEventChallenge extends QuestEvent {
|
public class QuestEventChallenge extends QuestEvent {
|
||||||
// ID (default -1, should be explicitly set at later time.)
|
// ID (default -1, should be explicitly set at later time.)
|
||||||
/** The id. */
|
/** The id. */
|
||||||
private int id = -1;
|
private String id = "-1";
|
||||||
|
|
||||||
// Opponent name if different from the challenge name
|
// Opponent name if different from the challenge name
|
||||||
private String opponentName = null;
|
private String opponentName = null;
|
||||||
@@ -94,7 +94,7 @@ public class QuestEventChallenge extends QuestEvent {
|
|||||||
*
|
*
|
||||||
* @return {@link java.lang.Integer}.
|
* @return {@link java.lang.Integer}.
|
||||||
*/
|
*/
|
||||||
public final int getId() {
|
public final String getId() {
|
||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@ public class QuestEventChallenge extends QuestEvent {
|
|||||||
* @param id0
|
* @param id0
|
||||||
* the id to set
|
* the id to set
|
||||||
*/
|
*/
|
||||||
public void setId(final int id0) {
|
public void setId(final String id0) {
|
||||||
this.id = id0;
|
this.id = id0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,26 @@ package forge.quest;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public enum QuestEventDifficulty {
|
public enum QuestEventDifficulty {
|
||||||
EASY,
|
EASY("easy"),
|
||||||
MEDIUM,
|
MEDIUM("medium"),
|
||||||
HARD,
|
HARD("hard"),
|
||||||
EXPERT
|
EXPERT("very hard");
|
||||||
|
|
||||||
|
String inFile;
|
||||||
|
|
||||||
|
private QuestEventDifficulty(String storedInFile) {
|
||||||
|
inFile = storedInFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final String getTitle() {
|
||||||
|
return inFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static QuestEventDifficulty fromString(String src) {
|
||||||
|
for(QuestEventDifficulty qd : QuestEventDifficulty.values()) {
|
||||||
|
if( src.equalsIgnoreCase(qd.inFile) || src.equalsIgnoreCase(qd.name()) )
|
||||||
|
return qd;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
162
src/main/java/forge/quest/QuestEventDuelManager.java
Normal file
162
src/main/java/forge/quest/QuestEventDuelManager.java
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import forge.Singletons;
|
||||||
|
import forge.quest.data.QuestPreferences;
|
||||||
|
import forge.quest.data.QuestPreferences.DifficultyPrefs;
|
||||||
|
import forge.quest.io.QuestDuelReader;
|
||||||
|
import forge.util.maps.CollectionSuppliers;
|
||||||
|
import forge.util.maps.EnumMapOfLists;
|
||||||
|
import forge.util.maps.MapOfLists;
|
||||||
|
import forge.util.storage.IStorageView;
|
||||||
|
import forge.util.storage.StorageView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QuestEventManager.
|
||||||
|
*
|
||||||
|
* @author Forge
|
||||||
|
* @version $Id: QuestEventManager.java 20404 2013-03-17 05:34:13Z myk $
|
||||||
|
*/
|
||||||
|
public class QuestEventDuelManager {
|
||||||
|
|
||||||
|
private final MapOfLists<QuestEventDifficulty, QuestEventDuel> sortedDuels = new EnumMapOfLists<QuestEventDifficulty, QuestEventDuel>(QuestEventDifficulty.class, CollectionSuppliers.<QuestEventDuel>arrayLists());
|
||||||
|
private final IStorageView<QuestEventDuel> allDuels;
|
||||||
|
|
||||||
|
|
||||||
|
/** Instantiate all events and difficulty lists.
|
||||||
|
* @param dir   File object */
|
||||||
|
public QuestEventDuelManager(final File dir) {
|
||||||
|
allDuels = new StorageView<>(new QuestDuelReader(dir));
|
||||||
|
assembleDuelDifficultyLists();
|
||||||
|
} // End assembleAllEvents()
|
||||||
|
|
||||||
|
/** @return List<QuestEventDuel> */
|
||||||
|
public Iterable<QuestEventDuel> getAllDuels() {
|
||||||
|
return allDuels;
|
||||||
|
}
|
||||||
|
|
||||||
|
// define fallback orders if there aren't enough opponents defined for a particular difficultly level
|
||||||
|
private static List<QuestEventDifficulty> _easyOrder = Arrays.asList(QuestEventDifficulty.EASY, QuestEventDifficulty.MEDIUM, QuestEventDifficulty.HARD, QuestEventDifficulty.EXPERT);
|
||||||
|
private static List<QuestEventDifficulty> _mediumOrder = Arrays.asList(QuestEventDifficulty.MEDIUM, QuestEventDifficulty.HARD, QuestEventDifficulty.EASY, QuestEventDifficulty.EXPERT);
|
||||||
|
private static List<QuestEventDifficulty> _hardOrder = Arrays.asList(QuestEventDifficulty.HARD, QuestEventDifficulty.MEDIUM, QuestEventDifficulty.EASY, QuestEventDifficulty.EXPERT);
|
||||||
|
private static List<QuestEventDifficulty> _expertOrder = Arrays.asList(QuestEventDifficulty.EXPERT, QuestEventDifficulty.HARD, QuestEventDifficulty.MEDIUM, QuestEventDifficulty.EASY);
|
||||||
|
|
||||||
|
private void _addDuel(List<QuestEventDuel> outList, QuestEventDifficulty targetDifficulty, int toAdd) {
|
||||||
|
// if there's no way we can satisfy the request, return now
|
||||||
|
if (allDuels.size() <= toAdd) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<QuestEventDifficulty> difficultyOrder;
|
||||||
|
switch (targetDifficulty) {
|
||||||
|
case EASY: difficultyOrder = _easyOrder; break;
|
||||||
|
case MEDIUM: difficultyOrder = _mediumOrder; break;
|
||||||
|
case HARD: difficultyOrder = _hardOrder; break;
|
||||||
|
case EXPERT: difficultyOrder = _expertOrder; break;
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("unhandled difficulty: " + targetDifficulty);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (QuestEventDifficulty d : difficultyOrder) { // will add duels from preferred difficulty, will use others if the former has too few options.
|
||||||
|
for( QuestEventDuel duel : sortedDuels.get(d)) {
|
||||||
|
if(toAdd <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!outList.contains(duel)) {
|
||||||
|
outList.add(duel);
|
||||||
|
toAdd--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Generates an array of new duel opponents based on current win conditions.
|
||||||
|
*
|
||||||
|
* @return an array of {@link java.lang.String} objects.
|
||||||
|
*/
|
||||||
|
public final List<QuestEventDuel> generateDuels() {
|
||||||
|
final QuestPreferences qpref = Singletons.getModel().getQuestPreferences();
|
||||||
|
if (Singletons.getModel().getQuest().getAchievements() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final QuestController qCtrl = Singletons.getModel().getQuest();
|
||||||
|
final int cntWins = qCtrl.getAchievements().getWin();
|
||||||
|
|
||||||
|
final int index = qCtrl.getAchievements().getDifficulty();
|
||||||
|
final List<QuestEventDuel> duelOpponents = new ArrayList<QuestEventDuel>();
|
||||||
|
|
||||||
|
if (cntWins < qpref.getPrefInt(DifficultyPrefs.WINS_MEDIUMAI, index)) {
|
||||||
|
_addDuel(duelOpponents, QuestEventDifficulty.EASY, 3);
|
||||||
|
} else if (cntWins == qpref.getPrefInt(DifficultyPrefs.WINS_MEDIUMAI, index)) {
|
||||||
|
_addDuel(duelOpponents, QuestEventDifficulty.EASY, 1);
|
||||||
|
_addDuel(duelOpponents, QuestEventDifficulty.MEDIUM, 2);
|
||||||
|
} else if (cntWins < qpref.getPrefInt(DifficultyPrefs.WINS_HARDAI, index)) {
|
||||||
|
_addDuel(duelOpponents, QuestEventDifficulty.MEDIUM, 3);
|
||||||
|
} else if (cntWins == qpref.getPrefInt(DifficultyPrefs.WINS_HARDAI, index)) {
|
||||||
|
_addDuel(duelOpponents, QuestEventDifficulty.MEDIUM, 1);
|
||||||
|
_addDuel(duelOpponents, QuestEventDifficulty.HARD, 2);
|
||||||
|
} else if (cntWins < qpref.getPrefInt(DifficultyPrefs.WINS_EXPERTAI, index)) {
|
||||||
|
_addDuel(duelOpponents, QuestEventDifficulty.HARD, 3);
|
||||||
|
} else {
|
||||||
|
_addDuel(duelOpponents, QuestEventDifficulty.HARD, 2);
|
||||||
|
_addDuel(duelOpponents, QuestEventDifficulty.EXPERT, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return duelOpponents;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* assembleDuelDifficultyLists.
|
||||||
|
* </p>
|
||||||
|
* Assemble duel deck difficulty lists
|
||||||
|
*/
|
||||||
|
private void assembleDuelDifficultyLists() {
|
||||||
|
sortedDuels.clear();
|
||||||
|
sortedDuels.put(QuestEventDifficulty.EASY, new ArrayList<QuestEventDuel>());
|
||||||
|
sortedDuels.put(QuestEventDifficulty.MEDIUM, new ArrayList<QuestEventDuel>());
|
||||||
|
sortedDuels.put(QuestEventDifficulty.HARD, new ArrayList<QuestEventDuel>());
|
||||||
|
sortedDuels.put(QuestEventDifficulty.EXPERT, new ArrayList<QuestEventDuel>());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (final QuestEventDuel qd : allDuels) {
|
||||||
|
sortedDuels.add(qd.getDifficulty(), qd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
|
public void randomizeOpponents() {
|
||||||
|
final long seed = new Random().nextLong();
|
||||||
|
final Random r = new Random(seed);
|
||||||
|
for(QuestEventDifficulty qd : sortedDuels.keySet()) {
|
||||||
|
List<QuestEventDuel> list = (List<QuestEventDuel>) sortedDuels.get(qd);
|
||||||
|
Collections.shuffle(list, r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,464 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.EnumMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import forge.ImageCache;
|
|
||||||
import forge.Singletons;
|
|
||||||
import forge.deck.Deck;
|
|
||||||
import forge.deck.io.DeckSerializer;
|
|
||||||
import forge.quest.bazaar.QuestItemType;
|
|
||||||
import forge.quest.data.QuestAchievements;
|
|
||||||
import forge.quest.data.QuestPreferences;
|
|
||||||
import forge.quest.data.QuestPreferences.DifficultyPrefs;
|
|
||||||
import forge.util.FileSection;
|
|
||||||
import forge.util.FileUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* QuestEventManager.
|
|
||||||
*
|
|
||||||
* @author Forge
|
|
||||||
* @version $Id$
|
|
||||||
*/
|
|
||||||
public class QuestEventManager {
|
|
||||||
|
|
||||||
private final Map<QuestEventDifficulty, List<QuestEventDuel>> sortedDuels = new EnumMap<QuestEventDifficulty, List<QuestEventDuel>>(QuestEventDifficulty.class);
|
|
||||||
private final List<QuestEventDuel> allDuels = new ArrayList<QuestEventDuel>();
|
|
||||||
private final List<QuestEventChallenge> allChallenges = new ArrayList<QuestEventChallenge>();
|
|
||||||
|
|
||||||
/** Instantiate all events and difficulty lists.
|
|
||||||
* @param dir   File object */
|
|
||||||
public QuestEventManager(final File dir) {
|
|
||||||
QuestEvent tempEvent;
|
|
||||||
|
|
||||||
final File[] allFiles = dir.listFiles(DeckSerializer.DCK_FILE_FILTER);
|
|
||||||
|
|
||||||
for (final File f : allFiles) {
|
|
||||||
final Map<String, List<String>> contents = FileSection.parseSections(FileUtil.readFile(f));
|
|
||||||
|
|
||||||
if (contents.containsKey("quest")) {
|
|
||||||
tempEvent = readChallenge(contents.get("quest"));
|
|
||||||
allChallenges.add((QuestEventChallenge) tempEvent);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
tempEvent = readDuel(contents.get("metadata"));
|
|
||||||
allDuels.add((QuestEventDuel) tempEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assemble metadata (may not be necessary later) and deck object.
|
|
||||||
readMetadata(contents.get("metadata"), tempEvent);
|
|
||||||
tempEvent.setEventDeck(Deck.fromSections(contents));
|
|
||||||
} // End for(allFiles)
|
|
||||||
|
|
||||||
assembleDuelDifficultyLists();
|
|
||||||
} // End assembleAllEvents()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve single event, using its name.
|
|
||||||
*
|
|
||||||
* @param s0
|
|
||||||
*   {@link java.lang.String}
|
|
||||||
* @return {@link forge.quest.data.QuestEvent}
|
|
||||||
*/
|
|
||||||
public QuestEvent getEvent(final String s0) {
|
|
||||||
for (final QuestEvent q : allDuels) {
|
|
||||||
if (q.getName().equals(s0)) {
|
|
||||||
return q;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (final QuestEventChallenge q : allChallenges) {
|
|
||||||
if (q.getName().equals(s0)) {
|
|
||||||
return q;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return List<QuestEventDuel> */
|
|
||||||
public List<QuestEventDuel> getAllDuels() {
|
|
||||||
return allDuels;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return List<QuestEventChallenge> */
|
|
||||||
public List<QuestEventChallenge> getAllChallenges() {
|
|
||||||
return allChallenges;
|
|
||||||
}
|
|
||||||
|
|
||||||
// define fallback orders if there aren't enough opponents defined for a particular difficultly level
|
|
||||||
private static List<QuestEventDifficulty> _easyOrder = Arrays.asList(QuestEventDifficulty.EASY, QuestEventDifficulty.MEDIUM, QuestEventDifficulty.HARD, QuestEventDifficulty.EXPERT);
|
|
||||||
private static List<QuestEventDifficulty> _mediumOrder = Arrays.asList(QuestEventDifficulty.MEDIUM, QuestEventDifficulty.HARD, QuestEventDifficulty.EASY, QuestEventDifficulty.EXPERT);
|
|
||||||
private static List<QuestEventDifficulty> _hardOrder = Arrays.asList(QuestEventDifficulty.HARD, QuestEventDifficulty.MEDIUM, QuestEventDifficulty.EASY, QuestEventDifficulty.EXPERT);
|
|
||||||
private static List<QuestEventDifficulty> _expertOrder = Arrays.asList(QuestEventDifficulty.EXPERT, QuestEventDifficulty.HARD, QuestEventDifficulty.MEDIUM, QuestEventDifficulty.EASY);
|
|
||||||
private void _addDuel(List<QuestEventDuel> outList, QuestEventDifficulty targetDifficulty, int targetIdx) {
|
|
||||||
// if there's no way we can satisfy the request, return now
|
|
||||||
if (allDuels.size() <= targetIdx) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<QuestEventDifficulty> difficultyOrder;
|
|
||||||
switch (targetDifficulty) {
|
|
||||||
case EASY: difficultyOrder = _easyOrder; break;
|
|
||||||
case MEDIUM: difficultyOrder = _mediumOrder; break;
|
|
||||||
case HARD: difficultyOrder = _hardOrder; break;
|
|
||||||
case EXPERT: difficultyOrder = _expertOrder; break;
|
|
||||||
default:
|
|
||||||
throw new RuntimeException("unhandled difficulty: " + targetDifficulty);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (QuestEventDifficulty d : difficultyOrder) {
|
|
||||||
List<QuestEventDuel> opponents = sortedDuels.get(d);
|
|
||||||
if (opponents.size() > targetIdx) {
|
|
||||||
QuestEventDuel duel = opponents.get(targetIdx);
|
|
||||||
|
|
||||||
// if we wanted to get fancy here, we could search for a duel that hasn't been
|
|
||||||
// added yet. this is just intended to handle the simple (and common) case of
|
|
||||||
// not having enough opponents defined for a particular level, as often happens
|
|
||||||
// when new worlds are in development
|
|
||||||
if (!outList.contains(duel)) {
|
|
||||||
outList.add(duel);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
targetIdx -= opponents.size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Generates an array of new duel opponents based on current win conditions.
|
|
||||||
*
|
|
||||||
* @return an array of {@link java.lang.String} objects.
|
|
||||||
*/
|
|
||||||
public final List<QuestEventDuel> generateDuels() {
|
|
||||||
final QuestPreferences qpref = Singletons.getModel().getQuestPreferences();
|
|
||||||
if (Singletons.getModel().getQuest().getAchievements() == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final QuestController qCtrl = Singletons.getModel().getQuest();
|
|
||||||
final int cntWins = qCtrl.getAchievements().getWin();
|
|
||||||
|
|
||||||
final int index = qCtrl.getAchievements().getDifficulty();
|
|
||||||
final List<QuestEventDuel> duelOpponents = new ArrayList<QuestEventDuel>();
|
|
||||||
|
|
||||||
if (cntWins < qpref.getPrefInt(DifficultyPrefs.WINS_MEDIUMAI, index)) {
|
|
||||||
_addDuel(duelOpponents, QuestEventDifficulty.EASY, 0);
|
|
||||||
_addDuel(duelOpponents, QuestEventDifficulty.EASY, 1);
|
|
||||||
_addDuel(duelOpponents, QuestEventDifficulty.EASY, 2);
|
|
||||||
} else if (cntWins == qpref.getPrefInt(DifficultyPrefs.WINS_MEDIUMAI, index)) {
|
|
||||||
_addDuel(duelOpponents, QuestEventDifficulty.EASY, 0);
|
|
||||||
_addDuel(duelOpponents, QuestEventDifficulty.MEDIUM, 0);
|
|
||||||
_addDuel(duelOpponents, QuestEventDifficulty.MEDIUM, 1);
|
|
||||||
} else if (cntWins < qpref.getPrefInt(DifficultyPrefs.WINS_HARDAI, index)) {
|
|
||||||
_addDuel(duelOpponents, QuestEventDifficulty.MEDIUM, 0);
|
|
||||||
_addDuel(duelOpponents, QuestEventDifficulty.MEDIUM, 1);
|
|
||||||
_addDuel(duelOpponents, QuestEventDifficulty.MEDIUM, 2);
|
|
||||||
} else if (cntWins == qpref.getPrefInt(DifficultyPrefs.WINS_HARDAI, index)) {
|
|
||||||
_addDuel(duelOpponents, QuestEventDifficulty.MEDIUM, 0);
|
|
||||||
_addDuel(duelOpponents, QuestEventDifficulty.HARD, 0);
|
|
||||||
_addDuel(duelOpponents, QuestEventDifficulty.HARD, 1);
|
|
||||||
} else if (cntWins < qpref.getPrefInt(DifficultyPrefs.WINS_EXPERTAI, index)) {
|
|
||||||
_addDuel(duelOpponents, QuestEventDifficulty.HARD, 0);
|
|
||||||
_addDuel(duelOpponents, QuestEventDifficulty.HARD, 1);
|
|
||||||
_addDuel(duelOpponents, QuestEventDifficulty.HARD, 2);
|
|
||||||
} else {
|
|
||||||
_addDuel(duelOpponents, QuestEventDifficulty.HARD, 0);
|
|
||||||
_addDuel(duelOpponents, QuestEventDifficulty.HARD, 1);
|
|
||||||
_addDuel(duelOpponents, QuestEventDifficulty.EXPERT, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return duelOpponents;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Generates an array of new challenge opponents based on current win conditions.
|
|
||||||
*
|
|
||||||
* @return a {@link java.util.List} object.
|
|
||||||
*/
|
|
||||||
public final List<QuestEventChallenge> generateChallenges() {
|
|
||||||
final QuestController qCtrl = Singletons.getModel().getQuest();
|
|
||||||
final QuestAchievements achievements = qCtrl.getAchievements();
|
|
||||||
final List<QuestEventChallenge> challengeOpponents = new ArrayList<QuestEventChallenge>();
|
|
||||||
final List<Integer> unlockedChallengeIds = new ArrayList<Integer>();
|
|
||||||
final List<Integer> availableChallengeIds = achievements.getCurrentChallenges();
|
|
||||||
|
|
||||||
int maxChallenges = ((achievements.getWin() / this.getTurnsToUnlockChallenge()) - achievements.getChallengesPlayed());
|
|
||||||
if (maxChallenges > 5) {
|
|
||||||
maxChallenges = 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate IDs as needed.
|
|
||||||
if (achievements.getCurrentChallenges().size() < maxChallenges) {
|
|
||||||
for (final QuestEventChallenge qc : allChallenges) {
|
|
||||||
if ((qc.getWinsReqd() <= achievements.getWin())
|
|
||||||
&& !achievements.getLockedChallenges().contains(qc.getId())
|
|
||||||
&& !availableChallengeIds.contains(qc.getId())) {
|
|
||||||
unlockedChallengeIds.add(qc.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Collections.shuffle(unlockedChallengeIds);
|
|
||||||
|
|
||||||
maxChallenges = Math.min(maxChallenges, unlockedChallengeIds.size());
|
|
||||||
|
|
||||||
for (int i = availableChallengeIds.size(); i < maxChallenges; i++) {
|
|
||||||
availableChallengeIds.add(unlockedChallengeIds.get(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
achievements.setCurrentChallenges(availableChallengeIds);
|
|
||||||
qCtrl.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finally, pull challenge events from available IDs and return.
|
|
||||||
for (final int i : achievements.getCurrentChallenges()) {
|
|
||||||
challengeOpponents.add(getChallengeEventByNumber(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
return challengeOpponents;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the current number of turns required to unlock a new challenge.
|
|
||||||
* Varies depending on map or zeppelin purchase.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public int getTurnsToUnlockChallenge() {
|
|
||||||
if (Singletons.getModel().getQuest().getAssets().hasItem(QuestItemType.ZEPPELIN)) {
|
|
||||||
return 8;
|
|
||||||
}
|
|
||||||
// User may have MAP and ZEPPELIN, so MAP must be tested second.
|
|
||||||
else if (Singletons.getModel().getQuest().getAssets().hasItem(QuestItemType.MAP)) {
|
|
||||||
return 9;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* assembleDuelUniqueData.
|
|
||||||
* </p>
|
|
||||||
* Handler for any unique data contained in duel files.
|
|
||||||
*
|
|
||||||
* @param contents
|
|
||||||
* @param qd
|
|
||||||
*/
|
|
||||||
private QuestEventDuel readDuel(final List<String> contents) {
|
|
||||||
final QuestEventDuel qd = new QuestEventDuel();
|
|
||||||
int eqpos;
|
|
||||||
String key, value;
|
|
||||||
|
|
||||||
for (final String s : contents) {
|
|
||||||
if (s.equals("")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
eqpos = s.indexOf('=');
|
|
||||||
if (eqpos < 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
key = s.substring(0, eqpos);
|
|
||||||
value = s.substring(eqpos + 1);
|
|
||||||
|
|
||||||
if (key.equalsIgnoreCase("Name")) {
|
|
||||||
qd.setName(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return qd;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* assembleChallengeUniquedata.
|
|
||||||
* </p>
|
|
||||||
* Handler for any unique data contained in a challenge file.
|
|
||||||
*
|
|
||||||
* @param contents
|
|
||||||
* @param qc
|
|
||||||
*/
|
|
||||||
private QuestEventChallenge readChallenge(final List<String> contents) {
|
|
||||||
int eqpos;
|
|
||||||
String key, value;
|
|
||||||
|
|
||||||
final QuestEventChallenge qc = new QuestEventChallenge();
|
|
||||||
// Unique properties
|
|
||||||
for (final String s : contents) {
|
|
||||||
if (StringUtils.isBlank(s)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
eqpos = s.indexOf('=');
|
|
||||||
key = s.substring(0, eqpos);
|
|
||||||
value = s.substring(eqpos + 1).trim();
|
|
||||||
|
|
||||||
if (key.equalsIgnoreCase("ID")) {
|
|
||||||
qc.setId(Integer.parseInt(value));
|
|
||||||
} else if (key.equalsIgnoreCase("OpponentName")) {
|
|
||||||
qc.setOpponent(value);
|
|
||||||
} else if (key.equalsIgnoreCase("Repeat")) {
|
|
||||||
qc.setRepeatable(Boolean.parseBoolean(value));
|
|
||||||
} else if (key.equalsIgnoreCase("AILife")) {
|
|
||||||
qc.setAiLife(Integer.parseInt(value));
|
|
||||||
} else if (key.equalsIgnoreCase("Wins")) {
|
|
||||||
qc.setWinsReqd(Integer.parseInt(value));
|
|
||||||
} else if (key.equalsIgnoreCase("Credit Reward")) {
|
|
||||||
qc.setCreditsReward(Integer.parseInt(value));
|
|
||||||
} else if (key.equalsIgnoreCase("Card Reward")) {
|
|
||||||
qc.setCardReward(value);
|
|
||||||
}
|
|
||||||
// Human extra card list assembled here.
|
|
||||||
else if (key.equalsIgnoreCase("HumanExtras") && !value.equals("")) {
|
|
||||||
final String[] names = value.split("\\|");
|
|
||||||
final List<String> templist = new ArrayList<String>();
|
|
||||||
|
|
||||||
for (final String n : names) {
|
|
||||||
templist.add(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
qc.setHumanExtraCards(templist);
|
|
||||||
}
|
|
||||||
// AI extra card list assembled here.
|
|
||||||
else if (key.equalsIgnoreCase("AIExtras") && !value.equals("")) {
|
|
||||||
final String[] names = value.split("\\|");
|
|
||||||
final List<String> templist = new ArrayList<String>();
|
|
||||||
|
|
||||||
for (final String n : names) {
|
|
||||||
templist.add(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
qc.setAiExtraCards(templist);
|
|
||||||
}
|
|
||||||
// Card reward list assembled here.
|
|
||||||
else if (key.equalsIgnoreCase("Card Reward")) {
|
|
||||||
qc.setCardReward(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return qc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* assembleEventMetadata.
|
|
||||||
* </p>
|
|
||||||
* Handler for metadata contained in event files.
|
|
||||||
*
|
|
||||||
* @param contents
|
|
||||||
* @param qe
|
|
||||||
*/
|
|
||||||
private void readMetadata(final List<String> contents, final QuestEvent qe) {
|
|
||||||
int eqpos;
|
|
||||||
String key, value;
|
|
||||||
|
|
||||||
for (String s : contents) {
|
|
||||||
s = s.trim();
|
|
||||||
eqpos = s.indexOf('=');
|
|
||||||
|
|
||||||
if (eqpos == -1) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
key = s.substring(0, eqpos);
|
|
||||||
value = s.substring(eqpos + 1);
|
|
||||||
|
|
||||||
if (key.equalsIgnoreCase("Name")) {
|
|
||||||
qe.setName(value);
|
|
||||||
} else if (key.equalsIgnoreCase("Title")) {
|
|
||||||
qe.setTitle(value);
|
|
||||||
} else if (key.equalsIgnoreCase("Difficulty")) {
|
|
||||||
qe.setDifficulty(value);
|
|
||||||
} else if (key.equalsIgnoreCase("Description")) {
|
|
||||||
qe.setDescription(value);
|
|
||||||
} else if (key.equalsIgnoreCase("Icon")) {
|
|
||||||
qe.setIconImageKey(ImageCache.ICON_PREFIX + value);
|
|
||||||
} else if (key.equalsIgnoreCase("Card Reward")) {
|
|
||||||
qe.setCardReward(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* assembleDuelDifficultyLists.
|
|
||||||
* </p>
|
|
||||||
* Assemble duel deck difficulty lists
|
|
||||||
*/
|
|
||||||
private void assembleDuelDifficultyLists() {
|
|
||||||
sortedDuels.clear();
|
|
||||||
sortedDuels.put(QuestEventDifficulty.EASY, new ArrayList<QuestEventDuel>());
|
|
||||||
sortedDuels.put(QuestEventDifficulty.MEDIUM, new ArrayList<QuestEventDuel>());
|
|
||||||
sortedDuels.put(QuestEventDifficulty.HARD, new ArrayList<QuestEventDuel>());
|
|
||||||
sortedDuels.put(QuestEventDifficulty.EXPERT, new ArrayList<QuestEventDuel>());
|
|
||||||
|
|
||||||
String s;
|
|
||||||
|
|
||||||
for (final QuestEventDuel qd : allDuels) {
|
|
||||||
s = qd.getDifficulty();
|
|
||||||
if (s.equalsIgnoreCase("easy")) {
|
|
||||||
sortedDuels.get(QuestEventDifficulty.EASY).add(qd);
|
|
||||||
} else if (s.equalsIgnoreCase("medium")) {
|
|
||||||
sortedDuels.get(QuestEventDifficulty.MEDIUM).add(qd);
|
|
||||||
} else if (s.equalsIgnoreCase("hard")) {
|
|
||||||
sortedDuels.get(QuestEventDifficulty.HARD).add(qd);
|
|
||||||
} else if (s.equalsIgnoreCase("very hard")) {
|
|
||||||
sortedDuels.get(QuestEventDifficulty.EXPERT).add(qd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** */
|
|
||||||
public void randomizeOpponents() {
|
|
||||||
final long seed = new Random().nextLong();
|
|
||||||
final Random r = new Random(seed);
|
|
||||||
Collections.shuffle(sortedDuels.get(QuestEventDifficulty.EASY), r);
|
|
||||||
Collections.shuffle(sortedDuels.get(QuestEventDifficulty.MEDIUM), r);
|
|
||||||
Collections.shuffle(sortedDuels.get(QuestEventDifficulty.HARD), r);
|
|
||||||
Collections.shuffle(sortedDuels.get(QuestEventDifficulty.EXPERT), r);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* getChallengeOpponentByNumber.
|
|
||||||
* </p>
|
|
||||||
* Returns specific challenge event using its ID. This is to make sure that
|
|
||||||
* the opponents do not change when the deck editor is launched.
|
|
||||||
*
|
|
||||||
* @param n
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private QuestEventChallenge getChallengeEventByNumber(final int n) {
|
|
||||||
for (final QuestEventChallenge qc : allChallenges) {
|
|
||||||
if (qc.getId() == n) {
|
|
||||||
return qc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -15,10 +15,9 @@ public class QuestAchievements {
|
|||||||
// Challenge history
|
// Challenge history
|
||||||
/** The challenges played. */
|
/** The challenges played. */
|
||||||
private int challengesPlayed = 0;
|
private int challengesPlayed = 0;
|
||||||
/** */
|
|
||||||
private List<Integer> completedChallenges = new ArrayList<Integer>();
|
private List<String> completedChallenges = new ArrayList<String>();
|
||||||
/** */
|
private List<String> currentChallenges = new ArrayList<String>();
|
||||||
private List<Integer> currentChallenges = new ArrayList<Integer>();
|
|
||||||
|
|
||||||
private int win;
|
private int win;
|
||||||
private int winstreakBest = 0;
|
private int winstreakBest = 0;
|
||||||
@@ -75,7 +74,7 @@ public class QuestAchievements {
|
|||||||
*
|
*
|
||||||
* @return List<Integer>
|
* @return List<Integer>
|
||||||
*/
|
*/
|
||||||
public List<Integer> getLockedChallenges() {
|
public List<String> getLockedChallenges() {
|
||||||
return this.completedChallenges;
|
return this.completedChallenges;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +87,7 @@ public class QuestAchievements {
|
|||||||
* @param i
|
* @param i
|
||||||
* the i
|
* the i
|
||||||
*/
|
*/
|
||||||
public void addLockedChallenge(final int i) {
|
public void addLockedChallenge(final String i) {
|
||||||
this.completedChallenges.add(i);
|
this.completedChallenges.add(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,9 +96,9 @@ public class QuestAchievements {
|
|||||||
*
|
*
|
||||||
* @return List<Integer>
|
* @return List<Integer>
|
||||||
*/
|
*/
|
||||||
public List<Integer> getCurrentChallenges() {
|
public List<String> getCurrentChallenges() {
|
||||||
if (this.currentChallenges == null) {
|
if (this.currentChallenges == null) {
|
||||||
this.currentChallenges = new ArrayList<Integer>();
|
this.currentChallenges = new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.currentChallenges;
|
return this.currentChallenges;
|
||||||
@@ -110,7 +109,7 @@ public class QuestAchievements {
|
|||||||
*
|
*
|
||||||
* @param lst0 List<Integer>
|
* @param lst0 List<Integer>
|
||||||
*/
|
*/
|
||||||
public void setCurrentChallenges(final List<Integer> lst0) {
|
public void setCurrentChallenges(final List<String> lst0) {
|
||||||
this.currentChallenges = lst0;
|
this.currentChallenges = lst0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ import forge.quest.io.QuestDataIO;
|
|||||||
public final class QuestData {
|
public final class QuestData {
|
||||||
|
|
||||||
/** Holds the latest version of the Quest Data. */
|
/** Holds the latest version of the Quest Data. */
|
||||||
public static final int CURRENT_VERSION_NUMBER = 6;
|
public static final int CURRENT_VERSION_NUMBER = 7;
|
||||||
|
|
||||||
// This field places the version number into QD instance,
|
// This field places the version number into QD instance,
|
||||||
// but only when the object is created through the constructor
|
// but only when the object is created through the constructor
|
||||||
|
|||||||
60
src/main/java/forge/quest/io/QuestChallengeReader.java
Normal file
60
src/main/java/forge/quest/io/QuestChallengeReader.java
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package forge.quest.io;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import forge.ImageCache;
|
||||||
|
import forge.deck.Deck;
|
||||||
|
import forge.deck.io.DeckSerializer;
|
||||||
|
import forge.quest.QuestEvent;
|
||||||
|
import forge.quest.QuestEventChallenge;
|
||||||
|
import forge.quest.QuestEventDifficulty;
|
||||||
|
import forge.util.FileSection;
|
||||||
|
import forge.util.FileUtil;
|
||||||
|
import forge.util.TextUtil;
|
||||||
|
import forge.util.storage.StorageReaderFolder;
|
||||||
|
|
||||||
|
public class QuestChallengeReader extends StorageReaderFolder<QuestEventChallenge> {
|
||||||
|
public QuestChallengeReader(File deckDir0) {
|
||||||
|
super(deckDir0, QuestEvent.FN_GET_TITLE);
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected QuestEventChallenge read(File file) {
|
||||||
|
final Map<String, List<String>> contents = FileSection.parseSections(FileUtil.readFile(file));
|
||||||
|
final QuestEventChallenge qc = new QuestEventChallenge();
|
||||||
|
|
||||||
|
// Unique properties
|
||||||
|
FileSection sectionQuest = FileSection.parse(contents.get("quest"), "=");
|
||||||
|
qc.setId(sectionQuest.get("ID", "-1"));
|
||||||
|
qc.setOpponent(sectionQuest.get("OpponentName"));
|
||||||
|
qc.setRepeatable(sectionQuest.getBoolean("Repeat", false));
|
||||||
|
qc.setAiLife(sectionQuest.getInt("AILife", 25));
|
||||||
|
qc.setWinsReqd(sectionQuest.getInt("Wins", 20));
|
||||||
|
qc.setCreditsReward(sectionQuest.getInt("Credit Reward", 100));
|
||||||
|
qc.setCardReward(sectionQuest.get("Card Reward"));
|
||||||
|
qc.setHumanExtraCards(Arrays.asList(TextUtil.split(sectionQuest.get("HumanExtras", ""), '|')));
|
||||||
|
qc.setAiExtraCards(Arrays.asList(TextUtil.split(sectionQuest.get("AIExtras", ""), '|')));
|
||||||
|
|
||||||
|
// Common properties
|
||||||
|
FileSection sectionMeta = FileSection.parse(contents.get("metadata"), "=");
|
||||||
|
qc.setTitle(sectionMeta.get("Title"));
|
||||||
|
qc.setName(qc.getTitle()); // Challenges have unique titles
|
||||||
|
qc.setDifficulty(QuestEventDifficulty.fromString(sectionMeta.get("Difficulty")));
|
||||||
|
qc.setDescription(sectionMeta.get("Description"));
|
||||||
|
qc.setIconImageKey(ImageCache.ICON_PREFIX + sectionMeta.get("Icon"));
|
||||||
|
|
||||||
|
// Deck
|
||||||
|
qc.setEventDeck(Deck.fromSections(contents));
|
||||||
|
return qc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected FilenameFilter getFileFilter() {
|
||||||
|
return DeckSerializer.DCK_FILE_FILTER;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -121,7 +121,6 @@ public class QuestDataIO {
|
|||||||
QuestData data = null;
|
QuestData data = null;
|
||||||
|
|
||||||
final GZIPInputStream zin = new GZIPInputStream(new FileInputStream(xmlSaveFile));
|
final GZIPInputStream zin = new GZIPInputStream(new FileInputStream(xmlSaveFile));
|
||||||
|
|
||||||
final StringBuilder xml = new StringBuilder();
|
final StringBuilder xml = new StringBuilder();
|
||||||
final char[] buf = new char[1024];
|
final char[] buf = new char[1024];
|
||||||
final InputStreamReader reader = new InputStreamReader(zin);
|
final InputStreamReader reader = new InputStreamReader(zin);
|
||||||
@@ -135,11 +134,12 @@ public class QuestDataIO {
|
|||||||
|
|
||||||
zin.close();
|
zin.close();
|
||||||
|
|
||||||
data = (QuestData) QuestDataIO.getSerializer(true).fromXML(xml.toString());
|
String bigXML = xml.toString();
|
||||||
|
data = (QuestData) QuestDataIO.getSerializer(true).fromXML(bigXML);
|
||||||
|
|
||||||
if (data.getVersionNumber() != QuestData.CURRENT_VERSION_NUMBER) {
|
if (data.getVersionNumber() != QuestData.CURRENT_VERSION_NUMBER) {
|
||||||
try {
|
try {
|
||||||
QuestDataIO.updateSaveFile(data, xml.toString(), xmlSaveFile.getName().replace(".dat", ""));
|
QuestDataIO.updateSaveFile(data, bigXML, xmlSaveFile.getName().replace(".dat", ""));
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
forge.error.BugReporter.reportException(e);
|
forge.error.BugReporter.reportException(e);
|
||||||
}
|
}
|
||||||
@@ -204,9 +204,10 @@ public class QuestDataIO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final QuestAssets qS = newData.getAssets();
|
final QuestAssets qS = newData.getAssets();
|
||||||
|
final QuestAchievements qA = newData.getAchievements();
|
||||||
|
|
||||||
switch (saveVersion) {
|
switch (saveVersion) {
|
||||||
// There should be a fall-through b/w the cases so that each
|
// There should be a fall-through between the cases so that each
|
||||||
// version's changes get applied progressively
|
// version's changes get applied progressively
|
||||||
case 0:
|
case 0:
|
||||||
// First beta release with new file format,
|
// First beta release with new file format,
|
||||||
@@ -234,7 +235,6 @@ public class QuestDataIO {
|
|||||||
QuestDataIO.setFinalField(QuestData.class, "name", newData, filename);
|
QuestDataIO.setFinalField(QuestData.class, "name", newData, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
final QuestAchievements qA = newData.getAchievements();
|
|
||||||
QuestDataIO.setFinalField(QuestAchievements.class, "win", qA, Integer.parseInt(document.getElementsByTagName("win").item(0).getTextContent()));
|
QuestDataIO.setFinalField(QuestAchievements.class, "win", qA, Integer.parseInt(document.getElementsByTagName("win").item(0).getTextContent()));
|
||||||
QuestDataIO.setFinalField(QuestAchievements.class, "lost", qA, Integer.parseInt(document.getElementsByTagName("lost").item(0).getTextContent()));
|
QuestDataIO.setFinalField(QuestAchievements.class, "lost", qA, Integer.parseInt(document.getElementsByTagName("lost").item(0).getTextContent()));
|
||||||
|
|
||||||
@@ -319,6 +319,19 @@ public class QuestDataIO {
|
|||||||
|
|
||||||
// pet manager will be re-engineered here
|
// pet manager will be re-engineered here
|
||||||
|
|
||||||
|
case 6:
|
||||||
|
// have to convert completed challenges list members to strings.
|
||||||
|
for(int i = qA.getLockedChallenges().size()-1; i >= 0; i-- ) {
|
||||||
|
Object lc = qA.getLockedChallenges().get(i);
|
||||||
|
if (!(lc instanceof String))
|
||||||
|
qA.getLockedChallenges().set(i, lc.toString());
|
||||||
|
}
|
||||||
|
for(int i = qA.getCurrentChallenges().size()-1; i >= 0; i-- ) {
|
||||||
|
Object lc = qA.getCurrentChallenges().get(i);
|
||||||
|
if (!(lc instanceof String))
|
||||||
|
qA.getCurrentChallenges().set(i, lc.toString());
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
47
src/main/java/forge/quest/io/QuestDuelReader.java
Normal file
47
src/main/java/forge/quest/io/QuestDuelReader.java
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package forge.quest.io;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import forge.ImageCache;
|
||||||
|
import forge.deck.Deck;
|
||||||
|
import forge.deck.io.DeckSerializer;
|
||||||
|
import forge.quest.QuestEvent;
|
||||||
|
import forge.quest.QuestEventDifficulty;
|
||||||
|
import forge.quest.QuestEventDuel;
|
||||||
|
import forge.util.FileSection;
|
||||||
|
import forge.util.FileUtil;
|
||||||
|
import forge.util.storage.StorageReaderFolder;
|
||||||
|
|
||||||
|
public class QuestDuelReader extends StorageReaderFolder<QuestEventDuel> {
|
||||||
|
public QuestDuelReader(File deckDir0) {
|
||||||
|
super(deckDir0, QuestEvent.FN_GET_NAME);
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected QuestEventDuel read(File file) {
|
||||||
|
final Map<String, List<String>> contents = FileSection.parseSections(FileUtil.readFile(file));
|
||||||
|
final QuestEventDuel qc = new QuestEventDuel();
|
||||||
|
|
||||||
|
// Common properties
|
||||||
|
FileSection sectionMeta = FileSection.parse(contents.get("metadata"), "=");
|
||||||
|
qc.setTitle(sectionMeta.get("Title"));
|
||||||
|
qc.setName(sectionMeta.get("Name")); // Challenges have unique titles
|
||||||
|
qc.setDifficulty(QuestEventDifficulty.fromString(sectionMeta.get("Difficulty")));
|
||||||
|
qc.setDescription(sectionMeta.get("Description"));
|
||||||
|
qc.setCardReward(sectionMeta.get("Card Reward"));
|
||||||
|
qc.setIconImageKey(ImageCache.ICON_PREFIX + sectionMeta.get("Icon"));
|
||||||
|
|
||||||
|
// Deck
|
||||||
|
qc.setEventDeck(Deck.fromSections(contents));
|
||||||
|
return qc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected FilenameFilter getFileFilter() {
|
||||||
|
return DeckSerializer.DCK_FILE_FILTER;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,4 +32,15 @@ public class BinaryUtil {
|
|||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
} // bit count
|
} // bit count
|
||||||
|
|
||||||
|
public static int getLeastImportantBitIndex(final byte num) {
|
||||||
|
if( num == 0 ) return -1;
|
||||||
|
byte mask = 1;
|
||||||
|
for(int i = 0; mask != 0; i++) {
|
||||||
|
if( (mask & num) != 0)
|
||||||
|
return i;
|
||||||
|
mask = (byte) (mask << 1);
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,6 +105,14 @@ public class FileSection {
|
|||||||
return this.lines.get(fieldName);
|
return this.lines.get(fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String get(final String fieldName, final String defaultValue) {
|
||||||
|
return lines.containsKey(fieldName) ? this.lines.get(fieldName) : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(String keyName) {
|
||||||
|
return lines.containsKey(keyName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the int.
|
* Gets the int.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package forge.util;
|
package forge.util;
|
||||||
|
|
||||||
|
import java.security.SecureRandom;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,7 +31,7 @@ import java.util.Random;
|
|||||||
*/
|
*/
|
||||||
public class MyRandom {
|
public class MyRandom {
|
||||||
/** Constant <code>random</code>. */
|
/** Constant <code>random</code>. */
|
||||||
private static Random random = new Random();
|
private static Random random = new SecureRandom();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ package forge.util.storage;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Write javadoc for this type.
|
* TODO: Write javadoc for this type.
|
||||||
*
|
*
|
||||||
@@ -36,6 +38,8 @@ public interface IStorageView<T> extends Iterable<T> {
|
|||||||
*/
|
*/
|
||||||
T get(final String name);
|
T get(final String name);
|
||||||
|
|
||||||
|
T find(final Predicate<T> condition);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get names of decks.
|
* Get names of decks.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ import forge.util.IItemReader;
|
|||||||
public abstract class StorageReaderFolder<T> implements IItemReader<T> {
|
public abstract class StorageReaderFolder<T> implements IItemReader<T> {
|
||||||
|
|
||||||
private final File directory;
|
private final File directory;
|
||||||
private final Function<T, String> keySelector;
|
private final Function<? super T, String> keySelector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the directory.
|
* Gets the directory.
|
||||||
@@ -62,7 +62,7 @@ public abstract class StorageReaderFolder<T> implements IItemReader<T> {
|
|||||||
*
|
*
|
||||||
* @param deckDir0 the deck dir0
|
* @param deckDir0 the deck dir0
|
||||||
*/
|
*/
|
||||||
public StorageReaderFolder(final File deckDir0, Function<T, String> keySelector0) {
|
public StorageReaderFolder(final File deckDir0, Function<? super T, String> keySelector0) {
|
||||||
|
|
||||||
this.directory = deckDir0;
|
this.directory = deckDir0;
|
||||||
keySelector = keySelector0;
|
keySelector = keySelector0;
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ import java.util.Collection;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
import forge.util.IItemReader;
|
import forge.util.IItemReader;
|
||||||
|
|
||||||
//reads and writeDeck Deck objects
|
//reads and writeDeck Deck objects
|
||||||
@@ -58,6 +61,7 @@ public class StorageView<T> implements IStorageView<T> {
|
|||||||
return this.map.get(name);
|
return this.map.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
@@ -94,4 +98,9 @@ public class StorageView<T> implements IStorageView<T> {
|
|||||||
public int size() {
|
public int size() {
|
||||||
return this.map.size();
|
return this.map.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T find(Predicate<T> condition) {
|
||||||
|
return Iterables.tryFind(map.values(), condition).orNull();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user