Code cleanup

This commit is contained in:
drdev
2013-12-08 23:18:40 +00:00
parent 776ac3ee2b
commit abc2118a77

View File

@@ -161,17 +161,20 @@ public class CostExile extends CostPartWithList {
List<Card> typeList = new ArrayList<Card>();
if (type.equals("All")) {
return true; // this will always work
} else if (type.contains("FromTopGrave")) {
}
else if (type.contains("FromTopGrave")) {
type = type.replace("FromTopGrave", "");
}
if (this.getFrom().equals(ZoneType.Stack)) {
for (SpellAbilityStackInstance si : game.getStack()) {
typeList.add(si.getSourceCard());
}
} else {
}
else {
if (this.sameZone) {
typeList = new ArrayList<Card>(game.getCardsIn(this.getFrom()));
} else {
}
else {
typeList = new ArrayList<Card>(activator.getCardsIn(this.getFrom()));
}
}
@@ -196,7 +199,8 @@ public class CostExile extends CostPartWithList {
return false;
}
}
} else if (!typeList.contains(source)) {
}
else if (!typeList.contains(source)) {
return false;
}
@@ -227,7 +231,8 @@ public class CostExile extends CostPartWithList {
if (this.sameZone) {
list = new ArrayList<Card>(game.getCardsIn(this.getFrom()));
} else {
}
else {
list = new ArrayList<Card>(activator.getCardsIn(this.getFrom()));
}
@@ -243,28 +248,29 @@ public class CostExile extends CostPartWithList {
// Generalize this
if (sVar.equals("XChoice")) {
c = Cost.chooseXValue(source, ability, list.size());
} else {
}
else {
c = AbilityUtils.calculateAmount(source, amount, ability);
}
}
if (this.payCostFromSource())
if (this.payCostFromSource()) {
return source.getZone() == activator.getZone(from) && GuiDialog.confirm(source, source.getName() + " - Exile?") && executePayment(ability, source);
}
List<Card> validCards = CardLists.getValidCards(activator.getCardsIn(from), type.split(";"), activator, source);
if (this.from == ZoneType.Battlefield || this.from == ZoneType.Hand) {
InputSelectCards inp = new InputSelectCardsFromList(c, c, validCards);
inp.setMessage("Exile %d card(s) from your" + from );
inp.setMessage("Exile %d card(s) from your" + from);
inp.setCancelAllowed(true);
Singletons.getControl().getInputQueue().setInputAndWait(inp);
return !inp.hasCancelled() && executePayment(ability, inp.getSelected());
}
if (this.from == ZoneType.Stack) return exileFromStack(ability, c);
if (this.from == ZoneType.Library) return exileFromTop(ability, c);
if (fromTopGrave) return exileFromTopGraveType(ability, c, validCards);
if (!this.sameZone) return exileFromMiscZone(ability, c, validCards);
if (this.from == ZoneType.Stack) { return exileFromStack(ability, c); }
if (this.from == ZoneType.Library) { return exileFromTop(ability, c); }
if (fromTopGrave) { return exileFromTopGraveType(ability, c, validCards); }
if (!this.sameZone) { return exileFromMiscZone(ability, c, validCards); }
List<Player> players = game.getPlayers();
List<Player> payableZone = new ArrayList<Player>();
@@ -272,15 +278,14 @@ public class CostExile extends CostPartWithList {
List<Card> enoughType = CardLists.filter(list, CardPredicates.isOwner(p));
if (enoughType.size() < c) {
list.removeAll(enoughType);
} else {
}
else {
payableZone.add(p);
}
}
return exileFromSame(list, c, payableZone);
}
// Inputs
// Exile<Num/Type{/TypeDescription}>
@@ -289,26 +294,11 @@ public class CostExile extends CostPartWithList {
// ExileFromTop<Num/Type{/TypeDescription}> (of library)
// ExileSameGrave<Num/Type{/TypeDescription}>
/**
* TODO: Write javadoc for this type.
*
*/
/**
* TODO: Write javadoc for Constructor.
* @param list
* @param part
* @param payment
* @param sa
* @param nNeeded
* @param payableZone
*/
private boolean exileFromSame(List<Card> list, int nNeeded, List<Player> payableZone) {
if (nNeeded == 0) {
return true;
}
final Player p = GuiChoose.oneOrNone(String.format("Exile from whose %s?", getFrom()), payableZone);
if (p == null) {
return false;
@@ -326,7 +316,8 @@ public class CostExile extends CostPartWithList {
if (c != null) {
typeList.remove(c);
executePayment(null, c);
} else {
}
else {
return false;
}
}
@@ -380,19 +371,20 @@ public class CostExile extends CostPartWithList {
if (!c.isCopiedSpell()) {
executePayment(sa, c);
} else {
}
else {
addToList(c);
}
final SpellAbilityStackInstance si = game.getStack().getInstanceFromSpellAbility(toExile);
game.getStack().remove(si);
} else {
}
else {
return false;
}
}
return true;
}
private boolean exileFromTop(final SpellAbility sa, final int nNeeded) {
final StringBuilder sb = new StringBuilder();
sb.append("Exile ").append(nNeeded).append(" cards from the top of your library?");
@@ -410,14 +402,12 @@ public class CostExile extends CostPartWithList {
executePayment(sa, itr.next());
}
return true;
} else {
}
else {
return false;
}
}
// ExileFromGrave<Num/Type{/TypeDescription}>
private boolean exileFromMiscZone(SpellAbility sa, int nNeeded, List<Card> typeList) {
for (int i = 0; i < nNeeded; i++) {
if (typeList.isEmpty()) {
@@ -448,6 +438,7 @@ public class CostExile extends CostPartWithList {
}
return true;
}
/* (non-Javadoc)
* @see forge.card.cost.CostPartWithList#executePayment(forge.card.spellability.SpellAbility, forge.Card)
*/
@@ -476,7 +467,8 @@ public class CostExile extends CostPartWithList {
if (this.getType().equals("All")) {
return new PaymentDecision(new ArrayList<Card>(ai.getCardsIn(this.getFrom())));
} else if (this.getType().contains("FromTopGrave")) {
}
else if (this.getType().contains("FromTopGrave")) {
return null;
}
@@ -492,10 +484,12 @@ public class CostExile extends CostPartWithList {
if (this.from.equals(ZoneType.Library)) {
return new PaymentDecision(ai.getCardsIn(ZoneType.Library, c));
} else if (this.sameZone) {
}
else if (this.sameZone) {
// TODO Determine exile from same zone for AI
return null;
} else {
}
else {
List<Card> chosen = ComputerUtil.chooseExileFrom(ai, this.getFrom(), this.getType(), source, ability.getTargetCard(), c);
return null == chosen ? null : new PaymentDecision(chosen);
}