mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
- Merge: merging from trunk up to r20044 (inclusive). Help is needed to merge r20045 and up, please assist.
This commit is contained in:
@@ -19,6 +19,7 @@ package forge.card;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@@ -32,7 +33,8 @@ import forge.card.mana.ManaCost;
|
||||
* @version $Id: CardRules.java 9708 2011-08-09 19:34:12Z jendave $
|
||||
*/
|
||||
public final class CardRules implements ICardCharacteristics {
|
||||
|
||||
private final static EditionCollection editions = new EditionCollection(); // create a copy here, Singletons.model... is not initialized yet.
|
||||
|
||||
private final CardSplitType splitType;
|
||||
private final ICardFace mainPart;
|
||||
private final ICardFace otherPart;
|
||||
@@ -48,8 +50,14 @@ public final class CardRules implements ICardCharacteristics {
|
||||
mainPart = faces[0];
|
||||
otherPart = faces[1];
|
||||
aiHints = cah;
|
||||
setsPrinted.putAll(sets);
|
||||
|
||||
//System.out.print(faces[0].getName());
|
||||
|
||||
for (Entry<String, CardInSet> cs : sets.entrySet()) {
|
||||
if( editions.get(cs.getKey()) != null )
|
||||
setsPrinted.put(cs.getKey(), cs.getValue());
|
||||
}
|
||||
|
||||
if ( setsPrinted.isEmpty() ) {
|
||||
System.err.println(getName() + " was not assigned any set.");
|
||||
setsPrinted.put(CardEdition.UNKNOWN.getCode(), new CardInSet(CardRarity.Common, 1) );
|
||||
|
||||
@@ -221,8 +221,7 @@ public class CardRulesReader {
|
||||
} else
|
||||
this.faces[curFace].addSVar(variable, value);
|
||||
} else if ("SetInfo".equals(key)) {
|
||||
if ( curFace == 0 )
|
||||
CardRulesReader.parseSetInfoLine(value, sets);
|
||||
parseSetInfoLine(value);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -247,41 +246,33 @@ public class CardRulesReader {
|
||||
* @param setsData
|
||||
* the current mapping of set names to CardInSet instances
|
||||
*/
|
||||
private static void parseSetInfoLine(final String value, final Map<String, CardInSet> setsData) {
|
||||
final int setCodeIx = 0;
|
||||
final int rarityIx = 1;
|
||||
final int numPicIx = 3;
|
||||
|
||||
private void parseSetInfoLine(final String value) {
|
||||
// Sample SetInfo line:
|
||||
// SetInfo:POR|Land|http://magiccards.info/scans/en/po/203.jpg|4
|
||||
// SetInfo:POR Land x4
|
||||
|
||||
final String[] pieces = value.split("\\|");
|
||||
|
||||
if (pieces.length <= rarityIx) {
|
||||
throw new RuntimeException("SetInfo line <<" + value + ">> has insufficient pieces");
|
||||
int i = 0;
|
||||
String setCode = null;
|
||||
String txtRarity = "Common";
|
||||
String txtCount = "x1";
|
||||
|
||||
StringTokenizer stt = new StringTokenizer(value, " ");
|
||||
while(stt.hasMoreTokens()) {
|
||||
if( i == 0 ) setCode = stt.nextToken();
|
||||
if( i == 1 ) txtRarity = stt.nextToken();
|
||||
if( i == 2 ) txtCount = stt.nextToken();
|
||||
i++;
|
||||
}
|
||||
|
||||
final String setCode = pieces[setCodeIx];
|
||||
final String txtRarity = pieces[rarityIx];
|
||||
// pieces[2] is the magiccards.info URL for illustration #1, which we do
|
||||
// not need.
|
||||
int numIllustrations = 1;
|
||||
|
||||
if (setsData.containsKey(setCode)) {
|
||||
int numIllustrations = 1;
|
||||
if ( i > 2 )
|
||||
numIllustrations = Integer.parseInt(txtCount.substring(1));
|
||||
|
||||
if (sets.containsKey(setCode)) {
|
||||
System.err.print(faces[0].getName());
|
||||
throw new RuntimeException("Found multiple SetInfo lines for set code <<" + setCode + ">>");
|
||||
}
|
||||
|
||||
if (pieces.length > numPicIx) {
|
||||
try {
|
||||
numIllustrations = Integer.parseInt(pieces[numPicIx]);
|
||||
} catch (final NumberFormatException nfe) {
|
||||
throw new RuntimeException("Fourth item of SetInfo is not an integer in <<" + value + ">>");
|
||||
}
|
||||
|
||||
if (numIllustrations < 1) {
|
||||
throw new RuntimeException("Fourth item of SetInfo is not a positive integer, but" + numIllustrations);
|
||||
}
|
||||
}
|
||||
|
||||
CardRarity rarity = null;
|
||||
if ("Land".equals(txtRarity)) {
|
||||
@@ -302,7 +293,7 @@ public class CardRulesReader {
|
||||
|
||||
final CardInSet cardInSet = new CardInSet(rarity, numIllustrations);
|
||||
|
||||
setsData.put(setCode, cardInSet);
|
||||
sets.put(setCode, cardInSet);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.google.common.base.Function;
|
||||
|
||||
import forge.Command;
|
||||
import forge.Singletons;
|
||||
import forge.deck.CardPool;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckBase;
|
||||
import forge.deck.DeckSection;
|
||||
@@ -214,13 +215,18 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
||||
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()) {
|
||||
CardPool main = deck.getMain();
|
||||
for (final Entry<CardPrinted, Integer> e : main) {
|
||||
result.add(e.getKey());
|
||||
}
|
||||
if ( deck.has(DeckSection.Sideboard))
|
||||
if (deck.has(DeckSection.Sideboard)) {
|
||||
for (final Entry<CardPrinted, Integer> e : deck.get(DeckSection.Sideboard)) {
|
||||
result.add(e.getKey());
|
||||
// only add card if we haven't already encountered it in main
|
||||
if (!main.contains(e.getKey())) {
|
||||
result.add(e.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -218,8 +218,7 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
|
||||
* @return a int.
|
||||
*/
|
||||
protected final int getAverageTimePerObject() {
|
||||
int aTime = 0;
|
||||
int nz = 10;
|
||||
int numNonzero = 10;
|
||||
|
||||
if (this.tptr > 9) {
|
||||
this.tptr = 0;
|
||||
@@ -232,14 +231,12 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
|
||||
for (int i = 0; i < 10; i++) {
|
||||
tTime += this.times[i];
|
||||
if (this.times[i] == 0) {
|
||||
nz--;
|
||||
numNonzero--;
|
||||
}
|
||||
}
|
||||
aTime = tTime / nz;
|
||||
|
||||
|
||||
this.tptr++;
|
||||
|
||||
return aTime;
|
||||
return tTime / Math.max(1, numNonzero);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,21 +250,9 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
|
||||
private void update(final int card) {
|
||||
this.card = card;
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
final class Worker implements Runnable {
|
||||
private final int card;
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO: Write javadoc for Constructor.
|
||||
*
|
||||
* @param card
|
||||
* int
|
||||
*/
|
||||
Worker(final int card) {
|
||||
this.card = card;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public abstract class ItemPredicate {
|
||||
|
||||
public static final Predicate<Object> IsBoosterPack = Predicates.instanceOf(BoosterPack.class);
|
||||
public static final Predicate<Object> IsPrebuiltDeck = Predicates.instanceOf(PreconDeck.class);
|
||||
public static final Predicate<Object> IsFatPack = Predicates.instanceOf(TournamentPack.class);
|
||||
public static final Predicate<Object> IsFatPack = Predicates.instanceOf(FatPack.class);
|
||||
|
||||
/**
|
||||
* Checks that the inventory item is a Tournament Pack.
|
||||
|
||||
@@ -270,6 +270,7 @@ public final class QuestUtilCards {
|
||||
public void buyPack(final OpenablePack booster, final int value) {
|
||||
if (this.qa.getCredits() >= value) {
|
||||
this.qa.setCredits(this.qa.getCredits() - value);
|
||||
this.qa.getShopList().remove(booster);
|
||||
this.addAllCards(booster.getCards());
|
||||
}
|
||||
}
|
||||
@@ -350,11 +351,13 @@ public final class QuestUtilCards {
|
||||
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 ) {
|
||||
int nToRemoveFromSb = Math.min(cntInSb, nToRemoveFromThisDeck);
|
||||
if (nToRemoveFromSb > 0) {
|
||||
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
|
||||
nToRemoveFromThisDeck -= nToRemoveFromSb;
|
||||
if (0 >= nToRemoveFromThisDeck) {
|
||||
continue; // done here
|
||||
}
|
||||
}
|
||||
|
||||
deck.getMain().remove(card, nToRemoveFromThisDeck);
|
||||
@@ -508,7 +511,6 @@ public final class QuestUtilCards {
|
||||
* Generate cards in shop.
|
||||
*/
|
||||
public void generateCardsInShop() {
|
||||
|
||||
Iterable<CardPrinted> cardList = null;
|
||||
if (qc.getFormat() == null) {
|
||||
cardList = CardDb.instance().getAllCards(); }
|
||||
|
||||
Reference in New Issue
Block a user