mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
Support creating quick gauntlets for mobile game
Support AI opponents using preconstructed decks in gauntlets
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -16645,6 +16645,7 @@ forge-gui/src/main/java/forge/events/UiEventAttackerDeclared.java -text
|
||||
forge-gui/src/main/java/forge/events/UiEventBlockerAssigned.java -text
|
||||
forge-gui/src/main/java/forge/gauntlet/GauntletData.java -text
|
||||
forge-gui/src/main/java/forge/gauntlet/GauntletIO.java -text
|
||||
forge-gui/src/main/java/forge/gauntlet/GauntletUtil.java -text
|
||||
forge-gui/src/main/java/forge/gauntlet/GauntletWinLoseController.java -text
|
||||
forge-gui/src/main/java/forge/interfaces/IButton.java -text
|
||||
forge-gui/src/main/java/forge/interfaces/ICheckBox.java -text
|
||||
|
||||
@@ -3,25 +3,19 @@ package forge.screens.home.gauntlet;
|
||||
import forge.UiCommand;
|
||||
import forge.Singletons;
|
||||
import forge.control.FControl;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckgenUtil;
|
||||
import forge.deck.DeckgenUtil.DeckTypes;
|
||||
import forge.deck.DeckType;
|
||||
import forge.game.GameType;
|
||||
import forge.game.player.RegisteredPlayer;
|
||||
import forge.gauntlet.GauntletData;
|
||||
import forge.gauntlet.GauntletIO;
|
||||
import forge.gauntlet.GauntletUtil;
|
||||
import forge.gui.SOverlayUtils;
|
||||
import forge.gui.framework.ICDoc;
|
||||
import forge.model.FModel;
|
||||
import javax.swing.*;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Controls the "quick gauntlet" submenu in the home UI.
|
||||
@@ -55,25 +49,9 @@ public enum CSubmenuGauntletQuick implements ICDoc {
|
||||
@Override
|
||||
public void initialize() {
|
||||
view.getBtnStart().addActionListener(actStartGame);
|
||||
|
||||
updateData();
|
||||
|
||||
view.getGauntletLister().setSelectedIndex(0);
|
||||
view.getLstDecks().initialize();
|
||||
}
|
||||
|
||||
|
||||
private void updateData() {
|
||||
final File[] files = GauntletIO.getGauntletFilesUnlocked();
|
||||
final List<GauntletData> data = new ArrayList<GauntletData>();
|
||||
|
||||
for (final File f : files) {
|
||||
data.add(GauntletIO.loadGauntlet(f));
|
||||
}
|
||||
|
||||
view.getGauntletLister().setGauntlets(data);
|
||||
}
|
||||
|
||||
private void startGame() {
|
||||
// Start game overlay
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@@ -85,62 +63,19 @@ public enum CSubmenuGauntletQuick implements ICDoc {
|
||||
});
|
||||
|
||||
// Find appropriate filename for new save, create and set new save file.
|
||||
final File[] arrFiles = GauntletIO.getGauntletFilesQuick();
|
||||
final Set<String> setNames = new HashSet<String>();
|
||||
for (File f : arrFiles) { setNames.add(f.getName()); }
|
||||
List<DeckType> allowedDeckTypes = new ArrayList<DeckType>();
|
||||
if (view.getBoxColorDecks().isSelected()) { allowedDeckTypes.add(DeckType.COLOR_DECK); }
|
||||
if (view.getBoxThemeDecks().isSelected()) { allowedDeckTypes.add(DeckType.THEME_DECK); }
|
||||
if (view.getBoxUserDecks().isSelected()) { allowedDeckTypes.add(DeckType.CUSTOM_DECK); }
|
||||
if (view.getBoxQuestDecks().isSelected()) { allowedDeckTypes.add(DeckType.QUEST_OPPONENT_DECK); }
|
||||
if (view.getBoxPreconDecks().isSelected()) { allowedDeckTypes.add(DeckType.PRECONSTRUCTED_DECK); }
|
||||
|
||||
int num = 1;
|
||||
while (setNames.contains(GauntletIO.PREFIX_QUICK + num + GauntletIO.SUFFIX_DATA)) { num++; }
|
||||
FModel.getGauntletData().setName(GauntletIO.PREFIX_QUICK + num);
|
||||
|
||||
// Pull user deck
|
||||
final Deck userDeck = view.getLstDecks().getPlayer().getDeck();
|
||||
|
||||
// Generate gauntlet decks
|
||||
final int numOpponents = view.getSliOpponents().getValue();
|
||||
final List<DeckTypes> lstDecktypes = new ArrayList<DeckTypes>();
|
||||
final List<String> lstEventNames = new ArrayList<String>();
|
||||
final List<Deck> lstGauntletDecks = new ArrayList<Deck>();
|
||||
Deck tempDeck;
|
||||
int randType;
|
||||
|
||||
if (view.getBoxColorDecks().isSelected()) { lstDecktypes.add(DeckTypes.COLORS); }
|
||||
if (view.getBoxThemeDecks().isSelected()) { lstDecktypes.add(DeckTypes.THEMES); }
|
||||
if (view.getBoxUserDecks().isSelected()) { lstDecktypes.add(DeckTypes.CUSTOM); }
|
||||
if (view.getBoxQuestDecks().isSelected()) { lstDecktypes.add(DeckTypes.QUESTEVENTS); }
|
||||
|
||||
for (int i = 0; i < numOpponents; i++) {
|
||||
randType = (int) Math.round(Math.random() * (lstDecktypes.size() - 1));
|
||||
if (lstDecktypes.get(randType).equals(DeckTypes.COLORS)) {
|
||||
tempDeck = DeckgenUtil.getRandomColorDeck(true);
|
||||
lstEventNames.add("Random colors deck");
|
||||
}
|
||||
else if (lstDecktypes.get(randType).equals(DeckTypes.CUSTOM)) {
|
||||
tempDeck = DeckgenUtil.getRandomCustomDeck();
|
||||
lstEventNames.add(tempDeck.getName());
|
||||
}
|
||||
else {
|
||||
tempDeck = DeckgenUtil.getRandomQuestDeck();
|
||||
lstEventNames.add(tempDeck.getName());
|
||||
}
|
||||
|
||||
lstGauntletDecks.add(tempDeck);
|
||||
}
|
||||
|
||||
final GauntletData gd = FModel.getGauntletData();
|
||||
gd.setDecks(lstGauntletDecks);
|
||||
gd.setEventNames(lstEventNames);
|
||||
gd.setUserDeck(userDeck);
|
||||
|
||||
// Reset all variable fields to 0, stamps and saves automatically.
|
||||
gd.reset();
|
||||
|
||||
final Deck aiDeck = gd.getDecks().get(gd.getCompleted());
|
||||
final GauntletData gd = GauntletUtil.createQuickGauntlet(view.getLstDecks().getPlayer().getDeck(), view.getSliOpponents().getValue(), allowedDeckTypes);
|
||||
|
||||
List<RegisteredPlayer> starter = new ArrayList<RegisteredPlayer>();
|
||||
FControl fc = Singletons.getControl();
|
||||
starter.add(new RegisteredPlayer(gd.getUserDeck()).setPlayer(fc.getGuiPlayer()));
|
||||
starter.add(new RegisteredPlayer(aiDeck).setPlayer(fc.getAiPlayer()));
|
||||
starter.add(new RegisteredPlayer(gd.getDecks().get(gd.getCompleted())).setPlayer(fc.getAiPlayer()));
|
||||
|
||||
fc.startMatch(GameType.Gauntlet, starter);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package forge.screens.home.gauntlet;
|
||||
|
||||
import forge.deck.DeckType;
|
||||
import forge.deckchooser.FDeckChooser;
|
||||
import forge.gui.framework.DragCell;
|
||||
import forge.gui.framework.DragTab;
|
||||
@@ -46,13 +47,13 @@ public enum VSubmenuGauntletQuick implements IVSubmenu<CSubmenuGauntletQuick> {
|
||||
private final SkinnedSlider sliOpponents = new SkinnedSlider(SwingConstants.HORIZONTAL, 5, 50, 20);
|
||||
//private SkinnedSlider sliGamesPerMatch = new SkinnedSlider(JSlider.HORIZONTAL, 1, 7, 3);
|
||||
|
||||
private final JCheckBox boxUserDecks = new FCheckBox("Custom User Decks");
|
||||
private final JCheckBox boxQuestDecks = new FCheckBox("Quest Decks");
|
||||
private final JCheckBox boxColorDecks = new FCheckBox("Fully random color Decks");
|
||||
private final JCheckBox boxThemeDecks = new FCheckBox("Semi-random theme Decks");
|
||||
private final JCheckBox boxUserDecks = new FCheckBox(DeckType.CUSTOM_DECK.toString());
|
||||
private final JCheckBox boxPreconDecks = new FCheckBox(DeckType.PRECONSTRUCTED_DECK.toString());
|
||||
private final JCheckBox boxQuestDecks = new FCheckBox(DeckType.QUEST_OPPONENT_DECK.toString());
|
||||
private final JCheckBox boxColorDecks = new FCheckBox(DeckType.COLOR_DECK.toString());
|
||||
private final JCheckBox boxThemeDecks = new FCheckBox(DeckType.THEME_DECK.toString());
|
||||
|
||||
private final FDeckChooser lstDecks = new FDeckChooser(false);
|
||||
private final QuickGauntletLister gauntletList = new QuickGauntletLister();
|
||||
|
||||
private final FLabel lblOptions = new FLabel.Builder().fontSize(16)
|
||||
.fontStyle(Font.BOLD).text("OPTIONS").fontAlign(SwingConstants.CENTER).build();
|
||||
@@ -73,6 +74,7 @@ public enum VSubmenuGauntletQuick implements IVSubmenu<CSubmenuGauntletQuick> {
|
||||
lblTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
||||
|
||||
boxUserDecks.setSelected(true);
|
||||
boxPreconDecks.setSelected(true);
|
||||
boxQuestDecks.setSelected(true);
|
||||
boxThemeDecks.setSelected(true);
|
||||
boxColorDecks.setSelected(true);
|
||||
@@ -93,6 +95,7 @@ public enum VSubmenuGauntletQuick implements IVSubmenu<CSubmenuGauntletQuick> {
|
||||
pnlOptions.add(lblDesc3, "w 96%!, gap 2% 0 0 0");
|
||||
pnlOptions.setCornerDiameter(0);
|
||||
pnlOptions.add(boxUserDecks, "w 96%!, h 30px!, gap 2% 0 0 5px");
|
||||
pnlOptions.add(boxPreconDecks, "w 96%!, h 30px!, gap 2% 0 0 5px");
|
||||
pnlOptions.add(boxQuestDecks, "w 96%!, h 30px!, gap 2% 0 0 5px");
|
||||
pnlOptions.add(boxThemeDecks, "w 96%!, h 30px!, gap 2% 0 0 5px");
|
||||
pnlOptions.add(boxColorDecks, "w 96%!, h 30px!, gap 2% 0 0 0");
|
||||
@@ -148,16 +151,16 @@ public enum VSubmenuGauntletQuick implements IVSubmenu<CSubmenuGauntletQuick> {
|
||||
return this.lstDecks;
|
||||
}
|
||||
|
||||
/** @return {@link forge.screens.home.gauntlet.QuickGauntletLister} */
|
||||
public QuickGauntletLister getGauntletLister() {
|
||||
return this.gauntletList;
|
||||
}
|
||||
|
||||
/** @return {@link javax.swing.JCheckBox} */
|
||||
public JCheckBox getBoxUserDecks() {
|
||||
return boxUserDecks;
|
||||
}
|
||||
|
||||
/** @return {@link javax.swing.JCheckBox} */
|
||||
public JCheckBox getBoxPreconDecks() {
|
||||
return boxPreconDecks;
|
||||
}
|
||||
|
||||
/** @return {@link javax.swing.JCheckBox} */
|
||||
public JCheckBox getBoxQuestDecks() {
|
||||
return boxQuestDecks;
|
||||
|
||||
@@ -3,6 +3,7 @@ package forge.screens.gauntlet;
|
||||
import java.io.File;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
@@ -10,7 +11,6 @@ import java.util.List;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
||||
|
||||
import forge.FThreads;
|
||||
import forge.Forge;
|
||||
import forge.Graphics;
|
||||
import forge.GuiBase;
|
||||
import forge.assets.FSkinColor;
|
||||
@@ -18,11 +18,13 @@ import forge.assets.FSkinColor.Colors;
|
||||
import forge.assets.FSkinFont;
|
||||
import forge.card.CardRenderer;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckType;
|
||||
import forge.deck.FDeckChooser;
|
||||
import forge.game.GameType;
|
||||
import forge.game.player.RegisteredPlayer;
|
||||
import forge.gauntlet.GauntletData;
|
||||
import forge.gauntlet.GauntletIO;
|
||||
import forge.gauntlet.GauntletUtil;
|
||||
import forge.model.FModel;
|
||||
import forge.quest.QuestUtil;
|
||||
import forge.screens.LaunchScreen;
|
||||
@@ -31,6 +33,8 @@ import forge.toolbox.FButton;
|
||||
import forge.toolbox.FEvent;
|
||||
import forge.toolbox.FList;
|
||||
import forge.toolbox.FOptionPane;
|
||||
import forge.toolbox.GuiChoose;
|
||||
import forge.toolbox.ListChooser;
|
||||
import forge.toolbox.FEvent.FEventHandler;
|
||||
import forge.util.Callback;
|
||||
import forge.util.ThreadUtil;
|
||||
@@ -53,7 +57,28 @@ public class GauntletScreen extends LaunchScreen {
|
||||
btnNewGauntlet.setCommand(new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
Forge.openScreen(new NewGauntletScreen());
|
||||
GuiChoose.oneOrNone("Select a Gauntlet Type", new String[] {
|
||||
"Quick Gauntlet",
|
||||
"Custom Gauntlet",
|
||||
"Gauntlet Contest",
|
||||
}, new Callback<String>() {
|
||||
@Override
|
||||
public void run(String result) {
|
||||
if (result == null) { return; }
|
||||
|
||||
switch (result) {
|
||||
case "Quick Gauntlet":
|
||||
createQuickGauntlet();
|
||||
break;
|
||||
case "Custom Gauntlet":
|
||||
createCustomGauntlet();
|
||||
break;
|
||||
default:
|
||||
createGauntletContest();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
btnRenameGauntlet.setFont(btnNewGauntlet.getFont());
|
||||
@@ -107,6 +132,48 @@ public class GauntletScreen extends LaunchScreen {
|
||||
btnDeleteGauntlet.setBounds(x, y, buttonWidth, buttonHeight);
|
||||
}
|
||||
|
||||
private void createQuickGauntlet() {
|
||||
GuiChoose.getInteger("How many opponents are you willing to face?", 5, 50, new Callback<Integer>() {
|
||||
@Override
|
||||
public void run(final Integer numOpponents) {
|
||||
if (numOpponents == null) { return; }
|
||||
|
||||
ListChooser<DeckType> chooser = new ListChooser<DeckType>(
|
||||
"Choose allowed deck types", 0, 5, Arrays.asList(new DeckType[] {
|
||||
DeckType.CUSTOM_DECK,
|
||||
DeckType.PRECONSTRUCTED_DECK,
|
||||
DeckType.QUEST_OPPONENT_DECK,
|
||||
DeckType.COLOR_DECK,
|
||||
DeckType.THEME_DECK
|
||||
}), null, new Callback<List<DeckType>>() {
|
||||
@Override
|
||||
public void run(final List<DeckType> allowedDeckTypes) {
|
||||
if (allowedDeckTypes == null || allowedDeckTypes.isEmpty()) { return; }
|
||||
|
||||
FDeckChooser.promptForDeck("Select Deck for Gauntlet", GameType.Gauntlet, false, new Callback<Deck>() {
|
||||
@Override
|
||||
public void run(Deck userDeck) {
|
||||
if (userDeck == null) { return; }
|
||||
|
||||
lstGauntlets.addGauntlet(GauntletUtil.createQuickGauntlet(
|
||||
userDeck, numOpponents, allowedDeckTypes));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
chooser.show(null, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void createCustomGauntlet() {
|
||||
|
||||
}
|
||||
|
||||
private void createGauntletContest() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startMatch() {
|
||||
final GauntletData gauntlet = lstGauntlets.getSelectedGauntlet();
|
||||
@@ -124,7 +191,6 @@ public class GauntletScreen extends LaunchScreen {
|
||||
if (result != null) {
|
||||
gauntlet.setUserDeck(result);
|
||||
GauntletIO.saveGauntlet(gauntlet);
|
||||
startMatch();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -276,6 +342,13 @@ public class GauntletScreen extends LaunchScreen {
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void addGauntlet(GauntletData gauntlet) {
|
||||
if (gauntlets == null) { return; }
|
||||
gauntlets.add(gauntlet);
|
||||
refresh();
|
||||
setSelectedGauntlet(gauntlet);
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
List<GauntletData> sorted = new ArrayList<GauntletData>();
|
||||
for (GauntletData gauntlet : gauntlets) {
|
||||
@@ -293,6 +366,7 @@ public class GauntletScreen extends LaunchScreen {
|
||||
public boolean setSelectedIndex(int i0) {
|
||||
if (i0 >= getCount()) { return false; }
|
||||
selectedIndex = i0;
|
||||
scrollIntoView(i0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -305,6 +379,7 @@ public class GauntletScreen extends LaunchScreen {
|
||||
for (int i = 0; i < getCount(); i++) {
|
||||
if (getItemAt(i) == gauntlet) {
|
||||
selectedIndex = i;
|
||||
scrollIntoView(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ public class GuiChoose {
|
||||
}
|
||||
|
||||
ListChooser<T> c = new ListChooser<T>(message, min, max, choices, display, callback);
|
||||
c.show(selected);
|
||||
c.show(selected, false);
|
||||
}
|
||||
|
||||
public static <T> void many(final String title, final String topCaption, int cnt, final List<T> sourceChoices, Card referenceCard, final Callback<List<T>> callback) {
|
||||
|
||||
@@ -173,7 +173,7 @@ public class ListChooser<T> extends FContainer {
|
||||
}
|
||||
|
||||
public void show() {
|
||||
show(null);
|
||||
show(null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,14 +182,20 @@ public class ListChooser<T> extends FContainer {
|
||||
* @param index0 index to select when shown
|
||||
* @return a boolean.
|
||||
*/
|
||||
public void show(final T item) {
|
||||
public void show(final T item, final boolean selectMax) {
|
||||
if (called) {
|
||||
throw new IllegalStateException("Already shown");
|
||||
}
|
||||
called = true;
|
||||
lstChoices.selectedIndices.clear();
|
||||
if (item == null) {
|
||||
if (maxChoices == 1) { //select first item only if single-select
|
||||
if (selectMax) {
|
||||
int max = Math.min(maxChoices, list.size());
|
||||
for (int i = 0; i < max; i++) {
|
||||
lstChoices.selectedIndices.add(i);
|
||||
}
|
||||
}
|
||||
else if (maxChoices == 1) { //select first item only if single-select
|
||||
lstChoices.selectedIndices.add(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,7 +381,7 @@ public class DeckProxy implements InventoryItem {
|
||||
}
|
||||
}
|
||||
|
||||
public static Iterable<DeckProxy> getAllThemeDecks() {
|
||||
public static List<DeckProxy> getAllThemeDecks() {
|
||||
ArrayList<DeckProxy> decks = new ArrayList<DeckProxy>();
|
||||
for (final String s : DeckGeneratorTheme.getThemeNames()) {
|
||||
decks.add(new ThemeDeckGenerator(s));
|
||||
@@ -390,7 +390,7 @@ public class DeckProxy implements InventoryItem {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Iterable<DeckProxy> getAllPreconstructedDecks(IStorage<PreconDeck> iStorage) {
|
||||
public static List<DeckProxy> getAllPreconstructedDecks(IStorage<PreconDeck> iStorage) {
|
||||
ArrayList<DeckProxy> decks = new ArrayList<DeckProxy>();
|
||||
for (final PreconDeck preconDeck : iStorage) {
|
||||
decks.add(new DeckProxy(preconDeck, "Precon", (Function<IHasName, Deck>)(Object)PreconDeck.FN_GET_DECK, null, iStorage));
|
||||
@@ -398,7 +398,7 @@ public class DeckProxy implements InventoryItem {
|
||||
return decks;
|
||||
}
|
||||
|
||||
public static Iterable<DeckProxy> getAllQuestEventAndChallenges() {
|
||||
public static List<DeckProxy> getAllQuestEventAndChallenges() {
|
||||
ArrayList<DeckProxy> decks = new ArrayList<DeckProxy>();
|
||||
QuestController quest = FModel.getQuest();
|
||||
for (QuestEvent e : quest.getDuelsManager().getAllDuels()) {
|
||||
@@ -411,7 +411,7 @@ public class DeckProxy implements InventoryItem {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Iterable<DeckProxy> getAllSealedDecks(IStorage<DeckGroup> sealed) {
|
||||
public static List<DeckProxy> getAllSealedDecks(IStorage<DeckGroup> sealed) {
|
||||
final List<DeckProxy> humanDecks = new ArrayList<DeckProxy>();
|
||||
|
||||
// Since AI decks are tied directly to the human choice,
|
||||
@@ -422,7 +422,7 @@ public class DeckProxy implements InventoryItem {
|
||||
return humanDecks;
|
||||
}
|
||||
|
||||
public static Iterable<DeckProxy> getAllQuestDecks(IStorage<Deck> storage) {
|
||||
public static List<DeckProxy> getAllQuestDecks(IStorage<Deck> storage) {
|
||||
ArrayList<DeckProxy> decks = new ArrayList<DeckProxy>();
|
||||
if (storage != null) {
|
||||
for (final Deck deck : storage) {
|
||||
@@ -433,7 +433,7 @@ public class DeckProxy implements InventoryItem {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Iterable<DeckProxy> getDraftDecks(IStorage<DeckGroup> draft) {
|
||||
public static List<DeckProxy> getDraftDecks(IStorage<DeckGroup> draft) {
|
||||
ArrayList<DeckProxy> decks = new ArrayList<DeckProxy>();
|
||||
for (DeckGroup d : draft) {
|
||||
decks.add(new DeckProxy(d, "Draft", ((Function<IHasName, Deck>)(Object)DeckGroup.FN_HUMAN_DECK), GameType.Draft, draft));
|
||||
@@ -442,7 +442,7 @@ public class DeckProxy implements InventoryItem {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Iterable<DeckProxy> getWinstonDecks(IStorage<DeckGroup> draft) {
|
||||
public static List<DeckProxy> getWinstonDecks(IStorage<DeckGroup> draft) {
|
||||
ArrayList<DeckProxy> decks = new ArrayList<DeckProxy>();
|
||||
for (DeckGroup d : draft) {
|
||||
decks.add(new DeckProxy(d, "Winston", ((Function<IHasName, Deck>)(Object)DeckGroup.FN_HUMAN_DECK), GameType.Winston, draft));
|
||||
|
||||
@@ -39,15 +39,6 @@ import java.util.List;
|
||||
*/
|
||||
// TODO This class can be used for home menu constructed deck generation as well.
|
||||
public class DeckgenUtil {
|
||||
/** */
|
||||
public enum DeckTypes {
|
||||
COLORS,
|
||||
THEMES,
|
||||
CUSTOM,
|
||||
QUESTEVENTS,
|
||||
PRECON
|
||||
}
|
||||
|
||||
/**
|
||||
* @param selection {@link java.lang.String} array
|
||||
* @return {@link forge.deck.Deck}
|
||||
@@ -125,6 +116,20 @@ public class DeckgenUtil {
|
||||
return allDecks.get(name);
|
||||
}
|
||||
|
||||
/** @return {@link forge.deck.Deck} */
|
||||
public static Deck getRandomPreconDeck() {
|
||||
final List<DeckProxy> allDecks = DeckProxy.getAllPreconstructedDecks(QuestController.getPrecons());
|
||||
final int rand = (int) (Math.floor(Math.random() * allDecks.size()));
|
||||
return allDecks.get(rand).getDeck();
|
||||
}
|
||||
|
||||
/** @return {@link forge.deck.Deck} */
|
||||
public static Deck getRandomThemeDeck() {
|
||||
final List<DeckProxy> allDecks = DeckProxy.getAllThemeDecks();
|
||||
final int rand = (int) (Math.floor(Math.random() * allDecks.size()));
|
||||
return allDecks.get(rand).getDeck();
|
||||
}
|
||||
|
||||
public static Deck getRandomQuestDeck() {
|
||||
final List<Deck> allQuestDecks = new ArrayList<Deck>();
|
||||
QuestController qCtrl = FModel.getQuest();
|
||||
|
||||
67
forge-gui/src/main/java/forge/gauntlet/GauntletUtil.java
Normal file
67
forge-gui/src/main/java/forge/gauntlet/GauntletUtil.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package forge.gauntlet;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckType;
|
||||
import forge.deck.DeckgenUtil;
|
||||
import forge.model.FModel;
|
||||
|
||||
public class GauntletUtil {
|
||||
public static GauntletData createQuickGauntlet(final Deck userDeck, final int numOpponents, final List<DeckType> allowedDeckTypes) {
|
||||
final File[] arrFiles = GauntletIO.getGauntletFilesQuick();
|
||||
final Set<String> setNames = new HashSet<String>();
|
||||
for (File f : arrFiles) { setNames.add(f.getName()); }
|
||||
|
||||
int num = 1;
|
||||
while (setNames.contains(GauntletIO.PREFIX_QUICK + num + GauntletIO.SUFFIX_DATA)) { num++; }
|
||||
FModel.getGauntletData().setName(GauntletIO.PREFIX_QUICK + num);
|
||||
|
||||
// Generate gauntlet decks
|
||||
final List<String> lstEventNames = new ArrayList<String>();
|
||||
final List<Deck> lstGauntletDecks = new ArrayList<Deck>();
|
||||
Deck tempDeck;
|
||||
|
||||
for (int i = 0; i < numOpponents; i++) {
|
||||
int randType = (int)Math.floor(Math.random() * allowedDeckTypes.size());
|
||||
switch (allowedDeckTypes.get(randType)) {
|
||||
case COLOR_DECK:
|
||||
tempDeck = DeckgenUtil.getRandomColorDeck(true);
|
||||
lstEventNames.add("Random colors deck");
|
||||
break;
|
||||
case CUSTOM_DECK:
|
||||
tempDeck = DeckgenUtil.getRandomCustomDeck();
|
||||
lstEventNames.add(tempDeck.getName());
|
||||
break;
|
||||
case PRECONSTRUCTED_DECK:
|
||||
tempDeck = DeckgenUtil.getRandomPreconDeck();
|
||||
lstEventNames.add(tempDeck.getName());
|
||||
break;
|
||||
case QUEST_OPPONENT_DECK:
|
||||
tempDeck = DeckgenUtil.getRandomQuestDeck();
|
||||
lstEventNames.add(tempDeck.getName());
|
||||
break;
|
||||
case THEME_DECK:
|
||||
tempDeck = DeckgenUtil.getRandomThemeDeck();
|
||||
lstEventNames.add(tempDeck.getName());
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
lstGauntletDecks.add(tempDeck);
|
||||
}
|
||||
|
||||
final GauntletData gd = FModel.getGauntletData();
|
||||
gd.setDecks(lstGauntletDecks);
|
||||
gd.setEventNames(lstEventNames);
|
||||
gd.setUserDeck(userDeck);
|
||||
|
||||
// Reset all variable fields to 0, stamps and saves automatically.
|
||||
gd.reset();
|
||||
return gd;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user