mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
commander stored as a single card in deck/Deck.java
removed inpropper use of getType of InventoryItem objects
This commit is contained in:
@@ -35,6 +35,7 @@ import com.google.common.base.Function;
|
||||
import forge.deck.io.DeckFileHeader;
|
||||
import forge.deck.io.DeckSerializer;
|
||||
import forge.gui.deckeditor.tables.TableSorter;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.game.GameType;
|
||||
@@ -62,7 +63,7 @@ public class Deck extends DeckBase {
|
||||
|
||||
private final DeckSection main;
|
||||
private final DeckSection sideboard;
|
||||
private final DeckSection commander;
|
||||
private CardPrinted commander;
|
||||
private final DeckSection planes;
|
||||
private final DeckSection schemes;
|
||||
|
||||
@@ -85,7 +86,7 @@ public class Deck extends DeckBase {
|
||||
super(name0);
|
||||
this.main = new DeckSection();
|
||||
this.sideboard = new DeckSection();
|
||||
this.commander = new DeckSection();
|
||||
this.commander = null;
|
||||
this.planes = new DeckSection();
|
||||
this.schemes = new DeckSection();
|
||||
}
|
||||
@@ -203,7 +204,9 @@ public class Deck extends DeckBase {
|
||||
|
||||
d.getMain().set(Deck.readCardList(sections.get("main")));
|
||||
d.getSideboard().set(Deck.readCardList(sections.get("sideboard")));
|
||||
d.getCommander().set(Deck.readCardList(sections.get("commander")));
|
||||
List<String> cmd = Deck.readCardList(sections.get("commander"));
|
||||
String cmdName = cmd.isEmpty() ? null : cmd.get(0);
|
||||
d.commander = CardDb.instance().isCardSupported(cmdName) ? CardDb.instance().getCard(cmdName) : null;
|
||||
d.getPlanes().set(Deck.readCardList(sections.get("planes")));
|
||||
d.getSchemes().set(Deck.readCardList(sections.get("schemes")));
|
||||
return d;
|
||||
@@ -244,17 +247,21 @@ public class Deck extends DeckBase {
|
||||
Collections.sort(main2sort, TableSorter.BY_NAME_THEN_SET);
|
||||
final List<String> out = new ArrayList<String>();
|
||||
for (final Entry<CardPrinted, Integer> e : main2sort) {
|
||||
final CardPrinted card = e.getKey();
|
||||
final boolean hasBadSetInfo = "???".equals(card.getEdition()) || StringUtils.isBlank(card.getEdition());
|
||||
if (hasBadSetInfo) {
|
||||
out.add(String.format("%d %s", e.getValue(), card.getName()));
|
||||
} else {
|
||||
out.add(String.format("%d %s|%s", e.getValue(), card.getName(), card.getEdition()));
|
||||
}
|
||||
out.add(serializeSingleCard(e.getKey(), e.getValue()));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static String serializeSingleCard(CardPrinted card, Integer n) {
|
||||
|
||||
final boolean hasBadSetInfo = "???".equals(card.getEdition()) || StringUtils.isBlank(card.getEdition());
|
||||
if (hasBadSetInfo) {
|
||||
return String.format("%d %s", n, card.getName());
|
||||
} else {
|
||||
return String.format("%d %s|%s", n, card.getName(), card.getEdition());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* writeDeck.
|
||||
@@ -279,8 +286,10 @@ public class Deck extends DeckBase {
|
||||
out.add(String.format("%s", "[sideboard]"));
|
||||
out.addAll(Deck.writeCardPool(this.getSideboard()));
|
||||
|
||||
out.add(String.format("%s", "[commander]"));
|
||||
out.addAll(Deck.writeCardPool(this.getCommander()));
|
||||
if ( getCommander() != null ) {
|
||||
out.add(String.format("%s", "[commander]"));
|
||||
out.add(Deck.serializeSingleCard(getCommander(), 1));
|
||||
}
|
||||
|
||||
out.add(String.format("%s", "[planes]"));
|
||||
out.addAll(Deck.writeCardPool(this.getPlanes()));
|
||||
@@ -346,14 +355,14 @@ public class Deck extends DeckBase {
|
||||
if(type == GameType.Commander)
|
||||
{//Must contain exactly 1 legendary Commander and no sideboard.
|
||||
//TODO:Enforce color identity
|
||||
if(getCommander().countAll() != 1)
|
||||
if ( null == getCommander())
|
||||
return false;
|
||||
|
||||
if(!getCommander().toFlatList().get(0).getType().contains("Legendary"))
|
||||
if(!getCommander().getCard().getType().isLegendary())
|
||||
return false;
|
||||
|
||||
//No sideboarding in Commander
|
||||
if(getSideboard().countAll() > 0)
|
||||
if(!getSideboard().isEmpty())
|
||||
return false;
|
||||
}
|
||||
else if(type == GameType.Planechase)
|
||||
@@ -389,7 +398,7 @@ public class Deck extends DeckBase {
|
||||
/**
|
||||
* @return the commander
|
||||
*/
|
||||
public DeckSection getCommander() {
|
||||
public CardPrinted getCommander() {
|
||||
return commander;
|
||||
}
|
||||
|
||||
|
||||
@@ -220,6 +220,8 @@ public final class CardDb {
|
||||
* @return true, if is card supported
|
||||
*/
|
||||
public boolean isCardSupported(final String cardName0) {
|
||||
if ( null == cardName0 ) return false; // obviously
|
||||
|
||||
final boolean isFoil = this.isFoil(cardName0);
|
||||
final String cardName = isFoil ? this.removeFoilSuffix(cardName0) : cardName0;
|
||||
final ImmutablePair<String, String> nameWithSet = CardDb.splitCardName(cardName);
|
||||
|
||||
@@ -13,141 +13,85 @@ public abstract class ItemPredicate {
|
||||
|
||||
// Static builder methods - they choose concrete implementation by
|
||||
// themselves
|
||||
/**
|
||||
* Booster Pack.
|
||||
*
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<InventoryItem> boosterPack() {
|
||||
return new PredicateBoosterPack();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fat Pack.
|
||||
*
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<InventoryItem> fatPack() {
|
||||
return new PredicateFatPack();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tournament Pack.
|
||||
*
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<InventoryItem> tournamentPack() {
|
||||
return new PredicateTournamentPack();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starter Deck.
|
||||
*
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<InventoryItem> starterDeck() {
|
||||
return new PredicateStarterDeck();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prebuilt Deck.
|
||||
*
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<InventoryItem> prebuiltDeck() {
|
||||
return new PredicatePrebuiltDeck();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the inventory item is a Booster Pack.
|
||||
*
|
||||
* @return the predicate
|
||||
*/
|
||||
public static class PredicateBoosterPack implements Predicate<InventoryItem> {
|
||||
public static Predicate<InventoryItem> IsBoosterPack = new Predicate<InventoryItem>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(final InventoryItem card) {
|
||||
return card.getType() == "Booster Pack";
|
||||
return card instanceof BoosterPack;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks that the inventory item is a Fat Pack.
|
||||
*
|
||||
* @return the predicate
|
||||
*/
|
||||
public static class PredicateFatPack implements Predicate<InventoryItem> {
|
||||
public static Predicate<InventoryItem> IsFatPack = new Predicate<InventoryItem>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(final InventoryItem card) {
|
||||
return card.getType() == "Fat Pack";
|
||||
return card instanceof FatPack;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks that the inventory item is a Tournament Pack.
|
||||
*
|
||||
* @return the predicate
|
||||
*/
|
||||
public static class PredicateTournamentPack implements Predicate<InventoryItem> {
|
||||
public static Predicate<InventoryItem> IsTournamentPack = new Predicate<InventoryItem>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(final InventoryItem card) {
|
||||
return card.getType() == "Tournament Pack";
|
||||
return card instanceof TournamentPack && !((TournamentPack)card).isStarterDeck();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks that the inventory item is a Starter Deck.
|
||||
*
|
||||
* @return the predicate
|
||||
*/
|
||||
public static class PredicateStarterDeck implements Predicate<InventoryItem> {
|
||||
public static Predicate<InventoryItem> IsStarterDeck = new Predicate<InventoryItem>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(final InventoryItem card) {
|
||||
return card.getType() == "Starter Deck";
|
||||
return card instanceof TournamentPack && ((TournamentPack)card).isStarterDeck();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks that the inventory item is a Prebuilt Deck.
|
||||
*
|
||||
* @return the predicate
|
||||
*/
|
||||
public static class PredicatePrebuiltDeck implements Predicate<InventoryItem> {
|
||||
public static Predicate<InventoryItem> IsPrebuiltDeck = new Predicate<InventoryItem>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(final InventoryItem card) {
|
||||
return card.getType() == "Prebuilt Deck";
|
||||
return card instanceof PreconDeck;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The Class Presets.
|
||||
*/
|
||||
public static class Presets {
|
||||
|
||||
/** The Item IsBoosterPack. */
|
||||
public static final Predicate<InventoryItem> IS_BOOSTER_PACK = boosterPack();
|
||||
|
||||
/** The Item IsFatPack. */
|
||||
public static final Predicate<InventoryItem> IS_FAT_PACK = fatPack();
|
||||
|
||||
/** The Item IsTournamentPack. */
|
||||
public static final Predicate<InventoryItem> IS_TOURNAMENT_PACK = tournamentPack();
|
||||
|
||||
/** The Item IsPack. */
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final Predicate<InventoryItem> IS_PACK = Predicates.or(IS_BOOSTER_PACK, IS_FAT_PACK, IS_TOURNAMENT_PACK);
|
||||
|
||||
/** The Item IsStarterDeck. */
|
||||
public static final Predicate<InventoryItem> IS_STARTER_DECK = starterDeck();
|
||||
|
||||
/** The Item IsPrebuiltDeck. */
|
||||
public static final Predicate<InventoryItem> IS_PREBUILT_DECK = prebuiltDeck();
|
||||
public static final Predicate<InventoryItem> IS_PACK = Predicates.or(IsBoosterPack, IsFatPack, IsTournamentPack);
|
||||
|
||||
/** The Item IsDeck. */
|
||||
public static final Predicate<InventoryItem> IS_DECK = Predicates.or(IS_STARTER_DECK, IS_PREBUILT_DECK);
|
||||
public static final Predicate<InventoryItem> IS_DECK = Predicates.or(IsStarterDeck, IsPrebuiltDeck);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,10 +58,14 @@ public class TournamentPack extends OpenablePack {
|
||||
return ImageCache.SEALED_PRODUCT + "tournamentpacks/" + this.contents.getEdition();
|
||||
}
|
||||
|
||||
public final boolean isStarterDeck() {
|
||||
return contents.getCommon() < 30;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final String getType() {
|
||||
return contents.getCommon() >= 30 ? "Tournament Pack" : "Starter Deck";
|
||||
return !isStarterDeck() ? "Tournament Pack" : "Starter Deck";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user