mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
merge from trunk
This commit is contained in:
@@ -4,7 +4,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@@ -80,7 +79,6 @@ final class CardFace implements ICardFace {
|
||||
public final void setColor(ColorSet color0) { this.color = color0; }
|
||||
public final void setOracleText(String text) { this.oracleText = text; }
|
||||
public final void setInitialLoyalty(int value) { this.initialLoyalty = value; }
|
||||
public final Map<String, CardInSet> getSetsData() { return this.setsPrinted; } // reader will add sets here
|
||||
|
||||
public void setPtText(String value) {
|
||||
final int slashPos = value.indexOf('/');
|
||||
@@ -105,7 +103,6 @@ final class CardFace implements ICardFace {
|
||||
|
||||
public void assignMissingFields() { // Most scripts do not specify color explicitly
|
||||
if ( null == oracleText ) { System.err.println(name + " has no Oracle text."); oracleText = ""; }
|
||||
if ( setsPrinted.isEmpty() ) { System.err.println(name + " was not assigned any set."); setsPrinted.put(CardEdition.UNKNOWN.getCode(), new CardInSet(CardRarity.Common, 1, null) ) ; }
|
||||
if ( manaCost == null && color == null ) System.err.println(name + " has neither ManaCost nor Color");
|
||||
if ( color == null ) color = ColorSet.fromManaCost(manaCost);
|
||||
|
||||
@@ -119,14 +116,4 @@ final class CardFace implements ICardFace {
|
||||
}
|
||||
|
||||
|
||||
// This should not be here, but I don't know a better place yet
|
||||
private final Map<String, CardInSet> setsPrinted = new TreeMap<String, CardInSet>(String.CASE_INSENSITIVE_ORDER);
|
||||
@Override public Set<String> getSets() { return this.setsPrinted.keySet(); }
|
||||
@Override public CardInSet getEditionInfo(final String setCode) {
|
||||
final CardInSet result = this.setsPrinted.get(setCode);
|
||||
return result; // if returns null, String.format("Card '%s' was never printed in set '%s'", this.getName(), setCode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ package forge.card;
|
||||
public class CardInSet {
|
||||
private final CardRarity rarity;
|
||||
private final int numCopies;
|
||||
private final String url;
|
||||
|
||||
/**
|
||||
* Instantiates a new card in set.
|
||||
@@ -39,10 +38,9 @@ public class CardInSet {
|
||||
* @param cntCopies
|
||||
* the cnt copies
|
||||
*/
|
||||
public CardInSet(final CardRarity rarity, final int cntCopies, final String picUrl ) {
|
||||
public CardInSet(final CardRarity rarity, final int cntCopies ) {
|
||||
this.rarity = rarity;
|
||||
this.numCopies = cntCopies;
|
||||
this.url = picUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,11 +61,4 @@ public class CardInSet {
|
||||
return this.rarity;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
* @return
|
||||
*/
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
package forge.card;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import forge.card.mana.ManaCost;
|
||||
|
||||
/**
|
||||
@@ -28,20 +33,35 @@ 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;
|
||||
|
||||
private CardAiHints aiHints;
|
||||
private final Map<String, CardInSet> setsPrinted = new TreeMap<String, CardInSet>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
|
||||
|
||||
public CardRules(ICardFace[] faces, CardSplitType altMode, CardAiHints cah) {
|
||||
|
||||
public CardRules(ICardFace[] faces, CardSplitType altMode, CardAiHints cah, Map<String, CardInSet> sets) {
|
||||
splitType = altMode;
|
||||
mainPart = faces[0];
|
||||
otherPart = faces[1];
|
||||
aiHints = cah;
|
||||
|
||||
//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) );
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isTraditional() {
|
||||
@@ -131,8 +151,11 @@ public final class CardRules implements ICardCharacteristics {
|
||||
}
|
||||
|
||||
|
||||
public Iterable<String> getSets() { return mainPart.getSets(); }
|
||||
public CardInSet getEditionInfo(final String setCode) { return mainPart.getEditionInfo(setCode); }
|
||||
public Set<String> getSets() { return this.setsPrinted.keySet(); }
|
||||
public CardInSet getEditionInfo(final String setCode) {
|
||||
final CardInSet result = this.setsPrinted.get(setCode);
|
||||
return result; // if returns null, String.format("Card '%s' was never printed in set '%s'", this.getName(), setCode);
|
||||
}
|
||||
|
||||
|
||||
// vanguard card fields, they don't use sides.
|
||||
|
||||
@@ -19,6 +19,7 @@ package forge.card;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@@ -45,6 +46,8 @@ public class CardRulesReader {
|
||||
private CardSplitType altMode = CardSplitType.None;
|
||||
private String handLife = null;
|
||||
|
||||
private Map<String,CardInSet> sets = new TreeMap<String, CardInSet>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
// fields to build CardAiHints
|
||||
private boolean removedFromAIDecks = false;
|
||||
private boolean removedFromRandomDecks = false;
|
||||
@@ -64,6 +67,8 @@ public class CardRulesReader {
|
||||
this.faces[1] = null;
|
||||
this.pictureUrl[0] = null;
|
||||
this.pictureUrl[1] = null;
|
||||
|
||||
this.sets.clear();
|
||||
|
||||
this.handLife = null;
|
||||
this.altMode = CardSplitType.None;
|
||||
@@ -83,7 +88,7 @@ public class CardRulesReader {
|
||||
CardAiHints cah = new CardAiHints(removedFromAIDecks, removedFromRandomDecks, hints, needs );
|
||||
faces[0].assignMissingFields();
|
||||
if ( null != faces[1] ) faces[1].assignMissingFields();
|
||||
final CardRules result = new CardRules(faces, altMode, cah);
|
||||
final CardRules result = new CardRules(faces, altMode, cah, sets);
|
||||
result.setDlUrls(pictureUrl);
|
||||
if ( StringUtils.isNotBlank(handLife))
|
||||
result.setVanguardProperties(handLife);
|
||||
@@ -216,7 +221,7 @@ public class CardRulesReader {
|
||||
} else
|
||||
this.faces[curFace].addSVar(variable, value);
|
||||
} else if ("SetInfo".equals(key)) {
|
||||
CardRulesReader.parseSetInfoLine(value, this.faces[this.curFace].getSetsData());
|
||||
parseSetInfoLine(value);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -241,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)) {
|
||||
@@ -294,9 +291,9 @@ public class CardRulesReader {
|
||||
throw new RuntimeException("Unrecognized rarity string <<" + txtRarity + ">>");
|
||||
}
|
||||
|
||||
final CardInSet cardInSet = new CardInSet(rarity, numIllustrations, pieces.length > 2 ? pieces[2] : null);
|
||||
final CardInSet cardInSet = new CardInSet(rarity, numIllustrations);
|
||||
|
||||
setsData.put(setCode, cardInSet);
|
||||
sets.put(setCode, cardInSet);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,198 +0,0 @@
|
||||
/*
|
||||
* 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.card;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* SetInfo class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class EditionInfo {
|
||||
|
||||
/** The Code. */
|
||||
private String code;
|
||||
|
||||
/** The Rarity. */
|
||||
private String rarity;
|
||||
|
||||
/** The URL. */
|
||||
private String url;
|
||||
|
||||
/** The Pic count. */
|
||||
private int picCount;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for SetInfo.
|
||||
* </p>
|
||||
*/
|
||||
public EditionInfo() {
|
||||
this.setCode("");
|
||||
this.setRarity("");
|
||||
this.setUrl("");
|
||||
this.setPicCount(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for SetInfo.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a {@link java.lang.String} object.
|
||||
* @param r
|
||||
* a {@link java.lang.String} object.
|
||||
* @param u
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public EditionInfo(final String c, final String r, final String u) {
|
||||
this.setCode(c);
|
||||
this.setRarity(r);
|
||||
this.setUrl(u);
|
||||
this.setPicCount(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for SetInfo.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a {@link java.lang.String} object.
|
||||
* @param r
|
||||
* a {@link java.lang.String} object.
|
||||
* @param u
|
||||
* a {@link java.lang.String} object.
|
||||
* @param p
|
||||
* a int.
|
||||
*/
|
||||
public EditionInfo(final String c, final String r, final String u, final int p) {
|
||||
this.setCode(c);
|
||||
this.setRarity(r);
|
||||
this.setUrl(u);
|
||||
this.setPicCount(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* toString.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
@Override
|
||||
public final String toString() {
|
||||
return this.getCode();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final boolean equals(final Object o) {
|
||||
if (o instanceof EditionInfo) {
|
||||
final EditionInfo siO = (EditionInfo) o;
|
||||
return this.getCode().equals(siO.getCode());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (41 * (41 + this.getCode().hashCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the code.
|
||||
*
|
||||
* @return the code
|
||||
*/
|
||||
public String getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the code.
|
||||
*
|
||||
* @param code0
|
||||
* the code to set
|
||||
*/
|
||||
public void setCode(final String code0) {
|
||||
this.code = code0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rarity.
|
||||
*
|
||||
* @return the rarity
|
||||
*/
|
||||
public String getRarity() {
|
||||
return this.rarity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rarity.
|
||||
*
|
||||
* @param rarity0
|
||||
* the rarity to set
|
||||
*/
|
||||
public void setRarity(final String rarity0) {
|
||||
this.rarity = rarity0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the url.
|
||||
*
|
||||
* @return the url
|
||||
*/
|
||||
public String getUrl() {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the url.
|
||||
*
|
||||
* @param url0
|
||||
* the url to set
|
||||
*/
|
||||
public void setUrl(final String url0) {
|
||||
this.url = url0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the pic count.
|
||||
*
|
||||
* @return the picCount
|
||||
*/
|
||||
public int getPicCount() {
|
||||
return this.picCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the pic count.
|
||||
*
|
||||
* @param picCount0
|
||||
* the picCount to set
|
||||
*/
|
||||
public void setPicCount(final int picCount0) {
|
||||
this.picCount = picCount0;
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,4 @@ public interface ICardCharacteristics {
|
||||
public abstract int getInitialLoyalty();
|
||||
|
||||
public abstract String getOracleText();
|
||||
|
||||
public abstract Iterable<String> getSets();
|
||||
public abstract CardInSet getEditionInfo(final String setCode);
|
||||
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import forge.card.ICardFace;
|
||||
import forge.card.cost.Cost;
|
||||
import forge.card.replacement.ReplacementHandler;
|
||||
import forge.card.spellability.AbilityActivated;
|
||||
import forge.card.spellability.AbilitySub;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.card.spellability.SpellPermanent;
|
||||
import forge.card.spellability.Target;
|
||||
@@ -156,7 +157,7 @@ public class CardFactory {
|
||||
*/
|
||||
public final void copySpellontoStack(final Card source, final Card original, final SpellAbility sa,
|
||||
final boolean bCopyDetails) {
|
||||
Player originalController = original.getController();
|
||||
//Player originalController = original.getController();
|
||||
Player controller = sa.getActivatingPlayer();
|
||||
final Card c = copyCard(original);
|
||||
|
||||
@@ -174,8 +175,9 @@ public class CardFactory {
|
||||
|
||||
c.addColor(finalColors, c, !sourceSA.hasParam("OverwriteColors"), true);
|
||||
}
|
||||
|
||||
c.addController(controller);
|
||||
|
||||
c.clearControllers();
|
||||
c.setOwner(controller);
|
||||
c.setCopiedSpell(true);
|
||||
c.refreshUniqueNumber();
|
||||
|
||||
@@ -189,6 +191,14 @@ public class CardFactory {
|
||||
{
|
||||
copySA = sa.copy();
|
||||
copySA.setSourceCard(c);
|
||||
SpellAbility subSA = copySA.getSubAbility();
|
||||
if (subSA != null) {
|
||||
AbilitySub copySubSA = ((AbilitySub) subSA).getCopy();
|
||||
copySA.setSubAbility(copySubSA);
|
||||
copySubSA.setParent(copySA);
|
||||
copySubSA.setSourceCard(c);
|
||||
copySubSA.setCopied(true);
|
||||
}
|
||||
}
|
||||
copySA.setCopied(true);
|
||||
//remove all costs
|
||||
@@ -216,7 +226,7 @@ public class CardFactory {
|
||||
|
||||
controller.getController().mayPlaySpellAbilityForFree(copySA);
|
||||
|
||||
c.addController(originalController);
|
||||
//c.addController(originalController);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -200,8 +200,7 @@ public class SpellAbilityCondition extends SpellAbilityVariables {
|
||||
}
|
||||
}
|
||||
if (this.isAllTargetsLegal()) {
|
||||
SpellAbility root = sa.getRootAbility();
|
||||
for (Card c : root.getTarget().getTargetCards()) {
|
||||
for (Card c : sa.getTarget().getTargetCards()) {
|
||||
if (!CardFactoryUtil.isTargetStillValid(sa, c)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import javax.swing.filechooser.FileFilter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.gui.download.GuiDownloadSetPicturesLQ;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.util.FileSection;
|
||||
import forge.util.FileSectionManual;
|
||||
@@ -149,7 +150,8 @@ public class DeckSerializer extends StorageReaderFolder<Deck> implements IItemSe
|
||||
for (final Entry<CardPrinted, Integer> card : d.getMain()) {
|
||||
// System.out.println(card.getSets().get(card.getSets().size() - 1).URL);
|
||||
for( int i = card.getValue().intValue(); i > 0; --i ) {
|
||||
list.add(card.getKey().getRules().getEditionInfo(card.getKey().getEdition()).getUrl());
|
||||
String url = GuiDownloadSetPicturesLQ.getCardPictureUrl(card.getKey(), card.getKey().getName());
|
||||
list.add(url);
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
@@ -21,6 +21,8 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -450,7 +452,7 @@ public final class GameActionUtil {
|
||||
if (part instanceof CostPayLife) {
|
||||
String amountString = part.getAmount();
|
||||
|
||||
final int amount = amountString.matches("[0-9][0-9]?") ? Integer.parseInt(amountString)
|
||||
final int amount = StringUtils.isNumeric(amountString) ? Integer.parseInt(amountString)
|
||||
: AbilityUtils.calculateAmount(source, amountString, sourceAbility);
|
||||
if (p.canPayLife(amount) && GuiDialog.confirm(source, "Do you want to pay " + amount + " life?" + orString)) {
|
||||
p.payLife(amount, null);
|
||||
@@ -463,7 +465,7 @@ public final class GameActionUtil {
|
||||
|
||||
else if (part instanceof CostDamage) {
|
||||
String amountString = part.getAmount();
|
||||
final int amount = amountString.matches("[0-9][0-9]?") ? Integer.parseInt(amountString)
|
||||
final int amount = StringUtils.isNumeric(amountString) ? Integer.parseInt(amountString)
|
||||
: CardFactoryUtil.xCount(source, source.getSVar(amountString));
|
||||
if (p.canPayLife(amount) && GuiDialog.confirm(source, "Do you want " + source + " to deal " + amount + " damage to you?")) {
|
||||
p.addDamage(amount, source);
|
||||
@@ -477,7 +479,7 @@ public final class GameActionUtil {
|
||||
else if (part instanceof CostPutCounter) {
|
||||
String amountString = part.getAmount();
|
||||
CounterType counterType = ((CostPutCounter) part).getCounter();
|
||||
int amount = amountString.matches("[0-9][0-9]?") ? Integer.parseInt(amountString)
|
||||
int amount = StringUtils.isNumeric(amountString) ? Integer.parseInt(amountString)
|
||||
: CardFactoryUtil.xCount(source, source.getSVar(amountString));
|
||||
String plural = amount > 1 ? "s" : "";
|
||||
if (GuiDialog.confirm(source, "Do you want to put " + amount + " " + counterType.getName()
|
||||
@@ -500,7 +502,7 @@ public final class GameActionUtil {
|
||||
else if (part instanceof CostRemoveCounter) {
|
||||
String amountString = part.getAmount();
|
||||
CounterType counterType = ((CostRemoveCounter) part).getCounter();
|
||||
int amount = amountString.matches("[0-9][0-9]?") ? Integer.parseInt(amountString)
|
||||
int amount = StringUtils.isNumeric(amountString) ? Integer.parseInt(amountString)
|
||||
: CardFactoryUtil.xCount(source, source.getSVar(amountString));
|
||||
String plural = amount > 1 ? "s" : "";
|
||||
if (part.canPay(sourceAbility, source, p, cost, game)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -60,23 +60,34 @@ public class GuiDownloadSetPicturesLQ extends GuiDownloader {
|
||||
* the card name
|
||||
*/
|
||||
protected final void addCardToList(final ArrayList<DownloadObject> cList, final CardPrinted c, final String cardName) {
|
||||
final String setCode3 = c.getEdition();
|
||||
final CardEdition thisSet = Singletons.getModel().getEditions().get(setCode3);
|
||||
final String setCode2 = thisSet.getCode2();
|
||||
final int artsCnt = c.getRules().getEditionInfo(setCode3).getCopiesCount();
|
||||
|
||||
final String imgFN = CardUtil.buildFilename(c, cardName);
|
||||
final boolean foundSetImage = imgFN.contains(setCode3) || imgFN.contains(setCode2);
|
||||
|
||||
if (!foundSetImage) {
|
||||
String url = getCardPictureUrl(c, cardName);
|
||||
|
||||
final String filename = GuiDownloadPicturesLQ.buildIdealFilename(cardName, c.getArtIndex(), artsCnt);
|
||||
cList.add(new DownloadObject(url, new File(this.picturesPath + File.separator + setCode3, filename)));
|
||||
|
||||
System.out.println(String.format("%s [%s - %s]", cardName, setCode3, thisSet.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
public static String getCardPictureUrl(final CardPrinted c, final String cardName) {
|
||||
final String urlBase = ForgeProps.getProperty(NewConstants.CARDFORGE_URL) + "/fpics/";
|
||||
|
||||
final String setCode3 = c.getEdition();
|
||||
final CardEdition thisSet = Singletons.getModel().getEditions().get(setCode3);
|
||||
final String setCode2 = thisSet.getCode2();
|
||||
|
||||
final String imgFN = CardUtil.buildFilename(c, cardName);
|
||||
final boolean foundSetImage = imgFN.contains(setCode3) || imgFN.contains(setCode2);
|
||||
|
||||
if (!foundSetImage) {
|
||||
final int artsCnt = c.getRules().getEditionInfo(setCode3).getCopiesCount();
|
||||
final String filename = GuiDownloadPicturesLQ.buildIdealFilename(cardName, c.getArtIndex(), artsCnt);
|
||||
String url = urlBase + setCode2 + "/" + Base64Coder.encodeString(filename, true);
|
||||
cList.add(new DownloadObject(url, new File(this.picturesPath + File.separator + setCode3, filename)));
|
||||
|
||||
System.out.println(String.format("%s [%s - %s]", cardName, setCode3, thisSet.getName()));
|
||||
}
|
||||
|
||||
final int artsCnt = c.getRules().getEditionInfo(setCode3).getCopiesCount();
|
||||
final String filename = GuiDownloadPicturesLQ.buildIdealFilename(cardName, c.getArtIndex(), artsCnt);
|
||||
return urlBase + setCode2 + "/" + Base64Coder.encodeString(filename, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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