mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
Support creating custom gauntlet for mobile game
This commit is contained in:
@@ -85,7 +85,7 @@ public enum CSubmenuGauntletLoad implements ICDoc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateData() {
|
private void updateData() {
|
||||||
final File[] files = GauntletIO.getGauntletFilesUnlocked();
|
final File[] files = GauntletIO.getGauntletFilesUnlocked(null);
|
||||||
final List<GauntletData> data = new ArrayList<GauntletData>();
|
final List<GauntletData> data = new ArrayList<GauntletData>();
|
||||||
|
|
||||||
for (final File f : files) {
|
for (final File f : files) {
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public class GauntletScreen extends LaunchScreen {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
final File[] files = GauntletIO.getGauntletFilesUnlocked();
|
final File[] files = GauntletIO.getGauntletFilesUnlocked(null);
|
||||||
final List<GauntletData> data = new ArrayList<GauntletData>();
|
final List<GauntletData> data = new ArrayList<GauntletData>();
|
||||||
|
|
||||||
for (final File f : files) {
|
for (final File f : files) {
|
||||||
@@ -131,7 +131,7 @@ public class GauntletScreen extends LaunchScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createQuickGauntlet() {
|
private void createQuickGauntlet() {
|
||||||
GuiChoose.getInteger("How many opponents are you willing to face?", 5, 50, new Callback<Integer>() {
|
GuiChoose.getInteger("How many opponents are you willing to face?", 3, 50, new Callback<Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(final Integer numOpponents) {
|
public void run(final Integer numOpponents) {
|
||||||
if (numOpponents == null) { return; }
|
if (numOpponents == null) { return; }
|
||||||
@@ -148,7 +148,7 @@ public class GauntletScreen extends LaunchScreen {
|
|||||||
public void run(final List<DeckType> allowedDeckTypes) {
|
public void run(final List<DeckType> allowedDeckTypes) {
|
||||||
if (allowedDeckTypes == null || allowedDeckTypes.isEmpty()) { return; }
|
if (allowedDeckTypes == null || allowedDeckTypes.isEmpty()) { return; }
|
||||||
|
|
||||||
FDeckChooser.promptForDeck("Select Deck for Gauntlet", GameType.Gauntlet, false, new Callback<Deck>() {
|
FDeckChooser.promptForDeck("Select Your Deck", GameType.Gauntlet, false, new Callback<Deck>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(Deck userDeck) {
|
public void run(Deck userDeck) {
|
||||||
if (userDeck == null) { return; }
|
if (userDeck == null) { return; }
|
||||||
@@ -165,7 +165,48 @@ public class GauntletScreen extends LaunchScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createCustomGauntlet() {
|
private void createCustomGauntlet() {
|
||||||
|
GuiChoose.getInteger("How many opponents are you willing to face?", 3, 50, new Callback<Integer>() {
|
||||||
|
@Override
|
||||||
|
public void run(final Integer numOpponents) {
|
||||||
|
if (numOpponents == null) { return; }
|
||||||
|
|
||||||
|
GauntletData gauntlet = new GauntletData();
|
||||||
|
gauntlet.setDecks(new ArrayList<Deck>());
|
||||||
|
promptForAiDeck(gauntlet, numOpponents);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void promptForAiDeck(final GauntletData gauntlet, final int numOpponents) {
|
||||||
|
final int opponentNum = gauntlet.getDecks().size() + 1;
|
||||||
|
FDeckChooser.promptForDeck("Select Deck for Opponent " + opponentNum + " / " + numOpponents, GameType.Gauntlet, true, new Callback<Deck>() {
|
||||||
|
@Override
|
||||||
|
public void run(Deck aiDeck) {
|
||||||
|
if (aiDeck == null) { return; }
|
||||||
|
|
||||||
|
gauntlet.getDecks().add(aiDeck);
|
||||||
|
gauntlet.getEventNames().add(aiDeck.getName());
|
||||||
|
|
||||||
|
if (opponentNum < numOpponents) {
|
||||||
|
promptForAiDeck(gauntlet, numOpponents);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//once all ai decks have been selected, prompt for user deck
|
||||||
|
FDeckChooser.promptForDeck("Select Your Deck", GameType.Gauntlet, false, new Callback<Deck>() {
|
||||||
|
@Override
|
||||||
|
public void run(Deck userDeck) {
|
||||||
|
if (userDeck == null) { return; }
|
||||||
|
|
||||||
|
gauntlet.setUserDeck(userDeck);
|
||||||
|
GauntletUtil.setDefaultGauntletName(gauntlet, GauntletIO.PREFIX_CUSTOM);
|
||||||
|
FModel.setGauntletData(gauntlet);
|
||||||
|
gauntlet.reset();
|
||||||
|
lstGauntlets.addGauntlet(gauntlet);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createGauntletContest() {
|
private void createGauntletContest() {
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ public class GauntletIO {
|
|||||||
public static final String SUFFIX_DATA = ".dat";
|
public static final String SUFFIX_DATA = ".dat";
|
||||||
/** Prefix for quick gauntlet save files. */
|
/** Prefix for quick gauntlet save files. */
|
||||||
public static final String PREFIX_QUICK = "Quick_";
|
public static final String PREFIX_QUICK = "Quick_";
|
||||||
|
/** Prefix for custom gauntlet save files. */
|
||||||
|
public static final String PREFIX_CUSTOM = "Custom_";
|
||||||
/** Regex for locked gauntlet save files. */
|
/** Regex for locked gauntlet save files. */
|
||||||
public static final String PREFIX_LOCKED = "LOCKED_";
|
public static final String PREFIX_LOCKED = "LOCKED_";
|
||||||
|
|
||||||
@@ -46,23 +48,11 @@ public class GauntletIO {
|
|||||||
return getGauntletFile(gd.getName());
|
return getGauntletFile(gd.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File[] getGauntletFilesUnlocked() {
|
public static File[] getGauntletFilesUnlocked(final String prefix) {
|
||||||
final FilenameFilter filter = new FilenameFilter() {
|
final FilenameFilter filter = new FilenameFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File dir, String name) {
|
public boolean accept(File dir, String name) {
|
||||||
return (name.endsWith(SUFFIX_DATA));
|
return ((prefix == null || name.startsWith(prefix)) && name.endsWith(SUFFIX_DATA));
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
File folder = new File(ForgeConstants.GAUNTLET_DIR.userPrefLoc);
|
|
||||||
return folder.listFiles(filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File[] getGauntletFilesQuick() {
|
|
||||||
final FilenameFilter filter = new FilenameFilter() {
|
|
||||||
@Override
|
|
||||||
public boolean accept(File dir, String name) {
|
|
||||||
return (name.startsWith(PREFIX_QUICK) && name.endsWith(SUFFIX_DATA));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,58 +13,64 @@ import forge.model.FModel;
|
|||||||
|
|
||||||
public class GauntletUtil {
|
public class GauntletUtil {
|
||||||
public static GauntletData createQuickGauntlet(final Deck userDeck, final int numOpponents, final List<DeckType> allowedDeckTypes) {
|
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++; }
|
|
||||||
GauntletData gauntlet = new GauntletData();
|
GauntletData gauntlet = new GauntletData();
|
||||||
gauntlet.setName(GauntletIO.PREFIX_QUICK + num);
|
setDefaultGauntletName(gauntlet, GauntletIO.PREFIX_QUICK);
|
||||||
FModel.setGauntletData(gauntlet);
|
FModel.setGauntletData(gauntlet);
|
||||||
|
|
||||||
// Generate gauntlet decks
|
// Generate gauntlet decks
|
||||||
final List<String> lstEventNames = new ArrayList<String>();
|
Deck deck;
|
||||||
final List<Deck> lstGauntletDecks = new ArrayList<Deck>();
|
final List<String> eventNames = new ArrayList<String>();
|
||||||
Deck tempDeck;
|
final List<Deck> decks = new ArrayList<Deck>();
|
||||||
|
|
||||||
for (int i = 0; i < numOpponents; i++) {
|
for (int i = 0; i < numOpponents; i++) {
|
||||||
int randType = (int)Math.floor(Math.random() * allowedDeckTypes.size());
|
int randType = (int)Math.floor(Math.random() * allowedDeckTypes.size());
|
||||||
switch (allowedDeckTypes.get(randType)) {
|
switch (allowedDeckTypes.get(randType)) {
|
||||||
case COLOR_DECK:
|
case COLOR_DECK:
|
||||||
tempDeck = DeckgenUtil.getRandomColorDeck(true);
|
deck = DeckgenUtil.getRandomColorDeck(true);
|
||||||
lstEventNames.add("Random colors deck");
|
eventNames.add("Random colors deck");
|
||||||
break;
|
break;
|
||||||
case CUSTOM_DECK:
|
case CUSTOM_DECK:
|
||||||
tempDeck = DeckgenUtil.getRandomCustomDeck();
|
deck = DeckgenUtil.getRandomCustomDeck();
|
||||||
lstEventNames.add(tempDeck.getName());
|
eventNames.add(deck.getName());
|
||||||
break;
|
break;
|
||||||
case PRECONSTRUCTED_DECK:
|
case PRECONSTRUCTED_DECK:
|
||||||
tempDeck = DeckgenUtil.getRandomPreconDeck();
|
deck = DeckgenUtil.getRandomPreconDeck();
|
||||||
lstEventNames.add(tempDeck.getName());
|
eventNames.add(deck.getName());
|
||||||
break;
|
break;
|
||||||
case QUEST_OPPONENT_DECK:
|
case QUEST_OPPONENT_DECK:
|
||||||
tempDeck = DeckgenUtil.getRandomQuestDeck();
|
deck = DeckgenUtil.getRandomQuestDeck();
|
||||||
lstEventNames.add(tempDeck.getName());
|
eventNames.add(deck.getName());
|
||||||
break;
|
break;
|
||||||
case THEME_DECK:
|
case THEME_DECK:
|
||||||
tempDeck = DeckgenUtil.getRandomThemeDeck();
|
deck = DeckgenUtil.getRandomThemeDeck();
|
||||||
lstEventNames.add(tempDeck.getName());
|
eventNames.add(deck.getName());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
lstGauntletDecks.add(tempDeck);
|
decks.add(deck);
|
||||||
}
|
}
|
||||||
|
|
||||||
gauntlet.setDecks(lstGauntletDecks);
|
gauntlet.setDecks(decks);
|
||||||
gauntlet.setEventNames(lstEventNames);
|
gauntlet.setEventNames(eventNames);
|
||||||
gauntlet.setUserDeck(userDeck);
|
gauntlet.setUserDeck(userDeck);
|
||||||
|
|
||||||
// Reset all variable fields to 0, stamps and saves automatically.
|
// Reset all variable fields to 0, stamps and saves automatically.
|
||||||
gauntlet.reset();
|
gauntlet.reset();
|
||||||
return gauntlet;
|
return gauntlet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setDefaultGauntletName(GauntletData gauntlet, String prefix) {
|
||||||
|
final File[] arrFiles = GauntletIO.getGauntletFilesUnlocked(prefix);
|
||||||
|
final Set<String> setNames = new HashSet<String>();
|
||||||
|
for (File f : arrFiles) {
|
||||||
|
setNames.add(f.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
int num = 1;
|
||||||
|
while (setNames.contains(prefix + num + GauntletIO.SUFFIX_DATA)) {
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
gauntlet.setName(prefix + num);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user