checkstyle

This commit is contained in:
jendave
2011-10-31 14:35:24 +00:00
parent 8d0900e79a
commit c0f3b69d65
21 changed files with 880 additions and 819 deletions

View File

@@ -1161,16 +1161,15 @@ public class CardFactory_Creatures {
// spread damage // spread damage
for (int x = 0; x < target.getNetAttack(); x++) { for (int x = 0; x < target.getNetAttack(); x++) {
AllZone.getInputControl().setInput( AllZone.getInputControl().setInput(
CardFactoryUtil.masterOfTheWildHuntInputTargetCreature(this, wolves, CardFactoryUtil.masterOfTheWildHuntInputTargetCreature(this, wolves, new Command() {
new Command() { private static final long serialVersionUID = -328305150127775L;
private static final long serialVersionUID = -328305150127775L;
@Override @Override
public void execute() { public void execute() {
getTargetCard().addDamage(1, target); getTargetCard().addDamage(1, target);
AllZone.getGameAction().checkStateEffects(); AllZone.getGameAction().checkStateEffects();
} }
})); }));
} }
} else { // AI Choose spread Damage } else { // AI Choose spread Damage
final CardList damageableWolves = wolves.filter(new CardListFilter() { final CardList damageableWolves = wolves.filter(new CardListFilter() {
@@ -1780,7 +1779,7 @@ public class CardFactory_Creatures {
public void execute() { public void execute() {
int intermSumPower = 0; int intermSumPower = 0;
int intermSumToughness = 0; int intermSumToughness = 0;
//intermSumPower = intermSumToughness = 0; // intermSumPower = intermSumToughness = 0;
CardList creats = card.getController().getCardsIn(Zone.Graveyard); CardList creats = card.getController().getCardsIn(Zone.Graveyard);
creats = creats.filter(new CardListFilter() { creats = creats.filter(new CardListFilter() {
@Override @Override
@@ -2206,8 +2205,7 @@ public class CardFactory_Creatures {
else if (cardName.equals("Clone") || cardName.equals("Vesuvan Doppelganger") else if (cardName.equals("Clone") || cardName.equals("Vesuvan Doppelganger")
|| cardName.equals("Quicksilver Gargantuan") || cardName.equals("Jwari Shapeshifter") || cardName.equals("Quicksilver Gargantuan") || cardName.equals("Jwari Shapeshifter")
|| cardName.equals("Phyrexian Metamorph") || cardName.equals("Phantasmal Image") || cardName.equals("Phyrexian Metamorph") || cardName.equals("Phantasmal Image")
|| cardName.equals("Body Double") || cardName.equals("Body Double") || cardName.equals("Evil Twin")) {
|| cardName.equals("Evil Twin")) {
final CardFactoryInterface cfact = cf; final CardFactoryInterface cfact = cf;
final Card[] copyTarget = new Card[1]; final Card[] copyTarget = new Card[1];
final Card[] cloned = new Card[1]; final Card[] cloned = new Card[1];
@@ -2325,9 +2323,14 @@ public class CardFactory_Creatures {
cloned[0].setSVar(svarName.toString(), "AB$Sacrifice | Cost$ 0 | Defined$ Self"); cloned[0].setSVar(svarName.toString(), "AB$Sacrifice | Cost$ 0 | Defined$ Self");
} }
if(cardName.equals("Evil Twin")) { if (cardName.equals("Evil Twin")) {
AbilityFactory AF = new AbilityFactory(); final AbilityFactory abilityFactory = new AbilityFactory();
SpellAbility destroySameName = AF.getAbility("AB$Destroy | Cost$ U B T | ValidTgts$ Creature.sameName | TgtPrompt$ Select target creature with the same name. | SpellDescription$ Destroy target creature with the same name as this creature.", cloned[0]); final SpellAbility destroySameName = abilityFactory
.getAbility(
"AB$Destroy | Cost$ U B T | ValidTgts$ Creature.sameName | "
+ "TgtPrompt$ Select target creature with the same name. | "
+ "SpellDescription$ Destroy target creature with the same name as this creature.",
cloned[0]);
cloned[0].addSpellAbility(destroySameName); cloned[0].addSpellAbility(destroySameName);
} }

View File

@@ -20,7 +20,7 @@ import forge.card.spellability.SpellAbility;
*/ */
public class Cost { public class Cost {
private boolean isAbility = true; private boolean isAbility = true;
private ArrayList<CostPart> costParts = new ArrayList<CostPart>(); private final ArrayList<CostPart> costParts = new ArrayList<CostPart>();
/** /**
* Gets the cost parts. * Gets the cost parts.
@@ -28,7 +28,7 @@ public class Cost {
* @return the cost parts * @return the cost parts
*/ */
public final ArrayList<CostPart> getCostParts() { public final ArrayList<CostPart> getCostParts() {
return costParts; return this.costParts;
} }
private boolean sacCost = false; private boolean sacCost = false;
@@ -41,7 +41,7 @@ public class Cost {
* @return a boolean. * @return a boolean.
*/ */
public final boolean getSacCost() { public final boolean getSacCost() {
return sacCost; return this.sacCost;
} }
private boolean tapCost = false; private boolean tapCost = false;
@@ -54,7 +54,7 @@ public class Cost {
* @return a boolean. * @return a boolean.
*/ */
public final boolean getTap() { public final boolean getTap() {
return tapCost; return this.tapCost;
} }
/** /**
@@ -65,10 +65,11 @@ public class Cost {
* @return a boolean. * @return a boolean.
*/ */
public final boolean hasNoManaCost() { public final boolean hasNoManaCost() {
for (CostPart part : costParts) for (final CostPart part : this.costParts) {
if (part instanceof CostMana) { if (part instanceof CostMana) {
return false; return false;
} }
}
return true; return true;
} }
@@ -82,10 +83,11 @@ public class Cost {
*/ */
public final boolean isOnlyManaCost() { public final boolean isOnlyManaCost() {
// Only used by Morph and Equip... why do we need this? // Only used by Morph and Equip... why do we need this?
for (CostPart part : costParts) for (final CostPart part : this.costParts) {
if (!(part instanceof CostMana)) { if (!(part instanceof CostMana)) {
return false; return false;
} }
}
return true; return true;
} }
@@ -98,15 +100,16 @@ public class Cost {
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
public final String getTotalMana() { public final String getTotalMana() {
for (CostPart part : costParts) for (final CostPart part : this.costParts) {
if (part instanceof CostMana) { if (part instanceof CostMana) {
return part.toString(); return part.toString();
} }
}
return "0"; return "0";
} }
private String name; private final String name;
// Parsing Strings // Parsing Strings
private static final String tapXStr = "tapXType<"; private static final String tapXStr = "tapXType<";
@@ -137,164 +140,164 @@ public class Cost {
* a boolean. * a boolean.
*/ */
public Cost(String parse, final String cardName, final boolean bAbility) { public Cost(String parse, final String cardName, final boolean bAbility) {
isAbility = bAbility; this.isAbility = bAbility;
// when adding new costs for cost string, place them here // when adding new costs for cost string, place them here
name = cardName; this.name = cardName;
while (parse.contains(tapXStr)) { while (parse.contains(Cost.tapXStr)) {
String[] splitStr = abCostParse(parse, tapXStr, 3); final String[] splitStr = this.abCostParse(parse, Cost.tapXStr, 3);
parse = abUpdateParse(parse, tapXStr); parse = this.abUpdateParse(parse, Cost.tapXStr);
String description = splitStr.length > 2 ? splitStr[2] : null; final String description = splitStr.length > 2 ? splitStr[2] : null;
costParts.add(new CostTapType(splitStr[0], splitStr[1], description)); this.costParts.add(new CostTapType(splitStr[0], splitStr[1], description));
} }
while (parse.contains(subStr)) { while (parse.contains(Cost.subStr)) {
// SubCounter<NumCounters/CounterType> // SubCounter<NumCounters/CounterType>
String[] splitStr = abCostParse(parse, subStr, 4); final String[] splitStr = this.abCostParse(parse, Cost.subStr, 4);
parse = abUpdateParse(parse, subStr); parse = this.abUpdateParse(parse, Cost.subStr);
String type = splitStr.length > 2 ? splitStr[2] : "CARDNAME"; final String type = splitStr.length > 2 ? splitStr[2] : "CARDNAME";
String description = splitStr.length > 3 ? splitStr[3] : null; final String description = splitStr.length > 3 ? splitStr[3] : null;
costParts.add(new CostRemoveCounter(splitStr[0], Counters.valueOf(splitStr[1]), type, description)); this.costParts.add(new CostRemoveCounter(splitStr[0], Counters.valueOf(splitStr[1]), type, description));
} }
while (parse.contains(addStr)) { while (parse.contains(Cost.addStr)) {
// AddCounter<NumCounters/CounterType> // AddCounter<NumCounters/CounterType>
String[] splitStr = abCostParse(parse, addStr, 4); final String[] splitStr = this.abCostParse(parse, Cost.addStr, 4);
parse = abUpdateParse(parse, addStr); parse = this.abUpdateParse(parse, Cost.addStr);
String type = splitStr.length > 2 ? splitStr[2] : "CARDNAME"; final String type = splitStr.length > 2 ? splitStr[2] : "CARDNAME";
String description = splitStr.length > 3 ? splitStr[3] : null; final String description = splitStr.length > 3 ? splitStr[3] : null;
costParts.add(new CostPutCounter(splitStr[0], Counters.valueOf(splitStr[1]), type, description)); this.costParts.add(new CostPutCounter(splitStr[0], Counters.valueOf(splitStr[1]), type, description));
} }
// While no card has "PayLife<2> PayLife<3> there might be a card that // While no card has "PayLife<2> PayLife<3> there might be a card that
// Changes Cost by adding a Life Payment // Changes Cost by adding a Life Payment
while (parse.contains(lifeStr)) { while (parse.contains(Cost.lifeStr)) {
// PayLife<LifeCost> // PayLife<LifeCost>
String[] splitStr = abCostParse(parse, lifeStr, 1); final String[] splitStr = this.abCostParse(parse, Cost.lifeStr, 1);
parse = abUpdateParse(parse, lifeStr); parse = this.abUpdateParse(parse, Cost.lifeStr);
costParts.add(new CostPayLife(splitStr[0])); this.costParts.add(new CostPayLife(splitStr[0]));
} }
while (parse.contains(lifeGainStr)) { while (parse.contains(Cost.lifeGainStr)) {
// PayLife<LifeCost> // PayLife<LifeCost>
String[] splitStr = abCostParse(parse, lifeGainStr, 1); final String[] splitStr = this.abCostParse(parse, Cost.lifeGainStr, 1);
parse = abUpdateParse(parse, lifeGainStr); parse = this.abUpdateParse(parse, Cost.lifeGainStr);
costParts.add(new CostGainLife(splitStr[0])); this.costParts.add(new CostGainLife(splitStr[0]));
} }
while (parse.contains(millStr)) { while (parse.contains(Cost.millStr)) {
// PayLife<LifeCost> // PayLife<LifeCost>
String[] splitStr = abCostParse(parse, millStr, 1); final String[] splitStr = this.abCostParse(parse, Cost.millStr, 1);
parse = abUpdateParse(parse, millStr); parse = this.abUpdateParse(parse, Cost.millStr);
costParts.add(new CostMill(splitStr[0])); this.costParts.add(new CostMill(splitStr[0]));
} }
while (parse.contains(discStr)) { while (parse.contains(Cost.discStr)) {
// Discard<NumCards/Type> // Discard<NumCards/Type>
String[] splitStr = abCostParse(parse, discStr, 3); final String[] splitStr = this.abCostParse(parse, Cost.discStr, 3);
parse = abUpdateParse(parse, discStr); parse = this.abUpdateParse(parse, Cost.discStr);
String description = splitStr.length > 2 ? splitStr[2] : null; final String description = splitStr.length > 2 ? splitStr[2] : null;
costParts.add(new CostDiscard(splitStr[0], splitStr[1], description)); this.costParts.add(new CostDiscard(splitStr[0], splitStr[1], description));
} }
while (parse.contains(sacStr)) { while (parse.contains(Cost.sacStr)) {
sacCost = true; this.sacCost = true;
String[] splitStr = abCostParse(parse, sacStr, 3); final String[] splitStr = this.abCostParse(parse, Cost.sacStr, 3);
parse = abUpdateParse(parse, sacStr); parse = this.abUpdateParse(parse, Cost.sacStr);
String description = splitStr.length > 2 ? splitStr[2] : null; final String description = splitStr.length > 2 ? splitStr[2] : null;
costParts.add(new CostSacrifice(splitStr[0], splitStr[1], description)); this.costParts.add(new CostSacrifice(splitStr[0], splitStr[1], description));
} }
while (parse.contains(exileStr)) { while (parse.contains(Cost.exileStr)) {
String[] splitStr = abCostParse(parse, exileStr, 3); final String[] splitStr = this.abCostParse(parse, Cost.exileStr, 3);
parse = abUpdateParse(parse, exileStr); parse = this.abUpdateParse(parse, Cost.exileStr);
String description = splitStr.length > 2 ? splitStr[2] : null; final String description = splitStr.length > 2 ? splitStr[2] : null;
costParts.add(new CostExile(splitStr[0], splitStr[1], description, Constant.Zone.Battlefield)); this.costParts.add(new CostExile(splitStr[0], splitStr[1], description, Constant.Zone.Battlefield));
} }
while (parse.contains(exileFromHandStr)) { while (parse.contains(Cost.exileFromHandStr)) {
String[] splitStr = abCostParse(parse, exileFromHandStr, 3); final String[] splitStr = this.abCostParse(parse, Cost.exileFromHandStr, 3);
parse = abUpdateParse(parse, exileFromHandStr); parse = this.abUpdateParse(parse, Cost.exileFromHandStr);
String description = splitStr.length > 2 ? splitStr[2] : null; final String description = splitStr.length > 2 ? splitStr[2] : null;
costParts.add(new CostExile(splitStr[0], splitStr[1], description, Constant.Zone.Hand)); this.costParts.add(new CostExile(splitStr[0], splitStr[1], description, Constant.Zone.Hand));
} }
while (parse.contains(exileFromGraveStr)) { while (parse.contains(Cost.exileFromGraveStr)) {
String[] splitStr = abCostParse(parse, exileFromGraveStr, 3); final String[] splitStr = this.abCostParse(parse, Cost.exileFromGraveStr, 3);
parse = abUpdateParse(parse, exileFromGraveStr); parse = this.abUpdateParse(parse, Cost.exileFromGraveStr);
String description = splitStr.length > 2 ? splitStr[2] : null; final String description = splitStr.length > 2 ? splitStr[2] : null;
costParts.add(new CostExile(splitStr[0], splitStr[1], description, Constant.Zone.Graveyard)); this.costParts.add(new CostExile(splitStr[0], splitStr[1], description, Constant.Zone.Graveyard));
} }
while (parse.contains(exileFromTopStr)) { while (parse.contains(Cost.exileFromTopStr)) {
String[] splitStr = abCostParse(parse, exileFromTopStr, 3); final String[] splitStr = this.abCostParse(parse, Cost.exileFromTopStr, 3);
parse = abUpdateParse(parse, exileFromTopStr); parse = this.abUpdateParse(parse, Cost.exileFromTopStr);
String description = splitStr.length > 2 ? splitStr[2] : null; final String description = splitStr.length > 2 ? splitStr[2] : null;
costParts.add(new CostExile(splitStr[0], splitStr[1], description, Constant.Zone.Library)); this.costParts.add(new CostExile(splitStr[0], splitStr[1], description, Constant.Zone.Library));
} }
while (parse.contains(returnStr)) { while (parse.contains(Cost.returnStr)) {
String[] splitStr = abCostParse(parse, returnStr, 3); final String[] splitStr = this.abCostParse(parse, Cost.returnStr, 3);
parse = abUpdateParse(parse, returnStr); parse = this.abUpdateParse(parse, Cost.returnStr);
String description = splitStr.length > 2 ? splitStr[2] : null; final String description = splitStr.length > 2 ? splitStr[2] : null;
costParts.add(new CostReturn(splitStr[0], splitStr[1], description)); this.costParts.add(new CostReturn(splitStr[0], splitStr[1], description));
} }
while (parse.contains(revealStr)) { while (parse.contains(Cost.revealStr)) {
String[] splitStr = abCostParse(parse, revealStr, 3); final String[] splitStr = this.abCostParse(parse, Cost.revealStr, 3);
parse = abUpdateParse(parse, revealStr); parse = this.abUpdateParse(parse, Cost.revealStr);
String description = splitStr.length > 2 ? splitStr[2] : null; final String description = splitStr.length > 2 ? splitStr[2] : null;
costParts.add(new CostReveal(splitStr[0], splitStr[1], description)); this.costParts.add(new CostReveal(splitStr[0], splitStr[1], description));
} }
int manaLocation = 0; int manaLocation = 0;
// These won't show up with multiples // These won't show up with multiples
if (parse.contains("Untap")) { if (parse.contains("Untap")) {
parse = parse.replace("Untap", "").trim(); parse = parse.replace("Untap", "").trim();
costParts.add(0, new CostUntap()); this.costParts.add(0, new CostUntap());
manaLocation++; manaLocation++;
} }
if (parse.contains("Q")) { if (parse.contains("Q")) {
parse = parse.replace("Q", "").trim(); parse = parse.replace("Q", "").trim();
costParts.add(0, new CostUntap()); this.costParts.add(0, new CostUntap());
manaLocation++; manaLocation++;
} }
if (parse.contains("T")) { if (parse.contains("T")) {
tapCost = true; this.tapCost = true;
parse = parse.replace("T", "").trim(); parse = parse.replace("T", "").trim();
costParts.add(0, new CostTap()); this.costParts.add(0, new CostTap());
manaLocation++; manaLocation++;
} }
String stripXCost = parse.replaceAll("X", ""); final String stripXCost = parse.replaceAll("X", "");
int amountX = parse.length() - stripXCost.length(); final int amountX = parse.length() - stripXCost.length();
String mana = stripXCost.trim(); String mana = stripXCost.trim();
if (mana.equals("")) { if (mana.equals("")) {
mana = "0"; mana = "0";
} }
if (amountX > 0 || !mana.equals("0")) { if ((amountX > 0) || !mana.equals("0")) {
costParts.add(manaLocation, new CostMana(mana, amountX)); this.costParts.add(manaLocation, new CostMana(mana, amountX));
} }
} }
@@ -312,13 +315,13 @@ public class Cost {
* @return an array of {@link java.lang.String} objects. * @return an array of {@link java.lang.String} objects.
*/ */
private String[] abCostParse(final String parse, final String subkey, final int numParse) { private String[] abCostParse(final String parse, final String subkey, final int numParse) {
int startPos = parse.indexOf(subkey); final int startPos = parse.indexOf(subkey);
int endPos = parse.indexOf(">", startPos); final int endPos = parse.indexOf(">", startPos);
String str = parse.substring(startPos, endPos); String str = parse.substring(startPos, endPos);
str = str.replace(subkey, ""); str = str.replace(subkey, "");
String[] splitStr = str.split("/", numParse); final String[] splitStr = str.split("/", numParse);
return splitStr; return splitStr;
} }
@@ -334,9 +337,9 @@ public class Cost {
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
private String abUpdateParse(final String parse, final String subkey) { private String abUpdateParse(final String parse, final String subkey) {
int startPos = parse.indexOf(subkey); final int startPos = parse.indexOf(subkey);
int endPos = parse.indexOf(">", startPos); final int endPos = parse.indexOf(">", startPos);
String str = parse.substring(startPos, endPos + 1); final String str = parse.substring(startPos, endPos + 1);
return parse.replace(str, "").trim(); return parse.replace(str, "").trim();
} }
@@ -350,13 +353,13 @@ public class Cost {
*/ */
public final void changeCost(final SpellAbility sa) { public final void changeCost(final SpellAbility sa) {
// TODO: Change where ChangeCost happens // TODO: Change where ChangeCost happens
for (CostPart part : costParts) { for (final CostPart part : this.costParts) {
if (part instanceof CostMana) { if (part instanceof CostMana) {
CostMana costMana = (CostMana) part; final CostMana costMana = (CostMana) part;
String mana = getTotalMana(); final String mana = this.getTotalMana();
ManaCost changedCost = AllZone.getGameAction().getSpellCostChange(sa, new ManaCost(mana)); final ManaCost changedCost = AllZone.getGameAction().getSpellCostChange(sa, new ManaCost(mana));
costMana.setAdjustedMana(changedCost.toString(false)); costMana.setAdjustedMana(changedCost.toString(false));
} }
@@ -373,8 +376,9 @@ public class Cost {
*/ */
public final void refundPaidCost(final Card source) { public final void refundPaidCost(final Card source) {
// prereq: isUndoable is called first // prereq: isUndoable is called first
for (CostPart part : costParts) for (final CostPart part : this.costParts) {
part.refund(source); part.refund(source);
}
} }
/** /**
@@ -385,10 +389,11 @@ public class Cost {
* @return a boolean. * @return a boolean.
*/ */
public final boolean isUndoable() { public final boolean isUndoable() {
for (CostPart part : costParts) for (final CostPart part : this.costParts) {
if (!part.isUndoable()) { if (!part.isUndoable()) {
return false; return false;
} }
}
return true; return true;
} }
@@ -401,12 +406,13 @@ public class Cost {
* @return a boolean. * @return a boolean.
*/ */
public final boolean isReusuableResource() { public final boolean isReusuableResource() {
for (CostPart part : costParts) for (final CostPart part : this.costParts) {
if (!part.isReusable()) { if (!part.isReusable()) {
return false; return false;
} }
}
return isAbility; return this.isAbility;
} }
/** /**
@@ -416,11 +422,12 @@ public class Cost {
* *
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
@Override
public final String toString() { public final String toString() {
if (isAbility) { if (this.isAbility) {
return abilityToString(); return this.abilityToString();
} else { } else {
return spellToString(true); return this.spellToString(true);
} }
} }
@@ -435,7 +442,7 @@ public class Cost {
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
public final String toStringAlt() { public final String toStringAlt() {
return spellToString(false); return this.spellToString(false);
} }
/** /**
@@ -448,11 +455,11 @@ public class Cost {
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
private String spellToString(final boolean bFlag) { private String spellToString(final boolean bFlag) {
StringBuilder cost = new StringBuilder(); final StringBuilder cost = new StringBuilder();
boolean first = true; boolean first = true;
if (bFlag) { if (bFlag) {
cost.append("As an additional cost to cast ").append(name).append(", "); cost.append("As an additional cost to cast ").append(this.name).append(", ");
} else { } else {
// usually no additional mana cost for spells // usually no additional mana cost for spells
// only three Alliances cards have additional mana costs, but they // only three Alliances cards have additional mana costs, but they
@@ -463,7 +470,7 @@ public class Cost {
*/ */
} }
for (CostPart part : costParts) { for (final CostPart part : this.costParts) {
if (part instanceof CostMana) { if (part instanceof CostMana) {
continue; continue;
} }
@@ -493,10 +500,10 @@ public class Cost {
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
private String abilityToString() { private String abilityToString() {
StringBuilder cost = new StringBuilder(); final StringBuilder cost = new StringBuilder();
boolean first = true; boolean first = true;
for (CostPart part : costParts) { for (final CostPart part : this.costParts) {
boolean append = true; boolean append = true;
if (!first) { if (!first) {
if (part instanceof CostMana) { if (part instanceof CostMana) {
@@ -523,12 +530,12 @@ public class Cost {
// TODO: If a Cost needs to pay more than 10 of something, fill this array // TODO: If a Cost needs to pay more than 10 of something, fill this array
// as appropriate // as appropriate
/** /**
* Constant * Constant.
* <code>numNames="{zero, a, two, three, four, five, six, "{trunked}</code> * <code>numNames="{zero, a, two, three, four, five, six, "{trunked}</code>
*/ */
private static final String[] numNames = { "zero", "a", "two", "three", "four", "five", "six", "seven", "eight", private static final String[] numNames = { "zero", "a", "two", "three", "four", "five", "six", "seven", "eight",
"nine", "ten" }; "nine", "ten" };
/** Constant <code>vowelPattern</code> */ /** Constant <code>vowelPattern</code>. */
private static final Pattern vowelPattern = Pattern.compile("^[aeiou]", Pattern.CASE_INSENSITIVE); private static final Pattern vowelPattern = Pattern.compile("^[aeiou]", Pattern.CASE_INSENSITIVE);
/** /**
@@ -544,10 +551,10 @@ public class Cost {
*/ */
public static String convertAmountTypeToWords(final Integer i, final String amount, final String type) { public static String convertAmountTypeToWords(final Integer i, final String amount, final String type) {
if (i == null) { if (i == null) {
return convertAmountTypeToWords(amount, type); return Cost.convertAmountTypeToWords(amount, type);
} }
return convertIntAndTypeToWords(i.intValue(), type); return Cost.convertIntAndTypeToWords(i.intValue(), type);
} }
/** /**
@@ -562,14 +569,14 @@ public class Cost {
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
public static String convertIntAndTypeToWords(final int i, final String type) { public static String convertIntAndTypeToWords(final int i, final String type) {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
if (i >= numNames.length) { if (i >= Cost.numNames.length) {
sb.append(i); sb.append(i);
} else if (1 == i && vowelPattern.matcher(type).find()) { } else if ((1 == i) && Cost.vowelPattern.matcher(type).find()) {
sb.append("an"); sb.append("an");
} else { } else {
sb.append(numNames[i]); sb.append(Cost.numNames[i]);
} }
sb.append(" "); sb.append(" ");
@@ -591,7 +598,7 @@ public class Cost {
* @return the string * @return the string
*/ */
public static String convertAmountTypeToWords(final String amount, final String type) { public static String convertAmountTypeToWords(final String amount, final String type) {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append(amount); sb.append(amount);
sb.append(" "); sb.append(" ");

View File

@@ -41,29 +41,29 @@ public class CostDiscard extends CostPartWithList {
*/ */
@Override @Override
public final String toString() { public final String toString() {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append("Discard "); sb.append("Discard ");
Integer i = convertAmount(); final Integer i = this.convertAmount();
if (getThis()) { if (this.getThis()) {
sb.append(type); sb.append(this.getType());
} else if (type.equals("Hand")) { } else if (this.getType().equals("Hand")) {
sb.append("your hand"); sb.append("your hand");
} else if (type.equals("LastDrawn")) { } else if (this.getType().equals("LastDrawn")) {
sb.append("last drawn card"); sb.append("last drawn card");
} else { } else {
StringBuilder desc = new StringBuilder(); final StringBuilder desc = new StringBuilder();
if (type.equals("Card") || type.equals("Random")) { if (this.getType().equals("Card") || this.getType().equals("Random")) {
desc.append("Card"); desc.append("Card");
} else { } else {
desc.append(typeDescription == null ? type : typeDescription).append(" card"); desc.append(this.getTypeDescription() == null ? this.getType() : this.getTypeDescription()).append(" card");
} }
sb.append(Cost.convertAmountTypeToWords(i, amount, desc.toString())); sb.append(Cost.convertAmountTypeToWords(i, this.getAmount(), desc.toString()));
if (type.equals("Random")) { if (this.getType().equals("Random")) {
sb.append(" at random"); sb.append(" at random");
} }
} }
@@ -92,23 +92,23 @@ public class CostDiscard extends CostPartWithList {
@Override @Override
public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) { public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) {
CardList handList = activator.getCardsIn(Zone.Hand); CardList handList = activator.getCardsIn(Zone.Hand);
String type = getType(); final String type = this.getType();
Integer amount = convertAmount(); final Integer amount = this.convertAmount();
if (getThis()) { if (this.getThis()) {
if (!AllZone.getZoneOf(source).is(Constant.Zone.Hand)) { if (!AllZone.getZoneOf(source).is(Constant.Zone.Hand)) {
return false; return false;
} }
} else if (type.equals("Hand")) { } else if (type.equals("Hand")) {
// this will always work // this will always work
} else if (type.equals("LastDrawn")) { } else if (type.equals("LastDrawn")) {
Card c = activator.getLastDrawnCard(); final Card c = activator.getLastDrawnCard();
return handList.contains(c); return handList.contains(c);
} else { } else {
if (!type.equals("Random")) { if (!type.equals("Random")) {
handList = handList.getValidCards(type.split(";"), activator, source); handList = handList.getValidCards(type.split(";"), activator, source);
} }
if (amount != null && amount > handList.size()) { if ((amount != null) && (amount > handList.size())) {
// not enough cards in hand to pay // not enough cards in hand to pay
return false; return false;
} }
@@ -125,8 +125,8 @@ public class CostDiscard extends CostPartWithList {
*/ */
@Override @Override
public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) {
Player activator = ability.getActivatingPlayer(); final Player activator = ability.getActivatingPlayer();
for (Card c : list) { for (final Card c : this.getList()) {
activator.discard(c, ability); activator.discard(c, ability);
} }
} }
@@ -140,37 +140,37 @@ public class CostDiscard extends CostPartWithList {
*/ */
@Override @Override
public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) {
Player activator = ability.getActivatingPlayer(); final Player activator = ability.getActivatingPlayer();
CardList handList = activator.getCardsIn(Zone.Hand); CardList handList = activator.getCardsIn(Zone.Hand);
String discType = getType(); final String discType = this.getType();
String amount = getAmount(); final String amount = this.getAmount();
resetList(); this.resetList();
if (getThis()) { if (this.getThis()) {
if (!handList.contains(source)) { if (!handList.contains(source)) {
return false; return false;
} }
activator.discard(source, ability); activator.discard(source, ability);
payment.setPaidManaPart(this, true); payment.setPaidManaPart(this, true);
addToList(source); this.addToList(source);
} else if (discType.equals("Hand")) { } else if (discType.equals("Hand")) {
list = handList; this.list = handList;
activator.discardHand(ability); activator.discardHand(ability);
payment.setPaidManaPart(this, true); payment.setPaidManaPart(this, true);
} else if (discType.equals("LastDrawn")) { } else if (discType.equals("LastDrawn")) {
Card lastDrawn = activator.getLastDrawnCard(); final Card lastDrawn = activator.getLastDrawnCard();
addToList(lastDrawn); this.addToList(lastDrawn);
if (!handList.contains(lastDrawn)) { if (!handList.contains(lastDrawn)) {
return false; return false;
} }
activator.discard(lastDrawn, ability); activator.discard(lastDrawn, ability);
payment.setPaidManaPart(this, true); payment.setPaidManaPart(this, true);
} else { } else {
Integer c = convertAmount(); Integer c = this.convertAmount();
if (discType.equals("Random")) { if (discType.equals("Random")) {
if (c == null) { if (c == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(amount);
// Generalize this // Generalize this
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
c = CostUtil.chooseXValue(source, handList.size()); c = CostUtil.chooseXValue(source, handList.size());
@@ -179,14 +179,14 @@ public class CostDiscard extends CostPartWithList {
} }
} }
list = activator.discardRandom(c, ability); this.list = activator.discardRandom(c, ability);
payment.setPaidManaPart(this, true); payment.setPaidManaPart(this, true);
} else { } else {
String[] validType = discType.split(";"); final String[] validType = discType.split(";");
handList = handList.getValidCards(validType, activator, ability.getSourceCard()); handList = handList.getValidCards(validType, activator, ability.getSourceCard());
if (c == null) { if (c == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(amount);
// Generalize this // Generalize this
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
c = CostUtil.chooseXValue(source, handList.size()); c = CostUtil.chooseXValue(source, handList.size());
@@ -195,11 +195,11 @@ public class CostDiscard extends CostPartWithList {
} }
} }
CostUtil.setInput(CostDiscard.input_discardCost(discType, handList, ability, payment, this, c)); CostUtil.setInput(CostDiscard.inputDiscardCost(discType, handList, ability, payment, this, c));
return false; return false;
} }
} }
addListToHash(ability, "Discarded"); this.addListToHash(ability, "Discarded");
return true; return true;
} }
@@ -212,46 +212,46 @@ public class CostDiscard extends CostPartWithList {
*/ */
@Override @Override
public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) {
String type = getType(); final String type = this.getType();
Player activator = ability.getActivatingPlayer(); final Player activator = ability.getActivatingPlayer();
CardList hand = activator.getCardsIn(Zone.Hand); final CardList hand = activator.getCardsIn(Zone.Hand);
resetList(); this.resetList();
if (type.equals("LastDrawn")) { if (type.equals("LastDrawn")) {
if (!hand.contains(activator.getLastDrawnCard())) { if (!hand.contains(activator.getLastDrawnCard())) {
return false; return false;
} }
addToList(activator.getLastDrawnCard()); this.addToList(activator.getLastDrawnCard());
} }
else if (getThis()) { else if (this.getThis()) {
if (!hand.contains(source)) { if (!hand.contains(source)) {
return false; return false;
} }
addToList(source); this.addToList(source);
} }
else if (type.equals("Hand")) { else if (type.equals("Hand")) {
list.addAll(hand); this.list.addAll(hand);
} }
else { else {
Integer c = convertAmount(); Integer c = this.convertAmount();
if (c == null) { if (c == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(this.getAmount());
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
return false; return false;
} }
c = AbilityFactory.calculateAmount(source, amount, ability); c = AbilityFactory.calculateAmount(source, this.getAmount(), ability);
} }
if (type.equals("Random")) { if (type.equals("Random")) {
list = CardListUtil.getRandomSubList(hand, c); this.list = CardListUtil.getRandomSubList(hand, c);
} else { } else {
list = ComputerUtil.discardNumTypeAI(c, type.split(";"), ability); this.list = ComputerUtil.discardNumTypeAI(c, type.split(";"), ability);
} }
} }
return list != null; return this.list != null;
} }
// Inputs // Inputs
@@ -276,34 +276,34 @@ public class CostDiscard extends CostPartWithList {
* *
* @return a {@link forge.gui.input.Input} object. * @return a {@link forge.gui.input.Input} object.
*/ */
public static Input input_discardCost(final String discType, final CardList handList, final SpellAbility sa, public static Input inputDiscardCost(final String discType, final CardList handList, final SpellAbility sa,
final Cost_Payment payment, final CostDiscard part, final int nNeeded) { final Cost_Payment payment, final CostDiscard part, final int nNeeded) {
final SpellAbility sp = sa; final SpellAbility sp = sa;
Input target = new Input() { final Input target = new Input() {
private static final long serialVersionUID = -329993322080934435L; private static final long serialVersionUID = -329993322080934435L;
int nDiscard = 0; private int nDiscard = 0;
@Override @Override
public void showMessage() { public void showMessage() {
if (nNeeded == 0) { if (nNeeded == 0) {
done(); this.done();
} }
if (AllZone.getHumanPlayer().getZone(Zone.Hand).size() == 0) { if (AllZone.getHumanPlayer().getZone(Zone.Hand).size() == 0) {
stop(); this.stop();
} }
StringBuilder type = new StringBuilder(""); final StringBuilder type = new StringBuilder("");
if (!discType.equals("Card")) { if (!discType.equals("Card")) {
type.append(" ").append(discType); type.append(" ").append(discType);
} }
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append("Select a "); sb.append("Select a ");
sb.append(part.getDescriptiveType()); sb.append(part.getDescriptiveType());
sb.append(" to discard."); sb.append(" to discard.");
if (nNeeded > 1) { if (nNeeded > 1) {
sb.append(" You have "); sb.append(" You have ");
sb.append(nNeeded - nDiscard); sb.append(nNeeded - this.nDiscard);
sb.append(" remaining."); sb.append(" remaining.");
} }
AllZone.getDisplay().showMessage(sb.toString()); AllZone.getDisplay().showMessage(sb.toString());
@@ -312,7 +312,7 @@ public class CostDiscard extends CostPartWithList {
@Override @Override
public void selectButtonCancel() { public void selectButtonCancel() {
cancel(); this.cancel();
} }
@Override @Override
@@ -322,29 +322,29 @@ public class CostDiscard extends CostPartWithList {
card.getController().discard(card, sp); card.getController().discard(card, sp);
part.addToList(card); part.addToList(card);
handList.remove(card); handList.remove(card);
nDiscard++; this.nDiscard++;
// in case no more cards in hand // in case no more cards in hand
if (nDiscard == nNeeded) { if (this.nDiscard == nNeeded) {
done(); this.done();
} else if (AllZone.getHumanPlayer().getZone(Zone.Hand).size() == 0) { } else if (AllZone.getHumanPlayer().getZone(Zone.Hand).size() == 0) {
// really // really
// shouldn't // shouldn't
// happen // happen
cancel(); this.cancel();
} else { } else {
showMessage(); this.showMessage();
} }
} }
} }
public void cancel() { public void cancel() {
stop(); this.stop();
payment.cancelCost(); payment.cancelCost();
} }
public void done() { public void done() {
stop(); this.stop();
part.addListToHash(sp, "Discarded"); part.addListToHash(sp, "Discarded");
payment.paidCost(part); payment.paidCost(part);
} }

View File

@@ -36,7 +36,7 @@ public class CostExile extends CostPartWithList {
* @return the from * @return the from
*/ */
public final Constant.Zone getFrom() { public final Constant.Zone getFrom() {
return from; return this.from;
} }
/** /**
@@ -65,23 +65,23 @@ public class CostExile extends CostPartWithList {
*/ */
@Override @Override
public final String toString() { public final String toString() {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
Integer i = convertAmount(); final Integer i = this.convertAmount();
sb.append("Exile "); sb.append("Exile ");
if (getThis()) { if (this.getThis()) {
sb.append(type); sb.append(this.getType());
if (!from.equals(Zone.Battlefield)) { if (!this.from.equals(Zone.Battlefield)) {
sb.append(" from your ").append(from); sb.append(" from your ").append(this.from);
} }
return sb.toString(); return sb.toString();
} }
if (from.equals(Zone.Battlefield)) { if (this.from.equals(Zone.Battlefield)) {
String desc = typeDescription == null ? type : typeDescription; final String desc = this.getTypeDescription() == null ? this.getType() : this.getTypeDescription();
sb.append(Cost.convertAmountTypeToWords(i, amount, desc)); sb.append(Cost.convertAmountTypeToWords(i, this.getAmount(), desc));
if (!getThis()) { if (!this.getThis()) {
sb.append(" you control"); sb.append(" you control");
} }
return sb.toString(); return sb.toString();
@@ -90,16 +90,16 @@ public class CostExile extends CostPartWithList {
if (i != null) { if (i != null) {
sb.append(i); sb.append(i);
} else { } else {
sb.append(amount); sb.append(this.getAmount());
} }
if (!type.equals("Card")) { if (!this.getType().equals("Card")) {
sb.append(" " + type); sb.append(" " + this.getType());
} }
sb.append(" card"); sb.append(" card");
if (i == null || i > 1) { if ((i == null) || (i > 1)) {
sb.append("s"); sb.append("s");
} }
sb.append(" from your ").append(from); sb.append(" from your ").append(this.from);
return sb.toString(); return sb.toString();
} }
@@ -124,12 +124,12 @@ public class CostExile extends CostPartWithList {
*/ */
@Override @Override
public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) { public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) {
CardList typeList = activator.getCardsIn(getFrom()); CardList typeList = activator.getCardsIn(this.getFrom());
if (!getThis()) { if (!this.getThis()) {
typeList = typeList.getValidCards(getType().split(";"), activator, source); typeList = typeList.getValidCards(this.getType().split(";"), activator, source);
Integer amount = convertAmount(); final Integer amount = this.convertAmount();
if (amount != null && typeList.size() < amount) { if ((amount != null) && (typeList.size() < amount)) {
return false; return false;
} }
} else if (!typeList.contains(source)) { } else if (!typeList.contains(source)) {
@@ -147,8 +147,9 @@ public class CostExile extends CostPartWithList {
*/ */
@Override @Override
public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) {
for (Card c : list) for (final Card c : this.list) {
AllZone.getGameAction().exile(c); AllZone.getGameAction().exile(c);
}
} }
/* /*
@@ -160,13 +161,13 @@ public class CostExile extends CostPartWithList {
*/ */
@Override @Override
public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) {
String amount = getAmount(); final String amount = this.getAmount();
Integer c = convertAmount(); Integer c = this.convertAmount();
Player activator = ability.getActivatingPlayer(); final Player activator = ability.getActivatingPlayer();
CardList list = activator.getCardsIn(getFrom()); CardList list = activator.getCardsIn(this.getFrom());
list = list.getValidCards(type.split(";"), activator, source); list = list.getValidCards(this.getType().split(";"), activator, source);
if (c == null) { if (c == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(amount);
// Generalize this // Generalize this
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
c = CostUtil.chooseXValue(source, list.size()); c = CostUtil.chooseXValue(source, list.size());
@@ -174,14 +175,14 @@ public class CostExile extends CostPartWithList {
c = AbilityFactory.calculateAmount(source, amount, ability); c = AbilityFactory.calculateAmount(source, amount, ability);
} }
} }
if (getThis()) { if (this.getThis()) {
CostUtil.setInput(CostExile.exileThis(ability, payment, this)); CostUtil.setInput(CostExile.exileThis(ability, payment, this));
} else if (from.equals(Constant.Zone.Battlefield) || from.equals(Constant.Zone.Hand)) { } else if (this.from.equals(Constant.Zone.Battlefield) || this.from.equals(Constant.Zone.Hand)) {
CostUtil.setInput(CostExile.exileType(ability, this, getType(), payment, c)); CostUtil.setInput(CostExile.exileType(ability, this, this.getType(), payment, c));
} else if (from.equals(Constant.Zone.Library)) { } else if (this.from.equals(Constant.Zone.Library)) {
CostExile.exileFromTop(ability, this, payment, c); CostExile.exileFromTop(ability, this, payment, c);
} else { } else {
CostUtil.setInput(CostExile.exileFrom(ability, this, getType(), payment, c)); CostUtil.setInput(CostExile.exileFrom(ability, this, this.getType(), payment, c));
} }
return false; return false;
} }
@@ -195,27 +196,28 @@ public class CostExile extends CostPartWithList {
*/ */
@Override @Override
public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) {
resetList(); this.resetList();
if (getThis()) { if (this.getThis()) {
list.add(source); this.list.add(source);
} else { } else {
Integer c = convertAmount(); Integer c = this.convertAmount();
if (c == null) { if (c == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(this.getAmount());
// Generalize this // Generalize this
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
return false; return false;
} }
c = AbilityFactory.calculateAmount(source, amount, ability); c = AbilityFactory.calculateAmount(source, this.getAmount(), ability);
} }
if (from.equals(Constant.Zone.Library)) { if (this.from.equals(Constant.Zone.Library)) {
list = AllZone.getComputerPlayer().getCardsIn(Zone.Library, c); this.list = AllZone.getComputerPlayer().getCardsIn(Zone.Library, c);
} else { } else {
list = ComputerUtil.chooseExileFrom(getFrom(), getType(), source, ability.getTargetCard(), c); this.list = ComputerUtil.chooseExileFrom(this.getFrom(), this.getType(), source,
ability.getTargetCard(), c);
} }
if (list == null || list.size() < c) { if ((this.list == null) || (this.list.size() < c)) {
return false; return false;
} }
} }
@@ -238,9 +240,9 @@ public class CostExile extends CostPartWithList {
*/ */
public static void exileFromTop(final SpellAbility sa, final CostExile part, final Cost_Payment payment, public static void exileFromTop(final SpellAbility sa, final CostExile part, final Cost_Payment payment,
final int nNeeded) { final int nNeeded) {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append("Exile ").append(nNeeded).append(" cards from the top of your library?"); sb.append("Exile ").append(nNeeded).append(" cards from the top of your library?");
CardList list = sa.getActivatingPlayer().getCardsIn(Zone.Library, nNeeded); final CardList list = sa.getActivatingPlayer().getCardsIn(Zone.Library, nNeeded);
if (list.size() > nNeeded) { if (list.size() > nNeeded) {
// I don't believe this is possible // I don't believe this is possible
@@ -248,11 +250,11 @@ public class CostExile extends CostPartWithList {
return; return;
} }
boolean doExile = GameActionUtil.showYesNoDialog(sa.getSourceCard(), sb.toString()); final boolean doExile = GameActionUtil.showYesNoDialog(sa.getSourceCard(), sb.toString());
if (doExile) { if (doExile) {
Iterator<Card> itr = list.iterator(); final Iterator<Card> itr = list.iterator();
while (itr.hasNext()) { while (itr.hasNext()) {
Card c = (Card) itr.next(); final Card c = itr.next();
part.addToList(c); part.addToList(c);
AllZone.getGameAction().exile(c); AllZone.getGameAction().exile(c);
} }
@@ -280,36 +282,38 @@ public class CostExile extends CostPartWithList {
*/ */
public static Input exileFrom(final SpellAbility sa, final CostExile part, final String type, public static Input exileFrom(final SpellAbility sa, final CostExile part, final String type,
final Cost_Payment payment, final int nNeeded) { final Cost_Payment payment, final int nNeeded) {
Input target = new Input() { final Input target = new Input() {
private static final long serialVersionUID = 734256837615635021L; private static final long serialVersionUID = 734256837615635021L;
CardList typeList; private CardList typeList;
@Override @Override
public void showMessage() { public void showMessage() {
if (nNeeded == 0) { if (nNeeded == 0) {
done(); this.done();
} }
typeList = sa.getActivatingPlayer().getCardsIn(part.getFrom()); this.typeList = sa.getActivatingPlayer().getCardsIn(part.getFrom());
typeList = typeList.getValidCards(type.split(";"), sa.getActivatingPlayer(), sa.getSourceCard()); this.typeList = this.typeList.getValidCards(type.split(";"), sa.getActivatingPlayer(),
sa.getSourceCard());
for (int i = 0; i < nNeeded; i++) { for (int i = 0; i < nNeeded; i++) {
if (typeList.size() == 0) { if (this.typeList.size() == 0) {
cancel(); this.cancel();
} }
Object o = GuiUtils.getChoiceOptional("Exile from " + part.getFrom(), typeList.toArray()); final Object o = GuiUtils
.getChoiceOptional("Exile from " + part.getFrom(), this.typeList.toArray());
if (o != null) { if (o != null) {
Card c = (Card) o; final Card c = (Card) o;
typeList.remove(c); this.typeList.remove(c);
part.addToList(c); part.addToList(c);
AllZone.getGameAction().exile(c); AllZone.getGameAction().exile(c);
if (i == nNeeded - 1) { if (i == (nNeeded - 1)) {
done(); this.done();
} }
} else { } else {
cancel(); this.cancel();
break; break;
} }
} }
@@ -317,22 +321,22 @@ public class CostExile extends CostPartWithList {
@Override @Override
public void selectButtonCancel() { public void selectButtonCancel() {
cancel(); this.cancel();
} }
public void done() { public void done() {
stop(); this.stop();
part.addListToHash(sa, "Exiled"); part.addListToHash(sa, "Exiled");
payment.paidCost(part); payment.paidCost(part);
} }
public void cancel() { public void cancel() {
stop(); this.stop();
payment.cancelCost(); payment.cancelCost();
} }
}; };
return target; return target;
}// exileFrom() } // exileFrom()
/** /**
* <p> * <p>
@@ -353,7 +357,7 @@ public class CostExile extends CostPartWithList {
*/ */
public static Input exileType(final SpellAbility sa, final CostExile part, final String type, public static Input exileType(final SpellAbility sa, final CostExile part, final String type,
final Cost_Payment payment, final int nNeeded) { final Cost_Payment payment, final int nNeeded) {
Input target = new Input() { final Input target = new Input() {
private static final long serialVersionUID = 1403915758082824694L; private static final long serialVersionUID = 1403915758082824694L;
private CardList typeList; private CardList typeList;
@@ -362,11 +366,11 @@ public class CostExile extends CostPartWithList {
@Override @Override
public void showMessage() { public void showMessage() {
if (nNeeded == 0) { if (nNeeded == 0) {
done(); this.done();
} }
StringBuilder msg = new StringBuilder("Exile "); final StringBuilder msg = new StringBuilder("Exile ");
int nLeft = nNeeded - nExiles; final int nLeft = nNeeded - this.nExiles;
msg.append(nLeft).append(" "); msg.append(nLeft).append(" ");
msg.append(type); msg.append(type);
if (nLeft > 1) { if (nLeft > 1) {
@@ -376,50 +380,51 @@ public class CostExile extends CostPartWithList {
if (part.getFrom().equals(Constant.Zone.Hand)) { if (part.getFrom().equals(Constant.Zone.Hand)) {
msg.append(" from your Hand"); msg.append(" from your Hand");
} }
typeList = sa.getActivatingPlayer().getCardsIn(part.getFrom()); this.typeList = sa.getActivatingPlayer().getCardsIn(part.getFrom());
typeList = typeList.getValidCards(type.split(";"), sa.getActivatingPlayer(), sa.getSourceCard()); this.typeList = this.typeList.getValidCards(type.split(";"), sa.getActivatingPlayer(),
sa.getSourceCard());
AllZone.getDisplay().showMessage(msg.toString()); AllZone.getDisplay().showMessage(msg.toString());
ButtonUtil.enableOnlyCancel(); ButtonUtil.enableOnlyCancel();
} }
@Override @Override
public void selectButtonCancel() { public void selectButtonCancel() {
cancel(); this.cancel();
} }
@Override @Override
public void selectCard(final Card card, final PlayerZone zone) { public void selectCard(final Card card, final PlayerZone zone) {
if (typeList.contains(card)) { if (this.typeList.contains(card)) {
nExiles++; this.nExiles++;
part.addToList(card); part.addToList(card);
AllZone.getGameAction().exile(card); AllZone.getGameAction().exile(card);
typeList.remove(card); this.typeList.remove(card);
// in case nothing else to exile // in case nothing else to exile
if (nExiles == nNeeded) { if (this.nExiles == nNeeded) {
done(); this.done();
} else if (typeList.size() == 0) { } else if (this.typeList.size() == 0) {
// happen // happen
cancel(); this.cancel();
} else { } else {
showMessage(); this.showMessage();
} }
} }
} }
public void done() { public void done() {
stop(); this.stop();
part.addListToHash(sa, "Exiled"); part.addListToHash(sa, "Exiled");
payment.paidCost(part); payment.paidCost(part);
} }
public void cancel() { public void cancel() {
stop(); this.stop();
payment.cancelCost(); payment.cancelCost();
} }
}; };
return target; return target;
}// exileType() } // exileType()
/** /**
* <p> * <p>
@@ -435,30 +440,30 @@ public class CostExile extends CostPartWithList {
* @return a {@link forge.gui.input.Input} object. * @return a {@link forge.gui.input.Input} object.
*/ */
public static Input exileThis(final SpellAbility sa, final Cost_Payment payment, final CostExile part) { public static Input exileThis(final SpellAbility sa, final Cost_Payment payment, final CostExile part) {
Input target = new Input() { final Input target = new Input() {
private static final long serialVersionUID = 678668673002725001L; private static final long serialVersionUID = 678668673002725001L;
@Override @Override
public void showMessage() { public void showMessage() {
Card card = sa.getSourceCard(); final Card card = sa.getSourceCard();
if (sa.getActivatingPlayer().isHuman() if (sa.getActivatingPlayer().isHuman()
&& sa.getActivatingPlayer().getZone(part.getFrom()).contains(card)) { && sa.getActivatingPlayer().getZone(part.getFrom()).contains(card)) {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append(card.getName()); sb.append(card.getName());
sb.append(" - Exile?"); sb.append(" - Exile?");
Object[] possibleValues = { "Yes", "No" }; final Object[] possibleValues = { "Yes", "No" };
Object choice = JOptionPane.showOptionDialog(null, sb.toString(), card.getName() + " - Cost", final Object choice = JOptionPane.showOptionDialog(null, sb.toString(), card.getName() + " - Cost",
JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, possibleValues, JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, possibleValues,
possibleValues[0]); possibleValues[0]);
if (choice.equals(0)) { if (choice.equals(0)) {
payment.getAbility().addCostToHashList(card, "Exiled"); payment.getAbility().addCostToHashList(card, "Exiled");
AllZone.getGameAction().exile(card); AllZone.getGameAction().exile(card);
part.addToList(card); part.addToList(card);
stop(); this.stop();
part.addListToHash(sa, "Exiled"); part.addListToHash(sa, "Exiled");
payment.paidCost(part); payment.paidCost(part);
} else { } else {
stop(); this.stop();
payment.cancelCost(); payment.cancelCost();
} }
} }
@@ -466,5 +471,5 @@ public class CostExile extends CostPartWithList {
}; };
return target; return target;
}// input_exile() } // input_exile()
} }

View File

@@ -19,7 +19,7 @@ public class CostGainLife extends CostPart {
* @return the last paid amount * @return the last paid amount
*/ */
public final int getLastPaidAmount() { public final int getLastPaidAmount() {
return lastPaidAmount; return this.lastPaidAmount;
} }
/** /**
@@ -29,7 +29,7 @@ public class CostGainLife extends CostPart {
* the new last paid amount * the new last paid amount
*/ */
public final void setLastPaidAmount(final int paidAmount) { public final void setLastPaidAmount(final int paidAmount) {
lastPaidAmount = paidAmount; this.lastPaidAmount = paidAmount;
} }
/** /**
@@ -39,7 +39,7 @@ public class CostGainLife extends CostPart {
* the amount * the amount
*/ */
public CostGainLife(final String amount) { public CostGainLife(final String amount) {
this.amount = amount; this.setAmount(amount);
} }
/* /*
@@ -49,8 +49,8 @@ public class CostGainLife extends CostPart {
*/ */
@Override @Override
public final String toString() { public final String toString() {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append("Have each other player gain ").append(amount).append(" Life"); sb.append("Have each other player gain ").append(this.getAmount()).append(" Life");
return sb.toString(); return sb.toString();
} }
@@ -73,8 +73,8 @@ public class CostGainLife extends CostPart {
*/ */
@Override @Override
public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) { public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) {
Integer amount = convertAmount(); final Integer amount = this.convertAmount();
if (amount != null && !activator.getOpponent().canGainLife()) { if ((amount != null) && !activator.getOpponent().canGainLife()) {
return false; return false;
} }
@@ -89,7 +89,7 @@ public class CostGainLife extends CostPart {
*/ */
@Override @Override
public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) {
AllZone.getHumanPlayer().gainLife(getLastPaidAmount(), null); AllZone.getHumanPlayer().gainLife(this.getLastPaidAmount(), null);
} }
/* /*
@@ -101,13 +101,13 @@ public class CostGainLife extends CostPart {
*/ */
@Override @Override
public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) {
String amount = getAmount(); final String amount = this.getAmount();
Player activator = ability.getActivatingPlayer(); final Player activator = ability.getActivatingPlayer();
int life = activator.getLife(); final int life = activator.getLife();
Integer c = convertAmount(); Integer c = this.convertAmount();
if (c == null) { if (c == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(amount);
// Generalize this // Generalize this
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
c = CostUtil.chooseXValue(source, life); c = CostUtil.chooseXValue(source, life);
@@ -116,12 +116,12 @@ public class CostGainLife extends CostPart {
} }
} }
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append(source.getName()).append(" - Have each other player gain ").append(c).append(" Life?"); sb.append(source.getName()).append(" - Have each other player gain ").append(c).append(" Life?");
if (GameActionUtil.showYesNoDialog(source, sb.toString()) && activator.getOpponent().canGainLife()) { if (GameActionUtil.showYesNoDialog(source, sb.toString()) && activator.getOpponent().canGainLife()) {
activator.getOpponent().gainLife(c, null); activator.getOpponent().gainLife(c, null);
setLastPaidAmount(c); this.setLastPaidAmount(c);
payment.setPaidManaPart(this, true); payment.setPaidManaPart(this, true);
} else { } else {
payment.setCancel(true); payment.setCancel(true);
@@ -140,22 +140,22 @@ public class CostGainLife extends CostPart {
*/ */
@Override @Override
public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) {
Player activator = ability.getActivatingPlayer(); final Player activator = ability.getActivatingPlayer();
Integer c = convertAmount(); Integer c = this.convertAmount();
if (c == null) { if (c == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(this.getAmount());
// Generalize this // Generalize this
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
return false; return false;
} else { } else {
c = AbilityFactory.calculateAmount(source, amount, ability); c = AbilityFactory.calculateAmount(source, this.getAmount(), ability);
} }
} }
if (!activator.getOpponent().canGainLife()) { if (!activator.getOpponent().canGainLife()) {
return false; return false;
} }
setLastPaidAmount(c); this.setLastPaidAmount(c);
return true; return true;
} }
} }

View File

@@ -32,7 +32,7 @@ public class CostMana extends CostPart {
*/ */
public final String getMana() { public final String getMana() {
// Only used for Human to pay for non-X cost first // Only used for Human to pay for non-X cost first
return mana; return this.mana;
} }
/** /**
@@ -42,7 +42,7 @@ public class CostMana extends CostPart {
* the new mana * the new mana
*/ */
public final void setMana(final String sCost) { public final void setMana(final String sCost) {
mana = sCost; this.mana = sCost;
} }
/** /**
@@ -51,7 +51,7 @@ public class CostMana extends CostPart {
* @return true, if successful * @return true, if successful
*/ */
public final boolean hasNoXManaCost() { public final boolean hasNoXManaCost() {
return amountX == 0; return this.amountX == 0;
} }
/** /**
@@ -60,7 +60,7 @@ public class CostMana extends CostPart {
* @return the x mana * @return the x mana
*/ */
public final int getXMana() { public final int getXMana() {
return amountX; return this.amountX;
} }
/** /**
@@ -70,7 +70,7 @@ public class CostMana extends CostPart {
* the new x mana * the new x mana
*/ */
public final void setXMana(final int xCost) { public final void setXMana(final int xCost) {
amountX = xCost; this.amountX = xCost;
} }
/** /**
@@ -79,7 +79,7 @@ public class CostMana extends CostPart {
* @return the adjusted mana * @return the adjusted mana
*/ */
public final String getAdjustedMana() { public final String getAdjustedMana() {
return adjustedMana; return this.adjustedMana;
} }
/** /**
@@ -99,11 +99,11 @@ public class CostMana extends CostPart {
*/ */
public final String getManaToPay() { public final String getManaToPay() {
// Only used for Human to pay for non-X cost first // Only used for Human to pay for non-X cost first
if (!adjustedMana.equals("")) { if (!this.adjustedMana.equals("")) {
return adjustedMana; return this.adjustedMana;
} }
return mana; return this.mana;
} }
/** /**
@@ -117,8 +117,8 @@ public class CostMana extends CostPart {
public CostMana(final String mana, final int amount) { public CostMana(final String mana, final int amount) {
this.mana = mana.trim(); this.mana = mana.trim();
this.amountX = amount; this.amountX = amount;
this.isUndoable = true; this.setUndoable(true);
this.isReusable = true; this.setReusable(true);
} }
/* /*
@@ -128,11 +128,11 @@ public class CostMana extends CostPart {
*/ */
@Override @Override
public final String toString() { public final String toString() {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append(Strings.repeat("X ", amountX)); sb.append(Strings.repeat("X ", this.amountX));
if (!mana.equals("0")) { if (!this.mana.equals("0")) {
sb.append(mana); sb.append(this.mana);
} }
return sb.toString().trim(); return sb.toString().trim();
@@ -184,17 +184,17 @@ public class CostMana extends CostPart {
@Override @Override
public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) {
int manaToAdd = 0; int manaToAdd = 0;
if (!hasNoXManaCost()) { if (!this.hasNoXManaCost()) {
// if X cost is a defined value, other than xPaid // if X cost is a defined value, other than xPaid
if (!source.getSVar("X").equals("Count$xPaid")) { if (!source.getSVar("X").equals("Count$xPaid")) {
// this currently only works for things about Targeted object // this currently only works for things about Targeted object
manaToAdd = AbilityFactory.calculateAmount(source, "X", ability) * getXMana(); manaToAdd = AbilityFactory.calculateAmount(source, "X", ability) * this.getXMana();
} }
} }
if (!getManaToPay().equals("0") || manaToAdd > 0) { if (!this.getManaToPay().equals("0") || (manaToAdd > 0)) {
CostUtil.setInput(CostMana.input_payMana(ability, payment, this, manaToAdd)); CostUtil.setInput(CostMana.inputPayMana(ability, payment, this, manaToAdd));
} else if (getXMana() > 0) { } else if (this.getXMana() > 0) {
CostUtil.setInput(CostMana.input_payXMana(ability, payment, this, getXMana())); CostUtil.setInput(CostMana.inputPayXMana(ability, payment, this, this.getXMana()));
} else { } else {
payment.paidCost(this); payment.paidCost(this);
} }
@@ -234,30 +234,30 @@ public class CostMana extends CostPart {
* *
* @return a {@link forge.gui.input.Input} object. * @return a {@link forge.gui.input.Input} object.
*/ */
public static Input input_payXMana(final SpellAbility sa, final Cost_Payment payment, final CostMana costMana, public static Input inputPayXMana(final SpellAbility sa, final Cost_Payment payment, final CostMana costMana,
final int numX) { final int numX) {
Input payX = new Input() { final Input payX = new Input() {
private static final long serialVersionUID = -6900234444347364050L; private static final long serialVersionUID = -6900234444347364050L;
int xPaid = 0; private int xPaid = 0;
ManaCost manaCost = new ManaCost(Integer.toString(numX)); private ManaCost manaCost = new ManaCost(Integer.toString(numX));
@Override @Override
public void showMessage() { public void showMessage() {
if (manaCost.toString().equals(Integer.toString(numX))) { if (this.manaCost.toString().equals(Integer.toString(numX))) {
// only // only
// cancel // cancel
// if // if
// partially // partially
// paid // paid
// an X // an X
// value // value
ButtonUtil.enableAll(); ButtonUtil.enableAll();
} else { } else {
ButtonUtil.enableOnlyCancel(); ButtonUtil.enableOnlyCancel();
} }
AllZone.getDisplay().showMessage( AllZone.getDisplay().showMessage(
"Pay X Mana Cost for " + sa.getSourceCard().getName() + "\n" + xPaid + " Paid so far."); "Pay X Mana Cost for " + sa.getSourceCard().getName() + "\n" + this.xPaid + " Paid so far.");
} }
// selectCard // selectCard
@@ -268,28 +268,28 @@ public class CostMana extends CostPart {
return; return;
} }
manaCost = Input_PayManaCostUtil.activateManaAbility(sa, card, manaCost); this.manaCost = Input_PayManaCostUtil.activateManaAbility(sa, card, this.manaCost);
if (manaCost.isPaid()) { if (this.manaCost.isPaid()) {
manaCost = new ManaCost(Integer.toString(numX)); this.manaCost = new ManaCost(Integer.toString(numX));
xPaid++; this.xPaid++;
} }
if (AllZone.getInputControl().getInput() == this) { if (AllZone.getInputControl().getInput() == this) {
showMessage(); this.showMessage();
} }
} }
@Override @Override
public void selectButtonCancel() { public void selectButtonCancel() {
stop(); this.stop();
payment.cancelCost(); payment.cancelCost();
AllZone.getHumanPlayer().getZone(Zone.Battlefield).updateObservers(); AllZone.getHumanPlayer().getZone(Zone.Battlefield).updateObservers();
} }
@Override @Override
public void selectButtonOK() { public void selectButtonOK() {
stop(); this.stop();
payment.getCard().setXManaCostPaid(xPaid); payment.getCard().setXManaCostPaid(this.xPaid);
payment.paidCost(costMana); payment.paidCost(costMana);
} }
@@ -313,7 +313,7 @@ public class CostMana extends CostPart {
* a int. * a int.
* @return a {@link forge.gui.input.Input} object. * @return a {@link forge.gui.input.Input} object.
*/ */
public static Input input_payMana(final SpellAbility sa, final Cost_Payment payment, final CostMana costMana, public static Input inputPayMana(final SpellAbility sa, final Cost_Payment payment, final CostMana costMana,
final int manaToAdd) { final int manaToAdd) {
final ManaCost manaCost; final ManaCost manaCost;
@@ -321,7 +321,7 @@ public class CostMana extends CostPart {
if (sa.getSourceCard().isCopiedSpell() && sa.isSpell()) { if (sa.getSourceCard().isCopiedSpell() && sa.isSpell()) {
manaCost = new ManaCost("0"); manaCost = new ManaCost("0");
} else { } else {
String mana = costMana.getManaToPay(); final String mana = costMana.getManaToPay();
manaCost = new ManaCost(mana); manaCost = new ManaCost(mana);
manaCost.increaseColorlessMana(manaToAdd); manaCost.increaseColorlessMana(manaToAdd);
} }
@@ -330,7 +330,7 @@ public class CostMana extends CostPart {
manaCost = new ManaCost(sa.getManaCost()); manaCost = new ManaCost(sa.getManaCost());
} }
Input payMana = new Input() { final Input payMana = new Input() {
private ManaCost mana = manaCost; private ManaCost mana = manaCost;
private static final long serialVersionUID = 3467312982164195091L; private static final long serialVersionUID = 3467312982164195091L;
@@ -339,8 +339,8 @@ public class CostMana extends CostPart {
private int phyLifeToLose = 0; private int phyLifeToLose = 0;
private void resetManaCost() { private void resetManaCost() {
mana = new ManaCost(originalManaCost); this.mana = new ManaCost(this.originalManaCost);
phyLifeToLose = 0; this.phyLifeToLose = 0;
} }
@Override @Override
@@ -351,12 +351,12 @@ public class CostMana extends CostPart {
return; return;
} }
mana = Input_PayManaCostUtil.activateManaAbility(sa, card, mana); this.mana = Input_PayManaCostUtil.activateManaAbility(sa, card, this.mana);
if (mana.isPaid()) { if (this.mana.isPaid()) {
done(); this.done();
} else if (AllZone.getInputControl().getInput() == this) { } else if (AllZone.getInputControl().getInput() == this) {
showMessage(); this.showMessage();
} }
} }
@@ -364,36 +364,36 @@ public class CostMana extends CostPart {
public void selectPlayer(final Player player) { public void selectPlayer(final Player player) {
if (player.isHuman()) { if (player.isHuman()) {
if (manaCost.payPhyrexian()) { if (manaCost.payPhyrexian()) {
phyLifeToLose += 2; this.phyLifeToLose += 2;
} }
showMessage(); this.showMessage();
} }
} }
private void done() { private void done() {
Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
if (phyLifeToLose > 0) { if (this.phyLifeToLose > 0) {
AllZone.getHumanPlayer().payLife(phyLifeToLose, source); AllZone.getHumanPlayer().payLife(this.phyLifeToLose, source);
} }
source.setColorsPaid(mana.getColorsPaid()); source.setColorsPaid(this.mana.getColorsPaid());
source.setSunburstValue(mana.getSunburst()); source.setSunburstValue(this.mana.getSunburst());
resetManaCost(); this.resetManaCost();
stop(); this.stop();
if (costMana.hasNoXManaCost() || manaToAdd > 0) { if (costMana.hasNoXManaCost() || (manaToAdd > 0)) {
payment.paidCost(costMana); payment.paidCost(costMana);
} else { } else {
source.setXManaCostPaid(0); source.setXManaCostPaid(0);
CostUtil.setInput(CostMana.input_payXMana(sa, payment, costMana, costMana.getXMana())); CostUtil.setInput(CostMana.inputPayXMana(sa, payment, costMana, costMana.getXMana()));
} }
} }
@Override @Override
public void selectButtonCancel() { public void selectButtonCancel() {
stop(); this.stop();
resetManaCost(); this.resetManaCost();
payment.cancelCost(); payment.cancelCost();
AllZone.getHumanPlayer().getZone(Zone.Battlefield).updateObservers(); AllZone.getHumanPlayer().getZone(Zone.Battlefield).updateObservers();
} }
@@ -401,23 +401,23 @@ public class CostMana extends CostPart {
@Override @Override
public void showMessage() { public void showMessage() {
ButtonUtil.enableOnlyCancel(); ButtonUtil.enableOnlyCancel();
String displayMana = mana.toString().replace("X", "").trim(); final String displayMana = this.mana.toString().replace("X", "").trim();
AllZone.getDisplay().showMessage("Pay Mana Cost: " + displayMana); AllZone.getDisplay().showMessage("Pay Mana Cost: " + displayMana);
StringBuilder msg = new StringBuilder("Pay Mana Cost: " + displayMana); final StringBuilder msg = new StringBuilder("Pay Mana Cost: " + displayMana);
if (phyLifeToLose > 0) { if (this.phyLifeToLose > 0) {
msg.append(" ("); msg.append(" (");
msg.append(phyLifeToLose); msg.append(this.phyLifeToLose);
msg.append(" life paid for phyrexian mana)"); msg.append(" life paid for phyrexian mana)");
} }
if (mana.containsPhyrexianMana()) { if (this.mana.containsPhyrexianMana()) {
msg.append("\n(Click on your life total to pay life for phyrexian mana.)"); msg.append("\n(Click on your life total to pay life for phyrexian mana.)");
} }
AllZone.getDisplay().showMessage(msg.toString()); AllZone.getDisplay().showMessage(msg.toString());
if (mana.isPaid()) { if (this.mana.isPaid()) {
done(); this.done();
} }
} }
}; };

View File

@@ -27,7 +27,7 @@ public class CostMill extends CostPartWithList {
* the amount * the amount
*/ */
public CostMill(final String amount) { public CostMill(final String amount) {
this.amount = amount; this.setAmount(amount);
} }
/* /*
@@ -39,17 +39,17 @@ public class CostMill extends CostPartWithList {
*/ */
@Override @Override
public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) { public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) {
PlayerZone zone = activator.getZone(Constant.Zone.Library); final PlayerZone zone = activator.getZone(Constant.Zone.Library);
Integer i = convertAmount(); Integer i = this.convertAmount();
if (i == null) { if (i == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(this.getAmount());
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
return true; return true;
} }
i = AbilityFactory.calculateAmount(source, amount, ability); i = AbilityFactory.calculateAmount(source, this.getAmount(), ability);
} }
return i < zone.size(); return i < zone.size();
@@ -64,22 +64,22 @@ public class CostMill extends CostPartWithList {
*/ */
@Override @Override
public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) {
resetList(); this.resetList();
Integer c = convertAmount(); Integer c = this.convertAmount();
if (c == null) { if (c == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(this.getAmount());
// Generalize this // Generalize this
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
return false; return false;
} }
c = AbilityFactory.calculateAmount(source, amount, ability); c = AbilityFactory.calculateAmount(source, this.getAmount(), ability);
} }
list = AllZone.getComputerPlayer().getCardsIn(Zone.Library, c); this.list = AllZone.getComputerPlayer().getCardsIn(Zone.Library, c);
if (list == null || list.size() < c) { if ((this.list == null) || (this.list.size() < c)) {
return false; return false;
} }
@@ -94,8 +94,9 @@ public class CostMill extends CostPartWithList {
*/ */
@Override @Override
public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) {
for (Card c : list) for (final Card c : this.list) {
AllZone.getGameAction().moveToGraveyard(c); AllZone.getGameAction().moveToGraveyard(c);
}
} }
/* /*
@@ -107,40 +108,40 @@ public class CostMill extends CostPartWithList {
*/ */
@Override @Override
public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) {
String amount = getAmount(); final String amount = this.getAmount();
Integer c = convertAmount(); Integer c = this.convertAmount();
Player activator = ability.getActivatingPlayer(); final Player activator = ability.getActivatingPlayer();
if (c == null) { if (c == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(amount);
// Generalize this // Generalize this
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
c = CostUtil.chooseXValue(source, list.size()); c = CostUtil.chooseXValue(source, this.list.size());
} else { } else {
c = AbilityFactory.calculateAmount(source, amount, ability); c = AbilityFactory.calculateAmount(source, amount, ability);
} }
} }
CardList list = activator.getCardsIn(Zone.Library, c); final CardList list = activator.getCardsIn(Zone.Library, c);
if (list == null || list.size() > c) { if ((list == null) || (list.size() > c)) {
// I don't believe this is possible // I don't believe this is possible
payment.cancelCost(); payment.cancelCost();
return false; return false;
} }
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append("Mill ").append(c).append(" cards from your library?"); sb.append("Mill ").append(c).append(" cards from your library?");
boolean doMill = GameActionUtil.showYesNoDialog(source, sb.toString()); final boolean doMill = GameActionUtil.showYesNoDialog(source, sb.toString());
if (doMill) { if (doMill) {
resetList(); this.resetList();
Iterator<Card> itr = list.iterator(); final Iterator<Card> itr = list.iterator();
while (itr.hasNext()) { while (itr.hasNext()) {
Card card = (Card) itr.next(); final Card card = itr.next();
addToList(card); this.addToList(card);
AllZone.getGameAction().moveToGraveyard(card); AllZone.getGameAction().moveToGraveyard(card);
} }
addListToHash(ability, "Milled"); this.addListToHash(ability, "Milled");
payment.paidCost(this); payment.paidCost(this);
return false; return false;
} else { } else {
@@ -156,18 +157,18 @@ public class CostMill extends CostPartWithList {
*/ */
@Override @Override
public final String toString() { public final String toString() {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
Integer i = convertAmount(); final Integer i = this.convertAmount();
sb.append("Put the top "); sb.append("Put the top ");
if (i != null) { if (i != null) {
sb.append(i); sb.append(i);
} else { } else {
sb.append(amount); sb.append(this.getAmount());
} }
sb.append(" card"); sb.append(" card");
if (i == null || i > 1) { if ((i == null) || (i > 1)) {
sb.append("s"); sb.append("s");
} }
sb.append(" from the top of your library into your graveyard"); sb.append(" from the top of your library into your graveyard");

View File

@@ -10,25 +10,25 @@ import forge.card.spellability.SpellAbility;
public abstract class CostPart { public abstract class CostPart {
/** The is reusable. */ /** The is reusable. */
protected boolean isReusable = false; private boolean isReusable = false;
/** The is undoable. */ /** The is undoable. */
protected boolean isUndoable = false; private boolean isUndoable = false;
/** The optional. */ /** The optional. */
protected boolean optional = false; private boolean optional = false;
/** The optional type. */ /** The optional type. */
protected String optionalType = null; private String optionalType = null;
/** The amount. */ /** The amount. */
protected String amount = "1"; private String amount = "1";
/** The type. */ /** The type. */
protected String type = "Card"; private String type = "Card";
/** The type description. */ /** The type description. */
protected String typeDescription = null; private String typeDescription = null;
/** /**
* Instantiates a new cost part. * Instantiates a new cost part.
@@ -47,9 +47,9 @@ public abstract class CostPart {
* the description * the description
*/ */
public CostPart(final String amount, final String type, final String description) { public CostPart(final String amount, final String type, final String description) {
this.amount = amount; this.setAmount(amount);
this.type = type; this.setType(type);
this.typeDescription = description; this.setTypeDescription(description);
} }
/** /**
@@ -58,7 +58,7 @@ public abstract class CostPart {
* @return the amount * @return the amount
*/ */
public final String getAmount() { public final String getAmount() {
return amount; return this.amount;
} }
/** /**
@@ -67,7 +67,7 @@ public abstract class CostPart {
* @return the type * @return the type
*/ */
public final String getType() { public final String getType() {
return type; return this.type;
} }
/** /**
@@ -76,7 +76,7 @@ public abstract class CostPart {
* @return the this * @return the this
*/ */
public final boolean getThis() { public final boolean getThis() {
return type.equals("CARDNAME"); return this.getType().equals("CARDNAME");
} }
/** /**
@@ -85,7 +85,7 @@ public abstract class CostPart {
* @return the type description * @return the type description
*/ */
public final String getTypeDescription() { public final String getTypeDescription() {
return typeDescription; return this.typeDescription;
} }
/** /**
@@ -94,7 +94,7 @@ public abstract class CostPart {
* @return the descriptive type * @return the descriptive type
*/ */
public final String getDescriptiveType() { public final String getDescriptiveType() {
return typeDescription == null ? type : typeDescription; return this.getTypeDescription() == null ? this.getType() : this.getTypeDescription();
} }
/** /**
@@ -103,7 +103,7 @@ public abstract class CostPart {
* @return true, if is reusable * @return true, if is reusable
*/ */
public final boolean isReusable() { public final boolean isReusable() {
return isReusable; return this.isReusable;
} }
/** /**
@@ -112,7 +112,7 @@ public abstract class CostPart {
* @return true, if is undoable * @return true, if is undoable
*/ */
public final boolean isUndoable() { public final boolean isUndoable() {
return isUndoable; return this.isUndoable;
} }
/** /**
@@ -121,7 +121,7 @@ public abstract class CostPart {
* @return the optional type * @return the optional type
*/ */
public final String getOptionalType() { public final String getOptionalType() {
return optionalType; return this.optionalType;
} }
/** /**
@@ -142,8 +142,8 @@ public abstract class CostPart {
public final Integer convertAmount() { public final Integer convertAmount() {
Integer i = null; Integer i = null;
try { try {
i = Integer.parseInt(amount); i = Integer.parseInt(this.getAmount());
} catch (NumberFormatException e) { } catch (final NumberFormatException e) {
} }
return i; return i;
} }
@@ -206,6 +206,7 @@ public abstract class CostPart {
* *
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */
@Override
public abstract String toString(); public abstract String toString();
/** /**
@@ -215,4 +216,39 @@ public abstract class CostPart {
* the source * the source
*/ */
public abstract void refund(Card source); public abstract void refund(Card source);
/**
* @param isReusable the isReusable to set
*/
public void setReusable(boolean isReusable) {
this.isReusable = isReusable; // TODO: Add 0 to parameter's name.
}
/**
* @param amount the amount to set
*/
public void setAmount(String amount) {
this.amount = amount; // TODO: Add 0 to parameter's name.
}
/**
* @param type the type to set
*/
public void setType(String type) {
this.type = type; // TODO: Add 0 to parameter's name.
}
/**
* @param typeDescription the typeDescription to set
*/
public void setTypeDescription(String typeDescription) {
this.typeDescription = typeDescription; // TODO: Add 0 to parameter's name.
}
/**
* @param isUndoable the isUndoable to set
*/
public void setUndoable(boolean isUndoable) {
this.isUndoable = isUndoable; // TODO: Add 0 to parameter's name.
}
} }

View File

@@ -18,7 +18,7 @@ public abstract class CostPartWithList extends CostPart {
* @return the list * @return the list
*/ */
public final CardList getList() { public final CardList getList() {
return list; return this.list;
} }
/** /**
@@ -28,14 +28,14 @@ public abstract class CostPartWithList extends CostPart {
* the new list * the new list
*/ */
public final void setList(final CardList setList) { public final void setList(final CardList setList) {
list = setList; this.list = setList;
} }
/** /**
* Reset list. * Reset list.
*/ */
public final void resetList() { public final void resetList() {
list = new CardList(); this.list = new CardList();
} }
/** /**
@@ -45,10 +45,10 @@ public abstract class CostPartWithList extends CostPart {
* the c * the c
*/ */
public final void addToList(final Card c) { public final void addToList(final Card c) {
if (list == null) { if (this.list == null) {
resetList(); this.resetList();
} }
list.add(c); this.list.add(c);
} }
/** /**
@@ -60,7 +60,7 @@ public abstract class CostPartWithList extends CostPart {
* the hash * the hash
*/ */
public final void addListToHash(final SpellAbility sa, final String hash) { public final void addListToHash(final SpellAbility sa, final String hash) {
for (Card card : list) { for (final Card card : this.list) {
sa.addCostToHashList(card, hash); sa.addCostToHashList(card, hash);
} }
} }
@@ -83,6 +83,6 @@ public abstract class CostPartWithList extends CostPart {
*/ */
public CostPartWithList(final String amount, final String type, final String description) { public CostPartWithList(final String amount, final String type, final String description) {
super(amount, type, description); super(amount, type, description);
resetList(); this.resetList();
} }
} }

View File

@@ -19,7 +19,7 @@ public class CostPayLife extends CostPart {
* @return the last paid amount * @return the last paid amount
*/ */
public final int getLastPaidAmount() { public final int getLastPaidAmount() {
return lastPaidAmount; return this.lastPaidAmount;
} }
/** /**
@@ -29,7 +29,7 @@ public class CostPayLife extends CostPart {
* the new last paid amount * the new last paid amount
*/ */
public final void setLastPaidAmount(final int paidAmount) { public final void setLastPaidAmount(final int paidAmount) {
lastPaidAmount = paidAmount; this.lastPaidAmount = paidAmount;
} }
/** /**
@@ -39,7 +39,7 @@ public class CostPayLife extends CostPart {
* the amount * the amount
*/ */
public CostPayLife(final String amount) { public CostPayLife(final String amount) {
this.amount = amount; this.setAmount(amount);
} }
/* /*
@@ -49,8 +49,8 @@ public class CostPayLife extends CostPart {
*/ */
@Override @Override
public final String toString() { public final String toString() {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append("Pay ").append(amount).append(" Life"); sb.append("Pay ").append(this.getAmount()).append(" Life");
return sb.toString(); return sb.toString();
} }
@@ -62,7 +62,7 @@ public class CostPayLife extends CostPart {
@Override @Override
public final void refund(final Card source) { public final void refund(final Card source) {
// Really should be activating player // Really should be activating player
source.getController().payLife(lastPaidAmount * -1, null); source.getController().payLife(this.lastPaidAmount * -1, null);
} }
/* /*
@@ -74,8 +74,8 @@ public class CostPayLife extends CostPart {
*/ */
@Override @Override
public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) { public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) {
Integer amount = convertAmount(); final Integer amount = this.convertAmount();
if (amount != null && !activator.canPayLife(amount)) { if ((amount != null) && !activator.canPayLife(amount)) {
return false; return false;
} }
@@ -90,7 +90,7 @@ public class CostPayLife extends CostPart {
*/ */
@Override @Override
public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) {
AllZone.getComputerPlayer().payLife(getLastPaidAmount(), null); AllZone.getComputerPlayer().payLife(this.getLastPaidAmount(), null);
} }
/* /*
@@ -102,13 +102,13 @@ public class CostPayLife extends CostPart {
*/ */
@Override @Override
public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) {
String amount = getAmount(); final String amount = this.getAmount();
Player activator = ability.getActivatingPlayer(); final Player activator = ability.getActivatingPlayer();
int life = activator.getLife(); final int life = activator.getLife();
Integer c = convertAmount(); Integer c = this.convertAmount();
if (c == null) { if (c == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(amount);
// Generalize this // Generalize this
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
c = CostUtil.chooseXValue(source, life); c = CostUtil.chooseXValue(source, life);
@@ -117,12 +117,12 @@ public class CostPayLife extends CostPart {
} }
} }
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append(source.getName()).append(" - Pay ").append(c).append(" Life?"); sb.append(source.getName()).append(" - Pay ").append(c).append(" Life?");
if (GameActionUtil.showYesNoDialog(source, sb.toString()) && activator.canPayLife(c)) { if (GameActionUtil.showYesNoDialog(source, sb.toString()) && activator.canPayLife(c)) {
activator.payLife(c, null); activator.payLife(c, null);
setLastPaidAmount(c); this.setLastPaidAmount(c);
payment.setPaidManaPart(this, true); payment.setPaidManaPart(this, true);
} else { } else {
payment.setCancel(true); payment.setCancel(true);
@@ -141,23 +141,23 @@ public class CostPayLife extends CostPart {
*/ */
@Override @Override
public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) {
Player activator = ability.getActivatingPlayer(); final Player activator = ability.getActivatingPlayer();
Integer c = convertAmount(); Integer c = this.convertAmount();
if (c == null) { if (c == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(this.getAmount());
// Generalize this // Generalize this
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
return false; return false;
} else { } else {
c = AbilityFactory.calculateAmount(source, amount, ability); c = AbilityFactory.calculateAmount(source, this.getAmount(), ability);
} }
} }
if (!activator.canPayLife(c)) { if (!activator.canPayLife(c)) {
return false; return false;
} }
// activator.payLife(c, null); // activator.payLife(c, null);
setLastPaidAmount(c); this.setLastPaidAmount(c);
return true; return true;
} }
} }

View File

@@ -18,7 +18,7 @@ import forge.gui.input.Input;
*/ */
public class CostPutCounter extends CostPartWithList { public class CostPutCounter extends CostPartWithList {
// Put Counter doesn't really have a "Valid" portion of the cost // Put Counter doesn't really have a "Valid" portion of the cost
private Counters counter; private final Counters counter;
private int lastPaidAmount = 0; private int lastPaidAmount = 0;
/** /**
@@ -27,7 +27,7 @@ public class CostPutCounter extends CostPartWithList {
* @return the counter * @return the counter
*/ */
public final Counters getCounter() { public final Counters getCounter() {
return counter; return this.counter;
} }
/** /**
@@ -37,7 +37,7 @@ public class CostPutCounter extends CostPartWithList {
* the new last paid amount * the new last paid amount
*/ */
public final void setLastPaidAmount(final int paidAmount) { public final void setLastPaidAmount(final int paidAmount) {
lastPaidAmount = paidAmount; this.lastPaidAmount = paidAmount;
} }
/** /**
@@ -53,12 +53,12 @@ public class CostPutCounter extends CostPartWithList {
* the description * the description
*/ */
public CostPutCounter(final String amount, final Counters cntr, final String type, final String description) { public CostPutCounter(final String amount, final Counters cntr, final String type, final String description) {
isReusable = true; this.setReusable(true);
this.amount = amount; this.setAmount(amount);
this.counter = cntr; this.counter = cntr;
this.type = type; this.setType(type);
this.typeDescription = description; this.setTypeDescription(description);
} }
/* /*
@@ -68,19 +68,19 @@ public class CostPutCounter extends CostPartWithList {
*/ */
@Override @Override
public final String toString() { public final String toString() {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
if (counter.getName().equals("Loyalty")) { if (this.counter.getName().equals("Loyalty")) {
sb.append("+").append(amount); sb.append("+").append(this.getAmount());
} else { } else {
sb.append("Put "); sb.append("Put ");
Integer i = convertAmount(); final Integer i = this.convertAmount();
sb.append(Cost.convertAmountTypeToWords(i, amount, counter.getName() + " counter")); sb.append(Cost.convertAmountTypeToWords(i, this.getAmount(), this.counter.getName() + " counter"));
sb.append(" on "); sb.append(" on ");
if (getThis()) { if (this.getThis()) {
sb.append(type); sb.append(this.getType());
} else { } else {
String desc = typeDescription == null ? type : typeDescription; final String desc = this.getTypeDescription() == null ? this.getType() : this.getTypeDescription();
sb.append(desc); sb.append(desc);
} }
} }
@@ -94,8 +94,8 @@ public class CostPutCounter extends CostPartWithList {
*/ */
@Override @Override
public final void refund(final Card source) { public final void refund(final Card source) {
for (Card c : list) { for (final Card c : this.list) {
c.subtractCounter(counter, lastPaidAmount); c.subtractCounter(this.counter, this.lastPaidAmount);
} }
} }
@@ -108,17 +108,18 @@ public class CostPutCounter extends CostPartWithList {
*/ */
@Override @Override
public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) { public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) {
if (getThis()) { if (this.getThis()) {
if (source.hasKeyword("CARDNAME can't have counters placed on it.")) { if (source.hasKeyword("CARDNAME can't have counters placed on it.")) {
return false; return false;
} }
if (source.hasKeyword("CARDNAME can't have -1/-1 counters placed on it.") && counter.equals(Counters.M1M1)) { if (source.hasKeyword("CARDNAME can't have -1/-1 counters placed on it.")
&& this.counter.equals(Counters.M1M1)) {
return false; return false;
} }
} else { } else {
// 3 Cards have Put a -1/-1 Counter on a Creature you control. // 3 Cards have Put a -1/-1 Counter on a Creature you control.
CardList typeList = activator.getCardsIn(Zone.Battlefield).getValidCards(getType().split(";"), activator, final CardList typeList = activator.getCardsIn(Zone.Battlefield).getValidCards(this.getType().split(";"),
source); activator, source);
if (typeList.size() == 0) { if (typeList.size() == 0) {
return false; return false;
@@ -136,17 +137,17 @@ public class CostPutCounter extends CostPartWithList {
*/ */
@Override @Override
public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) {
Integer c = convertAmount(); Integer c = this.convertAmount();
if (c == null) { if (c == null) {
c = AbilityFactory.calculateAmount(source, amount, ability); c = AbilityFactory.calculateAmount(source, this.getAmount(), ability);
} }
if (getThis()) { if (this.getThis()) {
source.addCounterFromNonEffect(getCounter(), c); source.addCounterFromNonEffect(this.getCounter(), c);
} else { } else {
// Put counter on chosen card // Put counter on chosen card
for (Card card : list) { for (final Card card : this.list) {
card.addCounterFromNonEffect(getCounter(), 1); card.addCounterFromNonEffect(this.getCounter(), 1);
} }
} }
} }
@@ -160,18 +161,18 @@ public class CostPutCounter extends CostPartWithList {
*/ */
@Override @Override
public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) {
Integer c = convertAmount(); Integer c = this.convertAmount();
if (c == null) { if (c == null) {
c = AbilityFactory.calculateAmount(source, amount, ability); c = AbilityFactory.calculateAmount(source, this.getAmount(), ability);
} }
if (getThis()) { if (this.getThis()) {
source.addCounterFromNonEffect(getCounter(), c); source.addCounterFromNonEffect(this.getCounter(), c);
payment.setPaidManaPart(this, true); payment.setPaidManaPart(this, true);
addToList(source); this.addToList(source);
return true; return true;
} else { } else {
CostUtil.setInput(putCounterType(ability, getType(), payment, this, c)); CostUtil.setInput(CostPutCounter.putCounterType(ability, this.getType(), payment, this, c));
return false; return false;
} }
} }
@@ -185,27 +186,27 @@ public class CostPutCounter extends CostPartWithList {
*/ */
@Override @Override
public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) {
resetList(); this.resetList();
if (getThis()) { if (this.getThis()) {
addToList(source); this.addToList(source);
return true; return true;
} else { } else {
Player activator = ability.getActivatingPlayer(); final Player activator = ability.getActivatingPlayer();
Integer c = convertAmount(); Integer c = this.convertAmount();
if (c == null) { if (c == null) {
c = AbilityFactory.calculateAmount(source, amount, ability); c = AbilityFactory.calculateAmount(source, this.getAmount(), ability);
} }
CardList typeList = activator.getCardsIn(Zone.Battlefield).getValidCards(getType().split(";"), activator, final CardList typeList = activator.getCardsIn(Zone.Battlefield).getValidCards(this.getType().split(";"),
source); activator, source);
Card card = null; Card card = null;
if (type.equals("Creature.YouCtrl")) { if (this.getType().equals("Creature.YouCtrl")) {
card = CardFactoryUtil.getWorstCreatureAI(typeList); card = CardFactoryUtil.getWorstCreatureAI(typeList);
} else { } else {
card = CardFactoryUtil.getWorstPermanentAI(typeList, false, false, false, false); card = CardFactoryUtil.getWorstPermanentAI(typeList, false, false, false, false);
} }
addToList(card); this.addToList(card);
} }
return true; return true;
} }
@@ -229,19 +230,19 @@ public class CostPutCounter extends CostPartWithList {
*/ */
public static Input putCounterType(final SpellAbility sa, final String type, final Cost_Payment payment, public static Input putCounterType(final SpellAbility sa, final String type, final Cost_Payment payment,
final CostPutCounter costPutCounter, final int nNeeded) { final CostPutCounter costPutCounter, final int nNeeded) {
Input target = new Input() { final Input target = new Input() {
private static final long serialVersionUID = 2685832214519141903L; private static final long serialVersionUID = 2685832214519141903L;
private CardList typeList; private CardList typeList;
private int nPut = 0; private int nPut = 0;
@Override @Override
public void showMessage() { public void showMessage() {
if (nNeeded == 0 || nNeeded == nPut) { if ((nNeeded == 0) || (nNeeded == this.nPut)) {
done(); this.done();
} }
StringBuilder msg = new StringBuilder("Put "); final StringBuilder msg = new StringBuilder("Put ");
int nLeft = nNeeded - nPut; final int nLeft = nNeeded - this.nPut;
msg.append(nLeft).append(" "); msg.append(nLeft).append(" ");
msg.append(costPutCounter.getCounter()).append(" on "); msg.append(costPutCounter.getCounter()).append(" on ");
@@ -250,39 +251,40 @@ public class CostPutCounter extends CostPartWithList {
msg.append("s"); msg.append("s");
} }
typeList = sa.getActivatingPlayer().getCardsIn(Zone.Battlefield); this.typeList = sa.getActivatingPlayer().getCardsIn(Zone.Battlefield);
typeList = typeList.getValidCards(type.split(";"), sa.getActivatingPlayer(), sa.getSourceCard()); this.typeList = this.typeList.getValidCards(type.split(";"), sa.getActivatingPlayer(),
sa.getSourceCard());
AllZone.getDisplay().showMessage(msg.toString()); AllZone.getDisplay().showMessage(msg.toString());
ButtonUtil.enableOnlyCancel(); ButtonUtil.enableOnlyCancel();
} }
@Override @Override
public void selectButtonCancel() { public void selectButtonCancel() {
cancel(); this.cancel();
} }
@Override @Override
public void selectCard(final Card card, final PlayerZone zone) { public void selectCard(final Card card, final PlayerZone zone) {
if (typeList.contains(card)) { if (this.typeList.contains(card)) {
nPut++; this.nPut++;
costPutCounter.addToList(card); costPutCounter.addToList(card);
card.addCounterFromNonEffect(costPutCounter.getCounter(), 1); card.addCounterFromNonEffect(costPutCounter.getCounter(), 1);
if (nNeeded == nPut) { if (nNeeded == this.nPut) {
done(); this.done();
} else { } else {
showMessage(); this.showMessage();
} }
} }
} }
public void done() { public void done() {
stop(); this.stop();
payment.paidCost(costPutCounter); payment.paidCost(costPutCounter);
} }
public void cancel() { public void cancel() {
stop(); this.stop();
costPutCounter.addListToHash(sa, "CounterPut"); costPutCounter.addListToHash(sa, "CounterPut");
payment.cancelCost(); payment.cancelCost();
} }

View File

@@ -17,7 +17,7 @@ public class CostRemoveCounter extends CostPart {
// Counter is tough), // Counter is tough),
// Quillspike, Rift Elemental, Sage of Fables, Spike Rogue // Quillspike, Rift Elemental, Sage of Fables, Spike Rogue
private Counters counter; private final Counters counter;
private int lastPaidAmount = 0; private int lastPaidAmount = 0;
/** /**
@@ -26,7 +26,7 @@ public class CostRemoveCounter extends CostPart {
* @return the counter * @return the counter
*/ */
public final Counters getCounter() { public final Counters getCounter() {
return counter; return this.counter;
} }
/** /**
@@ -36,7 +36,7 @@ public class CostRemoveCounter extends CostPart {
* the new last paid amount * the new last paid amount
*/ */
public final void setLastPaidAmount(final int paidAmount) { public final void setLastPaidAmount(final int paidAmount) {
lastPaidAmount = paidAmount; this.lastPaidAmount = paidAmount;
} }
/** /**
@@ -53,7 +53,7 @@ public class CostRemoveCounter extends CostPart {
*/ */
public CostRemoveCounter(final String amount, final Counters counter, final String type, final String description) { public CostRemoveCounter(final String amount, final Counters counter, final String type, final String description) {
super(amount, type, description); super(amount, type, description);
isReusable = true; this.setReusable(true);
this.counter = counter; this.counter = counter;
} }
@@ -65,19 +65,19 @@ public class CostRemoveCounter extends CostPart {
*/ */
@Override @Override
public final String toString() { public final String toString() {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
if (counter.getName().equals("Loyalty")) { if (this.counter.getName().equals("Loyalty")) {
sb.append("-").append(amount); sb.append("-").append(this.getAmount());
} else { } else {
sb.append("Remove "); sb.append("Remove ");
Integer i = convertAmount(); final Integer i = this.convertAmount();
sb.append(Cost.convertAmountTypeToWords(i, amount, counter.getName() + " counter")); sb.append(Cost.convertAmountTypeToWords(i, this.getAmount(), this.counter.getName() + " counter"));
if (amount.equals("All")) { if (this.getAmount().equals("All")) {
sb.append("s"); sb.append("s");
} }
sb.append(" from ").append(typeDescription == null ? type : typeDescription); sb.append(" from ").append(this.getTypeDescription() == null ? this.getType() : this.getTypeDescription());
} }
return sb.toString(); return sb.toString();
} }
@@ -89,7 +89,7 @@ public class CostRemoveCounter extends CostPart {
*/ */
@Override @Override
public final void refund(final Card source) { public final void refund(final Card source) {
source.addCounterFromNonEffect(counter, lastPaidAmount); source.addCounterFromNonEffect(this.counter, this.lastPaidAmount);
} }
/* /*
@@ -101,10 +101,10 @@ public class CostRemoveCounter extends CostPart {
*/ */
@Override @Override
public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) { public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) {
Counters c = getCounter(); final Counters c = this.getCounter();
Integer amount = convertAmount(); final Integer amount = this.convertAmount();
if (amount != null && source.getCounters(c) - amount < 0) { if ((amount != null) && ((source.getCounters(c) - amount) < 0)) {
return false; return false;
} }
@@ -119,11 +119,11 @@ public class CostRemoveCounter extends CostPart {
*/ */
@Override @Override
public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) {
Integer c = convertAmount(); Integer c = this.convertAmount();
if (c == null) { if (c == null) {
c = AbilityFactory.calculateAmount(source, amount, ability); c = AbilityFactory.calculateAmount(source, this.getAmount(), ability);
} }
source.subtractCounter(getCounter(), c); source.subtractCounter(this.getCounter(), c);
} }
/* /*
@@ -135,16 +135,16 @@ public class CostRemoveCounter extends CostPart {
*/ */
@Override @Override
public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) {
String amount = getAmount(); final String amount = this.getAmount();
Counters type = getCounter(); final Counters type = this.getCounter();
Integer c = convertAmount(); Integer c = this.convertAmount();
int maxCounters = source.getCounters(type); final int maxCounters = source.getCounters(type);
if (amount.equals("All")) { if (amount.equals("All")) {
c = maxCounters; c = maxCounters;
} else { } else {
if (c == null) { if (c == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(amount);
// Generalize this // Generalize this
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
c = CostUtil.chooseXValue(source, maxCounters); c = CostUtil.chooseXValue(source, maxCounters);
@@ -157,7 +157,7 @@ public class CostRemoveCounter extends CostPart {
if (maxCounters >= c) { if (maxCounters >= c) {
source.setSVar("CostCountersRemoved", "Number$" + Integer.toString(c)); source.setSVar("CostCountersRemoved", "Number$" + Integer.toString(c));
source.subtractCounter(type, c); source.subtractCounter(type, c);
setLastPaidAmount(c); this.setLastPaidAmount(c);
payment.setPaidManaPart(this, true); payment.setPaidManaPart(this, true);
} else { } else {
payment.setCancel(true); payment.setCancel(true);
@@ -176,17 +176,17 @@ public class CostRemoveCounter extends CostPart {
*/ */
@Override @Override
public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) {
Integer c = convertAmount(); Integer c = this.convertAmount();
if (c == null) { if (c == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(this.getAmount());
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
return false; return false;
} }
c = AbilityFactory.calculateAmount(source, amount, ability); c = AbilityFactory.calculateAmount(source, this.getAmount(), ability);
} }
if (c > source.getCounters(getCounter())) { if (c > source.getCounters(this.getCounter())) {
System.out.println("Not enough " + getCounter() + " on " + source.getName()); System.out.println("Not enough " + this.getCounter() + " on " + source.getName());
return false; return false;
} }
return true; return true;

View File

@@ -42,23 +42,23 @@ public class CostReturn extends CostPartWithList {
*/ */
@Override @Override
public final String toString() { public final String toString() {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append("Return "); sb.append("Return ");
Integer i = convertAmount(); final Integer i = this.convertAmount();
String pronoun = "its"; String pronoun = "its";
if (getThis()) { if (this.getThis()) {
sb.append(type); sb.append(this.getType());
} else { } else {
String desc = typeDescription == null ? type : typeDescription; final String desc = this.getTypeDescription() == null ? this.getType() : this.getTypeDescription();
if (i != null) { if (i != null) {
sb.append(Cost.convertIntAndTypeToWords(i, desc)); sb.append(Cost.convertIntAndTypeToWords(i, desc));
if (i > 1) { if (i > 1) {
pronoun = "their"; pronoun = "their";
} }
} else { } else {
sb.append(Cost.convertAmountTypeToWords(amount, desc)); sb.append(Cost.convertAmountTypeToWords(this.getAmount(), desc));
} }
sb.append(" you control"); sb.append(" you control");
@@ -87,12 +87,12 @@ public class CostReturn extends CostPartWithList {
*/ */
@Override @Override
public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) { public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) {
if (!getThis()) { if (!this.getThis()) {
CardList typeList = activator.getCardsIn(Zone.Battlefield); CardList typeList = activator.getCardsIn(Zone.Battlefield);
typeList = typeList.getValidCards(getType().split(";"), activator, source); typeList = typeList.getValidCards(this.getType().split(";"), activator, source);
Integer amount = convertAmount(); final Integer amount = this.convertAmount();
if (amount != null && typeList.size() < amount) { if ((amount != null) && (typeList.size() < amount)) {
return false; return false;
} }
} else if (!AllZoneUtil.isCardInPlay(source)) { } else if (!AllZoneUtil.isCardInPlay(source)) {
@@ -110,8 +110,9 @@ public class CostReturn extends CostPartWithList {
*/ */
@Override @Override
public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) {
for (Card c : list) for (final Card c : this.list) {
AllZone.getGameAction().moveToHand(c); AllZone.getGameAction().moveToHand(c);
}
} }
/* /*
@@ -123,12 +124,12 @@ public class CostReturn extends CostPartWithList {
*/ */
@Override @Override
public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) {
String amount = getAmount(); final String amount = this.getAmount();
Integer c = convertAmount(); Integer c = this.convertAmount();
Player activator = ability.getActivatingPlayer(); final Player activator = ability.getActivatingPlayer();
CardList list = activator.getCardsIn(Zone.Battlefield); final CardList list = activator.getCardsIn(Zone.Battlefield);
if (c == null) { if (c == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(amount);
// Generalize this // Generalize this
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
c = CostUtil.chooseXValue(source, list.size()); c = CostUtil.chooseXValue(source, list.size());
@@ -136,10 +137,10 @@ public class CostReturn extends CostPartWithList {
c = AbilityFactory.calculateAmount(source, amount, ability); c = AbilityFactory.calculateAmount(source, amount, ability);
} }
} }
if (getThis()) { if (this.getThis()) {
CostUtil.setInput(CostReturn.returnThis(ability, payment, this)); CostUtil.setInput(CostReturn.returnThis(ability, payment, this));
} else { } else {
CostUtil.setInput(CostReturn.returnType(ability, getType(), payment, this, c)); CostUtil.setInput(CostReturn.returnType(ability, this.getType(), payment, this, c));
} }
return false; return false;
} }
@@ -153,17 +154,17 @@ public class CostReturn extends CostPartWithList {
*/ */
@Override @Override
public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) {
resetList(); this.resetList();
if (getThis()) { if (this.getThis()) {
list.add(source); this.list.add(source);
} else { } else {
Integer c = convertAmount(); Integer c = this.convertAmount();
if (c == null) { if (c == null) {
c = AbilityFactory.calculateAmount(source, amount, ability); c = AbilityFactory.calculateAmount(source, this.getAmount(), ability);
} }
list = ComputerUtil.chooseReturnType(getType(), source, ability.getTargetCard(), c); this.list = ComputerUtil.chooseReturnType(this.getType(), source, ability.getTargetCard(), c);
if (list == null) { if (this.list == null) {
return false; return false;
} }
} }
@@ -191,7 +192,7 @@ public class CostReturn extends CostPartWithList {
*/ */
public static Input returnType(final SpellAbility sa, final String type, final Cost_Payment payment, public static Input returnType(final SpellAbility sa, final String type, final Cost_Payment payment,
final CostReturn part, final int nNeeded) { final CostReturn part, final int nNeeded) {
Input target = new Input() { final Input target = new Input() {
private static final long serialVersionUID = 2685832214519141903L; private static final long serialVersionUID = 2685832214519141903L;
private CardList typeList; private CardList typeList;
private int nReturns = 0; private int nReturns = 0;
@@ -199,61 +200,62 @@ public class CostReturn extends CostPartWithList {
@Override @Override
public void showMessage() { public void showMessage() {
if (nNeeded == 0) { if (nNeeded == 0) {
done(); this.done();
} }
StringBuilder msg = new StringBuilder("Return "); final StringBuilder msg = new StringBuilder("Return ");
int nLeft = nNeeded - nReturns; final int nLeft = nNeeded - this.nReturns;
msg.append(nLeft).append(" "); msg.append(nLeft).append(" ");
msg.append(type); msg.append(type);
if (nLeft > 1) { if (nLeft > 1) {
msg.append("s"); msg.append("s");
} }
typeList = sa.getActivatingPlayer().getCardsIn(Zone.Battlefield); this.typeList = sa.getActivatingPlayer().getCardsIn(Zone.Battlefield);
typeList = typeList.getValidCards(type.split(";"), sa.getActivatingPlayer(), sa.getSourceCard()); this.typeList = this.typeList.getValidCards(type.split(";"), sa.getActivatingPlayer(),
sa.getSourceCard());
AllZone.getDisplay().showMessage(msg.toString()); AllZone.getDisplay().showMessage(msg.toString());
ButtonUtil.enableOnlyCancel(); ButtonUtil.enableOnlyCancel();
} }
@Override @Override
public void selectButtonCancel() { public void selectButtonCancel() {
cancel(); this.cancel();
} }
@Override @Override
public void selectCard(final Card card, final PlayerZone zone) { public void selectCard(final Card card, final PlayerZone zone) {
if (typeList.contains(card)) { if (this.typeList.contains(card)) {
nReturns++; this.nReturns++;
part.addToList(card); part.addToList(card);
AllZone.getGameAction().moveToHand(card); AllZone.getGameAction().moveToHand(card);
typeList.remove(card); this.typeList.remove(card);
// in case nothing else to return // in case nothing else to return
if (nReturns == nNeeded) { if (this.nReturns == nNeeded) {
done(); this.done();
} else if (typeList.size() == 0) { } else if (this.typeList.size() == 0) {
// happen // happen
cancel(); this.cancel();
} else { } else {
showMessage(); this.showMessage();
} }
} }
} }
public void done() { public void done() {
stop(); this.stop();
part.addListToHash(sa, "Returned"); part.addListToHash(sa, "Returned");
payment.paidCost(part); payment.paidCost(part);
} }
public void cancel() { public void cancel() {
stop(); this.stop();
payment.cancelCost(); payment.cancelCost();
} }
}; };
return target; return target;
}// returnType() } // returnType()
/** /**
* <p> * <p>
@@ -269,28 +271,28 @@ public class CostReturn extends CostPartWithList {
* @return a {@link forge.gui.input.Input} object. * @return a {@link forge.gui.input.Input} object.
*/ */
public static Input returnThis(final SpellAbility sa, final Cost_Payment payment, final CostReturn part) { public static Input returnThis(final SpellAbility sa, final Cost_Payment payment, final CostReturn part) {
Input target = new Input() { final Input target = new Input() {
private static final long serialVersionUID = 2685832214519141903L; private static final long serialVersionUID = 2685832214519141903L;
@Override @Override
public void showMessage() { public void showMessage() {
Card card = sa.getSourceCard(); final Card card = sa.getSourceCard();
if (card.getController().isHuman() && AllZoneUtil.isCardInPlay(card)) { if (card.getController().isHuman() && AllZoneUtil.isCardInPlay(card)) {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append(card.getName()); sb.append(card.getName());
sb.append(" - Return to Hand?"); sb.append(" - Return to Hand?");
Object[] possibleValues = { "Yes", "No" }; final Object[] possibleValues = { "Yes", "No" };
Object choice = JOptionPane.showOptionDialog(null, sb.toString(), card.getName() + " - Cost", final Object choice = JOptionPane.showOptionDialog(null, sb.toString(), card.getName() + " - Cost",
JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, possibleValues, JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, possibleValues,
possibleValues[0]); possibleValues[0]);
if (choice.equals(0)) { if (choice.equals(0)) {
part.addToList(card); part.addToList(card);
AllZone.getGameAction().moveToHand(card); AllZone.getGameAction().moveToHand(card);
stop(); this.stop();
part.addListToHash(sa, "Returned"); part.addListToHash(sa, "Returned");
payment.paidCost(part); payment.paidCost(part);
} else { } else {
stop(); this.stop();
payment.cancelCost(); payment.cancelCost();
} }
} }
@@ -298,5 +300,5 @@ public class CostReturn extends CostPartWithList {
}; };
return target; return target;
}// input_sacrifice() } // input_sacrifice()
} }

View File

@@ -42,19 +42,18 @@ public class CostReveal extends CostPartWithList {
* forge.Card, forge.Player, forge.card.cost.Cost) * forge.Card, forge.Player, forge.card.cost.Cost)
*/ */
@Override @Override
public final boolean canPay(final SpellAbility ability, public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) {
final Card source, final Player activator, final Cost cost) {
CardList handList = activator.getCardsIn(Zone.Hand); CardList handList = activator.getCardsIn(Zone.Hand);
String type = getType(); final String type = this.getType();
Integer amount = convertAmount(); final Integer amount = this.convertAmount();
if (getThis()) { if (this.getThis()) {
if (!AllZone.getZoneOf(source).is(Constant.Zone.Hand)) { if (!AllZone.getZoneOf(source).is(Constant.Zone.Hand)) {
return false; return false;
} }
} else { } else {
handList = handList.getValidCards(type.split(";"), activator, source); handList = handList.getValidCards(type.split(";"), activator, source);
if (amount != null && amount > handList.size()) { if ((amount != null) && (amount > handList.size())) {
// not enough cards in hand to pay // not enough cards in hand to pay
return false; return false;
} }
@@ -72,32 +71,32 @@ public class CostReveal extends CostPartWithList {
*/ */
@Override @Override
public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) {
String type = getType(); final String type = this.getType();
Player activator = ability.getActivatingPlayer(); final Player activator = ability.getActivatingPlayer();
CardList hand = activator.getCardsIn(Zone.Hand); CardList hand = activator.getCardsIn(Zone.Hand);
resetList(); this.resetList();
if (getThis()) { if (this.getThis()) {
if (!hand.contains(source)) { if (!hand.contains(source)) {
return false; return false;
} }
list.add(source); this.list.add(source);
} else { } else {
hand = hand.getValidCards(type.split(";"), activator, source); hand = hand.getValidCards(type.split(";"), activator, source);
Integer c = convertAmount(); Integer c = this.convertAmount();
if (c == null) { if (c == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(this.getAmount());
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
c = hand.size(); c = hand.size();
} else { } else {
c = AbilityFactory.calculateAmount(source, amount, ability); c = AbilityFactory.calculateAmount(source, this.getAmount(), ability);
} }
} }
list = ComputerUtil.discardNumTypeAI(c, type.split(";"), ability); this.list = ComputerUtil.discardNumTypeAI(c, type.split(";"), ability);
} }
return list != null; return this.list != null;
} }
/* /*
@@ -108,7 +107,7 @@ public class CostReveal extends CostPartWithList {
*/ */
@Override @Override
public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) {
GuiUtils.getChoiceOptional("Revealed cards:", list.toArray()); GuiUtils.getChoiceOptional("Revealed cards:", this.list.toArray());
} }
/* /*
@@ -120,21 +119,21 @@ public class CostReveal extends CostPartWithList {
*/ */
@Override @Override
public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) {
Player activator = ability.getActivatingPlayer(); final Player activator = ability.getActivatingPlayer();
String amount = getAmount(); final String amount = this.getAmount();
resetList(); this.resetList();
if (getThis()) { if (this.getThis()) {
addToList(source); this.addToList(source);
payment.setPaidManaPart(this, true); payment.setPaidManaPart(this, true);
} else { } else {
Integer c = convertAmount(); Integer c = this.convertAmount();
CardList handList = activator.getCardsIn(Zone.Hand); CardList handList = activator.getCardsIn(Zone.Hand);
handList = handList.getValidCards(type.split(";"), activator, ability.getSourceCard()); handList = handList.getValidCards(this.getType().split(";"), activator, ability.getSourceCard());
if (c == null) { if (c == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(amount);
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
c = CostUtil.chooseXValue(source, handList.size()); c = CostUtil.chooseXValue(source, handList.size());
} else { } else {
@@ -142,10 +141,10 @@ public class CostReveal extends CostPartWithList {
} }
} }
CostUtil.setInput(inputRevealCost(type, handList, payment, this, ability, c)); CostUtil.setInput(CostReveal.inputRevealCost(this.getType(), handList, payment, this, ability, c));
return false; return false;
} }
addListToHash(ability, "Revealed"); this.addListToHash(ability, "Revealed");
return true; return true;
} }
@@ -156,23 +155,23 @@ public class CostReveal extends CostPartWithList {
*/ */
@Override @Override
public final String toString() { public final String toString() {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append("Reveal "); sb.append("Reveal ");
Integer i = convertAmount(); final Integer i = this.convertAmount();
if (getThis()) { if (this.getThis()) {
sb.append(type); sb.append(this.getType());
} else { } else {
StringBuilder desc = new StringBuilder(); final StringBuilder desc = new StringBuilder();
if (type.equals("Card")) { if (this.getType().equals("Card")) {
desc.append("Card"); desc.append("Card");
} else { } else {
desc.append(typeDescription == null ? type : typeDescription).append(" card"); desc.append(this.getTypeDescription() == null ? this.getType() : this.getTypeDescription()).append(" card");
} }
sb.append(Cost.convertAmountTypeToWords(i, amount, desc.toString())); sb.append(Cost.convertAmountTypeToWords(i, this.getAmount(), desc.toString()));
} }
sb.append(" from your hand"); sb.append(" from your hand");
@@ -212,7 +211,7 @@ public class CostReveal extends CostPartWithList {
*/ */
public static Input inputRevealCost(final String discType, final CardList handList, final Cost_Payment payment, public static Input inputRevealCost(final String discType, final CardList handList, final Cost_Payment payment,
final CostReveal part, final SpellAbility sa, final int nNeeded) { final CostReveal part, final SpellAbility sa, final int nNeeded) {
Input target = new Input() { final Input target = new Input() {
private static final long serialVersionUID = -329993322080934435L; private static final long serialVersionUID = -329993322080934435L;
private int nReveal = 0; private int nReveal = 0;
@@ -220,23 +219,23 @@ public class CostReveal extends CostPartWithList {
@Override @Override
public void showMessage() { public void showMessage() {
if (nNeeded == 0) { if (nNeeded == 0) {
done(); this.done();
} }
if (AllZone.getHumanPlayer().getZone(Zone.Hand).size() < nNeeded) { if (AllZone.getHumanPlayer().getZone(Zone.Hand).size() < nNeeded) {
stop(); this.stop();
} }
StringBuilder type = new StringBuilder(""); final StringBuilder type = new StringBuilder("");
if (!discType.equals("Card")) { if (!discType.equals("Card")) {
type.append(" ").append(discType); type.append(" ").append(discType);
} }
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append("Select a "); sb.append("Select a ");
sb.append(part.getDescriptiveType()); sb.append(part.getDescriptiveType());
sb.append(" to reveal."); sb.append(" to reveal.");
if (nNeeded > 1) { if (nNeeded > 1) {
sb.append(" You have "); sb.append(" You have ");
sb.append(nNeeded - nReveal); sb.append(nNeeded - this.nReveal);
sb.append(" remaining."); sb.append(" remaining.");
} }
AllZone.getDisplay().showMessage(sb.toString()); AllZone.getDisplay().showMessage(sb.toString());
@@ -245,7 +244,7 @@ public class CostReveal extends CostPartWithList {
@Override @Override
public void selectButtonCancel() { public void selectButtonCancel() {
cancel(); this.cancel();
} }
@Override @Override
@@ -254,29 +253,29 @@ public class CostReveal extends CostPartWithList {
// send in CardList for Typing // send in CardList for Typing
handList.remove(card); handList.remove(card);
part.addToList(card); part.addToList(card);
nReveal++; this.nReveal++;
// in case no more cards in hand // in case no more cards in hand
if (nReveal == nNeeded) { if (this.nReveal == nNeeded) {
done(); this.done();
} else if (AllZone.getHumanPlayer().getZone(Zone.Hand).size() == 0) { } else if (AllZone.getHumanPlayer().getZone(Zone.Hand).size() == 0) {
// really // really
// shouldn't // shouldn't
// happen // happen
cancel(); this.cancel();
} else { } else {
showMessage(); this.showMessage();
} }
} }
} }
public void cancel() { public void cancel() {
stop(); this.stop();
payment.cancelCost(); payment.cancelCost();
} }
public void done() { public void done() {
stop(); this.stop();
// "Inform" AI of the revealed cards // "Inform" AI of the revealed cards
part.addListToHash(sa, "Revealed"); part.addListToHash(sa, "Revealed");
payment.paidCost(part); payment.paidCost(part);

View File

@@ -41,19 +41,19 @@ public class CostSacrifice extends CostPartWithList {
*/ */
@Override @Override
public final String toString() { public final String toString() {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append("Sacrifice "); sb.append("Sacrifice ");
Integer i = convertAmount(); final Integer i = this.convertAmount();
if (getThis()) { if (this.getThis()) {
sb.append(type); sb.append(this.getType());
} else { } else {
String desc = typeDescription == null ? type : typeDescription; final String desc = this.getTypeDescription() == null ? this.getType() : this.getTypeDescription();
if (i != null) { if (i != null) {
sb.append(Cost.convertIntAndTypeToWords(i, desc)); sb.append(Cost.convertIntAndTypeToWords(i, desc));
} else { } else {
sb.append(Cost.convertAmountTypeToWords(amount, desc)); sb.append(Cost.convertAmountTypeToWords(this.getAmount(), desc));
} }
} }
return sb.toString(); return sb.toString();
@@ -80,13 +80,13 @@ public class CostSacrifice extends CostPartWithList {
@Override @Override
public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) { public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) {
// You can always sac all // You can always sac all
if (!getThis()) { if (!this.getThis()) {
CardList typeList = activator.getCardsIn(Zone.Battlefield); CardList typeList = activator.getCardsIn(Zone.Battlefield);
typeList = typeList.getValidCards(getType().split(";"), activator, source); typeList = typeList.getValidCards(this.getType().split(";"), activator, source);
Integer amount = convertAmount(); final Integer amount = this.convertAmount();
if (amount != null && typeList.size() < amount) { if ((amount != null) && (typeList.size() < amount)) {
return false; return false;
} }
@@ -108,8 +108,9 @@ public class CostSacrifice extends CostPartWithList {
*/ */
@Override @Override
public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) {
for (Card c : list) for (final Card c : this.list) {
AllZone.getGameAction().sacrifice(c); AllZone.getGameAction().sacrifice(c);
}
} }
/* /*
@@ -121,23 +122,23 @@ public class CostSacrifice extends CostPartWithList {
*/ */
@Override @Override
public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) {
String amount = getAmount(); final String amount = this.getAmount();
String type = getType(); final String type = this.getType();
Player activator = ability.getActivatingPlayer(); final Player activator = ability.getActivatingPlayer();
CardList list = activator.getCardsIn(Zone.Battlefield); CardList list = activator.getCardsIn(Zone.Battlefield);
list = list.getValidCards(type.split(";"), activator, source); list = list.getValidCards(type.split(";"), activator, source);
if (getThis()) { if (this.getThis()) {
CostUtil.setInput(CostSacrifice.sacrificeThis(ability, payment, this)); CostUtil.setInput(CostSacrifice.sacrificeThis(ability, payment, this));
} else if (amount.equals("All")) { } else if (amount.equals("All")) {
this.list = list; this.list = list;
CostSacrifice.sacrificeAll(ability, payment, this, list); CostSacrifice.sacrificeAll(ability, payment, this, list);
addListToHash(ability, "Sacrificed"); this.addListToHash(ability, "Sacrificed");
return true; return true;
} else { } else {
Integer c = convertAmount(); Integer c = this.convertAmount();
if (c == null) { if (c == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(amount);
// Generalize this // Generalize this
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
c = CostUtil.chooseXValue(source, list.size()); c = CostUtil.chooseXValue(source, list.size());
@@ -161,26 +162,26 @@ public class CostSacrifice extends CostPartWithList {
*/ */
@Override @Override
public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) {
resetList(); this.resetList();
Player activator = ability.getActivatingPlayer(); final Player activator = ability.getActivatingPlayer();
if (getThis()) { if (this.getThis()) {
list.add(source); this.list.add(source);
} else if (amount.equals("All")) { } else if (this.getAmount().equals("All")) {
CardList typeList = activator.getCardsIn(Zone.Battlefield); CardList typeList = activator.getCardsIn(Zone.Battlefield);
typeList = typeList.getValidCards(type.split(","), activator, source); typeList = typeList.getValidCards(this.getType().split(","), activator, source);
// Does the AI want to use Sacrifice All? // Does the AI want to use Sacrifice All?
return false; return false;
} else { } else {
Integer c = convertAmount(); Integer c = this.convertAmount();
if (c == null) { if (c == null) {
if (source.getSVar(amount).equals("XChoice")) { if (source.getSVar(this.getAmount()).equals("XChoice")) {
return false; return false;
} }
c = AbilityFactory.calculateAmount(source, amount, ability); c = AbilityFactory.calculateAmount(source, this.getAmount(), ability);
} }
list = ComputerUtil.chooseSacrificeType(type, source, ability.getTargetCard(), c); this.list = ComputerUtil.chooseSacrificeType(this.getType(), source, ability.getTargetCard(), c);
if (list == null) { if (this.list == null) {
return false; return false;
} }
} }
@@ -203,9 +204,10 @@ public class CostSacrifice extends CostPartWithList {
* @param typeList * @param typeList
* TODO * TODO
*/ */
public static void sacrificeAll(final SpellAbility sa, final Cost_Payment payment, final CostPart part, final CardList typeList) { public static void sacrificeAll(final SpellAbility sa, final Cost_Payment payment, final CostPart part,
final CardList typeList) {
// TODO Ask First // TODO Ask First
for (Card card : typeList) { for (final Card card : typeList) {
payment.getAbility().addCostToHashList(card, "Sacrificed"); payment.getAbility().addCostToHashList(card, "Sacrificed");
AllZone.getGameAction().sacrifice(card); AllZone.getGameAction().sacrifice(card);
} }
@@ -232,18 +234,18 @@ public class CostSacrifice extends CostPartWithList {
*/ */
public static Input sacrificeFromList(final SpellAbility sa, final Cost_Payment payment, final CostSacrifice part, public static Input sacrificeFromList(final SpellAbility sa, final Cost_Payment payment, final CostSacrifice part,
final CardList typeList, final int nNeeded) { final CardList typeList, final int nNeeded) {
Input target = new Input() { final Input target = new Input() {
private static final long serialVersionUID = 2685832214519141903L; private static final long serialVersionUID = 2685832214519141903L;
private int nSacrifices = 0; private int nSacrifices = 0;
@Override @Override
public void showMessage() { public void showMessage() {
if (nNeeded == 0) { if (nNeeded == 0) {
done(); this.done();
} }
StringBuilder msg = new StringBuilder("Sacrifice "); final StringBuilder msg = new StringBuilder("Sacrifice ");
int nLeft = nNeeded - nSacrifices; final int nLeft = nNeeded - this.nSacrifices;
msg.append(nLeft).append(" "); msg.append(nLeft).append(" ");
msg.append(part.getDescriptiveType()); msg.append(part.getDescriptiveType());
if (nLeft > 1) { if (nLeft > 1) {
@@ -256,43 +258,43 @@ public class CostSacrifice extends CostPartWithList {
@Override @Override
public void selectButtonCancel() { public void selectButtonCancel() {
cancel(); this.cancel();
} }
@Override @Override
public void selectCard(final Card card, final PlayerZone zone) { public void selectCard(final Card card, final PlayerZone zone) {
if (typeList.contains(card)) { if (typeList.contains(card)) {
nSacrifices++; this.nSacrifices++;
part.addToList(card); part.addToList(card);
AllZone.getGameAction().sacrifice(card); AllZone.getGameAction().sacrifice(card);
typeList.remove(card); typeList.remove(card);
// in case nothing else to sacrifice // in case nothing else to sacrifice
if (nSacrifices == nNeeded) { if (this.nSacrifices == nNeeded) {
done(); this.done();
} else if (typeList.size() == 0) { } else if (typeList.size() == 0) {
// happen // happen
cancel(); this.cancel();
} else { } else {
showMessage(); this.showMessage();
} }
} }
} }
public void done() { public void done() {
stop(); this.stop();
part.addListToHash(sa, "Sacrificed"); part.addListToHash(sa, "Sacrificed");
payment.paidCost(part); payment.paidCost(part);
} }
public void cancel() { public void cancel() {
stop(); this.stop();
payment.cancelCost(); payment.cancelCost();
} }
}; };
return target; return target;
}// sacrificeType() } // sacrificeType()
/** /**
* <p> * <p>
@@ -308,28 +310,28 @@ public class CostSacrifice extends CostPartWithList {
* @return a {@link forge.gui.input.Input} object. * @return a {@link forge.gui.input.Input} object.
*/ */
public static Input sacrificeThis(final SpellAbility sa, final Cost_Payment payment, final CostSacrifice part) { public static Input sacrificeThis(final SpellAbility sa, final Cost_Payment payment, final CostSacrifice part) {
Input target = new Input() { final Input target = new Input() {
private static final long serialVersionUID = 2685832214519141903L; private static final long serialVersionUID = 2685832214519141903L;
@Override @Override
public void showMessage() { public void showMessage() {
Card card = sa.getSourceCard(); final Card card = sa.getSourceCard();
if (card.getController().isHuman() && AllZoneUtil.isCardInPlay(card)) { if (card.getController().isHuman() && AllZoneUtil.isCardInPlay(card)) {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append(card.getName()); sb.append(card.getName());
sb.append(" - Sacrifice?"); sb.append(" - Sacrifice?");
Object[] possibleValues = { "Yes", "No" }; final Object[] possibleValues = { "Yes", "No" };
Object choice = JOptionPane.showOptionDialog(null, sb.toString(), card.getName() + " - Cost", final Object choice = JOptionPane.showOptionDialog(null, sb.toString(), card.getName() + " - Cost",
JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, possibleValues, JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, possibleValues,
possibleValues[0]); possibleValues[0]);
if (choice.equals(0)) { if (choice.equals(0)) {
part.addToList(card); part.addToList(card);
part.addListToHash(sa, "Sacrificed"); part.addListToHash(sa, "Sacrificed");
AllZone.getGameAction().sacrifice(card); AllZone.getGameAction().sacrifice(card);
stop(); this.stop();
payment.paidCost(part); payment.paidCost(part);
} else { } else {
stop(); this.stop();
payment.cancelCost(); payment.cancelCost();
} }
} }
@@ -337,5 +339,5 @@ public class CostSacrifice extends CostPartWithList {
}; };
return target; return target;
}// input_sacrifice() } // input_sacrifice()
} }

View File

@@ -13,8 +13,8 @@ public class CostTap extends CostPart {
* Instantiates a new cost tap. * Instantiates a new cost tap.
*/ */
public CostTap() { public CostTap() {
isReusable = true; this.setReusable(true);
isUndoable = true; this.setUndoable(true);
} }
/* /*

View File

@@ -31,7 +31,7 @@ public class CostTapType extends CostPartWithList {
*/ */
public CostTapType(final String amount, final String type, final String description) { public CostTapType(final String amount, final String type, final String description) {
super(amount, type, description); super(amount, type, description);
isReusable = true; this.setReusable(true);
} }
/** /**
@@ -40,7 +40,7 @@ public class CostTapType extends CostPartWithList {
* @return the description * @return the description
*/ */
public final String getDescription() { public final String getDescription() {
return typeDescription == null ? type : typeDescription; return this.getTypeDescription() == null ? this.getType() : this.getTypeDescription();
} }
/* /*
@@ -50,13 +50,13 @@ public class CostTapType extends CostPartWithList {
*/ */
@Override @Override
public final String toString() { public final String toString() {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append("Tap "); sb.append("Tap ");
Integer i = convertAmount(); final Integer i = this.convertAmount();
String desc = getDescription(); final String desc = this.getDescription();
sb.append(Cost.convertAmountTypeToWords(i, amount, "untapped " + desc)); sb.append(Cost.convertAmountTypeToWords(i, this.getAmount(), "untapped " + desc));
sb.append(" you control"); sb.append(" you control");
@@ -70,7 +70,7 @@ public class CostTapType extends CostPartWithList {
* the c * the c
*/ */
public final void addToTappedList(final Card c) { public final void addToTappedList(final Card c) {
list.add(c); this.list.add(c);
} }
/* /*
@@ -80,11 +80,11 @@ public class CostTapType extends CostPartWithList {
*/ */
@Override @Override
public final void refund(final Card source) { public final void refund(final Card source) {
for (Card c : list) { for (final Card c : this.list) {
c.untap(); c.untap();
} }
list.clear(); this.list.clear();
} }
/* /*
@@ -98,15 +98,15 @@ public class CostTapType extends CostPartWithList {
public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) { public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) {
CardList typeList = activator.getCardsIn(Zone.Battlefield); CardList typeList = activator.getCardsIn(Zone.Battlefield);
typeList = typeList.getValidCards(getType().split(";"), activator, source); typeList = typeList.getValidCards(this.getType().split(";"), activator, source);
if (cost.getTap()) { if (cost.getTap()) {
typeList.remove(source); typeList.remove(source);
} }
typeList = typeList.filter(CardListFilter.UNTAPPED); typeList = typeList.filter(CardListFilter.UNTAPPED);
Integer amount = convertAmount(); final Integer amount = this.convertAmount();
if (typeList.size() == 0 || (amount != null && typeList.size() < amount)) { if ((typeList.size() == 0) || ((amount != null) && (typeList.size() < amount))) {
return false; return false;
} }
@@ -121,8 +121,9 @@ public class CostTapType extends CostPartWithList {
*/ */
@Override @Override
public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final void payAI(final SpellAbility ability, final Card source, final Cost_Payment payment) {
for (Card c : list) for (final Card c : this.list) {
c.tap(); c.tap();
}
} }
/* /*
@@ -135,12 +136,13 @@ public class CostTapType extends CostPartWithList {
@Override @Override
public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) {
CardList typeList = ability.getActivatingPlayer().getCardsIn(Zone.Battlefield); CardList typeList = ability.getActivatingPlayer().getCardsIn(Zone.Battlefield);
typeList = typeList.getValidCards(getType().split(";"), ability.getActivatingPlayer(), ability.getSourceCard()); typeList = typeList.getValidCards(this.getType().split(";"), ability.getActivatingPlayer(),
ability.getSourceCard());
typeList = typeList.filter(CardListFilter.UNTAPPED); typeList = typeList.filter(CardListFilter.UNTAPPED);
String amount = getAmount(); final String amount = this.getAmount();
Integer c = convertAmount(); Integer c = this.convertAmount();
if (c == null) { if (c == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(amount);
// Generalize this // Generalize this
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
c = CostUtil.chooseXValue(source, typeList.size()); c = CostUtil.chooseXValue(source, typeList.size());
@@ -149,7 +151,7 @@ public class CostTapType extends CostPartWithList {
} }
} }
CostUtil.setInput(CostTapType.input_tapXCost(this, typeList, ability, payment, c)); CostUtil.setInput(CostTapType.inputTapXCost(this, typeList, ability, payment, c));
return false; return false;
} }
@@ -162,15 +164,15 @@ public class CostTapType extends CostPartWithList {
*/ */
@Override @Override
public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) { public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) {
boolean tap = payment.getCost().getTap(); final boolean tap = payment.getCost().getTap();
Integer c = convertAmount(); final Integer c = this.convertAmount();
if (c == null) { if (c == null) {
// Determine Amount // Determine Amount
} }
list = ComputerUtil.chooseTapType(getType(), source, tap, c); this.list = ComputerUtil.chooseTapType(this.getType(), source, tap, c);
if (list == null) { if (this.list == null) {
System.out.println("Couldn't find a valid card to tap for: " + source.getName()); System.out.println("Couldn't find a valid card to tap for: " + source.getName());
return false; return false;
} }
@@ -197,24 +199,24 @@ public class CostTapType extends CostPartWithList {
* a int. * a int.
* @return a {@link forge.gui.input.Input} object. * @return a {@link forge.gui.input.Input} object.
*/ */
public static Input input_tapXCost(final CostTapType tapType, final CardList cardList, final SpellAbility sa, public static Input inputTapXCost(final CostTapType tapType, final CardList cardList, final SpellAbility sa,
final Cost_Payment payment, final int nCards) { final Cost_Payment payment, final int nCards) {
Input target = new Input() { final Input target = new Input() {
private static final long serialVersionUID = 6438988130447851042L; private static final long serialVersionUID = 6438988130447851042L;
int nTapped = 0; private int nTapped = 0;
@Override @Override
public void showMessage() { public void showMessage() {
if (nCards == 0) { if (nCards == 0) {
done(); this.done();
} }
if (cardList.size() == 0) { if (cardList.size() == 0) {
stop(); this.stop();
} }
int left = nCards - nTapped; final int left = nCards - this.nTapped;
AllZone.getDisplay() AllZone.getDisplay()
.showMessage("Select a " + tapType.getDescription() + " to tap (" + left + " left)"); .showMessage("Select a " + tapType.getDescription() + " to tap (" + left + " left)");
ButtonUtil.enableOnlyCancel(); ButtonUtil.enableOnlyCancel();
@@ -222,7 +224,7 @@ public class CostTapType extends CostPartWithList {
@Override @Override
public void selectButtonCancel() { public void selectButtonCancel() {
cancel(); this.cancel();
} }
@Override @Override
@@ -233,31 +235,31 @@ public class CostTapType extends CostPartWithList {
tapType.addToList(card); tapType.addToList(card);
cardList.remove(card); cardList.remove(card);
nTapped++; this.nTapped++;
if (nTapped == nCards) { if (this.nTapped == nCards) {
done(); this.done();
} else if (cardList.size() == 0) { } else if (cardList.size() == 0) {
// happen // happen
cancel(); this.cancel();
} else { } else {
showMessage(); this.showMessage();
} }
} }
} }
public void cancel() { public void cancel() {
stop(); this.stop();
payment.cancelCost(); payment.cancelCost();
} }
public void done() { public void done() {
stop(); this.stop();
tapType.addListToHash(sa, "Tapped"); tapType.addListToHash(sa, "Tapped");
payment.paidCost(tapType); payment.paidCost(tapType);
} }
}; };
return target; return target;
}// input_tapXCost() } // input_tapXCost()
} }

View File

@@ -13,8 +13,8 @@ public class CostUntap extends CostPart {
* Instantiates a new cost untap. * Instantiates a new cost untap.
*/ */
public CostUntap() { public CostUntap() {
isReusable = true; this.setReusable(true);
isUndoable = true; this.setUndoable(true);
} }
/* /*

View File

@@ -18,8 +18,8 @@ import forge.gui.input.Input;
*/ */
public class CostUtil { public class CostUtil {
private static Random r = new Random(); private static Random r = new Random();
private static double P1P1Percent = .25; private static double p1p1Percent = .25;
private static double OtherPercent = .9; private static double otherPercent = .9;
/** /**
* Check sacrifice cost. * Check sacrifice cost.
@@ -31,11 +31,11 @@ public class CostUtil {
* @return true, if successful * @return true, if successful
*/ */
public static boolean checkSacrificeCost(final Cost cost, final Card source) { public static boolean checkSacrificeCost(final Cost cost, final Card source) {
for (CostPart part : cost.getCostParts()) { for (final CostPart part : cost.getCostParts()) {
if (part instanceof CostSacrifice) { if (part instanceof CostSacrifice) {
CostSacrifice sac = (CostSacrifice) part; final CostSacrifice sac = (CostSacrifice) part;
String type = sac.getType(); final String type = sac.getType();
if (type.equals("CARDNAME")) { if (type.equals("CARDNAME")) {
continue; continue;
@@ -61,9 +61,9 @@ public class CostUtil {
* @return true, if successful * @return true, if successful
*/ */
public static boolean checkCreatureSacrificeCost(final Cost cost, final Card source) { public static boolean checkCreatureSacrificeCost(final Cost cost, final Card source) {
for (CostPart part : cost.getCostParts()) { for (final CostPart part : cost.getCostParts()) {
if (part instanceof CostSacrifice) { if (part instanceof CostSacrifice) {
CostSacrifice sac = (CostSacrifice) part; final CostSacrifice sac = (CostSacrifice) part;
if (sac.getThis() && source.isCreature()) { if (sac.getThis() && source.isCreature()) {
return false; return false;
} }
@@ -84,10 +84,10 @@ public class CostUtil {
* @return true, if successful * @return true, if successful
*/ */
public static boolean checkLifeCost(final Cost cost, final Card source, final int remainingLife) { public static boolean checkLifeCost(final Cost cost, final Card source, final int remainingLife) {
for (CostPart part : cost.getCostParts()) { for (final CostPart part : cost.getCostParts()) {
if (part instanceof CostPayLife) { if (part instanceof CostPayLife) {
CostPayLife payLife = (CostPayLife) part; final CostPayLife payLife = (CostPayLife) part;
if (AllZone.getComputerPlayer().getLife() - payLife.convertAmount() < remainingLife) { if ((AllZone.getComputerPlayer().getLife() - payLife.convertAmount()) < remainingLife) {
return false; return false;
} }
} }
@@ -105,11 +105,11 @@ public class CostUtil {
* @return true, if successful * @return true, if successful
*/ */
public static boolean checkDiscardCost(final Cost cost, final Card source) { public static boolean checkDiscardCost(final Cost cost, final Card source) {
for (CostPart part : cost.getCostParts()) { for (final CostPart part : cost.getCostParts()) {
if (part instanceof CostDiscard) { if (part instanceof CostDiscard) {
CostDiscard disc = (CostDiscard) part; final CostDiscard disc = (CostDiscard) part;
String type = disc.getType(); final String type = disc.getType();
CardList typeList = AllZone.getComputerPlayer().getCardsIn(Zone.Hand); CardList typeList = AllZone.getComputerPlayer().getCardsIn(Zone.Hand);
typeList = typeList.getValidCards(type.split(","), source.getController(), source); typeList = typeList.getValidCards(type.split(","), source.getController(), source);
if (ComputerUtil.getCardPreference(source, "DiscardCost", typeList) == null) { if (ComputerUtil.getCardPreference(source, "DiscardCost", typeList) == null) {
@@ -130,19 +130,19 @@ public class CostUtil {
* @return true, if successful * @return true, if successful
*/ */
public static boolean checkRemoveCounterCost(final Cost cost, final Card source) { public static boolean checkRemoveCounterCost(final Cost cost, final Card source) {
for (CostPart part : cost.getCostParts()) { for (final CostPart part : cost.getCostParts()) {
if (part instanceof CostRemoveCounter) { if (part instanceof CostRemoveCounter) {
CostRemoveCounter remCounter = (CostRemoveCounter) part; final CostRemoveCounter remCounter = (CostRemoveCounter) part;
// A card has a 25% chance per counter to be able to pass // A card has a 25% chance per counter to be able to pass
// through here // through here
// 4+ counters will always pass. 0 counters will never // 4+ counters will always pass. 0 counters will never
Counters type = remCounter.getCounter(); final Counters type = remCounter.getCounter();
double percent = type.name().equals("P1P1") ? P1P1Percent : OtherPercent; final double percent = type.name().equals("P1P1") ? CostUtil.p1p1Percent : CostUtil.otherPercent;
int currentNum = source.getCounters(type); final int currentNum = source.getCounters(type);
double chance = percent * (currentNum / part.convertAmount()); final double chance = percent * (currentNum / part.convertAmount());
if (chance <= r.nextFloat()) { if (chance <= CostUtil.r.nextFloat()) {
return false; return false;
} }
} }
@@ -161,10 +161,10 @@ public class CostUtil {
* @return true, if successful * @return true, if successful
*/ */
public static boolean checkAddM1M1CounterCost(final Cost cost, final Card source) { public static boolean checkAddM1M1CounterCost(final Cost cost, final Card source) {
for (CostPart part : cost.getCostParts()) { for (final CostPart part : cost.getCostParts()) {
if (part instanceof CostPutCounter) { if (part instanceof CostPutCounter) {
CostPutCounter addCounter = (CostPutCounter) part; final CostPutCounter addCounter = (CostPutCounter) part;
Counters type = addCounter.getCounter(); final Counters type = addCounter.getCounter();
if (type.equals(Counters.M1M1)) { if (type.equals(Counters.M1M1)) {
return false; return false;
@@ -183,9 +183,9 @@ public class CostUtil {
* @return true, if successful * @return true, if successful
*/ */
public static boolean hasDiscardHandCost(final Cost cost) { public static boolean hasDiscardHandCost(final Cost cost) {
for (CostPart part : cost.getCostParts()) { for (final CostPart part : cost.getCostParts()) {
if (part instanceof CostDiscard) { if (part instanceof CostDiscard) {
CostDiscard disc = (CostDiscard) part; final CostDiscard disc = (CostDiscard) part;
if (disc.getType().equals("Hand")) { if (disc.getType().equals("Hand")) {
return true; return true;
} }
@@ -207,11 +207,12 @@ public class CostUtil {
* the max choice * the max choice
* @return the integer * @return the integer
*/ */
public static Integer determineAmount(final CostPart part, final Card source, final SpellAbility ability, final int maxChoice) { public static Integer determineAmount(final CostPart part, final Card source, final SpellAbility ability,
String amount = part.getAmount(); final int maxChoice) {
final String amount = part.getAmount();
Integer c = part.convertAmount(); Integer c = part.convertAmount();
if (c == null) { if (c == null) {
String sVar = source.getSVar(amount); final String sVar = source.getSVar(amount);
// Generalize this // Generalize this
if (sVar.equals("XChoice")) { if (sVar.equals("XChoice")) {
c = CostUtil.chooseXValue(source, maxChoice); c = CostUtil.chooseXValue(source, maxChoice);
@@ -232,17 +233,17 @@ public class CostUtil {
* @return the int * @return the int
*/ */
public static int chooseXValue(final Card card, final int maxValue) { public static int chooseXValue(final Card card, final int maxValue) {
String chosen = card.getSVar("ChosenX"); final String chosen = card.getSVar("ChosenX");
if (chosen.length() > 0) { if (chosen.length() > 0) {
return AbilityFactory.calculateAmount(card, "ChosenX", null); return AbilityFactory.calculateAmount(card, "ChosenX", null);
} }
Integer[] choiceArray = new Integer[maxValue + 1]; final Integer[] choiceArray = new Integer[maxValue + 1];
for (int i = 0; i < choiceArray.length; i++) { for (int i = 0; i < choiceArray.length; i++) {
choiceArray[i] = i; choiceArray[i] = i;
} }
Object o = GuiUtils.getChoice(card.toString() + " - Choose a Value for X", choiceArray); final Object o = GuiUtils.getChoice(card.toString() + " - Choose a Value for X", choiceArray);
int chosenX = (Integer) o; final int chosenX = (Integer) o;
card.setSVar("ChosenX", "Number$" + Integer.toString(chosenX)); card.setSVar("ChosenX", "Number$" + Integer.toString(chosenX));
return chosenX; return chosenX;

View File

@@ -24,7 +24,7 @@ public class Cost_Payment {
private Card card = null; private Card card = null;
private SpellAbility_Requirements req = null; private SpellAbility_Requirements req = null;
private boolean bCancel = false; private boolean bCancel = false;
private Map<CostPart, Boolean> paidCostParts = new HashMap<CostPart, Boolean>(); private final Map<CostPart, Boolean> paidCostParts = new HashMap<CostPart, Boolean>();
/** /**
* <p> * <p>
@@ -34,7 +34,7 @@ public class Cost_Payment {
* @return a {@link forge.card.cost.Cost} object. * @return a {@link forge.card.cost.Cost} object.
*/ */
public final Cost getCost() { public final Cost getCost() {
return cost; return this.cost;
} }
/** /**
@@ -45,7 +45,7 @@ public class Cost_Payment {
* @return a {@link forge.card.spellability.SpellAbility} object. * @return a {@link forge.card.spellability.SpellAbility} object.
*/ */
public final SpellAbility getAbility() { public final SpellAbility getAbility() {
return ability; return this.ability;
} }
/** /**
@@ -56,7 +56,7 @@ public class Cost_Payment {
* @return a {@link forge.Card} object. * @return a {@link forge.Card} object.
*/ */
public final Card getCard() { public final Card getCard() {
return card; return this.card;
} }
/** /**
@@ -69,7 +69,7 @@ public class Cost_Payment {
* object. * object.
*/ */
public final void setRequirements(final SpellAbility_Requirements reqs) { public final void setRequirements(final SpellAbility_Requirements reqs) {
req = reqs; this.req = reqs;
} }
/** /**
@@ -78,7 +78,7 @@ public class Cost_Payment {
* @return the requirements * @return the requirements
*/ */
public final SpellAbility_Requirements getRequirements() { public final SpellAbility_Requirements getRequirements() {
return req; return this.req;
} }
/** /**
@@ -90,7 +90,7 @@ public class Cost_Payment {
* a boolean. * a boolean.
*/ */
public final void setCancel(final boolean cancel) { public final void setCancel(final boolean cancel) {
bCancel = cancel; this.bCancel = cancel;
} }
/** /**
@@ -101,7 +101,7 @@ public class Cost_Payment {
* @return a boolean. * @return a boolean.
*/ */
public final boolean isCanceled() { public final boolean isCanceled() {
return bCancel; return this.bCancel;
} }
/** /**
@@ -117,10 +117,10 @@ public class Cost_Payment {
public Cost_Payment(final Cost cost, final SpellAbility abil) { public Cost_Payment(final Cost cost, final SpellAbility abil) {
this.cost = cost; this.cost = cost;
this.ability = abil; this.ability = abil;
card = abil.getSourceCard(); this.card = abil.getSourceCard();
for (CostPart part : cost.getCostParts()) { for (final CostPart part : cost.getCostParts()) {
paidCostParts.put(part, false); this.paidCostParts.put(part, false);
} }
} }
@@ -147,7 +147,7 @@ public class Cost_Payment {
activator = card.getController(); activator = card.getController();
} }
for (CostPart part : cost.getCostParts()) { for (final CostPart part : cost.getCostParts()) {
if (!part.canPay(ability, card, activator, cost)) { if (!part.canPay(ability, card, activator, cost)) {
return false; return false;
} }
@@ -165,7 +165,7 @@ public class Cost_Payment {
* the b paid * the b paid
*/ */
public final void setPaidManaPart(final CostPart part, final boolean bPaid) { public final void setPaidManaPart(final CostPart part, final boolean bPaid) {
paidCostParts.put(part, bPaid); this.paidCostParts.put(part, bPaid);
} }
/** /**
@@ -175,16 +175,16 @@ public class Cost_Payment {
* the part * the part
*/ */
public final void paidCost(final CostPart part) { public final void paidCost(final CostPart part) {
setPaidManaPart(part, true); this.setPaidManaPart(part, true);
payCost(); this.payCost();
} }
/** /**
* Cancel cost. * Cancel cost.
*/ */
public final void cancelCost() { public final void cancelCost() {
setCancel(true); this.setCancel(true);
req.finishPaying(); this.req.finishPaying();
} }
/** /**
@@ -196,24 +196,24 @@ public class Cost_Payment {
*/ */
public final boolean payCost() { public final boolean payCost() {
// Nothing actually ever checks this return value, is it needed? // Nothing actually ever checks this return value, is it needed?
if (bCancel) { if (this.bCancel) {
req.finishPaying(); this.req.finishPaying();
return false; return false;
} }
for (CostPart part : cost.getCostParts()) { for (final CostPart part : this.cost.getCostParts()) {
// This portion of the cost is already paid for, keep moving // This portion of the cost is already paid for, keep moving
if (paidCostParts.get(part)) { if (this.paidCostParts.get(part)) {
continue; continue;
} }
if (!part.payHuman(ability, card, this)) { if (!part.payHuman(this.ability, this.card, this)) {
return false; return false;
} }
} }
resetUndoList(); this.resetUndoList();
req.finishPaying(); this.req.finishPaying();
return true; return true;
} }
@@ -225,8 +225,8 @@ public class Cost_Payment {
* @return a boolean. * @return a boolean.
*/ */
public final boolean isAllPaid() { public final boolean isAllPaid() {
for (CostPart part : paidCostParts.keySet()) { for (final CostPart part : this.paidCostParts.keySet()) {
if (!paidCostParts.get(part)) { if (!this.paidCostParts.get(part)) {
return false; return false;
} }
} }
@@ -240,7 +240,7 @@ public class Cost_Payment {
* </p> * </p>
*/ */
public final void resetUndoList() { public final void resetUndoList() {
for (CostPart part : paidCostParts.keySet()) { for (final CostPart part : this.paidCostParts.keySet()) {
if (part instanceof CostPartWithList) { if (part instanceof CostPartWithList) {
((CostPartWithList) part).resetList(); ((CostPartWithList) part).resetList();
} }
@@ -253,14 +253,14 @@ public class Cost_Payment {
* </p> * </p>
*/ */
public final void cancelPayment() { public final void cancelPayment() {
for (CostPart part : paidCostParts.keySet()) { for (final CostPart part : this.paidCostParts.keySet()) {
if (paidCostParts.get(part) && part.isUndoable()) { if (this.paidCostParts.get(part) && part.isUndoable()) {
part.refund(card); part.refund(this.card);
} }
} }
// Move this to CostMana // Move this to CostMana
AllZone.getHumanPlayer().getManaPool().unpaid(ability, false); AllZone.getHumanPlayer().getManaPool().unpaid(this.ability, false);
} }
/** /**
@@ -275,21 +275,21 @@ public class Cost_Payment {
// Just in case it wasn't set, but honestly it shouldn't have gotten // Just in case it wasn't set, but honestly it shouldn't have gotten
// here without being set // here without being set
Player activator = AllZone.getComputerPlayer(); final Player activator = AllZone.getComputerPlayer();
ability.setActivatingPlayer(activator); this.ability.setActivatingPlayer(activator);
Card source = ability.getSourceCard(); final Card source = this.ability.getSourceCard();
ArrayList<CostPart> parts = cost.getCostParts(); final ArrayList<CostPart> parts = this.cost.getCostParts();
// Set all of the decisions before attempting to pay anything // Set all of the decisions before attempting to pay anything
for (CostPart part : parts) { for (final CostPart part : parts) {
if (!part.decideAIPayment(ability, source, this)) { if (!part.decideAIPayment(this.ability, source, this)) {
return false; return false;
} }
} }
for (CostPart part : parts) { for (final CostPart part : parts) {
part.payAI(ability, ability.getSourceCard(), this); part.payAI(this.ability, this.ability.getSourceCard(), this);
} }
return true; return true;
} }
@@ -300,6 +300,6 @@ public class Cost_Payment {
* </p> * </p>
*/ */
public final void changeCost() { public final void changeCost() {
cost.changeCost(ability); this.cost.changeCost(this.ability);
} }
} }

View File

@@ -1,2 +1,3 @@
/** Forge Card Game. */ /** Forge Card Game. */
package forge.card.cost; package forge.card.cost;