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
for (int x = 0; x < target.getNetAttack(); x++) {
AllZone.getInputControl().setInput(
CardFactoryUtil.masterOfTheWildHuntInputTargetCreature(this, wolves,
new Command() {
private static final long serialVersionUID = -328305150127775L;
CardFactoryUtil.masterOfTheWildHuntInputTargetCreature(this, wolves, new Command() {
private static final long serialVersionUID = -328305150127775L;
@Override
public void execute() {
getTargetCard().addDamage(1, target);
AllZone.getGameAction().checkStateEffects();
}
}));
@Override
public void execute() {
getTargetCard().addDamage(1, target);
AllZone.getGameAction().checkStateEffects();
}
}));
}
} else { // AI Choose spread Damage
final CardList damageableWolves = wolves.filter(new CardListFilter() {
@@ -1780,7 +1779,7 @@ public class CardFactory_Creatures {
public void execute() {
int intermSumPower = 0;
int intermSumToughness = 0;
//intermSumPower = intermSumToughness = 0;
// intermSumPower = intermSumToughness = 0;
CardList creats = card.getController().getCardsIn(Zone.Graveyard);
creats = creats.filter(new CardListFilter() {
@Override
@@ -2206,8 +2205,7 @@ public class CardFactory_Creatures {
else if (cardName.equals("Clone") || cardName.equals("Vesuvan Doppelganger")
|| cardName.equals("Quicksilver Gargantuan") || cardName.equals("Jwari Shapeshifter")
|| cardName.equals("Phyrexian Metamorph") || cardName.equals("Phantasmal Image")
|| cardName.equals("Body Double")
|| cardName.equals("Evil Twin")) {
|| cardName.equals("Body Double") || cardName.equals("Evil Twin")) {
final CardFactoryInterface cfact = cf;
final Card[] copyTarget = 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");
}
if(cardName.equals("Evil Twin")) {
AbilityFactory AF = 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]);
if (cardName.equals("Evil Twin")) {
final AbilityFactory abilityFactory = new AbilityFactory();
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);
}

View File

@@ -20,7 +20,7 @@ import forge.card.spellability.SpellAbility;
*/
public class Cost {
private boolean isAbility = true;
private ArrayList<CostPart> costParts = new ArrayList<CostPart>();
private final ArrayList<CostPart> costParts = new ArrayList<CostPart>();
/**
* Gets the cost parts.
@@ -28,7 +28,7 @@ public class Cost {
* @return the cost parts
*/
public final ArrayList<CostPart> getCostParts() {
return costParts;
return this.costParts;
}
private boolean sacCost = false;
@@ -41,7 +41,7 @@ public class Cost {
* @return a boolean.
*/
public final boolean getSacCost() {
return sacCost;
return this.sacCost;
}
private boolean tapCost = false;
@@ -54,7 +54,7 @@ public class Cost {
* @return a boolean.
*/
public final boolean getTap() {
return tapCost;
return this.tapCost;
}
/**
@@ -65,10 +65,11 @@ public class Cost {
* @return a boolean.
*/
public final boolean hasNoManaCost() {
for (CostPart part : costParts)
for (final CostPart part : this.costParts) {
if (part instanceof CostMana) {
return false;
}
}
return true;
}
@@ -82,10 +83,11 @@ public class Cost {
*/
public final boolean isOnlyManaCost() {
// 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)) {
return false;
}
}
return true;
}
@@ -98,15 +100,16 @@ public class Cost {
* @return a {@link java.lang.String} object.
*/
public final String getTotalMana() {
for (CostPart part : costParts)
for (final CostPart part : this.costParts) {
if (part instanceof CostMana) {
return part.toString();
}
}
return "0";
}
private String name;
private final String name;
// Parsing Strings
private static final String tapXStr = "tapXType<";
@@ -137,164 +140,164 @@ public class Cost {
* a boolean.
*/
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
name = cardName;
this.name = cardName;
while (parse.contains(tapXStr)) {
String[] splitStr = abCostParse(parse, tapXStr, 3);
parse = abUpdateParse(parse, tapXStr);
while (parse.contains(Cost.tapXStr)) {
final String[] splitStr = this.abCostParse(parse, Cost.tapXStr, 3);
parse = this.abUpdateParse(parse, Cost.tapXStr);
String description = splitStr.length > 2 ? splitStr[2] : null;
costParts.add(new CostTapType(splitStr[0], splitStr[1], description));
final String description = splitStr.length > 2 ? splitStr[2] : null;
this.costParts.add(new CostTapType(splitStr[0], splitStr[1], description));
}
while (parse.contains(subStr)) {
while (parse.contains(Cost.subStr)) {
// SubCounter<NumCounters/CounterType>
String[] splitStr = abCostParse(parse, subStr, 4);
parse = abUpdateParse(parse, subStr);
final String[] splitStr = this.abCostParse(parse, Cost.subStr, 4);
parse = this.abUpdateParse(parse, Cost.subStr);
String type = splitStr.length > 2 ? splitStr[2] : "CARDNAME";
String description = splitStr.length > 3 ? splitStr[3] : null;
final String type = splitStr.length > 2 ? splitStr[2] : "CARDNAME";
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>
String[] splitStr = abCostParse(parse, addStr, 4);
parse = abUpdateParse(parse, addStr);
final String[] splitStr = this.abCostParse(parse, Cost.addStr, 4);
parse = this.abUpdateParse(parse, Cost.addStr);
String type = splitStr.length > 2 ? splitStr[2] : "CARDNAME";
String description = splitStr.length > 3 ? splitStr[3] : null;
final String type = splitStr.length > 2 ? splitStr[2] : "CARDNAME";
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
// Changes Cost by adding a Life Payment
while (parse.contains(lifeStr)) {
while (parse.contains(Cost.lifeStr)) {
// PayLife<LifeCost>
String[] splitStr = abCostParse(parse, lifeStr, 1);
parse = abUpdateParse(parse, lifeStr);
final String[] splitStr = this.abCostParse(parse, Cost.lifeStr, 1);
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>
String[] splitStr = abCostParse(parse, lifeGainStr, 1);
parse = abUpdateParse(parse, lifeGainStr);
final String[] splitStr = this.abCostParse(parse, Cost.lifeGainStr, 1);
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>
String[] splitStr = abCostParse(parse, millStr, 1);
parse = abUpdateParse(parse, millStr);
final String[] splitStr = this.abCostParse(parse, Cost.millStr, 1);
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>
String[] splitStr = abCostParse(parse, discStr, 3);
parse = abUpdateParse(parse, discStr);
final String[] splitStr = this.abCostParse(parse, Cost.discStr, 3);
parse = this.abUpdateParse(parse, Cost.discStr);
String description = splitStr.length > 2 ? splitStr[2] : null;
costParts.add(new CostDiscard(splitStr[0], splitStr[1], description));
final String description = splitStr.length > 2 ? splitStr[2] : null;
this.costParts.add(new CostDiscard(splitStr[0], splitStr[1], description));
}
while (parse.contains(sacStr)) {
sacCost = true;
String[] splitStr = abCostParse(parse, sacStr, 3);
parse = abUpdateParse(parse, sacStr);
while (parse.contains(Cost.sacStr)) {
this.sacCost = true;
final String[] splitStr = this.abCostParse(parse, Cost.sacStr, 3);
parse = this.abUpdateParse(parse, Cost.sacStr);
String description = splitStr.length > 2 ? splitStr[2] : null;
costParts.add(new CostSacrifice(splitStr[0], splitStr[1], description));
final String description = splitStr.length > 2 ? splitStr[2] : null;
this.costParts.add(new CostSacrifice(splitStr[0], splitStr[1], description));
}
while (parse.contains(exileStr)) {
String[] splitStr = abCostParse(parse, exileStr, 3);
parse = abUpdateParse(parse, exileStr);
while (parse.contains(Cost.exileStr)) {
final String[] splitStr = this.abCostParse(parse, Cost.exileStr, 3);
parse = this.abUpdateParse(parse, Cost.exileStr);
String description = splitStr.length > 2 ? splitStr[2] : null;
costParts.add(new CostExile(splitStr[0], splitStr[1], description, Constant.Zone.Battlefield));
final String description = splitStr.length > 2 ? splitStr[2] : null;
this.costParts.add(new CostExile(splitStr[0], splitStr[1], description, Constant.Zone.Battlefield));
}
while (parse.contains(exileFromHandStr)) {
String[] splitStr = abCostParse(parse, exileFromHandStr, 3);
parse = abUpdateParse(parse, exileFromHandStr);
while (parse.contains(Cost.exileFromHandStr)) {
final String[] splitStr = this.abCostParse(parse, Cost.exileFromHandStr, 3);
parse = this.abUpdateParse(parse, Cost.exileFromHandStr);
String description = splitStr.length > 2 ? splitStr[2] : null;
costParts.add(new CostExile(splitStr[0], splitStr[1], description, Constant.Zone.Hand));
final String description = splitStr.length > 2 ? splitStr[2] : null;
this.costParts.add(new CostExile(splitStr[0], splitStr[1], description, Constant.Zone.Hand));
}
while (parse.contains(exileFromGraveStr)) {
String[] splitStr = abCostParse(parse, exileFromGraveStr, 3);
parse = abUpdateParse(parse, exileFromGraveStr);
while (parse.contains(Cost.exileFromGraveStr)) {
final String[] splitStr = this.abCostParse(parse, Cost.exileFromGraveStr, 3);
parse = this.abUpdateParse(parse, Cost.exileFromGraveStr);
String description = splitStr.length > 2 ? splitStr[2] : null;
costParts.add(new CostExile(splitStr[0], splitStr[1], description, Constant.Zone.Graveyard));
final String description = splitStr.length > 2 ? splitStr[2] : null;
this.costParts.add(new CostExile(splitStr[0], splitStr[1], description, Constant.Zone.Graveyard));
}
while (parse.contains(exileFromTopStr)) {
String[] splitStr = abCostParse(parse, exileFromTopStr, 3);
parse = abUpdateParse(parse, exileFromTopStr);
while (parse.contains(Cost.exileFromTopStr)) {
final String[] splitStr = this.abCostParse(parse, Cost.exileFromTopStr, 3);
parse = this.abUpdateParse(parse, Cost.exileFromTopStr);
String description = splitStr.length > 2 ? splitStr[2] : null;
costParts.add(new CostExile(splitStr[0], splitStr[1], description, Constant.Zone.Library));
final String description = splitStr.length > 2 ? splitStr[2] : null;
this.costParts.add(new CostExile(splitStr[0], splitStr[1], description, Constant.Zone.Library));
}
while (parse.contains(returnStr)) {
String[] splitStr = abCostParse(parse, returnStr, 3);
parse = abUpdateParse(parse, returnStr);
while (parse.contains(Cost.returnStr)) {
final String[] splitStr = this.abCostParse(parse, Cost.returnStr, 3);
parse = this.abUpdateParse(parse, Cost.returnStr);
String description = splitStr.length > 2 ? splitStr[2] : null;
costParts.add(new CostReturn(splitStr[0], splitStr[1], description));
final String description = splitStr.length > 2 ? splitStr[2] : null;
this.costParts.add(new CostReturn(splitStr[0], splitStr[1], description));
}
while (parse.contains(revealStr)) {
String[] splitStr = abCostParse(parse, revealStr, 3);
parse = abUpdateParse(parse, revealStr);
while (parse.contains(Cost.revealStr)) {
final String[] splitStr = this.abCostParse(parse, Cost.revealStr, 3);
parse = this.abUpdateParse(parse, Cost.revealStr);
String description = splitStr.length > 2 ? splitStr[2] : null;
costParts.add(new CostReveal(splitStr[0], splitStr[1], description));
final String description = splitStr.length > 2 ? splitStr[2] : null;
this.costParts.add(new CostReveal(splitStr[0], splitStr[1], description));
}
int manaLocation = 0;
// These won't show up with multiples
if (parse.contains("Untap")) {
parse = parse.replace("Untap", "").trim();
costParts.add(0, new CostUntap());
this.costParts.add(0, new CostUntap());
manaLocation++;
}
if (parse.contains("Q")) {
parse = parse.replace("Q", "").trim();
costParts.add(0, new CostUntap());
this.costParts.add(0, new CostUntap());
manaLocation++;
}
if (parse.contains("T")) {
tapCost = true;
this.tapCost = true;
parse = parse.replace("T", "").trim();
costParts.add(0, new CostTap());
this.costParts.add(0, new CostTap());
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();
if (mana.equals("")) {
mana = "0";
}
if (amountX > 0 || !mana.equals("0")) {
costParts.add(manaLocation, new CostMana(mana, amountX));
if ((amountX > 0) || !mana.equals("0")) {
this.costParts.add(manaLocation, new CostMana(mana, amountX));
}
}
@@ -312,13 +315,13 @@ public class Cost {
* @return an array of {@link java.lang.String} objects.
*/
private String[] abCostParse(final String parse, final String subkey, final int numParse) {
int startPos = parse.indexOf(subkey);
int endPos = parse.indexOf(">", startPos);
final int startPos = parse.indexOf(subkey);
final int endPos = parse.indexOf(">", startPos);
String str = parse.substring(startPos, endPos);
str = str.replace(subkey, "");
String[] splitStr = str.split("/", numParse);
final String[] splitStr = str.split("/", numParse);
return splitStr;
}
@@ -334,9 +337,9 @@ public class Cost {
* @return a {@link java.lang.String} object.
*/
private String abUpdateParse(final String parse, final String subkey) {
int startPos = parse.indexOf(subkey);
int endPos = parse.indexOf(">", startPos);
String str = parse.substring(startPos, endPos + 1);
final int startPos = parse.indexOf(subkey);
final int endPos = parse.indexOf(">", startPos);
final String str = parse.substring(startPos, endPos + 1);
return parse.replace(str, "").trim();
}
@@ -350,13 +353,13 @@ public class Cost {
*/
public final void changeCost(final SpellAbility sa) {
// TODO: Change where ChangeCost happens
for (CostPart part : costParts) {
for (final CostPart part : this.costParts) {
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));
}
@@ -373,8 +376,9 @@ public class Cost {
*/
public final void refundPaidCost(final Card source) {
// prereq: isUndoable is called first
for (CostPart part : costParts)
for (final CostPart part : this.costParts) {
part.refund(source);
}
}
/**
@@ -385,10 +389,11 @@ public class Cost {
* @return a boolean.
*/
public final boolean isUndoable() {
for (CostPart part : costParts)
for (final CostPart part : this.costParts) {
if (!part.isUndoable()) {
return false;
}
}
return true;
}
@@ -401,12 +406,13 @@ public class Cost {
* @return a boolean.
*/
public final boolean isReusuableResource() {
for (CostPart part : costParts)
for (final CostPart part : this.costParts) {
if (!part.isReusable()) {
return false;
}
}
return isAbility;
return this.isAbility;
}
/**
@@ -416,11 +422,12 @@ public class Cost {
*
* @return a {@link java.lang.String} object.
*/
@Override
public final String toString() {
if (isAbility) {
return abilityToString();
if (this.isAbility) {
return this.abilityToString();
} else {
return spellToString(true);
return this.spellToString(true);
}
}
@@ -435,7 +442,7 @@ public class Cost {
* @return a {@link java.lang.String} object.
*/
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.
*/
private String spellToString(final boolean bFlag) {
StringBuilder cost = new StringBuilder();
final StringBuilder cost = new StringBuilder();
boolean first = true;
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 {
// usually no additional mana cost for spells
// 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) {
continue;
}
@@ -493,10 +500,10 @@ public class Cost {
* @return a {@link java.lang.String} object.
*/
private String abilityToString() {
StringBuilder cost = new StringBuilder();
final StringBuilder cost = new StringBuilder();
boolean first = true;
for (CostPart part : costParts) {
for (final CostPart part : this.costParts) {
boolean append = true;
if (!first) {
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
// as appropriate
/**
* Constant
* Constant.
* <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",
"nine", "ten" };
/** Constant <code>vowelPattern</code> */
/** Constant <code>vowelPattern</code>. */
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) {
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.
*/
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);
} else if (1 == i && vowelPattern.matcher(type).find()) {
} else if ((1 == i) && Cost.vowelPattern.matcher(type).find()) {
sb.append("an");
} else {
sb.append(numNames[i]);
sb.append(Cost.numNames[i]);
}
sb.append(" ");
@@ -591,7 +598,7 @@ public class Cost {
* @return the string
*/
public static String convertAmountTypeToWords(final String amount, final String type) {
StringBuilder sb = new StringBuilder();
final StringBuilder sb = new StringBuilder();
sb.append(amount);
sb.append(" ");

View File

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

View File

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

View File

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

View File

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

View File

@@ -27,7 +27,7 @@ public class CostMill extends CostPartWithList {
* the amount
*/
public CostMill(final String amount) {
this.amount = amount;
this.setAmount(amount);
}
/*
@@ -39,17 +39,17 @@ public class CostMill extends CostPartWithList {
*/
@Override
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) {
String sVar = source.getSVar(amount);
final String sVar = source.getSVar(this.getAmount());
if (sVar.equals("XChoice")) {
return true;
}
i = AbilityFactory.calculateAmount(source, amount, ability);
i = AbilityFactory.calculateAmount(source, this.getAmount(), ability);
}
return i < zone.size();
@@ -64,22 +64,22 @@ public class CostMill extends CostPartWithList {
*/
@Override
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) {
String sVar = source.getSVar(amount);
final String sVar = source.getSVar(this.getAmount());
// Generalize this
if (sVar.equals("XChoice")) {
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;
}
@@ -94,8 +94,9 @@ public class CostMill extends CostPartWithList {
*/
@Override
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);
}
}
/*
@@ -107,40 +108,40 @@ public class CostMill extends CostPartWithList {
*/
@Override
public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) {
String amount = getAmount();
Integer c = convertAmount();
Player activator = ability.getActivatingPlayer();
final String amount = this.getAmount();
Integer c = this.convertAmount();
final Player activator = ability.getActivatingPlayer();
if (c == null) {
String sVar = source.getSVar(amount);
final String sVar = source.getSVar(amount);
// Generalize this
if (sVar.equals("XChoice")) {
c = CostUtil.chooseXValue(source, list.size());
c = CostUtil.chooseXValue(source, this.list.size());
} else {
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
payment.cancelCost();
return false;
}
StringBuilder sb = new StringBuilder();
final StringBuilder sb = new StringBuilder();
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) {
resetList();
Iterator<Card> itr = list.iterator();
this.resetList();
final Iterator<Card> itr = list.iterator();
while (itr.hasNext()) {
Card card = (Card) itr.next();
addToList(card);
final Card card = itr.next();
this.addToList(card);
AllZone.getGameAction().moveToGraveyard(card);
}
addListToHash(ability, "Milled");
this.addListToHash(ability, "Milled");
payment.paidCost(this);
return false;
} else {
@@ -156,18 +157,18 @@ public class CostMill extends CostPartWithList {
*/
@Override
public final String toString() {
StringBuilder sb = new StringBuilder();
Integer i = convertAmount();
final StringBuilder sb = new StringBuilder();
final Integer i = this.convertAmount();
sb.append("Put the top ");
if (i != null) {
sb.append(i);
} else {
sb.append(amount);
sb.append(this.getAmount());
}
sb.append(" card");
if (i == null || i > 1) {
if ((i == null) || (i > 1)) {
sb.append("s");
}
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 {
/** The is reusable. */
protected boolean isReusable = false;
private boolean isReusable = false;
/** The is undoable. */
protected boolean isUndoable = false;
private boolean isUndoable = false;
/** The optional. */
protected boolean optional = false;
private boolean optional = false;
/** The optional type. */
protected String optionalType = null;
private String optionalType = null;
/** The amount. */
protected String amount = "1";
private String amount = "1";
/** The type. */
protected String type = "Card";
private String type = "Card";
/** The type description. */
protected String typeDescription = null;
private String typeDescription = null;
/**
* Instantiates a new cost part.
@@ -47,9 +47,9 @@ public abstract class CostPart {
* the description
*/
public CostPart(final String amount, final String type, final String description) {
this.amount = amount;
this.type = type;
this.typeDescription = description;
this.setAmount(amount);
this.setType(type);
this.setTypeDescription(description);
}
/**
@@ -58,7 +58,7 @@ public abstract class CostPart {
* @return the amount
*/
public final String getAmount() {
return amount;
return this.amount;
}
/**
@@ -67,7 +67,7 @@ public abstract class CostPart {
* @return the type
*/
public final String getType() {
return type;
return this.type;
}
/**
@@ -76,7 +76,7 @@ public abstract class CostPart {
* @return the this
*/
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
*/
public final String getTypeDescription() {
return typeDescription;
return this.typeDescription;
}
/**
@@ -94,7 +94,7 @@ public abstract class CostPart {
* @return the descriptive type
*/
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
*/
public final boolean isReusable() {
return isReusable;
return this.isReusable;
}
/**
@@ -112,7 +112,7 @@ public abstract class CostPart {
* @return true, if is undoable
*/
public final boolean isUndoable() {
return isUndoable;
return this.isUndoable;
}
/**
@@ -121,7 +121,7 @@ public abstract class CostPart {
* @return the optional type
*/
public final String getOptionalType() {
return optionalType;
return this.optionalType;
}
/**
@@ -142,8 +142,8 @@ public abstract class CostPart {
public final Integer convertAmount() {
Integer i = null;
try {
i = Integer.parseInt(amount);
} catch (NumberFormatException e) {
i = Integer.parseInt(this.getAmount());
} catch (final NumberFormatException e) {
}
return i;
}
@@ -206,6 +206,7 @@ public abstract class CostPart {
*
* @see java.lang.Object#toString()
*/
@Override
public abstract String toString();
/**
@@ -215,4 +216,39 @@ public abstract class CostPart {
* the 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
*/
public final CardList getList() {
return list;
return this.list;
}
/**
@@ -28,14 +28,14 @@ public abstract class CostPartWithList extends CostPart {
* the new list
*/
public final void setList(final CardList setList) {
list = setList;
this.list = setList;
}
/**
* Reset list.
*/
public final void resetList() {
list = new CardList();
this.list = new CardList();
}
/**
@@ -45,10 +45,10 @@ public abstract class CostPartWithList extends CostPart {
* the c
*/
public final void addToList(final Card c) {
if (list == null) {
resetList();
if (this.list == null) {
this.resetList();
}
list.add(c);
this.list.add(c);
}
/**
@@ -60,7 +60,7 @@ public abstract class CostPartWithList extends CostPart {
* the 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);
}
}
@@ -83,6 +83,6 @@ public abstract class CostPartWithList extends CostPart {
*/
public CostPartWithList(final String amount, final String type, final String description) {
super(amount, type, description);
resetList();
this.resetList();
}
}

View File

@@ -19,7 +19,7 @@ public class CostPayLife extends CostPart {
* @return the last paid amount
*/
public final int getLastPaidAmount() {
return lastPaidAmount;
return this.lastPaidAmount;
}
/**
@@ -29,7 +29,7 @@ public class CostPayLife extends CostPart {
* the new last paid amount
*/
public final void setLastPaidAmount(final int paidAmount) {
lastPaidAmount = paidAmount;
this.lastPaidAmount = paidAmount;
}
/**
@@ -39,7 +39,7 @@ public class CostPayLife extends CostPart {
* the amount
*/
public CostPayLife(final String amount) {
this.amount = amount;
this.setAmount(amount);
}
/*
@@ -49,8 +49,8 @@ public class CostPayLife extends CostPart {
*/
@Override
public final String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Pay ").append(amount).append(" Life");
final StringBuilder sb = new StringBuilder();
sb.append("Pay ").append(this.getAmount()).append(" Life");
return sb.toString();
}
@@ -62,7 +62,7 @@ public class CostPayLife extends CostPart {
@Override
public final void refund(final Card source) {
// 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
public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) {
Integer amount = convertAmount();
if (amount != null && !activator.canPayLife(amount)) {
final Integer amount = this.convertAmount();
if ((amount != null) && !activator.canPayLife(amount)) {
return false;
}
@@ -90,7 +90,7 @@ public class CostPayLife extends CostPart {
*/
@Override
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
public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) {
String amount = getAmount();
Player activator = ability.getActivatingPlayer();
int life = activator.getLife();
final String amount = this.getAmount();
final Player activator = ability.getActivatingPlayer();
final int life = activator.getLife();
Integer c = convertAmount();
Integer c = this.convertAmount();
if (c == null) {
String sVar = source.getSVar(amount);
final String sVar = source.getSVar(amount);
// Generalize this
if (sVar.equals("XChoice")) {
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?");
if (GameActionUtil.showYesNoDialog(source, sb.toString()) && activator.canPayLife(c)) {
activator.payLife(c, null);
setLastPaidAmount(c);
this.setLastPaidAmount(c);
payment.setPaidManaPart(this, true);
} else {
payment.setCancel(true);
@@ -141,23 +141,23 @@ public class CostPayLife extends CostPart {
*/
@Override
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) {
String sVar = source.getSVar(amount);
final String sVar = source.getSVar(this.getAmount());
// Generalize this
if (sVar.equals("XChoice")) {
return false;
} else {
c = AbilityFactory.calculateAmount(source, amount, ability);
c = AbilityFactory.calculateAmount(source, this.getAmount(), ability);
}
}
if (!activator.canPayLife(c)) {
return false;
}
// activator.payLife(c, null);
setLastPaidAmount(c);
this.setLastPaidAmount(c);
return true;
}
}

View File

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

View File

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

View File

@@ -42,23 +42,23 @@ public class CostReturn extends CostPartWithList {
*/
@Override
public final String toString() {
StringBuilder sb = new StringBuilder();
final StringBuilder sb = new StringBuilder();
sb.append("Return ");
Integer i = convertAmount();
final Integer i = this.convertAmount();
String pronoun = "its";
if (getThis()) {
sb.append(type);
if (this.getThis()) {
sb.append(this.getType());
} else {
String desc = typeDescription == null ? type : typeDescription;
final String desc = this.getTypeDescription() == null ? this.getType() : this.getTypeDescription();
if (i != null) {
sb.append(Cost.convertIntAndTypeToWords(i, desc));
if (i > 1) {
pronoun = "their";
}
} else {
sb.append(Cost.convertAmountTypeToWords(amount, desc));
sb.append(Cost.convertAmountTypeToWords(this.getAmount(), desc));
}
sb.append(" you control");
@@ -87,12 +87,12 @@ public class CostReturn extends CostPartWithList {
*/
@Override
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);
typeList = typeList.getValidCards(getType().split(";"), activator, source);
typeList = typeList.getValidCards(this.getType().split(";"), activator, source);
Integer amount = convertAmount();
if (amount != null && typeList.size() < amount) {
final Integer amount = this.convertAmount();
if ((amount != null) && (typeList.size() < amount)) {
return false;
}
} else if (!AllZoneUtil.isCardInPlay(source)) {
@@ -110,8 +110,9 @@ public class CostReturn extends CostPartWithList {
*/
@Override
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);
}
}
/*
@@ -123,12 +124,12 @@ public class CostReturn extends CostPartWithList {
*/
@Override
public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) {
String amount = getAmount();
Integer c = convertAmount();
Player activator = ability.getActivatingPlayer();
CardList list = activator.getCardsIn(Zone.Battlefield);
final String amount = this.getAmount();
Integer c = this.convertAmount();
final Player activator = ability.getActivatingPlayer();
final CardList list = activator.getCardsIn(Zone.Battlefield);
if (c == null) {
String sVar = source.getSVar(amount);
final String sVar = source.getSVar(amount);
// Generalize this
if (sVar.equals("XChoice")) {
c = CostUtil.chooseXValue(source, list.size());
@@ -136,10 +137,10 @@ public class CostReturn extends CostPartWithList {
c = AbilityFactory.calculateAmount(source, amount, ability);
}
}
if (getThis()) {
if (this.getThis()) {
CostUtil.setInput(CostReturn.returnThis(ability, payment, this));
} else {
CostUtil.setInput(CostReturn.returnType(ability, getType(), payment, this, c));
CostUtil.setInput(CostReturn.returnType(ability, this.getType(), payment, this, c));
}
return false;
}
@@ -153,17 +154,17 @@ public class CostReturn extends CostPartWithList {
*/
@Override
public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) {
resetList();
if (getThis()) {
list.add(source);
this.resetList();
if (this.getThis()) {
this.list.add(source);
} else {
Integer c = convertAmount();
Integer c = this.convertAmount();
if (c == null) {
c = AbilityFactory.calculateAmount(source, amount, ability);
c = AbilityFactory.calculateAmount(source, this.getAmount(), ability);
}
list = ComputerUtil.chooseReturnType(getType(), source, ability.getTargetCard(), c);
if (list == null) {
this.list = ComputerUtil.chooseReturnType(this.getType(), source, ability.getTargetCard(), c);
if (this.list == null) {
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,
final CostReturn part, final int nNeeded) {
Input target = new Input() {
final Input target = new Input() {
private static final long serialVersionUID = 2685832214519141903L;
private CardList typeList;
private int nReturns = 0;
@@ -199,61 +200,62 @@ public class CostReturn extends CostPartWithList {
@Override
public void showMessage() {
if (nNeeded == 0) {
done();
this.done();
}
StringBuilder msg = new StringBuilder("Return ");
int nLeft = nNeeded - nReturns;
final StringBuilder msg = new StringBuilder("Return ");
final int nLeft = nNeeded - this.nReturns;
msg.append(nLeft).append(" ");
msg.append(type);
if (nLeft > 1) {
msg.append("s");
}
typeList = sa.getActivatingPlayer().getCardsIn(Zone.Battlefield);
typeList = typeList.getValidCards(type.split(";"), sa.getActivatingPlayer(), sa.getSourceCard());
this.typeList = sa.getActivatingPlayer().getCardsIn(Zone.Battlefield);
this.typeList = this.typeList.getValidCards(type.split(";"), sa.getActivatingPlayer(),
sa.getSourceCard());
AllZone.getDisplay().showMessage(msg.toString());
ButtonUtil.enableOnlyCancel();
}
@Override
public void selectButtonCancel() {
cancel();
this.cancel();
}
@Override
public void selectCard(final Card card, final PlayerZone zone) {
if (typeList.contains(card)) {
nReturns++;
if (this.typeList.contains(card)) {
this.nReturns++;
part.addToList(card);
AllZone.getGameAction().moveToHand(card);
typeList.remove(card);
this.typeList.remove(card);
// in case nothing else to return
if (nReturns == nNeeded) {
done();
} else if (typeList.size() == 0) {
if (this.nReturns == nNeeded) {
this.done();
} else if (this.typeList.size() == 0) {
// happen
cancel();
this.cancel();
} else {
showMessage();
this.showMessage();
}
}
}
public void done() {
stop();
this.stop();
part.addListToHash(sa, "Returned");
payment.paidCost(part);
}
public void cancel() {
stop();
this.stop();
payment.cancelCost();
}
};
return target;
}// returnType()
} // returnType()
/**
* <p>
@@ -269,28 +271,28 @@ public class CostReturn extends CostPartWithList {
* @return a {@link forge.gui.input.Input} object.
*/
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;
@Override
public void showMessage() {
Card card = sa.getSourceCard();
final Card card = sa.getSourceCard();
if (card.getController().isHuman() && AllZoneUtil.isCardInPlay(card)) {
StringBuilder sb = new StringBuilder();
final StringBuilder sb = new StringBuilder();
sb.append(card.getName());
sb.append(" - Return to Hand?");
Object[] possibleValues = { "Yes", "No" };
Object choice = JOptionPane.showOptionDialog(null, sb.toString(), card.getName() + " - Cost",
final Object[] possibleValues = { "Yes", "No" };
final Object choice = JOptionPane.showOptionDialog(null, sb.toString(), card.getName() + " - Cost",
JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, possibleValues,
possibleValues[0]);
if (choice.equals(0)) {
part.addToList(card);
AllZone.getGameAction().moveToHand(card);
stop();
this.stop();
part.addListToHash(sa, "Returned");
payment.paidCost(part);
} else {
stop();
this.stop();
payment.cancelCost();
}
}
@@ -298,5 +300,5 @@ public class CostReturn extends CostPartWithList {
};
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)
*/
@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);
String type = getType();
Integer amount = convertAmount();
final String type = this.getType();
final Integer amount = this.convertAmount();
if (getThis()) {
if (this.getThis()) {
if (!AllZone.getZoneOf(source).is(Constant.Zone.Hand)) {
return false;
}
} else {
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
return false;
}
@@ -72,32 +71,32 @@ public class CostReveal extends CostPartWithList {
*/
@Override
public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) {
String type = getType();
Player activator = ability.getActivatingPlayer();
final String type = this.getType();
final Player activator = ability.getActivatingPlayer();
CardList hand = activator.getCardsIn(Zone.Hand);
resetList();
this.resetList();
if (getThis()) {
if (this.getThis()) {
if (!hand.contains(source)) {
return false;
}
list.add(source);
this.list.add(source);
} else {
hand = hand.getValidCards(type.split(";"), activator, source);
Integer c = convertAmount();
Integer c = this.convertAmount();
if (c == null) {
String sVar = source.getSVar(amount);
final String sVar = source.getSVar(this.getAmount());
if (sVar.equals("XChoice")) {
c = hand.size();
} 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
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
public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) {
Player activator = ability.getActivatingPlayer();
String amount = getAmount();
resetList();
final Player activator = ability.getActivatingPlayer();
final String amount = this.getAmount();
this.resetList();
if (getThis()) {
addToList(source);
if (this.getThis()) {
this.addToList(source);
payment.setPaidManaPart(this, true);
} else {
Integer c = convertAmount();
Integer c = this.convertAmount();
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) {
String sVar = source.getSVar(amount);
final String sVar = source.getSVar(amount);
if (sVar.equals("XChoice")) {
c = CostUtil.chooseXValue(source, handList.size());
} 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;
}
addListToHash(ability, "Revealed");
this.addListToHash(ability, "Revealed");
return true;
}
@@ -156,23 +155,23 @@ public class CostReveal extends CostPartWithList {
*/
@Override
public final String toString() {
StringBuilder sb = new StringBuilder();
final StringBuilder sb = new StringBuilder();
sb.append("Reveal ");
Integer i = convertAmount();
final Integer i = this.convertAmount();
if (getThis()) {
sb.append(type);
if (this.getThis()) {
sb.append(this.getType());
} else {
StringBuilder desc = new StringBuilder();
final StringBuilder desc = new StringBuilder();
if (type.equals("Card")) {
if (this.getType().equals("Card")) {
desc.append("Card");
} 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");
@@ -212,7 +211,7 @@ public class CostReveal extends CostPartWithList {
*/
public static Input inputRevealCost(final String discType, final CardList handList, final Cost_Payment payment,
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 int nReveal = 0;
@@ -220,23 +219,23 @@ public class CostReveal extends CostPartWithList {
@Override
public void showMessage() {
if (nNeeded == 0) {
done();
this.done();
}
if (AllZone.getHumanPlayer().getZone(Zone.Hand).size() < nNeeded) {
stop();
this.stop();
}
StringBuilder type = new StringBuilder("");
final StringBuilder type = new StringBuilder("");
if (!discType.equals("Card")) {
type.append(" ").append(discType);
}
StringBuilder sb = new StringBuilder();
final StringBuilder sb = new StringBuilder();
sb.append("Select a ");
sb.append(part.getDescriptiveType());
sb.append(" to reveal.");
if (nNeeded > 1) {
sb.append(" You have ");
sb.append(nNeeded - nReveal);
sb.append(nNeeded - this.nReveal);
sb.append(" remaining.");
}
AllZone.getDisplay().showMessage(sb.toString());
@@ -245,7 +244,7 @@ public class CostReveal extends CostPartWithList {
@Override
public void selectButtonCancel() {
cancel();
this.cancel();
}
@Override
@@ -254,29 +253,29 @@ public class CostReveal extends CostPartWithList {
// send in CardList for Typing
handList.remove(card);
part.addToList(card);
nReveal++;
this.nReveal++;
// in case no more cards in hand
if (nReveal == nNeeded) {
done();
if (this.nReveal == nNeeded) {
this.done();
} else if (AllZone.getHumanPlayer().getZone(Zone.Hand).size() == 0) {
// really
// shouldn't
// happen
cancel();
// shouldn't
// happen
this.cancel();
} else {
showMessage();
this.showMessage();
}
}
}
public void cancel() {
stop();
this.stop();
payment.cancelCost();
}
public void done() {
stop();
this.stop();
// "Inform" AI of the revealed cards
part.addListToHash(sa, "Revealed");
payment.paidCost(part);

View File

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

View File

@@ -13,8 +13,8 @@ public class CostTap extends CostPart {
* Instantiates a new cost tap.
*/
public CostTap() {
isReusable = true;
isUndoable = true;
this.setReusable(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) {
super(amount, type, description);
isReusable = true;
this.setReusable(true);
}
/**
@@ -40,7 +40,7 @@ public class CostTapType extends CostPartWithList {
* @return the description
*/
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
public final String toString() {
StringBuilder sb = new StringBuilder();
final StringBuilder sb = new StringBuilder();
sb.append("Tap ");
Integer i = convertAmount();
String desc = getDescription();
final Integer i = this.convertAmount();
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");
@@ -70,7 +70,7 @@ public class CostTapType extends CostPartWithList {
* the 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
public final void refund(final Card source) {
for (Card c : list) {
for (final Card c : this.list) {
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) {
CardList typeList = activator.getCardsIn(Zone.Battlefield);
typeList = typeList.getValidCards(getType().split(";"), activator, source);
typeList = typeList.getValidCards(this.getType().split(";"), activator, source);
if (cost.getTap()) {
typeList.remove(source);
}
typeList = typeList.filter(CardListFilter.UNTAPPED);
Integer amount = convertAmount();
if (typeList.size() == 0 || (amount != null && typeList.size() < amount)) {
final Integer amount = this.convertAmount();
if ((typeList.size() == 0) || ((amount != null) && (typeList.size() < amount))) {
return false;
}
@@ -121,8 +121,9 @@ public class CostTapType extends CostPartWithList {
*/
@Override
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();
}
}
/*
@@ -135,12 +136,13 @@ public class CostTapType extends CostPartWithList {
@Override
public final boolean payHuman(final SpellAbility ability, final Card source, final Cost_Payment payment) {
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);
String amount = getAmount();
Integer c = convertAmount();
final String amount = this.getAmount();
Integer c = this.convertAmount();
if (c == null) {
String sVar = source.getSVar(amount);
final String sVar = source.getSVar(amount);
// Generalize this
if (sVar.equals("XChoice")) {
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;
}
@@ -162,15 +164,15 @@ public class CostTapType extends CostPartWithList {
*/
@Override
public final boolean decideAIPayment(final SpellAbility ability, final Card source, final Cost_Payment payment) {
boolean tap = payment.getCost().getTap();
Integer c = convertAmount();
final boolean tap = payment.getCost().getTap();
final Integer c = this.convertAmount();
if (c == null) {
// 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());
return false;
}
@@ -197,24 +199,24 @@ public class CostTapType extends CostPartWithList {
* a int.
* @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) {
Input target = new Input() {
final Input target = new Input() {
private static final long serialVersionUID = 6438988130447851042L;
int nTapped = 0;
private int nTapped = 0;
@Override
public void showMessage() {
if (nCards == 0) {
done();
this.done();
}
if (cardList.size() == 0) {
stop();
this.stop();
}
int left = nCards - nTapped;
final int left = nCards - this.nTapped;
AllZone.getDisplay()
.showMessage("Select a " + tapType.getDescription() + " to tap (" + left + " left)");
ButtonUtil.enableOnlyCancel();
@@ -222,7 +224,7 @@ public class CostTapType extends CostPartWithList {
@Override
public void selectButtonCancel() {
cancel();
this.cancel();
}
@Override
@@ -233,31 +235,31 @@ public class CostTapType extends CostPartWithList {
tapType.addToList(card);
cardList.remove(card);
nTapped++;
this.nTapped++;
if (nTapped == nCards) {
done();
if (this.nTapped == nCards) {
this.done();
} else if (cardList.size() == 0) {
// happen
cancel();
this.cancel();
} else {
showMessage();
this.showMessage();
}
}
}
public void cancel() {
stop();
this.stop();
payment.cancelCost();
}
public void done() {
stop();
this.stop();
tapType.addListToHash(sa, "Tapped");
payment.paidCost(tapType);
}
};
return target;
}// input_tapXCost()
} // input_tapXCost()
}

View File

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

View File

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

View File

@@ -24,7 +24,7 @@ public class Cost_Payment {
private Card card = null;
private SpellAbility_Requirements req = null;
private boolean bCancel = false;
private Map<CostPart, Boolean> paidCostParts = new HashMap<CostPart, Boolean>();
private final Map<CostPart, Boolean> paidCostParts = new HashMap<CostPart, Boolean>();
/**
* <p>
@@ -34,7 +34,7 @@ public class Cost_Payment {
* @return a {@link forge.card.cost.Cost} object.
*/
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.
*/
public final SpellAbility getAbility() {
return ability;
return this.ability;
}
/**
@@ -56,7 +56,7 @@ public class Cost_Payment {
* @return a {@link forge.Card} object.
*/
public final Card getCard() {
return card;
return this.card;
}
/**
@@ -69,7 +69,7 @@ public class Cost_Payment {
* object.
*/
public final void setRequirements(final SpellAbility_Requirements reqs) {
req = reqs;
this.req = reqs;
}
/**
@@ -78,7 +78,7 @@ public class Cost_Payment {
* @return the requirements
*/
public final SpellAbility_Requirements getRequirements() {
return req;
return this.req;
}
/**
@@ -90,7 +90,7 @@ public class Cost_Payment {
* a boolean.
*/
public final void setCancel(final boolean cancel) {
bCancel = cancel;
this.bCancel = cancel;
}
/**
@@ -101,7 +101,7 @@ public class Cost_Payment {
* @return a boolean.
*/
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) {
this.cost = cost;
this.ability = abil;
card = abil.getSourceCard();
this.card = abil.getSourceCard();
for (CostPart part : cost.getCostParts()) {
paidCostParts.put(part, false);
for (final CostPart part : cost.getCostParts()) {
this.paidCostParts.put(part, false);
}
}
@@ -147,7 +147,7 @@ public class Cost_Payment {
activator = card.getController();
}
for (CostPart part : cost.getCostParts()) {
for (final CostPart part : cost.getCostParts()) {
if (!part.canPay(ability, card, activator, cost)) {
return false;
}
@@ -165,7 +165,7 @@ public class Cost_Payment {
* the b paid
*/
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
*/
public final void paidCost(final CostPart part) {
setPaidManaPart(part, true);
payCost();
this.setPaidManaPart(part, true);
this.payCost();
}
/**
* Cancel cost.
*/
public final void cancelCost() {
setCancel(true);
req.finishPaying();
this.setCancel(true);
this.req.finishPaying();
}
/**
@@ -196,24 +196,24 @@ public class Cost_Payment {
*/
public final boolean payCost() {
// Nothing actually ever checks this return value, is it needed?
if (bCancel) {
req.finishPaying();
if (this.bCancel) {
this.req.finishPaying();
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
if (paidCostParts.get(part)) {
if (this.paidCostParts.get(part)) {
continue;
}
if (!part.payHuman(ability, card, this)) {
if (!part.payHuman(this.ability, this.card, this)) {
return false;
}
}
resetUndoList();
req.finishPaying();
this.resetUndoList();
this.req.finishPaying();
return true;
}
@@ -225,8 +225,8 @@ public class Cost_Payment {
* @return a boolean.
*/
public final boolean isAllPaid() {
for (CostPart part : paidCostParts.keySet()) {
if (!paidCostParts.get(part)) {
for (final CostPart part : this.paidCostParts.keySet()) {
if (!this.paidCostParts.get(part)) {
return false;
}
}
@@ -240,7 +240,7 @@ public class Cost_Payment {
* </p>
*/
public final void resetUndoList() {
for (CostPart part : paidCostParts.keySet()) {
for (final CostPart part : this.paidCostParts.keySet()) {
if (part instanceof CostPartWithList) {
((CostPartWithList) part).resetList();
}
@@ -253,14 +253,14 @@ public class Cost_Payment {
* </p>
*/
public final void cancelPayment() {
for (CostPart part : paidCostParts.keySet()) {
if (paidCostParts.get(part) && part.isUndoable()) {
part.refund(card);
for (final CostPart part : this.paidCostParts.keySet()) {
if (this.paidCostParts.get(part) && part.isUndoable()) {
part.refund(this.card);
}
}
// 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
// here without being set
Player activator = AllZone.getComputerPlayer();
ability.setActivatingPlayer(activator);
final Player activator = AllZone.getComputerPlayer();
this.ability.setActivatingPlayer(activator);
Card source = ability.getSourceCard();
ArrayList<CostPart> parts = cost.getCostParts();
final Card source = this.ability.getSourceCard();
final ArrayList<CostPart> parts = this.cost.getCostParts();
// Set all of the decisions before attempting to pay anything
for (CostPart part : parts) {
if (!part.decideAIPayment(ability, source, this)) {
for (final CostPart part : parts) {
if (!part.decideAIPayment(this.ability, source, this)) {
return false;
}
}
for (CostPart part : parts) {
part.payAI(ability, ability.getSourceCard(), this);
for (final CostPart part : parts) {
part.payAI(this.ability, this.ability.getSourceCard(), this);
}
return true;
}
@@ -300,6 +300,6 @@ public class Cost_Payment {
* </p>
*/
public final void changeCost() {
cost.changeCost(ability);
this.cost.changeCost(this.ability);
}
}

View File

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