mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
rollback changes to Deck, ManaCost, StorageBase, CardPool
This commit is contained in:
@@ -22,9 +22,6 @@ import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import forge.card.ColorSet;
|
||||
import forge.card.MagicColor;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* CardManaCost class.
|
||||
@@ -49,20 +46,14 @@ public final class ManaCost implements Comparable<ManaCost>, Iterable<ManaCostSh
|
||||
public static final ManaCost TWO = new ManaCost(2);
|
||||
public static final ManaCost THREE = new ManaCost(3);
|
||||
public static final ManaCost FOUR = new ManaCost(4);
|
||||
public static final ManaCost WHITE = new ManaCost(MagicColor.WHITE);
|
||||
public static final ManaCost BLUE = new ManaCost(MagicColor.BLUE);
|
||||
public static final ManaCost BLACK = new ManaCost(MagicColor.BLACK);
|
||||
public static final ManaCost RED = new ManaCost(MagicColor.RED);
|
||||
public static final ManaCost GREEN = new ManaCost(MagicColor.GREEN);
|
||||
public static final ManaCost COLORLESS = new ManaCost(MagicColor.COLORLESS);
|
||||
|
||||
public static ManaCost get(int cntColorless) {
|
||||
switch (cntColorless) {
|
||||
case 0: { return ZERO; }
|
||||
case 1: { return ONE; }
|
||||
case 2: { return TWO; }
|
||||
case 3: { return THREE; }
|
||||
case 4: { return FOUR; }
|
||||
case 0: return ZERO;
|
||||
case 1: return ONE;
|
||||
case 2: return TWO;
|
||||
case 3: return THREE;
|
||||
case 4: return FOUR;
|
||||
}
|
||||
return cntColorless > 0 ? new ManaCost(cntColorless) : NO_COST;
|
||||
}
|
||||
@@ -95,47 +86,8 @@ public final class ManaCost implements Comparable<ManaCost>, Iterable<ManaCostSh
|
||||
shardsTemp.add(shard);
|
||||
} // null is OK - that was generic mana
|
||||
}
|
||||
this.genericCost = parser.getTotalColorlessCost();
|
||||
sealClass(shardsTemp);
|
||||
}
|
||||
|
||||
//constructor for mana cost from color profile
|
||||
public static ManaCost fromColorProfile(final byte colorProfile) {
|
||||
switch (colorProfile) {
|
||||
case MagicColor.WHITE: { return WHITE; }
|
||||
case MagicColor.BLUE: { return BLUE; }
|
||||
case MagicColor.BLACK: { return BLACK; }
|
||||
case MagicColor.RED: { return RED; }
|
||||
case MagicColor.GREEN: { return GREEN; }
|
||||
case MagicColor.COLORLESS: { return COLORLESS; }
|
||||
}
|
||||
return new ManaCost(colorProfile);
|
||||
}
|
||||
private ManaCost(final byte colorProfile) {
|
||||
final List<ManaCostShard> shardsTemp = new ArrayList<ManaCostShard>();
|
||||
this.hasNoCost = false;
|
||||
if (colorProfile == MagicColor.COLORLESS) {
|
||||
shardsTemp.add(ManaCostShard.X);
|
||||
}
|
||||
else {
|
||||
ColorSet colorSet = ColorSet.fromMask(colorProfile);
|
||||
if (colorSet.hasWhite()) {
|
||||
shardsTemp.add(ManaCostShard.WHITE);
|
||||
}
|
||||
if (colorSet.hasBlue()) {
|
||||
shardsTemp.add(ManaCostShard.BLUE);
|
||||
}
|
||||
if (colorSet.hasBlack()) {
|
||||
shardsTemp.add(ManaCostShard.BLACK);
|
||||
}
|
||||
if (colorSet.hasRed()) {
|
||||
shardsTemp.add(ManaCostShard.RED);
|
||||
}
|
||||
if (colorSet.hasGreen()) {
|
||||
shardsTemp.add(ManaCostShard.GREEN);
|
||||
}
|
||||
}
|
||||
this.genericCost = 0;
|
||||
this.genericCost = parser.getTotalColorlessCost(); // collect generic mana
|
||||
// here
|
||||
sealClass(shardsTemp);
|
||||
}
|
||||
|
||||
@@ -293,10 +245,6 @@ public final class ManaCost implements Comparable<ManaCost>, Iterable<ManaCostSh
|
||||
return iX;
|
||||
}
|
||||
|
||||
public boolean hasColor(byte colorCode) {
|
||||
return (colorCode & getColorProfile()) == colorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can this mana cost be paid with unlimited mana of given color set.
|
||||
* @param colorCode
|
||||
|
||||
@@ -35,58 +35,23 @@ import forge.util.ItemPool;
|
||||
*/
|
||||
public class CardPool extends ItemPool<PaperCard> {
|
||||
|
||||
/**
|
||||
* Instantiates a new deck section.
|
||||
*/
|
||||
public CardPool() {
|
||||
super(PaperCard.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new deck section.
|
||||
*
|
||||
* @param cards the cards
|
||||
*/
|
||||
public CardPool(final Iterable<Entry<PaperCard, Integer>> cards) {
|
||||
this();
|
||||
this.addAll(cards);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the card.
|
||||
*
|
||||
* @param cardName
|
||||
* the card name
|
||||
* @param setCode
|
||||
* the set code
|
||||
*/
|
||||
public void add(final String cardName, final String setCode) {
|
||||
this.add(cardName, setCode, -1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the card.
|
||||
*
|
||||
* @param cardName
|
||||
* the card name
|
||||
* @param setCode
|
||||
* the set code
|
||||
* @param amount
|
||||
* the amount of cards to add
|
||||
*/
|
||||
public void add(final String cardName, final String setCode, final int amount) {
|
||||
this.add(cardName, setCode, -1, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the card.
|
||||
*
|
||||
* @param cardName the card name
|
||||
* @param setCode the set code
|
||||
* @param artIndex the card art index, -1 for random
|
||||
* @param amount the amount
|
||||
*/
|
||||
public void add(final String cardName, final String setCode, final int artIndex, final int amount) {
|
||||
PaperCard cp = StaticData.instance().getCommonCards().tryGetCard(cardName, setCode, artIndex);
|
||||
if ( cp == null )
|
||||
|
||||
@@ -34,8 +34,8 @@ import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import forge.card.CardDb;
|
||||
import forge.card.ColorSet;
|
||||
import forge.card.MagicColor;
|
||||
import forge.card.mana.ManaCost;
|
||||
import forge.deck.io.DeckFileHeader;
|
||||
import forge.deck.io.DeckSerializer;
|
||||
import forge.item.PaperCard;
|
||||
@@ -59,9 +59,6 @@ import forge.util.ItemPoolView;
|
||||
public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPool>> {
|
||||
private final Map<DeckSection, CardPool> parts = new EnumMap<DeckSection, CardPool>(DeckSection.class);
|
||||
private final Set<String> tags = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
||||
private ManaCost color;
|
||||
private String format;
|
||||
private int formatCompare;
|
||||
|
||||
// gameType is from Constant.GameType, like GameType.Regular
|
||||
/**
|
||||
@@ -244,9 +241,6 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
|
||||
* @return the list
|
||||
*/
|
||||
public List<String> save() {
|
||||
this.color = null; //ensure color and format are recalculated
|
||||
this.format = null;
|
||||
|
||||
final List<String> out = new ArrayList<String>();
|
||||
out.add(String.format("[metadata]"));
|
||||
|
||||
@@ -289,75 +283,23 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
|
||||
return tags;
|
||||
}
|
||||
|
||||
public ManaCost getColor() {
|
||||
if (color == null) {
|
||||
byte colorProfile = MagicColor.COLORLESS;
|
||||
public ColorSet getColor() {
|
||||
byte colorProfile = MagicColor.COLORLESS;
|
||||
|
||||
for (Entry<DeckSection, CardPool> deckEntry : this) {
|
||||
switch (deckEntry.getKey()) {
|
||||
case Main:
|
||||
case Sideboard:
|
||||
case Commander:
|
||||
for (Entry<PaperCard, Integer> poolEntry : deckEntry.getValue()) {
|
||||
colorProfile |= poolEntry.getKey().getRules().getColor().getColor();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break; //ignore other sections
|
||||
for (Entry<DeckSection, CardPool> deckEntry : this) {
|
||||
switch (deckEntry.getKey()) {
|
||||
case Main:
|
||||
case Sideboard:
|
||||
case Commander:
|
||||
for (Entry<PaperCard, Integer> poolEntry : deckEntry.getValue()) {
|
||||
colorProfile |= poolEntry.getKey().getRules().getColor().getColor();
|
||||
}
|
||||
}
|
||||
color = ManaCost.fromColorProfile(colorProfile);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
public String getFormat(Map<String, Predicate<PaperCard>> formatPredicates) {
|
||||
if (format == null) {
|
||||
formatCompare = 0; //build format compare value, with higher values for being valid in a more recent format
|
||||
int value = (int)Math.pow(2, formatPredicates.size() - 1);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
formatLoop:
|
||||
for (Entry<String, Predicate<PaperCard>> format : formatPredicates.entrySet()) {
|
||||
for (Entry<DeckSection, CardPool> deckEntry : this) {
|
||||
switch (deckEntry.getKey()) {
|
||||
case Main:
|
||||
case Sideboard:
|
||||
case Commander:
|
||||
for (Entry<PaperCard, Integer> poolEntry : deckEntry.getValue()) {
|
||||
if (!format.getValue().apply(poolEntry.getKey())) {
|
||||
value /= 2;
|
||||
continue formatLoop; //if found card that's not legal in this format, move to next format
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break; //ignore other sections
|
||||
}
|
||||
}
|
||||
//add format if reached this point
|
||||
if (builder.length() > 0) {
|
||||
builder.append(", ");
|
||||
}
|
||||
builder.append(format.getKey());
|
||||
|
||||
formatCompare += value; //increment format compare value
|
||||
value /= 2;
|
||||
}
|
||||
|
||||
if (builder.length() > 0) {
|
||||
format = builder.toString();
|
||||
}
|
||||
else {
|
||||
format = "(none)";
|
||||
break;
|
||||
default:
|
||||
break; //ignore other sections
|
||||
}
|
||||
}
|
||||
return format;
|
||||
}
|
||||
|
||||
public int getFormatCompare(Map<String, Predicate<PaperCard>> formatPredicates) {
|
||||
getFormat(formatPredicates); //ensure formatCompare defined
|
||||
return formatCompare;
|
||||
return ColorSet.fromMask(colorProfile);
|
||||
}
|
||||
|
||||
//create predicate that applys a card predicate to all cards in deck
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
@@ -66,10 +65,6 @@ public class StorageBase<T> implements IStorage<T> {
|
||||
return new ArrayList<String>(this.map.keySet());
|
||||
}
|
||||
|
||||
public Iterable<Entry<String, T>> entrySet() {
|
||||
return this.map.entrySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return this.map.values().iterator();
|
||||
|
||||
Reference in New Issue
Block a user