mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
Support generating deck for planar conquest commander
This commit is contained in:
@@ -17,9 +17,9 @@
|
||||
*/
|
||||
package forge.deck;
|
||||
|
||||
import forge.card.ICardDatabase;
|
||||
import forge.deck.CardPool;
|
||||
import forge.deck.generation.DeckGeneratorBase;
|
||||
import forge.deck.generation.IDeckGenPool;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.MyRandom;
|
||||
@@ -47,8 +47,8 @@ public class DeckGeneratorTheme extends DeckGeneratorBase {
|
||||
* Constructor for ThemeDeckGenerator.
|
||||
* </p>
|
||||
*/
|
||||
public DeckGeneratorTheme(ICardDatabase cardDb) {
|
||||
super(cardDb);
|
||||
public DeckGeneratorTheme(IDeckGenPool pool) {
|
||||
super(pool);
|
||||
this.maxDuplicates = 4;
|
||||
}
|
||||
|
||||
@@ -133,10 +133,12 @@ public class DeckGeneratorTheme extends DeckGeneratorBase {
|
||||
}
|
||||
|
||||
final int n = cardCounts.get(ss[0]);
|
||||
if(ss.length == 1)
|
||||
tDeck.add(cardDb.getCard(ss[0]));
|
||||
else
|
||||
tDeck.add(cardDb.getCard(ss[0],ss[1]));
|
||||
if (ss.length == 1) {
|
||||
tDeck.add(pool.getCard(ss[0]));
|
||||
}
|
||||
else {
|
||||
tDeck.add(pool.getCard(ss[0],ss[1]));
|
||||
}
|
||||
cardCounts.put(ss[0], n + 1);
|
||||
errorBuilder.append(s + "\n");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package forge.planarconquest;
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.generation.DeckGenPool;
|
||||
import forge.item.PaperCard;
|
||||
|
||||
public class ConquestCommander {
|
||||
private final PaperCard card;
|
||||
private final Deck deck;
|
||||
|
||||
public ConquestCommander(PaperCard card0, DeckGenPool cardPool0) {
|
||||
card = card0;
|
||||
deck = ConquestUtil.generateHumanDeck(card0, cardPool0);
|
||||
}
|
||||
|
||||
public PaperCard getCard() {
|
||||
return card;
|
||||
}
|
||||
|
||||
public Deck getDeck() {
|
||||
return deck;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return card.getName();
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,10 @@ import com.google.common.eventbus.Subscribe;
|
||||
import forge.deck.CardPool;
|
||||
import forge.deck.Deck;
|
||||
import forge.game.event.GameEvent;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.quest.QuestUtil;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.gui.SOptionPane;
|
||||
import forge.util.storage.IStorage;
|
||||
|
||||
public class ConquestController {
|
||||
@@ -56,6 +60,27 @@ public class ConquestController {
|
||||
}
|
||||
}
|
||||
|
||||
public String promptForName() {
|
||||
String name;
|
||||
while (true) {
|
||||
name = SOptionPane.showInputDialog("Historians will recall your conquest as:", "Conquest Name");
|
||||
if (name == null) { return null; }
|
||||
|
||||
name = QuestUtil.cleanString(name);
|
||||
|
||||
if (name.isEmpty()) {
|
||||
SOptionPane.showMessageDialog("Please specify a conquest name.");
|
||||
continue;
|
||||
}
|
||||
if (FileUtil.doesFileExist(ForgeConstants.CONQUEST_SAVE_DIR + name + ".dat")) {
|
||||
SOptionPane.showMessageDialog("A conquest already exists with that name. Please pick another quest name.");
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void receiveGameEvent(GameEvent ev) { // Receives events only during planar conquest games
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public final class ConquestData {
|
||||
private int winStreakCurrent = 0;
|
||||
private int difficulty;
|
||||
private ConquestPlane startingPlane, currentPlane;
|
||||
private List<PaperCard> commanders = new ArrayList<PaperCard>();
|
||||
private List<ConquestCommander> commanders = new ArrayList<ConquestCommander>();
|
||||
|
||||
private final CardPool cardPool = new CardPool();
|
||||
private final HashMap<String, Deck> decks = new HashMap<String, Deck>();
|
||||
@@ -55,7 +55,7 @@ public final class ConquestData {
|
||||
difficulty = difficulty0;
|
||||
startingPlane = startingPlane0;
|
||||
currentPlane = startingPlane0;
|
||||
commanders.add(startingCommander0);
|
||||
commanders.add(new ConquestCommander(startingCommander0, startingPlane.getCardPool()));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
@@ -25,7 +25,7 @@ import forge.card.CardRulesPredicates;
|
||||
import forge.card.CardEdition.CardInSet;
|
||||
import forge.card.CardType;
|
||||
import forge.card.MagicColor;
|
||||
import forge.deck.CardPool;
|
||||
import forge.deck.generation.DeckGenPool;
|
||||
import forge.item.PaperCard;
|
||||
import forge.model.FModel;
|
||||
import forge.util.FCollection;
|
||||
@@ -250,7 +250,7 @@ public enum ConquestPlane {
|
||||
private final FCollection<CardEdition> editions = new FCollection<CardEdition>();
|
||||
private final FCollection<Region> regions;
|
||||
private final FCollection<String> bannedCards = new FCollection<String>();
|
||||
private final CardPool cardPool = new CardPool();
|
||||
private final DeckGenPool cardPool = new DeckGenPool();
|
||||
private final FCollection<PaperCard> commanders = new FCollection<PaperCard>();
|
||||
|
||||
private ConquestPlane(String name0, String[] setCodes0, Region[] regions0) {
|
||||
@@ -271,30 +271,28 @@ public enum ConquestPlane {
|
||||
PaperCard pc = FModel.getMagicDb().getCommonCards().getCard(card.name, setCode);
|
||||
if (pc != null) {
|
||||
CardType type = pc.getRules().getType();
|
||||
if (!type.isBasicLand()) { //don't include basic lands
|
||||
boolean isCommander = type.isLegendary() && type.isCreature();
|
||||
cardPool.add(pc);
|
||||
if (isCommander) {
|
||||
commanders.add(pc);
|
||||
}
|
||||
int count = 0;
|
||||
for (Region region : regions) {
|
||||
if (region.pred.apply(pc)) {
|
||||
region.cardPool.add(pc);
|
||||
if (isCommander) {
|
||||
region.commanders.add(pc);
|
||||
}
|
||||
count++;
|
||||
boolean isCommander = type.isLegendary() && type.isCreature();
|
||||
cardPool.add(pc);
|
||||
if (isCommander) {
|
||||
commanders.add(pc);
|
||||
}
|
||||
int count = 0;
|
||||
for (Region region : regions) {
|
||||
if (region.pred.apply(pc)) {
|
||||
region.cardPool.add(pc);
|
||||
if (isCommander) {
|
||||
region.commanders.add(pc);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
//if card doesn't match any region's predicate,
|
||||
//make card available to all regions
|
||||
if (count == 0) {
|
||||
for (Region region : regions) {
|
||||
region.cardPool.add(pc);
|
||||
if (isCommander) {
|
||||
region.commanders.add(pc);
|
||||
}
|
||||
}
|
||||
//if card doesn't match any region's predicate,
|
||||
//make card available to all regions
|
||||
if (count == 0) {
|
||||
for (Region region : regions) {
|
||||
region.cardPool.add(pc);
|
||||
if (isCommander) {
|
||||
region.commanders.add(pc);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -322,7 +320,7 @@ public enum ConquestPlane {
|
||||
return regions;
|
||||
}
|
||||
|
||||
public CardPool getCardPool() {
|
||||
public DeckGenPool getCardPool() {
|
||||
return cardPool;
|
||||
}
|
||||
|
||||
@@ -338,7 +336,7 @@ public enum ConquestPlane {
|
||||
private final String name;
|
||||
private final String artCardName;
|
||||
private final Predicate<PaperCard> pred;
|
||||
private final CardPool cardPool = new CardPool();
|
||||
private final DeckGenPool cardPool = new DeckGenPool();
|
||||
private final FCollection<PaperCard> commanders = new FCollection<PaperCard>();
|
||||
|
||||
private Region(String name0, String artCardName0, Predicate<PaperCard> pred0) {
|
||||
@@ -367,7 +365,7 @@ public enum ConquestPlane {
|
||||
return name;
|
||||
}
|
||||
|
||||
public CardPool getCardPool() {
|
||||
public DeckGenPool getCardPool() {
|
||||
return cardPool;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package forge.planarconquest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import forge.card.ColorSet;
|
||||
import forge.deck.CardPool;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.deck.generation.DeckGenerator2Color;
|
||||
import forge.deck.generation.DeckGenerator3Color;
|
||||
import forge.deck.generation.DeckGenerator5Color;
|
||||
import forge.deck.generation.DeckGeneratorBase;
|
||||
import forge.deck.generation.DeckGeneratorMonoColor;
|
||||
import forge.deck.generation.IDeckGenPool;
|
||||
import forge.item.PaperCard;
|
||||
import forge.util.Aggregates;
|
||||
|
||||
public class ConquestUtil {
|
||||
private ConquestUtil() {}
|
||||
|
||||
public static Deck generateHumanDeck(PaperCard commander, IDeckGenPool pool) {
|
||||
return generateDeck(commander, pool, false);
|
||||
}
|
||||
public static Deck generateAiDeck(Iterable<PaperCard> commanderOptions, IDeckGenPool pool) {
|
||||
return generateDeck(Aggregates.random(commanderOptions), pool, true);
|
||||
}
|
||||
private static Deck generateDeck(PaperCard commander, IDeckGenPool pool, boolean forAi) {
|
||||
ColorSet colorID = commander.getRules().getColorIdentity();
|
||||
|
||||
List<String> colors = new ArrayList<String>();
|
||||
if (colorID.hasWhite()) { colors.add("White"); }
|
||||
if (colorID.hasBlue()) { colors.add("Blue"); }
|
||||
if (colorID.hasBlack()) { colors.add("Black"); }
|
||||
if (colorID.hasRed()) { colors.add("Red"); }
|
||||
if (colorID.hasGreen()) { colors.add("Green"); }
|
||||
|
||||
DeckGeneratorBase gen;
|
||||
switch (colors.size()) {
|
||||
case 0:
|
||||
gen = new DeckGeneratorMonoColor(pool, "");
|
||||
break;
|
||||
case 1:
|
||||
gen = new DeckGeneratorMonoColor(pool, colors.get(0));
|
||||
break;
|
||||
case 2:
|
||||
gen = new DeckGenerator2Color(pool, colors.get(0), colors.get(1));
|
||||
break;
|
||||
case 3:
|
||||
gen = new DeckGenerator3Color(pool, colors.get(0), colors.get(1), colors.get(2));
|
||||
break;
|
||||
case 5:
|
||||
gen = new DeckGenerator5Color(pool);
|
||||
break;
|
||||
default:
|
||||
return null; //shouldn't happen
|
||||
}
|
||||
|
||||
gen.setSingleton(true);
|
||||
CardPool cards = gen.getDeck(60, forAi);
|
||||
|
||||
Deck deck = new Deck(commander.getName());
|
||||
deck.getMain().addAll(cards);
|
||||
deck.getOrCreate(DeckSection.Commander).add(commander);
|
||||
|
||||
return deck;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user