mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Support creating quick gauntlets for mobile game
Support AI opponents using preconstructed decks in gauntlets
This commit is contained in:
@@ -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