Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions forge-core/src/main/java/forge/StaticData.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class StaticData {

private Predicate<PaperCard> standardPredicate;
private Predicate<PaperCard> brawlPredicate;
private Predicate<PaperCard> duelCommanderPredicate;
private Predicate<CardRules> duelCommanderCommanderPredicate;
private Predicate<CardRules> duelCommanderCompanionPredicate;
private Predicate<PaperCard> pioneerPredicate;
private Predicate<PaperCard> modernPredicate;
private Predicate<PaperCard> commanderPredicate;
Expand Down Expand Up @@ -589,6 +592,12 @@ public boolean allowCustomCardsInDecksConformance() {

public void setBrawlPredicate(Predicate<PaperCard> brawlPredicate) { this.brawlPredicate = brawlPredicate; }

public void setDuelCommanderPredicate(Predicate<PaperCard> duelCommanderPredicate) { this.duelCommanderPredicate = duelCommanderPredicate; }

public void setDuelCommanderCommanderPredicate(Predicate<CardRules> duelCommanderCommanderPredicate) { this.duelCommanderCommanderPredicate = duelCommanderCommanderPredicate; }

public void setDuelCommanderCompanionPredicate(Predicate<CardRules> duelCommanderCompanionPredicate) { this.duelCommanderCompanionPredicate = duelCommanderCompanionPredicate; }

public Predicate<PaperCard> getStandardPredicate() { return standardPredicate; }

public Predicate<PaperCard> getPioneerPredicate() { return pioneerPredicate; }
Expand All @@ -601,6 +610,14 @@ public boolean allowCustomCardsInDecksConformance() {

public Predicate<PaperCard> getBrawlPredicate() { return brawlPredicate; }

public Predicate<PaperCard> getDuelCommanderPredicate() { return duelCommanderPredicate; }

/** Whether a card that is legal in a Duel Commander deck may also be its commander. */
public Predicate<CardRules> getDuelCommanderCommanderPredicate() { return duelCommanderCommanderPredicate; }

/** Whether a card that is legal in a Duel Commander deck may also be its companion. */
public Predicate<CardRules> getDuelCommanderCompanionPredicate() { return duelCommanderCompanionPredicate; }

/**
* Get an alternative card print for the given card wrt. the input setReleaseDate.
* The reference release date will be used to retrieve the alternative art, according
Expand Down
33 changes: 32 additions & 1 deletion forge-core/src/main/java/forge/deck/DeckFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,37 @@ public void adjustCMCLevels(List<ImmutablePair<FilterCMC, Integer>> cmcLevels) {
cmcLevels.add(ImmutablePair.of(new FilterCMC(3, 3), 3));
}
},
// Duel Commander (duelcommander.org): no sideboard (302.1), but a companion lives there in Forge (302.2).
DuelCommander ( Range.is(99), Range.of(0, 1), 1, null,
card -> StaticData.instance().getDuelCommanderPredicate().test(card)
) {
@Override
public boolean isLegalCommander(CardRules rules) {
// 304.2: some cards are legal in the 99 but banned as commander
return super.isLegalCommander(rules) && StaticData.instance().getDuelCommanderCommanderPredicate().test(rules);
}

@Override
public String getDeckConformanceProblem(Deck deck) {
String problem = super.getDeckConformanceProblem(deck);
if (problem != null) {
return problem;
}
CardPool sideboard = deck.get(DeckSection.Sideboard);
if (sideboard != null) {
for (final Entry<PaperCard, Integer> cp : sideboard) {
CardRules rules = cp.getKey().getRules();
if (!rules.hasStartOfKeyword("Companion")) {
return Localizer.getInstance().getMessage("lblDuelCommanderOnlyCompanion", cp.getKey().getName());
}
if (!StaticData.instance().getDuelCommanderCompanionPredicate().test(rules)) {
return Localizer.getInstance().getMessage("lblDuelCommanderBannedAsCompanion", cp.getKey().getName());
}
}
}
return null;
}
},
PlanarConquest ( Range.of(40, Integer.MAX_VALUE), Range.is(0), 1),
Adventure ( Range.of(40, Integer.MAX_VALUE), Range.of(0, Integer.MAX_VALUE), 4) {
@Override
Expand Down Expand Up @@ -181,7 +212,7 @@ public boolean allowCustomCards() {
}

public boolean hasCommander() {
return this == Commander || this == CommanderDraft || this == Oathbreaker || this == TinyLeaders || this == Brawl;
return this == Commander || this == CommanderDraft || this == Oathbreaker || this == TinyLeaders || this == Brawl || this == DuelCommander;
}

public boolean hasSignatureSpell() {
Expand Down
1 change: 1 addition & 0 deletions forge-game/src/main/java/forge/game/GameAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,7 @@ else if (c.hasBeenDealtDeathtouchDamage() || (c.getDamage() > 0 && c.getLethal()

if ((game.getRules().hasAppliedVariant(GameType.Commander)
|| game.getRules().hasAppliedVariant(GameType.Brawl)
|| game.getRules().hasAppliedVariant(GameType.DuelCommander)
|| game.getRules().hasAppliedVariant(GameType.Planeswalker)) && !checkAgain) {
for (final Card c : p.getCardsIn(ZoneType.Graveyard).threadSafeIterable()) {
checkAgain |= stateBasedAction_Commander(c, mapParams);
Expand Down
24 changes: 20 additions & 4 deletions forge-game/src/main/java/forge/game/GameFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ public GameFormat(final String fName, final Iterable<String> sets, final List<St
/**
* Rules on the whole deck, on top of which cards are legal. With singleton, a deck holds one copy of each card
* apart from those that allow more. Its main deck needs at least minMainDeckSize cards, and the points of its
* cards in cardPoints must not exceed maxPoints.
* cards in cardPoints must not exceed maxPoints. The cards in bannedAsCommander and bannedAsCompanion are legal in
* the deck but not as its commander or its companion (Duel Commander).
*/
public record DeckRules(boolean singleton, int minMainDeckSize, int maxPoints, Map<String, Integer> cardPoints) {
public static final DeckRules NONE = new DeckRules(false, 0, 0, Map.of());
public record DeckRules(boolean singleton, int minMainDeckSize, int maxPoints, Map<String, Integer> cardPoints,
List<String> bannedAsCommander, List<String> bannedAsCompanion) {
public static final DeckRules NONE = new DeckRules(false, 0, 0, Map.of(), List.of(), List.of());
}

public GameFormat(final String fName, final Date effectiveDate, final Iterable<String> sets, final List<String> bannedCards,
Expand Down Expand Up @@ -230,6 +232,14 @@ public List<String> getBannedCardNames() {
return this.bannedCardNames_ro;
}

public List<String> getBannedAsCommanderCardNames() {
return deckRules.bannedAsCommander();
}

public List<String> getBannedAsCompanionCardNames() {
return deckRules.bannedAsCompanion();
}

public List<String> getRestrictedCards() {
return restrictedCardNames_ro;
}
Expand Down Expand Up @@ -447,6 +457,7 @@ public static class Reader extends StorageReaderRecursiveFolderWithUserFolder<Ga
coreFormats.add("Extended.txt");
coreFormats.add("Brawl.txt");
coreFormats.add("Oathbreaker.txt");
coreFormats.add("DuelCommander.txt");
coreFormats.add("Premodern.txt");
coreFormats.add("Pauper.txt");
coreFormats.add("PreDH.txt");
Expand Down Expand Up @@ -575,7 +586,12 @@ private static DeckRules readDeckRules(final FileSection section, final String t
}
final Boolean singleton = section.getBoolean("singleton");
return new DeckRules(singleton != null && singleton, section.getInt("mindecksize"), section.getInt("maxpoints"),
Map.copyOf(cardPoints));
Map.copyOf(cardPoints), readCardList(section, "bannedascommander"), readCardList(section, "bannedascompanion"));
}

private static List<String> readCardList(final FileSection section, final String key) {
final String cards = section.get(key);
return cards == null ? List.of() : List.of(cards.split("; "));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion forge-game/src/main/java/forge/game/GameRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ public boolean hasCommander() {
return appliedVariants.contains(GameType.Commander)
|| appliedVariants.contains(GameType.Oathbreaker)
|| appliedVariants.contains(GameType.TinyLeaders)
|| appliedVariants.contains(GameType.Brawl);
|| appliedVariants.contains(GameType.Brawl)
|| appliedVariants.contains(GameType.DuelCommander);
}

/** Teams take turns and hold priority together (CR 805), as in Two-Headed Giant. */
Expand Down
1 change: 1 addition & 0 deletions forge-game/src/main/java/forge/game/GameType.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public enum GameType {
Oathbreaker (DeckFormat.Oathbreaker, false, false, false, "lblOathbreaker", "lblOathbreakerDesc"),
TinyLeaders (DeckFormat.TinyLeaders, false, false, false, "lblTinyLeaders", "lblTinyLeadersDesc"),
Brawl (DeckFormat.Brawl, false, false, false, "lblBrawl", "lblBrawlDesc"),
DuelCommander (DeckFormat.DuelCommander, false, false, false, "lblDuelCommander", "lblDuelCommanderDesc"),
Planeswalker (DeckFormat.PlanarConquest, false, false, true, "lblPlaneswalker", "lblPlaneswalkerDesc"),
Planechase (DeckFormat.Planechase, false, false, true, "lblPlanechase", "lblPlanechaseDesc"),
Archenemy (DeckFormat.Archenemy, false, false, true, "lblArchenemy", "lblArchenemyDesc"),
Expand Down
4 changes: 4 additions & 0 deletions forge-game/src/main/java/forge/game/card/CardProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,10 @@ else if (property.equals("blocked")) {
if (!card.isCommander()) {
return false;
}
} else if (property.equals("NoOtherCommanderCastFromCommandZone")) {
if (card.getOwner().isCommanderLockedInCommandZone(card)) {
return false;
}
} else if (property.startsWith("NotedFor")) {
final String key = property.substring("NotedFor".length());
for (String note : sourceController.getNotesForName(key)) {
Expand Down
9 changes: 9 additions & 0 deletions forge-game/src/main/java/forge/game/card/CardView.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,20 @@ void updateCommander(Card c) {
set(TrackableProperty.CommanderAltType, "Commander");
}
}
// Duel Commander 404: worked out on the host from the real commander, since a merged permanent has no cast count of its own
final Card real = isCommander ? c.getRealCommander() : null;
set(TrackableProperty.LockedInCommandZone, real != null && c.getGame().getRules().hasAppliedVariant(GameType.DuelCommander)
&& real.getOwner().isCommanderLockedInCommandZone(real));
}
public String getCommanderType() {
return get(TrackableProperty.CommanderAltType);
}

/** Duel Commander 404: another of its owner's commanders was cast from the command zone first. */
public boolean isLockedInCommandZone() {
return get(TrackableProperty.LockedInCommandZone);
}

public boolean hasSamePT(CardView otherCard) {
if (getCurrentState().getPower() != otherCard.getCurrentState().getPower())
return false;
Expand Down
29 changes: 26 additions & 3 deletions forge-game/src/main/java/forge/game/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -711,11 +711,12 @@ public final int addDamageAfterPrevention(final int amount, final Card source, f
addPoisonCounters(poisonCounters, source.getController(), counterTable);
}

//Oathbreaker, Tiny Leaders, and Brawl ignore commander damage rule
//Oathbreaker, Tiny Leaders, Brawl and Duel Commander ignore commander damage rule
if (source.isCommander() && isCombat
&& !this.getGame().getRules().hasAppliedVariant(GameType.Oathbreaker)
&& !this.getGame().getRules().hasAppliedVariant(GameType.TinyLeaders)
&& !this.getGame().getRules().hasAppliedVariant(GameType.Brawl)) {
&& !this.getGame().getRules().hasAppliedVariant(GameType.Brawl)
&& !this.getGame().getRules().hasAppliedVariant(GameType.DuelCommander)) {
// In case that commander is merged permanent, get the real commander card
final Card realCommander = source.getRealCommander();
// not in the CR: the Two-Headed Giant format page counts commander damage per team
Expand Down Expand Up @@ -2955,6 +2956,7 @@ public int getCommanderCast(Card commander) {
public void incCommanderCast(Card commander) {
commanderCast.merge(commander, 1, Integer::sum);
getView().updateCommanderCast(this, commander);
updateCommandZoneLocks();
getGame().fireEvent(new GameEventPlayerStatsChanged(this));
}

Expand All @@ -2968,6 +2970,21 @@ public void updateMergedCommanderInfo(Card target, Card commander) {
getView().updateMergedCommanderDamage(target, commander);
}

/** Duel Commander 404.1-404.4: another of this player's commanders has been cast from the command zone this game. */
public boolean isCommanderLockedInCommandZone(Card commander) {
return getTotalCommanderCast() > getCommanderCast(commander);
}

/** A cast can lock the other commanders (Duel Commander), which their card text says. */
private void updateCommandZoneLocks() {
if (!getGame().getRules().hasAppliedVariant(GameType.DuelCommander)) {
return;
}
for (final Card c : getCommanders()) {
c.updateCommanderView();
}
}

public int getTotalCommanderCast() {
int result = 0;
for (Integer i : commanderCast.values()) {
Expand Down Expand Up @@ -3363,7 +3380,13 @@ else if (game.getRules().hasAppliedVariant(GameType.Oathbreaker)) {
re.setOverridingAbility(AbilityFactory.getAbility(effStr, eff));
eff.addReplacementEffect(re);

String mayBePlayedAbility = "Mode$ Continuous | EffectZone$ Command | MayPlay$ True | Affected$ Card.IsCommander+YouOwn | AffectedZone$ Command";
String castableCommander = "Card.IsCommander+YouOwn";
if (game.getRules().hasAppliedVariant(GameType.DuelCommander)) {
// Duel Commander 404.1-404.4: once one of your commanders has been cast from the command zone, the others
// can't be cast from there this game. They can still be cast from any other zone (Command Beacon).
castableCommander += "+NoOtherCommanderCastFromCommandZone";
}
String mayBePlayedAbility = "Mode$ Continuous | EffectZone$ Command | MayPlay$ True | Affected$ " + castableCommander + " | AffectedZone$ Command";
if (game.getRules().hasAppliedVariant(GameType.Planeswalker)) { //support paying for Planeswalker with any color mana
mayBePlayedAbility += " | MayPlayIgnoreColor$ True";
}
Expand Down
4 changes: 4 additions & 0 deletions forge-game/src/main/java/forge/game/player/PlayerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ public final String getCommanderInfo(CardView v) {

sb.append(Localizer.getInstance().getMessage("lblCommanderCastCard", getCommanderCast(v)));
sb.append("\n");
if (v.isLockedInCommandZone()) {
sb.append(Localizer.getInstance().getMessage("lblDuelCommanderLockedInCommandZone"));
sb.append("\n");
}

final String name = CardTranslation.getTranslatedName(v.getName());
final Set<PlayerView> listed = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ public static RegisteredPlayer forVariants(final int playerCount,
start.commanders = deck.getCommanders();
start.setStartingLife(start.getStartingLife() + 5);
}
if (appliedVariants.contains(GameType.DuelCommander)) {
start.commanders = deck.getCommanders();
// Duel Commander 401.1: each player begins with 20 life, the base total, so nothing is added
// (unlike Commander's +20 above); other variants still layer on top of it.
}
if (appliedVariants.contains(GameType.Brawl)) {
start.commanders = deck.getCommanders();
if (playerCount == 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public enum TrackableProperty {
IsCommander(TrackableTypes.BooleanType),
IsRingBearer(TrackableTypes.BooleanType),
CommanderAltType(TrackableTypes.StringType),
LockedInCommandZone(TrackableTypes.BooleanType),
Damage(TrackableTypes.IntegerType),
AssignedDamage(TrackableTypes.IntegerType),
LethalDamage(TrackableTypes.IntegerType),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ private void updateCustom() {
case TinyLeaders:
updateDecks(DeckProxy.getAllTinyLeadersDecks(), ItemManagerConfig.COMMANDER_DECKS);
break;
case DuelCommander:
updateDecks(DeckProxy.getAllDuelCommanderDecks(), ItemManagerConfig.COMMANDER_DECKS);
break;
default:
updateDecks(DeckProxy.getAllConstructedDecks(), ItemManagerConfig.CONSTRUCTED_DECKS);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ public void editDeck(final DeckProxy deck) {
DeckPreferences.setTinyLeadersDeck((deck != null) ? deck.toString() : "");
editorCtrl = new CEditorConstructed(getCDetailPicture(), this.gameType);
break;
case DuelCommander:
screen = FScreen.DECK_EDITOR_CONSTRUCTED; // re-use "Deck Editor", rather than creating a new top level tab
DeckPreferences.setCommanderDeck((deck != null) ? deck.toString() : "");
editorCtrl = new CEditorConstructed(getCDetailPicture(), this.gameType);
break;
case Sealed:
screen = FScreen.DECK_EDITOR_SEALED;
editorCtrl = new CEditorLimited<>(FModel.getDecks().getSealed(), DeckGroup::new, screen, getCDetailPicture());
Expand Down Expand Up @@ -459,6 +464,7 @@ public boolean deleteDeck(final DeckProxy deck) {
case Commander:
case Oathbreaker:
case TinyLeaders:
case DuelCommander:
case Constructed:
case Draft:
case Sealed:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ private static String formatTabCaptionKey(final GameType gt) {
case Oathbreaker: return "lblOathbreakerDeckEditor";
case Brawl: return "lblBrawlDeckEditor";
case TinyLeaders: return "lblTinyLeadersDeckEditor";
case DuelCommander: return "lblDuelCommanderDeckEditor";
default: return "lblDeckEditorWithSpaces";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ else if (FOptionPane.showConfirmDialog(Localizer.getInstance().getMessage("lblTh
VBrawlDecks.SINGLETON_INSTANCE.getLstDecks().setSelectedString(deckStr);
break;
case Commander:
case DuelCommander: // kept with the Commander decks
CCommanderDecks.SINGLETON_INSTANCE.refresh();
VCommanderDecks.SINGLETON_INSTANCE.getLstDecks().setSelectedString(deckStr);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ public CEditorConstructed(final CDetailPicture cDetailPicture0, final GameType g
commanderPool = FModel.getTinyLeadersCommander();
normalPool = FModel.getAllCards();

wantUnique = true;
break;
case DuelCommander:
allSections.add(DeckSection.Commander);

commanderPool = FModel.getDuelCommanderCommander();
normalPool = FModel.getAllCards();

wantUnique = true;
break;
case Oathbreaker:
Expand Down Expand Up @@ -179,6 +187,10 @@ public CEditorConstructed(final CDetailPicture cDetailPicture0, final GameType g
case TinyLeaders:
this.controller = new DeckController<>(FModel.getDecks().getTinyLeaders(), this, newCreator);
break;
case DuelCommander:
// a Commander deck built and checked under Duel Commander rules
this.controller = new DeckController<>(FModel.getDecks().getCommander(), this, newCreator);
break;
default:
}

Expand All @@ -199,6 +211,7 @@ protected CardLimit getCardLimit() {
case Commander:
case Oathbreaker:
case TinyLeaders:
case DuelCommander:
case Brawl:
return CardLimit.Singleton;
default:
Expand Down
Loading