From abc2118a7783e7190c5f5b25c618b41f9c766df0 Mon Sep 17 00:00:00 2001 From: drdev Date: Sun, 8 Dec 2013 23:18:40 +0000 Subject: [PATCH] Code cleanup --- .../main/java/forge/game/cost/CostExile.java | 158 +++++++++--------- 1 file changed, 76 insertions(+), 82 deletions(-) diff --git a/forge-gui/src/main/java/forge/game/cost/CostExile.java b/forge-gui/src/main/java/forge/game/cost/CostExile.java index 504b1af46ef..635fc988681 100644 --- a/forge-gui/src/main/java/forge/game/cost/CostExile.java +++ b/forge-gui/src/main/java/forge/game/cost/CostExile.java @@ -157,21 +157,24 @@ public class CostExile extends CostPartWithList { final Card source = ability.getSourceCard(); final Game game = activator.getGame(); String type = this.getType(); - + List typeList = new ArrayList(); 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(game.getCardsIn(this.getFrom())); - } else { + } + else { typeList = new ArrayList(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; } @@ -222,12 +226,13 @@ public class CostExile extends CostPartWithList { type = type.replace("FromTopGrave", ""); fromTopGrave = true; } - + List list; if (this.sameZone) { list = new ArrayList(game.getCardsIn(this.getFrom())); - } else { + } + else { list = new ArrayList(activator.getCardsIn(this.getFrom())); } @@ -243,44 +248,44 @@ 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 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 players = game.getPlayers(); List payableZone = new ArrayList(); for (Player p : players) { List 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 @@ -288,45 +293,31 @@ public class CostExile extends CostPartWithList { // ExileFromGrave // ExileFromTop (of library) // ExileSameGrave - - /** - * 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 list, int nNeeded, List payableZone) { if (nNeeded == 0) { return true; } - - + final Player p = GuiChoose.oneOrNone(String.format("Exile from whose %s?", getFrom()), payableZone); if (p == null) { return false; } - + List typeList = CardLists.filter(list, CardPredicates.isOwner(p)); - + for (int i = 0; i < nNeeded; i++) { if (typeList.isEmpty()) { return false; } - + final Card c = GuiChoose.oneOrNone("Exile from " + getFrom(), typeList); - + if (c != null) { typeList.remove(c); executePayment(null, c); - } else { + } + else { return false; } } @@ -345,11 +336,11 @@ public class CostExile extends CostPartWithList { if (nNeeded == 0) { return true; } - + final Game game = sa.getActivatingPlayer().getGame(); ArrayList saList = new ArrayList(); ArrayList descList = new ArrayList(); - + for (SpellAbilityStackInstance si : game.getStack()) { final Card stC = si.getSourceCard(); final SpellAbility stSA = si.getSpellAbility().getRootAbility(); @@ -362,37 +353,38 @@ public class CostExile extends CostPartWithList { } } } - + for (int i = 0; i < nNeeded; i++) { if (saList.isEmpty()) { return false; } - + //Have to use the stack descriptions here because some copied spells have no description otherwise final String o = GuiChoose.oneOrNone("Exile from " + getFrom(), descList); - + if (o != null) { final SpellAbility toExile = saList.get(descList.indexOf(o)); final Card c = toExile.getSourceCard(); - + saList.remove(toExile); descList.remove(o); 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,44 +402,43 @@ public class CostExile extends CostPartWithList { executePayment(sa, itr.next()); } return true; - } else { + } + else { return false; } } - - // ExileFromGrave - - private boolean exileFromMiscZone(SpellAbility sa, int nNeeded, List typeList) { - for (int i = 0; i < nNeeded; i++) { - if (typeList.isEmpty()) { - return false; - } - - final Card c = GuiChoose.oneOrNone("Exile from " + getFrom(), typeList); - - if (c != null) { - typeList.remove(c); - executePayment(sa, c); - } else { - return false; - } + private boolean exileFromMiscZone(SpellAbility sa, int nNeeded, List typeList) { + for (int i = 0; i < nNeeded; i++) { + if (typeList.isEmpty()) { + return false; } - return true; - } - private boolean exileFromTopGraveType(SpellAbility sa, int nNeeded, List typeList) { - Collections.reverse(typeList); - for (int i = 0; i < nNeeded; i++) { - if (typeList.isEmpty()) { - return false; - } - final Card c = typeList.get(0); + final Card c = GuiChoose.oneOrNone("Exile from " + getFrom(), typeList); + + if (c != null) { typeList.remove(c); executePayment(sa, c); + } else { + return false; } - return true; } + return true; + } + + private boolean exileFromTopGraveType(SpellAbility sa, int nNeeded, List typeList) { + Collections.reverse(typeList); + for (int i = 0; i < nNeeded; i++) { + if (typeList.isEmpty()) { + return false; + } + final Card c = typeList.get(0); + typeList.remove(c); + executePayment(sa, c); + } + return true; + } + /* (non-Javadoc) * @see forge.card.cost.CostPartWithList#executePayment(forge.card.spellability.SpellAbility, forge.Card) */ @@ -472,11 +463,12 @@ public class CostExile extends CostPartWithList { public PaymentDecision decideAIPayment(Player ai, SpellAbility ability, Card source) { if (this.payCostFromSource()) { return new PaymentDecision(source); - } + } if (this.getType().equals("All")) { return new PaymentDecision(new ArrayList(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 chosen = ComputerUtil.chooseExileFrom(ai, this.getFrom(), this.getType(), source, ability.getTargetCard(), c); return null == chosen ? null : new PaymentDecision(chosen); }