Merge branch 'master' into 'master'

Commander quest mode

See merge request core-developers/forge!1053
This commit is contained in:
Michael Kamensky
2018-11-10 16:18:16 +00:00
20 changed files with 565 additions and 37 deletions

View File

@@ -18,8 +18,14 @@
package forge.screens.deckeditor.controllers;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Supplier;
import forge.UiCommand;
import forge.card.CardRules;
import forge.card.CardRulesPredicates;
import forge.card.ColorSet;
import forge.card.mana.ManaCost;
import forge.deck.CardPool;
import forge.deck.Deck;
import forge.deck.DeckSection;
@@ -35,6 +41,7 @@ import forge.itemmanager.views.ItemTableColumn;
import forge.model.FModel;
import forge.properties.ForgePreferences.FPref;
import forge.quest.QuestController;
import forge.quest.data.DeckConstructionRules;
import forge.screens.deckeditor.AddBasicLandsDialog;
import forge.screens.deckeditor.SEditorIO;
import forge.screens.deckeditor.views.VAllDecks;
@@ -103,6 +110,14 @@ public final class CEditorQuest extends CDeckEditor<Deck> {
allSections.add(DeckSection.Main);
allSections.add(DeckSection.Sideboard);
//Add sub-format specific sections
switch(FModel.getQuest().getDeckConstructionRules()){
case Default: break;
case Commander:
allSections.add(DeckSection.Commander);
break;
}
this.questData = questData0;
final CardManager catalogManager = new CardManager(cDetailPicture, false, true);
@@ -158,6 +173,10 @@ public final class CEditorQuest extends CDeckEditor<Deck> {
@Override
protected CardLimit getCardLimit() {
if (FModel.getPreferences().getPrefBoolean(FPref.ENFORCE_DECK_LEGALITY)) {
//If this is a commander quest, only allow single copies of cards
if(FModel.getQuest().getDeckConstructionRules() == DeckConstructionRules.Commander){
return CardLimit.Singleton;
}
return CardLimit.Default;
}
return CardLimit.None; //if not enforcing deck legality, don't enforce default limit
@@ -245,16 +264,103 @@ public final class CEditorQuest extends CDeckEditor<Deck> {
public void resetTables() {
this.sectionMode = DeckSection.Main;
final Deck deck = this.controller.getModel();
final CardPool cardpool = getInitialCatalog();
// remove bottom cards that are in the deck from the card pool
cardpool.removeAll(deck.getMain());
// remove sideboard cards from the catalog
cardpool.removeAll(deck.getOrCreate(DeckSection.Sideboard));
// show cards, makes this user friendly
this.getCatalogManager().setPool(cardpool);
this.getDeckManager().setPool(deck.getMain());
this.getCatalogManager().setPool(getRemainingCardPool());
this.getDeckManager().setPool(getDeck().getMain());
}
/***
* Provides the pool of cards the player has available to add to his or her deck. Also manages showing available cards
* to choose from for special deck construction rules, e.g.: Commander.
* @return CardPool of cards available to add to the player's deck.
*/
private CardPool getRemainingCardPool(){
final CardPool cardpool = getInitialCatalog();
// remove bottom cards that are in the deck from the card pool
cardpool.removeAll(getDeck().getMain());
// remove sideboard cards from the catalog
cardpool.removeAll(getDeck().getOrCreate(DeckSection.Sideboard));
switch(FModel.getQuest().getDeckConstructionRules()){
case Default: break;
case Commander:
//remove this deck's currently selected commander(s) from the catalog
cardpool.removeAll(getDeck().getOrCreate(DeckSection.Commander));
//TODO: Only thin if deck conformance is being applied
if(getDeck().getOrCreate(DeckSection.Commander).toFlatList().size() > 0) {
Predicate<PaperCard> identityPredicate = new MatchCommanderColorIdentity(getDeckColorIdentity());
CardPool filteredPool = cardpool.getFilteredPool(identityPredicate);
return filteredPool;
}
break;
}
return cardpool;
}
/**
* Predicate that filters out based on a color identity provided upon instantiation. Used to filter the card
* list when a commander is chosen so the user can more easily see what cards are available for his or her deck
* and avoid making additions that are not legal.
*/
public static class MatchCommanderColorIdentity implements Predicate<PaperCard> {
private final ColorSet allowedColor;
public MatchCommanderColorIdentity(ColorSet color) {
allowedColor = color;
}
@Override
public boolean apply(PaperCard subject) {
CardRules cr = subject.getRules();
ManaCost mc = cr.getManaCost();
return allowedColor.containsAllColorsFrom(cr.getColorIdentity().getColor());
}
}
/**
* Compiles the color identity of the loaded deck based on the commanders.
* @return A ColorSet containing the color identity of the currently loaded deck.
*/
public ColorSet getDeckColorIdentity(){
List<PaperCard> commanders = getDeck().getOrCreate(DeckSection.Commander).toFlatList();
List<String> colors = new ArrayList<>();
//Return early if there are no current commanders
if(commanders.size() == 0){
colors.add("c");
return ColorSet.fromNames(colors);
}
//For each commander,add each color of its color identity if not already added
for(PaperCard pc : commanders){
if(!colors.contains("w") && pc.getRules().getColorIdentity().hasWhite()) colors.add("w");
if(!colors.contains("u") && pc.getRules().getColorIdentity().hasBlue()) colors.add("u");
if(!colors.contains("b") && pc.getRules().getColorIdentity().hasBlack()) colors.add("b");
if(!colors.contains("r") && pc.getRules().getColorIdentity().hasRed()) colors.add("r");
if(!colors.contains("g") && pc.getRules().getColorIdentity().hasGreen()) colors.add("g");
}
colors.add("c");
return ColorSet.fromNames(colors);
}
/*
Used to make the code more readable in game terms.
*/
private Deck getDeck(){
return this.controller.getModel();
}
private ItemPool<PaperCard> getCommanderCardPool(){
Predicate<PaperCard> commanderPredicate = Predicates.compose(CardRulesPredicates.Presets.CAN_BE_COMMANDER, PaperCard.FN_GET_RULES);
return getRemainingCardPool().getFilteredPool(commanderPredicate);
}
@Override
@@ -280,14 +386,30 @@ public final class CEditorQuest extends CDeckEditor<Deck> {
}
/**
* Switch between the main deck and the sideboard editor.
* Switch between the main deck and the sideboard/Command Zone editor.
*/
public void setEditorMode(DeckSection sectionMode) {
if (sectionMode == DeckSection.Sideboard) {
this.getDeckManager().setPool(this.controller.getModel().getOrCreate(DeckSection.Sideboard));
}
else {
this.getDeckManager().setPool(this.controller.getModel().getMain());
//Fixes null pointer error on switching tabs while quest deck editor is open. TODO: Find source of bug possibly?
if(sectionMode == null) sectionMode = DeckSection.Main;
//Based on which section the editor is in, display the remaining card pool (or applicable card pool if in
//Commander) and the current section's cards
switch(sectionMode){
case Main :
this.getCatalogManager().setup(ItemManagerConfig.CARD_CATALOG);
this.getCatalogManager().setPool(getRemainingCardPool());
this.getDeckManager().setPool(this.controller.getModel().getMain());
break;
case Sideboard :
this.getCatalogManager().setup(ItemManagerConfig.CARD_CATALOG);
this.getCatalogManager().setPool(getRemainingCardPool());
this.getDeckManager().setPool(getDeck().getOrCreate(DeckSection.Sideboard));
break;
case Commander :
this.getCatalogManager().setup(ItemManagerConfig.COMMANDER_POOL);
this.getCatalogManager().setPool(getCommanderCardPool());
this.getDeckManager().setPool(getDeck().getOrCreate(DeckSection.Commander));
break;
}
this.sectionMode = sectionMode;

View File

@@ -10,6 +10,7 @@ import forge.model.FModel;
import forge.properties.ForgeConstants;
import forge.quest.*;
import forge.quest.StartingPoolPreferences.PoolType;
import forge.quest.data.DeckConstructionRules;
import forge.quest.data.GameFormatQuest;
import forge.quest.data.QuestData;
import forge.quest.data.QuestPreferences.QPref;
@@ -340,9 +341,16 @@ public enum CSubmenuQuestData implements ICDoc {
break;
}
//Apply the appropriate deck construction rules for this quest
DeckConstructionRules dcr = DeckConstructionRules.Default;
if(VSubmenuQuestData.SINGLETON_INSTANCE.isCommander()){
dcr = DeckConstructionRules.Commander;
}
final QuestController qc = FModel.getQuest();
qc.newGame(questName, difficulty, mode, fmtPrizes, view.isUnlockSetsAllowed(), dckStartPool, fmtStartPool, view.getStartingWorldName(), userPrefs);
qc.newGame(questName, difficulty, mode, fmtPrizes, view.isUnlockSetsAllowed(), dckStartPool, fmtStartPool, view.getStartingWorldName(), userPrefs, dcr);
FModel.getQuest().save();
// Save in preferences.

View File

@@ -62,6 +62,7 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
private final FRadioButton radHard = new FRadioButton("Hard");
private final FRadioButton radExpert = new FRadioButton("Expert");
private final FCheckBox boxFantasy = new FCheckBox("Fantasy Mode");
private final FCheckBox boxCommander = new FCheckBox("Commander Subformat");
private final FLabel lblStartingWorld = new FLabel.Builder().text("Starting world:").build();
private final FComboBoxWrapper<QuestWorld> cbxStartingWorld = new FComboBoxWrapper<>();
@@ -274,9 +275,25 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
}
});
// Fantasy box enabled by Default
// Fantasy box selected by Default
boxFantasy.setSelected(true);
boxFantasy.setEnabled(true);
// Commander box unselected by Default
boxCommander.setSelected(false);
boxCommander.setEnabled(true);
boxCommander.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
if(!isCommander()) return; //do nothing if unselecting Commander Subformat
//Otherwise, set the starting world to Random Commander
cbxStartingWorld.setSelectedItem(FModel.getWorlds().get("Random Commander"));
}
}
);
boxCompleteSet.setEnabled(true);
boxAllowDuplicates.setEnabled(true);
@@ -286,6 +303,7 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
final JPanel pnlDifficultyMode = new JPanel(new MigLayout("insets 0, gap 1%, flowy"));
pnlDifficultyMode.add(difficultyPanel, "gapright 4%");
pnlDifficultyMode.add(boxFantasy, "h 25px!, gapbottom 15, gapright 4%");
pnlDifficultyMode.add(boxCommander, "h 25px!, gapbottom 15, gapright 4%");
pnlDifficultyMode.add(lblStartingWorld, "h 25px!, hidemode 3");
cbxStartingWorld.addTo(pnlDifficultyMode, "h 27px!, w 40%, pushx, gapbottom 7");
pnlDifficultyMode.setOpaque(false);
@@ -487,6 +505,14 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
return boxFantasy.isSelected();
}
/**
* Auth. Imakuni
* @return True if the "Commander Subformat" check box is selected.
*/
public boolean isCommander() {
return boxCommander.isSelected();
}
public boolean startWithCompleteSet() {
return boxCompleteSet.isSelected();
}