mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
deck API changes. Deck is now a map of sections to cardpools. Schemes and planes have their own sections
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -13915,6 +13915,7 @@ src/main/java/forge/control/input/InputSelectManyPlayers.java -text
|
||||
src/main/java/forge/control/input/package-info.java svneol=native#text/plain
|
||||
src/main/java/forge/control/package-info.java -text
|
||||
src/main/java/forge/deck/CardCollections.java -text
|
||||
src/main/java/forge/deck/CardPool.java -text
|
||||
src/main/java/forge/deck/Deck.java svneol=native#text/plain
|
||||
src/main/java/forge/deck/DeckBase.java -text
|
||||
src/main/java/forge/deck/DeckFormat.java -text
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.util.List;
|
||||
|
||||
import forge.Card;
|
||||
import forge.CardCharacteristicName;
|
||||
import forge.Singletons;
|
||||
import forge.card.ability.AbilityUtils;
|
||||
import forge.card.ability.SpellEffect;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
|
||||
160
src/main/java/forge/deck/CardPool.java
Normal file
160
src/main/java/forge/deck/CardPool.java
Normal file
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.deck;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import forge.Card;
|
||||
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.ItemPool;
|
||||
|
||||
/**
|
||||
* Deck section.
|
||||
*
|
||||
*/
|
||||
public class CardPool extends ItemPool<CardPrinted> {
|
||||
|
||||
/**
|
||||
* Instantiates a new deck section.
|
||||
*/
|
||||
public CardPool() {
|
||||
super(CardPrinted.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new deck section.
|
||||
*
|
||||
* @param cards the cards
|
||||
*/
|
||||
public CardPool(final Iterable<Entry<CardPrinted, Integer>> cards) {
|
||||
this();
|
||||
this.addAll(cards);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the.
|
||||
*
|
||||
* @param cardNames
|
||||
* the card names
|
||||
*/
|
||||
public void set(final Iterable<String> cardNames) {
|
||||
this.clear();
|
||||
for (final String name : cardNames) {
|
||||
this.add(CardDb.instance().getCard(name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the.
|
||||
*
|
||||
* @param card
|
||||
* the card
|
||||
*/
|
||||
public void add(final Card card) {
|
||||
this.add(CardDb.instance().getCard(card));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the.
|
||||
*
|
||||
* @param cardName
|
||||
* the card name
|
||||
* @param setCode
|
||||
* the set code
|
||||
*/
|
||||
public void add(final String cardName, final String setCode) {
|
||||
this.add(CardDb.instance().getCard(cardName, setCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the.
|
||||
*
|
||||
* @param cardName the card name
|
||||
* @param setCode the set code
|
||||
* @param amount the amount
|
||||
*/
|
||||
public void add(final String cardName, final String setCode, final int amount) {
|
||||
this.add(CardDb.instance().getCard(cardName, setCode), amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the.
|
||||
*
|
||||
* @param cardList
|
||||
* the card list
|
||||
*/
|
||||
public void add(final List<Card> cardList) {
|
||||
for (final Card c : cardList) {
|
||||
this.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all from a List of CardPrinted.
|
||||
*
|
||||
* @param list
|
||||
* CardPrinteds to add
|
||||
*/
|
||||
public void add(final Iterable<CardPrinted> list) {
|
||||
for (CardPrinted cp : list) {
|
||||
this.add(cp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
*
|
||||
* @param cardName the card name
|
||||
*/
|
||||
public void add(final String cardName) {
|
||||
this.add(CardDb.instance().getCard(cardName));
|
||||
}
|
||||
|
||||
/**
|
||||
* returns n-th card from this DeckSection. LINEAR time. No fixed order between changes
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public CardPrinted get(int n) {
|
||||
for(Entry<CardPrinted, Integer> e : this)
|
||||
{
|
||||
n -= e.getValue();
|
||||
if ( n <= 0 ) return e.getKey();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this.isEmpty()) return "[]";
|
||||
|
||||
boolean isFirst = true;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('[');
|
||||
for (Entry<CardPrinted, Integer> e : this) {
|
||||
if ( isFirst ) isFirst = false;
|
||||
else sb.append(", ");
|
||||
|
||||
sb.append(e.getValue()).append(" x ").append(e.getKey().getName());
|
||||
}
|
||||
return sb.append(']').toString();
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ package forge.deck;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -34,7 +35,6 @@ 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.util.FileSection;
|
||||
@@ -53,16 +53,13 @@ import forge.util.FileUtil;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Deck extends DeckBase {
|
||||
public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPool>> {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -7478025567887481994L;
|
||||
|
||||
private final DeckSection main;
|
||||
private final DeckSection sideboard; // commander, planes or schemes are also stored here
|
||||
private CardPrinted avatar;
|
||||
private CardPrinted commander;
|
||||
private final Map<DeckSection, CardPool> parts = new EnumMap<DeckSection, CardPool>(DeckSection.class);
|
||||
|
||||
// gameType is from Constant.GameType, like GameType.Regular
|
||||
/**
|
||||
@@ -81,18 +78,10 @@ public class Deck extends DeckBase {
|
||||
*/
|
||||
public Deck(final String name0) {
|
||||
super(name0);
|
||||
this.main = new DeckSection();
|
||||
this.sideboard = new DeckSection();
|
||||
this.avatar = null;
|
||||
getOrCreate(DeckSection.Main);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* hashCode.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.getName().hashCode();
|
||||
@@ -104,13 +93,28 @@ public class Deck extends DeckBase {
|
||||
return this.getName();
|
||||
}
|
||||
|
||||
public DeckSection getMain() {
|
||||
return this.main;
|
||||
public CardPool getMain() {
|
||||
return this.parts.get(DeckSection.Main);
|
||||
}
|
||||
|
||||
// variants' extra deck sections used instead of sideboard (planes, commander, schemes) are here as well as usual sideboards
|
||||
public DeckSection getSideboard() {
|
||||
return this.sideboard;
|
||||
// may return nulls
|
||||
public CardPool get(DeckSection deckSection) {
|
||||
return this.parts.get(deckSection);
|
||||
}
|
||||
|
||||
public boolean has(DeckSection deckSection) {
|
||||
final CardPool cp = get(deckSection);
|
||||
return cp != null && !cp.isEmpty();
|
||||
}
|
||||
|
||||
// will return new if it was absent
|
||||
public CardPool getOrCreate(DeckSection deckSection) {
|
||||
CardPool p = get(deckSection);
|
||||
if ( p != null )
|
||||
return p;
|
||||
p = new CardPool();
|
||||
this.parts.put(deckSection, p);
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -120,7 +124,7 @@ public class Deck extends DeckBase {
|
||||
*/
|
||||
@Override
|
||||
public ItemPoolView<CardPrinted> getCardPool() {
|
||||
return this.main;
|
||||
return this.parts.get(DeckSection.Main);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -130,10 +134,11 @@ public class Deck extends DeckBase {
|
||||
protected void cloneFieldsTo(final DeckBase clone) {
|
||||
super.cloneFieldsTo(clone);
|
||||
final Deck result = (Deck) clone;
|
||||
result.main.addAll(this.main);
|
||||
result.sideboard.addAll(this.sideboard);
|
||||
result.avatar = this.avatar;
|
||||
result.commander = this.commander;
|
||||
for(Entry<DeckSection, CardPool> kv : parts.entrySet()) {
|
||||
CardPool cp = new CardPool();
|
||||
result.parts.put(kv.getKey(), cp);
|
||||
cp.addAll(kv.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -186,20 +191,23 @@ public class Deck extends DeckBase {
|
||||
final Deck d = new Deck(dh.getName());
|
||||
d.setComment(dh.getComment());
|
||||
|
||||
d.getMain().set(Deck.readCardList(sections.get("main")));
|
||||
d.getSideboard().set(Deck.readCardList(sections.get("sideboard")));
|
||||
// try also earlier deck formats
|
||||
if ( d.getSideboard().isEmpty() ) { d.getSideboard().set(Deck.readCardList(sections.get("schemes"))); }
|
||||
if ( d.getSideboard().isEmpty() ) { d.getSideboard().set(Deck.readCardList(sections.get("planes"))); }
|
||||
|
||||
List<String> av = Deck.readCardList(sections.get("avatar"));
|
||||
String avName = av.isEmpty() ? null : av.get(0);
|
||||
d.avatar = CardDb.instance().isCardSupported(avName) ? CardDb.instance().getCard(avName) : null;
|
||||
for(Entry<String, List<String>> s : sections.entrySet()) {
|
||||
DeckSection sec = DeckSection.smartValueOf(s.getKey());
|
||||
if ( null == sec )
|
||||
continue;
|
||||
|
||||
CardPool pool = new CardPool();
|
||||
pool.set(Deck.readCardList(s.getValue()));
|
||||
|
||||
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;
|
||||
// I used to store planes and schemes under sideboard header, so this will assign them to a correct section
|
||||
CardPrinted sample = pool.get(0);
|
||||
if ( sample != null && ( sample.getCard().getType().isPlane() || sample.getCard().getType().isPhenomenon() ) )
|
||||
sec = DeckSection.Planes;
|
||||
if ( sample != null && sample.getCard().getType().isScheme() )
|
||||
sec = DeckSection.Schemes;
|
||||
|
||||
d.parts.put(sec, pool);
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
@@ -270,38 +278,13 @@ public class Deck extends DeckBase {
|
||||
out.add(String.format("%s=%s", DeckFileHeader.COMMENT, this.getComment().replaceAll("\n", "")));
|
||||
}
|
||||
|
||||
out.add(String.format("%s", "[main]"));
|
||||
out.addAll(Deck.writeCardPool(this.getMain()));
|
||||
|
||||
out.add("[sideboard]");
|
||||
out.addAll(Deck.writeCardPool(this.getSideboard()));
|
||||
|
||||
if (getAvatar() != null) {
|
||||
out.add("[avatar]");
|
||||
out.add(Deck.serializeSingleCard(getAvatar(), 1));
|
||||
}
|
||||
|
||||
if (getCommander() != null) {
|
||||
out.add("[commander]");
|
||||
out.add(Deck.serializeSingleCard(getCommander(), 1));
|
||||
for(Entry<DeckSection, CardPool> s : parts.entrySet()) {
|
||||
out.add(String.format("[%s]", s.getKey().toString()));
|
||||
out.addAll(Deck.writeCardPool(s.getValue()));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the commander
|
||||
*/
|
||||
public CardPrinted getCommander() {
|
||||
return commander;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the avatar
|
||||
*/
|
||||
public CardPrinted getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public static final Function<Deck, String> FN_NAME_SELECTOR = new Function<Deck, String>() {
|
||||
@Override
|
||||
@@ -309,4 +292,12 @@ public class Deck extends DeckBase {
|
||||
return arg1.getName();
|
||||
}
|
||||
};
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Iterable#iterator()
|
||||
*/
|
||||
@Override
|
||||
public Iterator<Entry<DeckSection, CardPool>> iterator() {
|
||||
return parts.entrySet().iterator();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,28 +132,31 @@ public enum DeckFormat {
|
||||
switch(this) {
|
||||
case Commander: //Must contain exactly 1 legendary Commander and a sideboard of 10 or zero cards.
|
||||
|
||||
//TODO:Enforce color identity
|
||||
if (null == deck.getCommander()) {
|
||||
final CardPool cmd = deck.get(DeckSection.Commander);
|
||||
if (null == cmd || cmd.isEmpty()) {
|
||||
return "is missing a commander";
|
||||
}
|
||||
if (!deck.getCommander().getCard().getType().isLegendary()) {
|
||||
if (!cmd.get(0).getCard().getType().isLegendary()) {
|
||||
return "has a commander that is not a legendary creature";
|
||||
}
|
||||
|
||||
//TODO:Enforce color identity
|
||||
|
||||
break;
|
||||
|
||||
case Planechase: //Must contain at least 10 planes/phenomenons, but max 2 phenomenons. Singleton.
|
||||
if (deck.getSideboard().countAll() < 10) {
|
||||
final CardPool planes = deck.get(DeckSection.Planes);
|
||||
if (planes == null || planes.countAll() < 10) {
|
||||
return "should gave at least 10 planes";
|
||||
}
|
||||
int phenoms = 0;
|
||||
for (Entry<CardPrinted, Integer> cp : deck.getSideboard()) {
|
||||
for (Entry<CardPrinted, Integer> cp : planes) {
|
||||
|
||||
if (cp.getKey().getCard().getType().typeContains(CardCoreType.Phenomenon)) {
|
||||
phenoms++;
|
||||
}
|
||||
if (cp.getValue() > 1) {
|
||||
return "must not contain multiple copies of any Phenomena";
|
||||
return "must not contain multiple copies of any Plane or Phenomena";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -163,13 +166,14 @@ public enum DeckFormat {
|
||||
break;
|
||||
|
||||
case Archenemy: //Must contain at least 20 schemes, max 2 of each.
|
||||
if (deck.getSideboard().countAll() < 20) {
|
||||
final CardPool schemes = deck.get(DeckSection.Schemes);
|
||||
if (schemes == null || schemes.countAll() < 20) {
|
||||
return "must contain at least 20 schemes";
|
||||
}
|
||||
|
||||
for (Entry<CardPrinted, Integer> cp : deck.getSideboard()) {
|
||||
for (Entry<CardPrinted, Integer> cp : schemes) {
|
||||
if (cp.getValue() > 2) {
|
||||
return "must not contain more than 2 copies of any Scheme";
|
||||
return String.format("must not contain more than 2 copies of any Scheme, but has %d of '%s'", cp.getValue(), cp.getKey().getName());
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -181,11 +185,11 @@ public enum DeckFormat {
|
||||
//shared among the main deck and sideboard, except
|
||||
//basic lands and Relentless Rats
|
||||
|
||||
DeckSection tmp = new DeckSection(deck.getMain());
|
||||
tmp.addAll(deck.getSideboard());
|
||||
if (null != deck.getCommander() && this == Commander) {
|
||||
tmp.add(deck.getCommander());
|
||||
}
|
||||
CardPool tmp = new CardPool(deck.getMain());
|
||||
if ( deck.has(DeckSection.Sideboard))
|
||||
tmp.addAll(deck.get(DeckSection.Sideboard));
|
||||
if ( deck.has(DeckSection.Commander) && this == Commander)
|
||||
tmp.addAll(deck.get(DeckSection.Commander));
|
||||
|
||||
List<String> limitExceptions = Arrays.asList("Relentless Rats");
|
||||
|
||||
@@ -202,7 +206,7 @@ public enum DeckFormat {
|
||||
}
|
||||
|
||||
// The sideboard must contain either 0 or 15 cards
|
||||
int sideboardSize = deck.getSideboard().countAll();
|
||||
int sideboardSize = deck.has(DeckSection.Sideboard) ? deck.get(DeckSection.Sideboard).countAll() : 0;
|
||||
IntRange sbRange = getSideRange();
|
||||
if (sbRange != null && sideboardSize > 0 && !sbRange.containsInteger(sideboardSize)) {
|
||||
return sbRange.getMinimumInteger() == sbRange.getMaximumInteger()
|
||||
|
||||
@@ -1,160 +1,35 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.deck;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import forge.Card;
|
||||
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.ItemPool;
|
||||
|
||||
/**
|
||||
* Deck section.
|
||||
*
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class DeckSection extends ItemPool<CardPrinted> {
|
||||
public enum DeckSection {
|
||||
|
||||
Avatar(1),
|
||||
Commander(1),
|
||||
Main(60),
|
||||
Sideboard(15),
|
||||
Planes(10),
|
||||
Schemes(20);
|
||||
|
||||
/**
|
||||
* Instantiates a new deck section.
|
||||
*/
|
||||
public DeckSection() {
|
||||
super(CardPrinted.class);
|
||||
private final int typicalSize; // Rules enforcement is done in DeckFormat class, this is for reference only
|
||||
private DeckSection(int commonSize) {
|
||||
typicalSize = commonSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new deck section.
|
||||
*
|
||||
* @param cards the cards
|
||||
*/
|
||||
public DeckSection(final Iterable<Entry<CardPrinted, Integer>> cards) {
|
||||
this();
|
||||
this.addAll(cards);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the.
|
||||
*
|
||||
* @param cardNames
|
||||
* the card names
|
||||
*/
|
||||
public void set(final Iterable<String> cardNames) {
|
||||
this.clear();
|
||||
for (final String name : cardNames) {
|
||||
this.add(CardDb.instance().getCard(name));
|
||||
|
||||
public boolean isSingleCard() { return typicalSize == 1; }
|
||||
|
||||
public static DeckSection smartValueOf(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the.
|
||||
*
|
||||
* @param card
|
||||
* the card
|
||||
*/
|
||||
public void add(final Card card) {
|
||||
this.add(CardDb.instance().getCard(card));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the.
|
||||
*
|
||||
* @param cardName
|
||||
* the card name
|
||||
* @param setCode
|
||||
* the set code
|
||||
*/
|
||||
public void add(final String cardName, final String setCode) {
|
||||
this.add(CardDb.instance().getCard(cardName, setCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the.
|
||||
*
|
||||
* @param cardName the card name
|
||||
* @param setCode the set code
|
||||
* @param amount the amount
|
||||
*/
|
||||
public void add(final String cardName, final String setCode, final int amount) {
|
||||
this.add(CardDb.instance().getCard(cardName, setCode), amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the.
|
||||
*
|
||||
* @param cardList
|
||||
* the card list
|
||||
*/
|
||||
public void add(final List<Card> cardList) {
|
||||
for (final Card c : cardList) {
|
||||
this.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all from a List of CardPrinted.
|
||||
*
|
||||
* @param list
|
||||
* CardPrinteds to add
|
||||
*/
|
||||
public void add(final Iterable<CardPrinted> list) {
|
||||
for (CardPrinted cp : list) {
|
||||
this.add(cp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
*
|
||||
* @param cardName the card name
|
||||
*/
|
||||
public void add(final String cardName) {
|
||||
this.add(CardDb.instance().getCard(cardName));
|
||||
}
|
||||
|
||||
/**
|
||||
* returns n-th card from this DeckSection. LINEAR time.
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public CardPrinted get(int n) {
|
||||
for(Entry<CardPrinted, Integer> e : this)
|
||||
{
|
||||
n -= e.getValue();
|
||||
if ( n <= 0 ) return e.getKey();
|
||||
final String valToCompate = value.trim();
|
||||
for (final DeckSection v : DeckSection.values()) {
|
||||
if (v.name().compareToIgnoreCase(valToCompate) == 0) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this.isEmpty()) return "[]";
|
||||
|
||||
boolean isFirst = true;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('[');
|
||||
for (Entry<CardPrinted, Integer> e : this) {
|
||||
if ( isFirst ) isFirst = false;
|
||||
else sb.append(", ");
|
||||
|
||||
sb.append(e.getValue()).append(" x ").append(e.getKey().getName());
|
||||
}
|
||||
return sb.append(']').toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,32 +235,37 @@ public class DeckgenUtil {
|
||||
}
|
||||
|
||||
// Dump into map and display.
|
||||
final Map<String, Integer> deckMap = new TreeMap<String, Integer>();
|
||||
|
||||
for (final Entry<CardPrinted, Integer> s : deck.getMain()) {
|
||||
deckMap.put(s.getKey().getName(), s.getValue());
|
||||
}
|
||||
|
||||
final String nl = System.getProperty("line.separator");
|
||||
final StringBuilder deckList = new StringBuilder();
|
||||
final String dName = deck.getName();
|
||||
|
||||
deckList.append(dName == null ? "" : dName + nl + nl);
|
||||
|
||||
if (deck.getAvatar() != null) {
|
||||
deckList.append("Avatar: " + deck.getAvatar().getName() + nl + nl);
|
||||
}
|
||||
if (deck.getCommander() != null) {
|
||||
deckList.append("Commander: " + deck.getCommander().getName() + nl + nl);
|
||||
int nLines = 0;
|
||||
for(DeckSection s : DeckSection.values()){
|
||||
CardPool cp = deck.get(s);
|
||||
if ( cp == null || cp.isEmpty() )
|
||||
continue;
|
||||
|
||||
deckList.append(s.toString()).append(": ");
|
||||
if ( s.isSingleCard() ) {
|
||||
deckList.append(cp.get(0).getName()).append(nl);
|
||||
nLines++;
|
||||
} else {
|
||||
deckList.append(nl);
|
||||
nLines++;
|
||||
for (final Entry<CardPrinted, Integer> ev : cp) {
|
||||
deckList.append(ev.getValue()).append(" x ").append(ev.getKey()).append(nl);
|
||||
nLines++;
|
||||
}
|
||||
}
|
||||
deckList.append(nl);
|
||||
nLines++;
|
||||
}
|
||||
|
||||
for (final Entry<String, Integer> ev : deckMap.entrySet()) {
|
||||
deckList.append(ev.getValue() + " x " + ev.getKey() + nl);
|
||||
}
|
||||
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
if (deckMap.keySet().size() <= 32) {
|
||||
msg.append(deckList.toString() + nl);
|
||||
if (nLines <= 32) {
|
||||
msg.append(deckList.toString());
|
||||
} else {
|
||||
msg.append("Decklist too long for dialog." + nl + nl);
|
||||
}
|
||||
@@ -308,8 +313,8 @@ public class DeckgenUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Deck generateSchemeDeck() {
|
||||
Deck res = new Deck();
|
||||
public static CardPool generateSchemeDeck() {
|
||||
CardPool schemes = new CardPool();
|
||||
List<CardPrinted> allSchemes = new ArrayList<CardPrinted>();
|
||||
for (CardPrinted c : CardDb.instance().getAllNonTraditionalCards()) {
|
||||
if (c.getCard().getType().isScheme()) {
|
||||
@@ -321,20 +326,20 @@ public class DeckgenUtil {
|
||||
int attemptsLeft = 100; // to avoid endless loop
|
||||
while (schemesToAdd > 0 && attemptsLeft > 0) {
|
||||
CardPrinted cp = Aggregates.random(allSchemes);
|
||||
int appearances = res.getSideboard().count(cp) + 1;
|
||||
int appearances = schemes.count(cp) + 1;
|
||||
if (appearances < 2) {
|
||||
res.getSideboard().add(cp);
|
||||
schemes.add(cp);
|
||||
schemesToAdd--;
|
||||
} else {
|
||||
attemptsLeft--;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
return schemes;
|
||||
}
|
||||
|
||||
public static Deck generatePlanarDeck() {
|
||||
Deck res = new Deck();
|
||||
public static CardPool generatePlanarDeck() {
|
||||
CardPool res = new CardPool();
|
||||
List<CardPrinted> allPlanars = new ArrayList<CardPrinted>();
|
||||
for (CardPrinted c : CardDb.instance().getAllNonTraditionalCards()) {
|
||||
if (c.getCard().getType().isPlane() || c.getCard().getType().isPhenomenon()) {
|
||||
@@ -351,15 +356,15 @@ public class DeckgenUtil {
|
||||
|
||||
if(rndPlane.getCard().getType().isPhenomenon() && phenoms < 2)
|
||||
{
|
||||
res.getSideboard().add(rndPlane);
|
||||
res.add(rndPlane);
|
||||
phenoms++;
|
||||
}
|
||||
else if (rndPlane.getCard().getType().isPlane())
|
||||
{
|
||||
res.getSideboard().add(rndPlane);
|
||||
res.add(rndPlane);
|
||||
}
|
||||
|
||||
if(allPlanars.isEmpty() || res.getSideboard().countAll() == targetsize)
|
||||
if(allPlanars.isEmpty() || res.countAll() == targetsize)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class GameFormat {
|
||||
* @param bannedCards
|
||||
* the banned cards
|
||||
*/
|
||||
public GameFormat(final String fName, final List<String> sets, final List<String> bannedCards) {
|
||||
public GameFormat(final String fName, final Iterable<String> sets, final List<String> bannedCards) {
|
||||
this.name = fName;
|
||||
this.allowedSetCodes = Lists.newArrayList(sets);
|
||||
this.bannedCardNames = bannedCards == null ? new ArrayList<String>() : Lists.newArrayList(bannedCards);
|
||||
|
||||
@@ -28,6 +28,7 @@ import forge.card.trigger.TriggerType;
|
||||
import forge.control.input.InputControl;
|
||||
import forge.control.input.InputMulligan;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.CardPool;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.game.event.FlipCoinEvent;
|
||||
import forge.game.phase.PhaseHandler;
|
||||
@@ -49,7 +50,7 @@ import forge.util.MyRandom;
|
||||
*/
|
||||
public class GameNew {
|
||||
|
||||
private static void preparePlayerLibrary(Player player, final ZoneType zoneType, DeckSection secion, boolean canRandomFoil, Random generator) {
|
||||
private static void preparePlayerLibrary(Player player, final ZoneType zoneType, CardPool secion, boolean canRandomFoil, Random generator) {
|
||||
PlayerZone library = player.getZone(zoneType);
|
||||
for (final Entry<CardPrinted, Integer> stackOfCards : secion) {
|
||||
final CardPrinted cardPrinted = stackOfCards.getKey();
|
||||
@@ -112,7 +113,7 @@ public class GameNew {
|
||||
|
||||
GameType gameType = Singletons.getModel().getMatch().getGameType();
|
||||
boolean isFirstGame = Singletons.getModel().getMatch().getPlayedGames().isEmpty();
|
||||
boolean hasSideboard = !psc.getOriginalDeck().getSideboard().isEmpty();
|
||||
boolean hasSideboard = psc.getOriginalDeck().has(DeckSection.Sideboard);
|
||||
boolean canSideBoard = !isFirstGame && gameType.isSideboardingAllowed() && hasSideboard;
|
||||
|
||||
if (canSideBoard) {
|
||||
@@ -126,7 +127,8 @@ public class GameNew {
|
||||
Random generator = MyRandom.getRandom();
|
||||
|
||||
preparePlayerLibrary(player, ZoneType.Library, myDeck.getMain(), canRandomFoil, generator);
|
||||
preparePlayerLibrary(player, ZoneType.Sideboard, myDeck.getSideboard(), canRandomFoil, generator);
|
||||
if(hasSideboard)
|
||||
preparePlayerLibrary(player, ZoneType.Sideboard, myDeck.get(DeckSection.Sideboard), canRandomFoil, generator);
|
||||
|
||||
// Shuffling
|
||||
if (player instanceof AIPlayer && Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_SMOOTH_LAND)) {
|
||||
@@ -190,13 +192,12 @@ public class GameNew {
|
||||
|
||||
private static List<CardPrinted> getCardsAiCantPlayWell(final Deck toUse) {
|
||||
List<CardPrinted> result = new ArrayList<CardPrinted>();
|
||||
for (Entry<CardPrinted, Integer> cp : toUse.getMain()) {
|
||||
if ( cp.getKey().getCard().getRemAIDecks() )
|
||||
result.add(cp.getKey());
|
||||
}
|
||||
for (Entry<CardPrinted, Integer> cp : toUse.getSideboard()) {
|
||||
if ( cp.getKey().getCard().getRemAIDecks() )
|
||||
result.add(cp.getKey());
|
||||
|
||||
for ( Entry<DeckSection, CardPool> ds : toUse ) {
|
||||
for (Entry<CardPrinted, Integer> cp : ds.getValue()) {
|
||||
if ( cp.getKey().getCard().getRemAIDecks() )
|
||||
result.add(cp.getKey());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -204,18 +205,17 @@ public class GameNew {
|
||||
private static Set<CardPrinted> getRemovedAnteCards(Deck toUse) {
|
||||
final String keywordToRemove = "Remove CARDNAME from your deck before playing if you're not playing for ante.";
|
||||
Set<CardPrinted> myRemovedAnteCards = new HashSet<CardPrinted>();
|
||||
for (Entry<CardPrinted, Integer> cp : toUse.getMain()) {
|
||||
if ( cp.getKey().getCard().rulesContain(keywordToRemove) )
|
||||
myRemovedAnteCards.add(cp.getKey());
|
||||
}
|
||||
for (Entry<CardPrinted, Integer> cp : toUse.getSideboard()) {
|
||||
if ( cp.getKey().getCard().rulesContain(keywordToRemove) )
|
||||
myRemovedAnteCards.add(cp.getKey());
|
||||
for ( Entry<DeckSection, CardPool> ds : toUse ) {
|
||||
for (Entry<CardPrinted, Integer> cp : ds.getValue()) {
|
||||
if ( cp.getKey().getCard().rulesContain(keywordToRemove) )
|
||||
myRemovedAnteCards.add(cp.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
for(CardPrinted cp: myRemovedAnteCards) {
|
||||
toUse.getMain().remove(cp, 4);
|
||||
toUse.getSideboard().remove(cp, 4);
|
||||
for ( Entry<DeckSection, CardPool> ds : toUse ) {
|
||||
ds.getValue().remove(cp, Integer.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
return myRemovedAnteCards;
|
||||
}
|
||||
|
||||
@@ -112,16 +112,17 @@ public class MatchController {
|
||||
String statsSummary = ForgeProps.getLocalized(WinLoseText.WON) + humanWins
|
||||
+ ForgeProps.getLocalized(WinLoseText.LOST) + humanLosses;
|
||||
game.getGameLog().add("Final", statsSummary, 0);
|
||||
|
||||
|
||||
|
||||
ViewWinLose v = new ViewWinLose(this);
|
||||
v.setTitle(title);
|
||||
v.setOutcomes(outcomes);
|
||||
v.setStatsSummary(statsSummary);
|
||||
|
||||
// Play the win/lose sound
|
||||
boolean humanWon = result.isWinner(human);
|
||||
game.getEvents().post(new DuelOutcomeEvent(humanWon));
|
||||
game.getEvents().post(new DuelOutcomeEvent(result.isWinner(human)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
|
||||
@@ -25,7 +25,9 @@ import forge.card.CardRules;
|
||||
import forge.card.CardRulesPredicates;
|
||||
import forge.card.DeckHints;
|
||||
import forge.card.mana.ManaCostShard;
|
||||
import forge.deck.CardPool;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.deck.generate.GenerateDeckUtil;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
@@ -170,8 +172,9 @@ public class LimitedDeck {
|
||||
if (deckList.size() == 40) {
|
||||
Deck result = new Deck(generateName());
|
||||
result.getMain().add(deckList);
|
||||
result.getSideboard().add(aiPlayables);
|
||||
result.getSideboard().add(availableList);
|
||||
CardPool cp = result.getOrCreate(DeckSection.Sideboard);
|
||||
cp.add(aiPlayables);
|
||||
cp.add(availableList);
|
||||
if (Preferences.DEV_MODE) {
|
||||
debugFinalDeck();
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import forge.control.input.InputBlock;
|
||||
import forge.control.input.InputCleanup;
|
||||
import forge.control.input.InputPassPriority;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.CardPool;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.game.GameState;
|
||||
import forge.game.GameType;
|
||||
@@ -138,14 +139,15 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
*/
|
||||
@Override
|
||||
public Deck sideboard(Deck deck, GameType gameType) {
|
||||
DeckSection sideboard = deck.getSideboard();
|
||||
CardPool sideboard = deck.get(DeckSection.Sideboard);
|
||||
CardPool main = deck.get(DeckSection.Main);
|
||||
|
||||
// + deck.getSideboard().countAll()
|
||||
int deckMinSize = Math.min(deck.getMain().countAll(), gameType.getDecksFormat().getMainRange().getMinimumInteger());
|
||||
int deckMinSize = Math.min(main.countAll(), gameType.getDecksFormat().getMainRange().getMinimumInteger());
|
||||
//IntRange sbRange = gameType.getDecksFormat().getSideRange();
|
||||
int sideboardSize = sideboard.countAll();
|
||||
|
||||
DeckSection newSb = new DeckSection();
|
||||
CardPool newSb = new CardPool();
|
||||
List<CardPrinted> newMain = null;
|
||||
|
||||
|
||||
@@ -156,20 +158,21 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
JOptionPane.showMessageDialog(null, errMsg, "Invalid deck", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
newMain = GuiChoose.order("Sideboard", "Main Deck", sideboardSize, deck.getSideboard().toFlatList(), deck.getMain().toFlatList(), null, true);
|
||||
newMain = GuiChoose.order("Sideboard", "Main Deck", sideboardSize, sideboard.toFlatList(), main.toFlatList(), null, true);
|
||||
}
|
||||
|
||||
newSb.clear();
|
||||
newSb.addAll(deck.getMain());
|
||||
newSb.addAll(deck.getSideboard());
|
||||
newSb.addAll(main);
|
||||
newSb.addAll(sideboard);
|
||||
for(CardPrinted c : newMain)
|
||||
newSb.remove(c);
|
||||
|
||||
Deck res = (Deck) deck.copyTo(deck.getName());
|
||||
res.getMain().clear();
|
||||
res.getMain().add(newMain);
|
||||
res.getSideboard().clear();
|
||||
res.getSideboard().addAll(newSb);
|
||||
CardPool resSb = res.getOrCreate(DeckSection.Sideboard);
|
||||
resSb.clear();
|
||||
resSb.addAll(newSb);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.thoughtworks.xstream.converters.UnmarshallingContext;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
|
||||
import forge.deck.DeckSection;
|
||||
import forge.deck.CardPool;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
@@ -164,12 +164,12 @@ public class GauntletIO {
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public boolean canConvert(final Class clasz) {
|
||||
return clasz.equals(DeckSection.class);
|
||||
return clasz.equals(CardPool.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
|
||||
for (final Entry<CardPrinted, Integer> e : (DeckSection) source) {
|
||||
for (final Entry<CardPrinted, Integer> e : (CardPool) source) {
|
||||
this.writeCardPrinted(e.getKey(), e.getValue(), writer);
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ public class GauntletIO {
|
||||
|
||||
@Override
|
||||
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
|
||||
final DeckSection result = new DeckSection();
|
||||
final CardPool result = new CardPool();
|
||||
while (reader.hasMoreChildren()) {
|
||||
reader.moveDown();
|
||||
final String sCnt = reader.getAttribute("n");
|
||||
|
||||
@@ -44,6 +44,7 @@ import net.miginfocom.swing.MigLayout;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckBase;
|
||||
import forge.deck.DeckRecognizer;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.deck.DeckRecognizer.TokenType;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.deckeditor.controllers.ACEditorBase;
|
||||
@@ -230,7 +231,7 @@ public class DeckImport<TItem extends InventoryItem, TModel extends DeckBase> ex
|
||||
if (isMain) {
|
||||
result.getMain().add(crd, t.getNumber());
|
||||
} else {
|
||||
result.getSideboard().add(crd, t.getNumber());
|
||||
result.getOrCreate(DeckSection.Sideboard).add(crd, t.getNumber());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -24,6 +24,7 @@ import forge.Command;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.gui.deckeditor.SEditorIO;
|
||||
import forge.gui.deckeditor.SEditorIO.EditorPreference;
|
||||
import forge.gui.deckeditor.SEditorUtil;
|
||||
@@ -155,7 +156,7 @@ public final class CEditorConstructed extends ACEditorBase<CardPrinted, Deck> {
|
||||
|
||||
this.getTableCatalog().setAvailableColumns(lstCatalogCols);
|
||||
this.getTableCatalog().setDeck(this.controller.getModel().getMain());
|
||||
this.getTableDeck().setDeck(this.controller.getModel().getSideboard());
|
||||
this.getTableDeck().setDeck(this.controller.getModel().getOrCreate(DeckSection.Sideboard));
|
||||
} else {
|
||||
lstCatalogCols.remove(SColumnUtil.getColumn(ColumnName.CAT_QUANTITY));
|
||||
this.getTableCatalog().setAvailableColumns(lstCatalogCols);
|
||||
|
||||
@@ -22,8 +22,10 @@ import javax.swing.SwingUtilities;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.control.FControl;
|
||||
import forge.deck.CardPool;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckGroup;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.game.limited.BoosterDraft;
|
||||
import forge.game.limited.IBoosterDraft;
|
||||
import forge.gui.deckeditor.tables.DeckController;
|
||||
@@ -171,15 +173,16 @@ public class CEditorDraftingProcess extends ACEditorBase<CardPrinted, DeckGroup>
|
||||
final Deck deck = new Deck();
|
||||
|
||||
// add sideboard to deck
|
||||
deck.getSideboard().addAll(this.getTableDeck().getCards());
|
||||
CardPool side = deck.getOrCreate(DeckSection.Sideboard);
|
||||
side.addAll(this.getTableDeck().getCards());
|
||||
|
||||
final String landSet = IBoosterDraft.LAND_SET_CODE[0];
|
||||
final int landsCount = 20;
|
||||
deck.getSideboard().add(CardDb.instance().getCard("Forest", landSet), landsCount);
|
||||
deck.getSideboard().add(CardDb.instance().getCard("Mountain", landSet), landsCount);
|
||||
deck.getSideboard().add(CardDb.instance().getCard("Swamp", landSet), landsCount);
|
||||
deck.getSideboard().add(CardDb.instance().getCard("Island", landSet), landsCount);
|
||||
deck.getSideboard().add(CardDb.instance().getCard("Plains", landSet), landsCount);
|
||||
side.add(CardDb.instance().getCard("Forest", landSet), landsCount);
|
||||
side.add(CardDb.instance().getCard("Mountain", landSet), landsCount);
|
||||
side.add(CardDb.instance().getCard("Swamp", landSet), landsCount);
|
||||
side.add(CardDb.instance().getCard("Island", landSet), landsCount);
|
||||
side.add(CardDb.instance().getCard("Plains", landSet), landsCount);
|
||||
|
||||
return deck;
|
||||
} // getPlayersDeck()
|
||||
|
||||
@@ -22,6 +22,7 @@ import forge.Command;
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckGroup;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.gui.deckeditor.SEditorIO;
|
||||
import forge.gui.deckeditor.SEditorUtil;
|
||||
import forge.gui.deckeditor.tables.DeckController;
|
||||
@@ -129,7 +130,7 @@ public final class CEditorLimited extends ACEditorBase<CardPrinted, DeckGroup> {
|
||||
@Override
|
||||
public void resetTables() {
|
||||
final Deck toEdit = this.getSelectedDeck(this.controller.getModel());
|
||||
this.getTableCatalog().setDeck(toEdit.getSideboard());
|
||||
this.getTableCatalog().setDeck(toEdit.getOrCreate(DeckSection.Sideboard));
|
||||
this.getTableDeck().setDeck(toEdit.getMain());
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import forge.Command;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.gui.deckeditor.SEditorIO;
|
||||
import forge.gui.deckeditor.SEditorUtil;
|
||||
import forge.gui.deckeditor.tables.DeckController;
|
||||
@@ -180,7 +181,7 @@ public final class CEditorQuest extends ACEditorBase<CardPrinted, Deck> {
|
||||
// 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.getSideboard());
|
||||
cardpool.removeAll(deck.getOrCreate(DeckSection.Sideboard));
|
||||
// show cards, makes this user friendly
|
||||
this.getTableCatalog().setDeck(cardpool);
|
||||
this.getTableDeck().setDeck(deck.getMain());
|
||||
@@ -204,7 +205,7 @@ public final class CEditorQuest extends ACEditorBase<CardPrinted, Deck> {
|
||||
public void switchEditorMode(boolean isSideboarding) {
|
||||
if (isSideboarding) {
|
||||
this.getTableCatalog().setDeck(this.controller.getModel().getMain());
|
||||
this.getTableDeck().setDeck(this.controller.getModel().getSideboard());
|
||||
this.getTableDeck().setDeck(this.controller.getModel().getOrCreate(DeckSection.Sideboard));
|
||||
} else {
|
||||
resetTables();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package forge.gui.deckeditor.controllers;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -36,6 +35,7 @@ import forge.Command;
|
||||
import forge.Singletons;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckBase;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.gui.CardListViewer;
|
||||
import forge.gui.deckeditor.SEditorUtil;
|
||||
import forge.gui.deckeditor.tables.DeckController;
|
||||
@@ -99,7 +99,7 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
||||
// get pricelist:
|
||||
private final ReadPriceList r = new ReadPriceList();
|
||||
private final Map<String, Integer> mapPrices = this.r.getPriceList();
|
||||
private Map<CardPrinted, Integer> decksUsingMyCards;
|
||||
private ItemPool<InventoryItem> decksUsingMyCards;
|
||||
|
||||
// remember changed gui elements
|
||||
private String CCTabLabel = new String();
|
||||
@@ -205,19 +205,16 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
||||
}
|
||||
|
||||
// fills number of decks using each card
|
||||
private Map<CardPrinted, Integer> countDecksForEachCard() {
|
||||
final Map<CardPrinted, Integer> result = new HashMap<CardPrinted, Integer>();
|
||||
private ItemPool<InventoryItem> countDecksForEachCard() {
|
||||
final ItemPool<InventoryItem> result = new ItemPool<InventoryItem>(InventoryItem.class);
|
||||
for (final Deck deck : this.questData.getMyDecks()) {
|
||||
for (final Entry<CardPrinted, Integer> e : deck.getMain()) {
|
||||
final CardPrinted card = e.getKey();
|
||||
final Integer amount = result.get(card);
|
||||
result.put(card, Integer.valueOf(amount == null ? 1 : 1 + amount.intValue()));
|
||||
}
|
||||
for (final Entry<CardPrinted, Integer> e : deck.getSideboard()) {
|
||||
final CardPrinted card = e.getKey();
|
||||
final Integer amount = result.get(card);
|
||||
result.put(card, Integer.valueOf(amount == null ? 1 : 1 + amount.intValue()));
|
||||
result.add(e.getKey());
|
||||
}
|
||||
if ( deck.has(DeckSection.Sideboard))
|
||||
for (final Entry<CardPrinted, Integer> e : deck.get(DeckSection.Sideboard)) {
|
||||
result.add(e.getKey());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -281,14 +278,14 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
||||
private final Function<Entry<InventoryItem, Integer>, Comparable<?>> fnDeckCompare = new Function<Entry<InventoryItem, Integer>, Comparable<?>>() {
|
||||
@Override
|
||||
public Comparable<?> apply(final Entry<InventoryItem, Integer> from) {
|
||||
final Integer iValue = CEditorQuestCardShop.this.decksUsingMyCards.get(from.getKey());
|
||||
final Integer iValue = CEditorQuestCardShop.this.decksUsingMyCards.count(from.getKey());
|
||||
return iValue == null ? Integer.valueOf(0) : iValue;
|
||||
}
|
||||
};
|
||||
private final Function<Entry<InventoryItem, Integer>, Object> fnDeckGet = new Function<Entry<InventoryItem, Integer>, Object>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
final Integer iValue = CEditorQuestCardShop.this.decksUsingMyCards.get(from.getKey());
|
||||
final Integer iValue = CEditorQuestCardShop.this.decksUsingMyCards.count(from.getKey());
|
||||
return iValue == null ? "" : iValue.toString();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.gui.deckeditor.SEditorIO;
|
||||
import forge.gui.deckeditor.SEditorUtil;
|
||||
import forge.gui.deckeditor.tables.DeckController;
|
||||
@@ -131,7 +132,7 @@ public final class CEditorVariant extends ACEditorBase<CardPrinted, Deck> {
|
||||
allNT = Iterables.filter(allNT, cardPoolCondition);
|
||||
|
||||
this.getTableCatalog().setDeck(ItemPool.createFrom(allNT, CardPrinted.class), true);
|
||||
this.getTableDeck().setDeck(this.controller.getModel().getSideboard());
|
||||
this.getTableDeck().setDeck(this.controller.getModel().getOrCreate(DeckSection.Sideboard));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -4,14 +4,17 @@ import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import forge.Command;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.Singletons;
|
||||
import forge.game.GameFormat;
|
||||
import forge.gui.framework.ICDoc;
|
||||
@@ -225,19 +228,14 @@ public enum CSubmenuQuestData implements ICDoc {
|
||||
if (null == prizedPoolType) {
|
||||
fmtPrizes = fmtStartPool;
|
||||
if (null == fmtPrizes && dckStartPool != null) { // build it form deck
|
||||
List<String> sets = new ArrayList<String>();
|
||||
Set<String> sets = new HashSet<String>();
|
||||
for (Entry<CardPrinted, Integer> c : dckStartPool.getMain()) {
|
||||
String edition = c.getKey().getEdition();
|
||||
if (!sets.contains(edition)) {
|
||||
sets.add(edition);
|
||||
}
|
||||
sets.add(c.getKey().getEdition());
|
||||
}
|
||||
for (Entry<CardPrinted, Integer> c : dckStartPool.getSideboard()) {
|
||||
String edition = c.getKey().getEdition();
|
||||
if (!sets.contains(edition)) {
|
||||
sets.add(edition);
|
||||
if (dckStartPool.has(DeckSection.Sideboard))
|
||||
for (Entry<CardPrinted, Integer> c : dckStartPool.get(DeckSection.Sideboard)) {
|
||||
sets.add(c.getKey().getEdition());
|
||||
}
|
||||
}
|
||||
fmtPrizes = new GameFormat("From deck", sets, null);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -20,6 +20,7 @@ import forge.control.FControl;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckBase;
|
||||
import forge.deck.DeckGroup;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.game.limited.ReadDraftRankings;
|
||||
import forge.game.GameType;
|
||||
import forge.game.limited.SealedDeck;
|
||||
@@ -202,10 +203,10 @@ public enum CSubmenuSealed implements ICDoc {
|
||||
ItemPool<CardPrinted> aiDecks = sd.getCardpool(false);
|
||||
|
||||
final Deck deck = new Deck(sDeckName);
|
||||
deck.getSideboard().addAll(sDeck);
|
||||
deck.getOrCreate(DeckSection.Sideboard).addAll(sDeck);
|
||||
|
||||
for (final String element : Constant.Color.BASIC_LANDS) {
|
||||
deck.getSideboard().add(element, sd.getLandSetCode()[0], 18);
|
||||
deck.get(DeckSection.Sideboard).add(element, sd.getLandSetCode()[0], 18);
|
||||
}
|
||||
|
||||
final DeckGroup sealed = new DeckGroup(sDeckName);
|
||||
|
||||
@@ -14,6 +14,7 @@ import forge.Singletons;
|
||||
import forge.control.FControl;
|
||||
import forge.control.Lobby;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.deck.DeckgenUtil;
|
||||
import forge.game.GameType;
|
||||
import forge.game.MatchController;
|
||||
@@ -162,34 +163,31 @@ public enum CSubmenuArchenemy implements ICDoc {
|
||||
Object obj = view.getArchenemySchemes().getSelectedValue();
|
||||
|
||||
boolean useDefault = VSubmenuArchenemy.SINGLETON_INSTANCE.getCbUseDefaultSchemes().isSelected();
|
||||
useDefault &= !playerDecks.get(0).getSideboard().isEmpty();
|
||||
useDefault &= playerDecks.get(0).has(DeckSection.Schemes);
|
||||
|
||||
System.out.println(useDefault);
|
||||
if (useDefault) {
|
||||
|
||||
schemes = playerDecks.get(0).getSideboard().toFlatList();
|
||||
schemes = playerDecks.get(0).get(DeckSection.Schemes).toFlatList();
|
||||
System.out.println(schemes.toString());
|
||||
usedDefaults = true;
|
||||
|
||||
} else {
|
||||
|
||||
if (obj instanceof String) {
|
||||
String sel = (String) obj;
|
||||
if (sel.equals("Random")) {
|
||||
if (view.getAllSchemeDecks().isEmpty()) {
|
||||
//Generate if no constructed scheme decks are available
|
||||
System.out.println("Generating scheme deck - no others available");
|
||||
schemes = DeckgenUtil.generateSchemeDeck().getSideboard().toFlatList();
|
||||
schemes = DeckgenUtil.generateSchemeDeck().toFlatList();
|
||||
} else {
|
||||
System.out.println("Using scheme deck: " + Aggregates.random(view.getAllSchemeDecks()).getName());
|
||||
schemes = Aggregates.random(view.getAllSchemeDecks()).getSideboard().toFlatList();
|
||||
schemes = Aggregates.random(view.getAllSchemeDecks()).get(DeckSection.Schemes).toFlatList();
|
||||
}
|
||||
} else {
|
||||
//Generate
|
||||
schemes = DeckgenUtil.generateSchemeDeck().getSideboard().toFlatList();
|
||||
schemes = DeckgenUtil.generateSchemeDeck().toFlatList();
|
||||
}
|
||||
} else {
|
||||
schemes = ((Deck) obj).getSideboard().toFlatList();
|
||||
schemes = ((Deck) obj).get(DeckSection.Schemes).toFlatList();
|
||||
}
|
||||
}
|
||||
if (schemes == null) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import forge.Singletons;
|
||||
import forge.control.FControl;
|
||||
import forge.control.Lobby;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.deck.DeckgenUtil;
|
||||
import forge.game.GameType;
|
||||
import forge.game.MatchController;
|
||||
@@ -163,12 +164,12 @@ public enum CSubmenuPlanechase implements ICDoc {
|
||||
Object obj = view.getPlanarDeckLists().get(i).getSelectedValue();
|
||||
|
||||
boolean useDefault = VSubmenuPlanechase.SINGLETON_INSTANCE.getCbUseDefaultPlanes().isSelected();
|
||||
useDefault &= !playerDecks.get(i).getSideboard().isEmpty();
|
||||
useDefault &= playerDecks.get(i).has(DeckSection.Planes);
|
||||
|
||||
System.out.println(useDefault);
|
||||
if (useDefault) {
|
||||
|
||||
planes = playerDecks.get(i).getSideboard().toFlatList();
|
||||
planes = playerDecks.get(i).get(DeckSection.Planes).toFlatList();
|
||||
System.out.println(planes.toString());
|
||||
|
||||
} else {
|
||||
@@ -179,19 +180,19 @@ public enum CSubmenuPlanechase implements ICDoc {
|
||||
if (view.getAllPlanarDecks().isEmpty()) {
|
||||
//Generate if no constructed scheme decks are available
|
||||
System.out.println("Generating planar deck - no others available");
|
||||
planes = DeckgenUtil.generatePlanarDeck().getSideboard().toFlatList();
|
||||
planes = DeckgenUtil.generatePlanarDeck().toFlatList();
|
||||
} else {
|
||||
System.out.println("Using planar deck: " + Aggregates.random(view.getAllPlanarDecks()).getName());
|
||||
planes = Aggregates.random(view.getAllPlanarDecks()).getSideboard().toFlatList();
|
||||
planes = Aggregates.random(view.getAllPlanarDecks()).get(DeckSection.Planes).toFlatList();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
//Generate
|
||||
planes = DeckgenUtil.generatePlanarDeck().getSideboard().toFlatList();
|
||||
planes = DeckgenUtil.generatePlanarDeck().toFlatList();
|
||||
}
|
||||
} else {
|
||||
planes = ((Deck) obj).getSideboard().toFlatList();
|
||||
planes = ((Deck) obj).get(DeckSection.Planes).toFlatList();
|
||||
}
|
||||
}
|
||||
if (planes == null) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import forge.Command;
|
||||
import forge.Singletons;
|
||||
import forge.control.Lobby;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.game.GameType;
|
||||
import forge.game.MatchController;
|
||||
import forge.game.MatchStartHelper;
|
||||
@@ -137,11 +138,10 @@ public enum CSubmenuVanguard implements ICDoc {
|
||||
Object obj = view.getAvatarLists().get(i).getSelectedValue();
|
||||
|
||||
boolean useDefault = VSubmenuVanguard.SINGLETON_INSTANCE.getCbDefaultAvatars().isSelected();
|
||||
useDefault &= playerDecks.get(i).getAvatar() != null;
|
||||
useDefault &= playerDecks.get(i).get(DeckSection.Avatar) != null;
|
||||
|
||||
if (useDefault) {
|
||||
|
||||
avatar = playerDecks.get(i).getAvatar();
|
||||
avatar = playerDecks.get(i).get(DeckSection.Avatar).get(0);
|
||||
defaultAvatarInfo.append("Player " + (i + 1) + ": ");
|
||||
defaultAvatarInfo.append(avatar.getName() + nl);
|
||||
usedDefaults = true;
|
||||
|
||||
@@ -42,6 +42,7 @@ import forge.control.FControl;
|
||||
import forge.deck.CardCollections;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckBase;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.deckeditor.CDeckEditorUI;
|
||||
import forge.gui.deckeditor.controllers.ACEditorBase;
|
||||
@@ -151,7 +152,7 @@ public class DeckLister extends JPanel implements ILocalRepaint {
|
||||
row.add(new EditButton(row), "w 10%!, h 20px!, gaptop 5px");
|
||||
row.add(new GenericLabel(d.getName()), "w 58%!, h 20px!, gaptop 5px");
|
||||
row.add(new MainLabel(String.valueOf(d.getMain().countAll())), "w 10%, h 20px!, gaptop 5px");
|
||||
row.add(new GenericLabel(String.valueOf(d.getSideboard().countAll())), "w 10%!, h 20px!, gaptop 5px");
|
||||
row.add(new GenericLabel(d.has(DeckSection.Sideboard) ? String.valueOf(d.get(DeckSection.Sideboard).countAll()) : "none"), "w 10%!, h 20px!, gaptop 5px");
|
||||
this.add(row, "w 98%!, h 30px!, gapleft 1%");
|
||||
tempRows.add(row);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import forge.card.CardEdition;
|
||||
import forge.card.CardRarity;
|
||||
import forge.card.FormatCollection;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.item.BoosterPack;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
@@ -283,16 +284,10 @@ public final class QuestUtilCards {
|
||||
if (this.qa.getCredits() >= value) {
|
||||
this.qa.setCredits(this.qa.getCredits() - value);
|
||||
this.qa.getShopList().remove(precon);
|
||||
addPreconDeck(precon);
|
||||
this.addDeck(precon.getDeck());
|
||||
}
|
||||
}
|
||||
|
||||
void addPreconDeck(PreconDeck precon) {
|
||||
this.qc.getMyDecks().add(precon.getDeck());
|
||||
this.addAllCards(precon.getDeck().getMain().toFlatList());
|
||||
this.addAllCards(precon.getDeck().getSideboard().toFlatList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Import an existing deck.
|
||||
*
|
||||
@@ -305,7 +300,8 @@ public final class QuestUtilCards {
|
||||
}
|
||||
this.qc.getMyDecks().add(fromDeck);
|
||||
this.addAllCards(fromDeck.getMain().toFlatList());
|
||||
this.addAllCards(fromDeck.getSideboard().toFlatList());
|
||||
if (fromDeck.has(DeckSection.Sideboard))
|
||||
this.addAllCards(fromDeck.get(DeckSection.Sideboard).toFlatList());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -348,13 +344,13 @@ public final class QuestUtilCards {
|
||||
// remove sold cards from all decks:
|
||||
for (final Deck deck : this.qc.getMyDecks()) {
|
||||
int cntInMain = deck.getMain().count(card);
|
||||
int cntInSb = deck.getSideboard().count(card);
|
||||
int cntInSb = deck.has(DeckSection.Sideboard) ? deck.get(DeckSection.Sideboard).count(card) : 0;
|
||||
int nToRemoveFromThisDeck = cntInMain + cntInSb - leftInPool;
|
||||
if ( nToRemoveFromThisDeck <= 0 ) continue; // this is not the deck you are looking for
|
||||
|
||||
int nToRemoveFromSb = cntInSb - nToRemoveFromThisDeck;
|
||||
if( nToRemoveFromSb > 0 ) {
|
||||
deck.getSideboard().remove(card, nToRemoveFromSb);
|
||||
deck.get(DeckSection.Sideboard).remove(card, nToRemoveFromSb);
|
||||
nToRemoveFromThisDeck -= cntInSb; // actual removed count should be, but I take upper bound here
|
||||
if ( nToRemoveFromThisDeck <= 0 ) continue; // done here
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.card.CardEdition;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.deck.CardPool;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.quest.data.GameFormatQuest;
|
||||
import forge.item.BoosterPack;
|
||||
@@ -102,7 +102,7 @@ public class QuestDataIO {
|
||||
xStream.registerConverter(new QuestModeToXml());
|
||||
xStream.autodetectAnnotations(true);
|
||||
xStream.alias("CardPool", ItemPool.class);
|
||||
xStream.alias("DeckSection", DeckSection.class);
|
||||
xStream.alias("DeckSection", CardPool.class);
|
||||
return xStream;
|
||||
}
|
||||
|
||||
@@ -610,12 +610,12 @@ public class QuestDataIO {
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public boolean canConvert(final Class clasz) {
|
||||
return clasz.equals(DeckSection.class);
|
||||
return clasz.equals(CardPool.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
|
||||
for (final Entry<CardPrinted, Integer> e : (DeckSection) source) {
|
||||
for (final Entry<CardPrinted, Integer> e : (CardPool) source) {
|
||||
this.write(e.getKey(), e.getValue(), writer);
|
||||
}
|
||||
|
||||
@@ -623,7 +623,7 @@ public class QuestDataIO {
|
||||
|
||||
@Override
|
||||
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
|
||||
final DeckSection result = new DeckSection();
|
||||
final CardPool result = new CardPool();
|
||||
while (reader.hasMoreChildren()) {
|
||||
reader.moveDown();
|
||||
final String sCnt = reader.getAttribute("n");
|
||||
|
||||
Reference in New Issue
Block a user