From 40a945fa725d630a35de678b9a248c28e43931f0 Mon Sep 17 00:00:00 2001 From: Sol Date: Thu, 25 Aug 2011 00:25:20 +0000 Subject: [PATCH] Moving Inputs from Cost_Input into specific CostParts --- .gitattributes | 1 - .../java/forge/card/cost/CostDiscard.java | 87 +- src/main/java/forge/card/cost/CostExile.java | 202 ++++- src/main/java/forge/card/cost/CostMana.java | 190 ++++- src/main/java/forge/card/cost/CostReturn.java | 115 ++- .../java/forge/card/cost/CostSacrifice.java | 135 +++- .../java/forge/card/cost/CostTapType.java | 72 +- src/main/java/forge/card/cost/Cost_Input.java | 760 ------------------ 8 files changed, 788 insertions(+), 774 deletions(-) delete mode 100644 src/main/java/forge/card/cost/Cost_Input.java diff --git a/.gitattributes b/.gitattributes index 7017752f72e..1c8410df1d4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9616,7 +9616,6 @@ src/main/java/forge/card/cost/CostTap.java -text src/main/java/forge/card/cost/CostTapType.java -text src/main/java/forge/card/cost/CostUntap.java -text src/main/java/forge/card/cost/CostUtil.java -text -src/main/java/forge/card/cost/Cost_Input.java -text src/main/java/forge/card/cost/Cost_Payment.java svneol=native#text/plain src/main/java/forge/card/mana/Mana.java svneol=native#text/plain src/main/java/forge/card/mana/ManaCost.java svneol=native#text/plain diff --git a/src/main/java/forge/card/cost/CostDiscard.java b/src/main/java/forge/card/cost/CostDiscard.java index 40589553e1c..3f33a26df43 100644 --- a/src/main/java/forge/card/cost/CostDiscard.java +++ b/src/main/java/forge/card/cost/CostDiscard.java @@ -2,13 +2,16 @@ package forge.card.cost; import forge.AllZone; import forge.AllZoneUtil; +import forge.ButtonUtil; import forge.Card; import forge.CardList; import forge.CardListUtil; import forge.Constant; import forge.Player; +import forge.PlayerZone; import forge.card.abilityFactory.AbilityFactory; import forge.card.spellability.SpellAbility; +import forge.gui.input.Input; public class CostDiscard extends CostPartWithList { // Discard @@ -142,7 +145,7 @@ public class CostDiscard extends CostPartWithList { } } - CostUtil.setInput(Cost_Input.input_discardCost(discType, handList, ability, payment, this, c)); + CostUtil.setInput(CostDiscard.input_discardCost(discType, handList, ability, payment, this, c)); return false; } } @@ -191,4 +194,86 @@ public class CostDiscard extends CostPartWithList { } return list != null; } + + // Inputs + + /** + *

input_discardCost.

+ * @param discType a {@link java.lang.String} object. + * @param handList a {@link forge.CardList} object. + * @param sa a {@link forge.card.spellability.SpellAbility} object. + * @param payment a {@link forge.card.cost.Cost_Payment} object. + * @param part TODO + * @param nNeeded a int. + * + * @return a {@link forge.gui.input.Input} object. + */ + public static Input input_discardCost(final String discType, final CardList handList, SpellAbility sa, final Cost_Payment payment, final CostPart part, final int nNeeded) { + final SpellAbility sp = sa; + Input target = new Input() { + private static final long serialVersionUID = -329993322080934435L; + + int nDiscard = 0; + + @Override + public void showMessage() { + boolean any = discType.equals("Any") ? true : false; + if (AllZone.getHumanHand().size() == 0) stop(); + StringBuilder type = new StringBuilder(""); + if (any || !discType.equals("Card")) { + type.append(" ").append(discType); + } + StringBuilder sb = new StringBuilder(); + sb.append("Select "); + if (any) { + sb.append("any "); + } else { + sb.append("a ").append(type.toString()).append(" "); + } + sb.append("card to discard."); + if (nNeeded > 1) { + sb.append(" You have "); + sb.append(nNeeded - nDiscard); + sb.append(" remaining."); + } + AllZone.getDisplay().showMessage(sb.toString()); + ButtonUtil.enableOnlyCancel(); + } + + @Override + public void selectButtonCancel() { + cancel(); + } + + @Override + public void selectCard(Card card, PlayerZone zone) { + if (zone.is(Constant.Zone.Hand) && handList.contains(card)) { + // send in CardList for Typing + card.getController().discard(card, sp); + handList.remove(card); + nDiscard++; + + //in case no more cards in hand + if (nDiscard == nNeeded) + done(); + else if (AllZone.getHumanHand().size() == 0) // this really shouldn't happen + cancel(); + else + showMessage(); + } + } + + public void cancel() { + stop(); + payment.cancelCost(); + } + + public void done() { + stop(); + payment.paidCost(part); + } + }; + + return target; + }//input_discard() } diff --git a/src/main/java/forge/card/cost/CostExile.java b/src/main/java/forge/card/cost/CostExile.java index 340629ec475..bfc2baf5c24 100644 --- a/src/main/java/forge/card/cost/CostExile.java +++ b/src/main/java/forge/card/cost/CostExile.java @@ -1,15 +1,23 @@ package forge.card.cost; +import java.util.Iterator; + +import javax.swing.JOptionPane; + import forge.AllZone; import forge.AllZoneUtil; +import forge.ButtonUtil; import forge.Card; import forge.CardList; import forge.ComputerUtil; import forge.Constant; +import forge.GameActionUtil; import forge.Player; import forge.PlayerZone; import forge.card.abilityFactory.AbilityFactory; import forge.card.spellability.SpellAbility; +import forge.gui.GuiUtils; +import forge.gui.input.Input; public class CostExile extends CostPartWithList { //Exile @@ -104,16 +112,16 @@ public class CostExile extends CostPartWithList { } } if (getThis()){ - CostUtil.setInput(Cost_Input.exileThis(ability, payment, this)); + CostUtil.setInput(CostExile.exileThis(ability, payment, this)); } else if (from.equals(Constant.Zone.Battlefield) || from.equals(Constant.Zone.Hand)){ - CostUtil.setInput(Cost_Input.exileType(ability, this, getType(), payment, c)); + CostUtil.setInput(CostExile.exileType(ability, this, getType(), payment, c)); } else if (from.equals(Constant.Zone.Library)){ - Cost_Input.exileFromTop(ability, this, payment, c); + CostExile.exileFromTop(ability, this, payment, c); } else{ - CostUtil.setInput(Cost_Input.exileFrom(ability, this, getType(), payment, c)); + CostUtil.setInput(CostExile.exileFrom(ability, this, getType(), payment, c)); } return false; } @@ -146,4 +154,190 @@ public class CostExile extends CostPartWithList { } return true; } + + // Inputs + + public static void exileFromTop(final SpellAbility sa, final CostExile part, final Cost_Payment payment, final int nNeeded){ + StringBuilder sb = new StringBuilder(); + sb.append("Exile ").append(nNeeded).append(" cards from the top of your library?"); + CardList list = AllZoneUtil.getPlayerCardsInLibrary(sa.getActivatingPlayer(), nNeeded); + + if (list.size() > nNeeded){ + // I don't believe this is possible + payment.cancelCost(); + return; + } + + boolean doExile = GameActionUtil.showYesNoDialog(sa.getSourceCard(), sb.toString()); + if (doExile){ + Iterator itr = list.iterator(); + while(itr.hasNext()){ + Card c = (Card)itr.next(); + payment.getAbility().addCostToHashList(c, "Exiled"); + AllZone.getGameAction().exile(c); + } + payment.paidCost(part); + } + else{ + payment.cancelCost(); + } + } + + public static Input exileFrom(final SpellAbility sa, final CostExile part, final String type, final Cost_Payment payment, final int nNeeded) { + Input target = new Input() { + private static final long serialVersionUID = 734256837615635021L; + CardList typeList; + + @Override + public void showMessage() { + typeList = AllZoneUtil.getCardsInZone(part.getFrom(), sa.getActivatingPlayer()); + typeList = typeList.getValidCards(type.split(";"), sa.getActivatingPlayer(), sa.getSourceCard()); + + for (int i = 0; i < nNeeded; i++) { + if (typeList.size() == 0) + cancel(); + + Object o = GuiUtils.getChoiceOptional("Exile from "+part.getFrom(), typeList.toArray()); + + if (o != null) { + Card c = (Card) o; + typeList.remove(c); + payment.getAbility().addCostToHashList(c, "Exiled"); + AllZone.getGameAction().exile(c); + if (i == nNeeded - 1) done(); + } + else{ + cancel(); + break; + } + } + } + + @Override + public void selectButtonCancel() { + cancel(); + } + + public void done() { + stop(); + payment.paidCost(part); + } + + public void cancel() { + stop(); + payment.cancelCost(); + } + }; + return target; + }//exileFrom() + + /** + *

exileType.

+ * + * @param sa a {@link forge.card.spellability.SpellAbility} object. + * @param costExile TODO + * @param type a {@link java.lang.String} object. + * @param payment a {@link forge.card.cost.Cost_Payment} object. + * @return a {@link forge.gui.input.Input} object. + */ + public static Input exileType(final SpellAbility sa, final CostExile part, final String type, final Cost_Payment payment, final int nNeeded) { + Input target = new Input() { + private static final long serialVersionUID = 1403915758082824694L; + + private CardList typeList; + private int nExiles = 0; + + @Override + public void showMessage() { + StringBuilder msg = new StringBuilder("Exile "); + int nLeft = nNeeded - nExiles; + msg.append(nLeft).append(" "); + msg.append(type); + if (nLeft > 1) { + msg.append("s"); + } + + if (part.getFrom().equals(Constant.Zone.Hand)){ + msg.append(" from your Hand"); + } + typeList = AllZoneUtil.getCardsInZone(part.getFrom(), sa.getActivatingPlayer()); + typeList = typeList.getValidCards(type.split(";"), sa.getActivatingPlayer(), sa.getSourceCard()); + AllZone.getDisplay().showMessage(msg.toString()); + ButtonUtil.enableOnlyCancel(); + } + + @Override + public void selectButtonCancel() { + cancel(); + } + + @Override + public void selectCard(Card card, PlayerZone zone) { + if (typeList.contains(card)) { + nExiles++; + payment.getAbility().addCostToHashList(card, "Exiled"); + AllZone.getGameAction().exile(card); + typeList.remove(card); + //in case nothing else to exile + if (nExiles == nNeeded) + done(); + else if (typeList.size() == 0) // this really shouldn't happen + cancel(); + else + showMessage(); + } + } + + public void done() { + stop(); + payment.paidCost(part); + } + + public void cancel() { + stop(); + payment.cancelCost(); + } + }; + + return target; + }//exileType() + + /** + *

exileThis.

+ * + * @param sa a {@link forge.card.spellability.SpellAbility} object. + * @param payment a {@link forge.card.cost.Cost_Payment} object. + * @param costExile TODO + * @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() { + private static final long serialVersionUID = 678668673002725001L; + + @Override + public void showMessage() { + Card card = sa.getSourceCard(); + if (sa.getActivatingPlayer().isHuman() && AllZoneUtil.isCardInZone(AllZone.getZone(part.getFrom(), sa.getActivatingPlayer()), card)) { + 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", + JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, + null, possibleValues, possibleValues[0]); + if (choice.equals(0)) { + payment.getAbility().addCostToHashList(card, "Exiled"); + AllZone.getGameAction().exile(card); + stop(); + payment.paidCost(part); + } else { + stop(); + payment.cancelCost(); + } + } + } + }; + + return target; + }//input_exile() } diff --git a/src/main/java/forge/card/cost/CostMana.java b/src/main/java/forge/card/cost/CostMana.java index cd8c580e4d4..5062ea45025 100644 --- a/src/main/java/forge/card/cost/CostMana.java +++ b/src/main/java/forge/card/cost/CostMana.java @@ -2,11 +2,18 @@ package forge.card.cost; import com.google.common.base.Strings; +import forge.AllZone; +import forge.ButtonUtil; import forge.Card; import forge.ComputerUtil; +import forge.Phase; import forge.Player; +import forge.PlayerZone; import forge.card.abilityFactory.AbilityFactory; +import forge.card.mana.ManaCost; import forge.card.spellability.SpellAbility; +import forge.gui.input.Input; +import forge.gui.input.Input_PayManaCostUtil; public class CostMana extends CostPart { //"Leftover" @@ -89,9 +96,9 @@ public class CostMana extends CostPart { } } if (!getMana().equals("0") || manaToAdd > 0) - CostUtil.setInput(Cost_Input.input_payMana(ability, payment, this, manaToAdd)); + CostUtil.setInput(CostMana.input_payMana(ability, payment, this, manaToAdd)); else if (getXMana() > 0) - CostUtil.setInput(Cost_Input.input_payXMana(ability, payment, this, getXMana())); + CostUtil.setInput(CostMana.input_payXMana(ability, payment, this, getXMana())); // We return false here because the Inputs set above should recall payment.payCosts() return false; @@ -101,4 +108,183 @@ public class CostMana extends CostPart { public boolean decideAIPayment(SpellAbility ability, Card source, Cost_Payment payment) { return true; } + + // Inputs + + /** + *

input_payXMana.

+ * @param sa a {@link forge.card.spellability.SpellAbility} object. + * @param payment a {@link forge.card.cost.Cost_Payment} object. + * @param costMana TODO + * @param numX a int. + * + * @return a {@link forge.gui.input.Input} object. + */ + public static Input input_payXMana(final SpellAbility sa, final Cost_Payment payment, final CostMana costMana, final int numX) { + Input payX = new Input() { + private static final long serialVersionUID = -6900234444347364050L; + int xPaid = 0; + ManaCost manaCost = new ManaCost(Integer.toString(numX)); + + @Override + public void showMessage() { + if (manaCost.toString().equals(Integer.toString(numX))) // Can only 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."); + } + + // selectCard + @Override + public void selectCard(Card card, PlayerZone zone) { + if (sa.getSourceCard().equals(card) && sa.isTapAbility()) { + // this really shouldn't happen but just in case + return; + } + + manaCost = Input_PayManaCostUtil.activateManaAbility(sa, card, manaCost); + if (manaCost.isPaid()) { + manaCost = new ManaCost(Integer.toString(numX)); + xPaid++; + } + + if (AllZone.getInputControl().getInput() == this) + showMessage(); + } + + @Override + public void selectButtonCancel() { + stop(); + payment.cancelCost(); + AllZone.getHumanBattlefield().updateObservers(); + } + + @Override + public void selectButtonOK() { + stop(); + payment.getCard().setXManaCostPaid(xPaid); + payment.paidCost(costMana); + } + + }; + + return payX; + } + + /** + *

input_payMana.

+ * + * @param sa a {@link forge.card.spellability.SpellAbility} object. + * @param payment a {@link forge.card.cost.Cost_Payment} object. + * @param manaToAdd 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, final int manaToAdd) { + final ManaCost manaCost; + + if (Phase.getGameBegins() == 1) { + if (sa.getSourceCard().isCopiedSpell() && sa.isSpell()) { + manaCost = new ManaCost("0"); + } else { + String mana = costMana.getMana(); + manaCost = new ManaCost(mana); + manaCost.increaseColorlessMana(manaToAdd); + } + } else { + System.out.println("Is input_payMana ever called when the Game isn't in progress?"); + manaCost = new ManaCost(sa.getManaCost()); + } + + Input payMana = new Input() { + private ManaCost mana = manaCost; + private static final long serialVersionUID = 3467312982164195091L; + + private final String originalManaCost = costMana.getMana(); + + private int phyLifeToLose = 0; + + private void resetManaCost() { + mana = new ManaCost(originalManaCost); + phyLifeToLose = 0; + } + + @Override + public void selectCard(Card card, PlayerZone zone) { + // prevent cards from tapping themselves if ability is a tapability, although it should already be tapped + if (sa.getSourceCard().equals(card) && sa.isTapAbility()) { + return; + } + + mana = Input_PayManaCostUtil.activateManaAbility(sa, card, mana); + + if (mana.isPaid()) + done(); + else if (AllZone.getInputControl().getInput() == this) + showMessage(); + } + + @Override + public void selectPlayer(Player player) { + if (player.isHuman()) { + if (manaCost.payPhyrexian()) { + phyLifeToLose += 2; + } + + showMessage(); + } + } + + private void done() { + Card source = sa.getSourceCard(); + if (phyLifeToLose > 0) + AllZone.getHumanPlayer().payLife(phyLifeToLose, source); + source.setColorsPaid(mana.getColorsPaid()); + source.setSunburstValue(mana.getSunburst()); + resetManaCost(); + stop(); + + if (costMana.hasNoXManaCost() || manaToAdd > 0){ + payment.paidCost(costMana); + } + else{ + source.setXManaCostPaid(0); + CostUtil.setInput(CostMana.input_payXMana(sa, payment, costMana, costMana.getXMana())); + } + + } + + @Override + public void selectButtonCancel() { + stop(); + resetManaCost(); + payment.cancelCost(); + AllZone.getHumanBattlefield().updateObservers(); + } + + @Override + public void showMessage() { + ButtonUtil.enableOnlyCancel(); + String displayMana = mana.toString().replace("X", "").trim(); + AllZone.getDisplay().showMessage("Pay Mana Cost: " + displayMana); + + StringBuilder msg = new StringBuilder("Pay Mana Cost: " + displayMana); + if (phyLifeToLose > 0) { + msg.append(" ("); + msg.append(phyLifeToLose); + msg.append(" life paid for phyrexian mana)"); + } + + if (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(); + } + }; + return payMana; + } } diff --git a/src/main/java/forge/card/cost/CostReturn.java b/src/main/java/forge/card/cost/CostReturn.java index 08a668b12e6..03bd5e10d6f 100644 --- a/src/main/java/forge/card/cost/CostReturn.java +++ b/src/main/java/forge/card/cost/CostReturn.java @@ -1,13 +1,18 @@ package forge.card.cost; +import javax.swing.JOptionPane; + import forge.AllZone; import forge.AllZoneUtil; +import forge.ButtonUtil; import forge.Card; import forge.CardList; import forge.ComputerUtil; import forge.Player; +import forge.PlayerZone; import forge.card.abilityFactory.AbilityFactory; import forge.card.spellability.SpellAbility; +import forge.gui.input.Input; public class CostReturn extends CostPartWithList { // Return @@ -87,9 +92,9 @@ public class CostReturn extends CostPartWithList { } } if (getThis()) - CostUtil.setInput(Cost_Input.returnThis(ability, payment, this)); + CostUtil.setInput(CostReturn.returnThis(ability, payment, this)); else - CostUtil.setInput(Cost_Input.returnType(ability, getType(), payment, this, c)); + CostUtil.setInput(CostReturn.returnType(ability, getType(), payment, this, c)); return false; } @@ -110,4 +115,110 @@ public class CostReturn extends CostPartWithList { } return true; } + + // Inputs + + /** + *

returnType.

+ * + * @param sa a {@link forge.card.spellability.SpellAbility} object. + * @param type a {@link java.lang.String} object. + * @param payment a {@link forge.card.cost.Cost_Payment} object. + * @param part TODO + * @return a {@link forge.gui.input.Input} object. + */ + public static Input returnType(final SpellAbility sa, final String type, final Cost_Payment payment, final CostPart part, final int nNeeded) { + Input target = new Input() { + private static final long serialVersionUID = 2685832214519141903L; + private CardList typeList; + private int nReturns = 0; + + @Override + public void showMessage() { + StringBuilder msg = new StringBuilder("Return "); + int nLeft = nNeeded - nReturns; + msg.append(nLeft).append(" "); + msg.append(type); + if (nLeft > 1) { + msg.append("s"); + } + + typeList = AllZoneUtil.getPlayerCardsInPlay(sa.getSourceCard().getController()); + typeList = typeList.getValidCards(type.split(";"), sa.getActivatingPlayer(), sa.getSourceCard()); + AllZone.getDisplay().showMessage(msg.toString()); + ButtonUtil.enableOnlyCancel(); + } + + @Override + public void selectButtonCancel() { + cancel(); + } + + @Override + public void selectCard(Card card, PlayerZone zone) { + if (typeList.contains(card)) { + nReturns++; + AllZone.getGameAction().moveToHand(card); + typeList.remove(card); + //in case nothing else to return + if (nReturns == nNeeded) + done(); + else if (typeList.size() == 0) // this really shouldn't happen + cancel(); + else + showMessage(); + } + } + + public void done() { + stop(); + payment.paidCost(part); + } + + public void cancel() { + stop(); + payment.cancelCost(); + } + }; + + return target; + }//returnType() + + /** + *

returnThis.

+ * + * @param sa a {@link forge.card.spellability.SpellAbility} object. + * @param payment a {@link forge.card.cost.Cost_Payment} object. + * @param part TODO + * @return a {@link forge.gui.input.Input} object. + */ + public static Input returnThis(final SpellAbility sa, final Cost_Payment payment, final CostPart part) { + Input target = new Input() { + private static final long serialVersionUID = 2685832214519141903L; + + @Override + public void showMessage() { + Card card = sa.getSourceCard(); + if (card.getController().isHuman() && AllZoneUtil.isCardInPlay(card)) { + 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", + JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, + null, possibleValues, possibleValues[0]); + if (choice.equals(0)) { + AllZone.getGameAction().moveToHand(card); + stop(); + payment.paidCost(part); + } else { + stop(); + payment.cancelCost(); + } + } + } + }; + + return target; + }//input_sacrifice() } diff --git a/src/main/java/forge/card/cost/CostSacrifice.java b/src/main/java/forge/card/cost/CostSacrifice.java index 42abd25058f..c82d32a262c 100644 --- a/src/main/java/forge/card/cost/CostSacrifice.java +++ b/src/main/java/forge/card/cost/CostSacrifice.java @@ -1,13 +1,18 @@ package forge.card.cost; +import javax.swing.JOptionPane; + import forge.AllZone; import forge.AllZoneUtil; +import forge.ButtonUtil; import forge.Card; import forge.CardList; import forge.ComputerUtil; import forge.Player; +import forge.PlayerZone; import forge.card.abilityFactory.AbilityFactory; import forge.card.spellability.SpellAbility; +import forge.gui.input.Input; public class CostSacrifice extends CostPartWithList { @@ -77,10 +82,10 @@ public class CostSacrifice extends CostPartWithList { list = list.getValidCards(type.split(";"), activator, source); if (getThis()){ - CostUtil.setInput(Cost_Input.sacrificeThis(ability, payment, this)); + CostUtil.setInput(CostSacrifice.sacrificeThis(ability, payment, this)); } else if (amount.equals("All")){ - Cost_Input.sacrificeAll(ability, payment, this, list); + CostSacrifice.sacrificeAll(ability, payment, this, list); return true; } else{ @@ -96,7 +101,7 @@ public class CostSacrifice extends CostPartWithList { } } - CostUtil.setInput(Cost_Input.sacrificeFromList(ability, payment, this, list, c)); + CostUtil.setInput(CostSacrifice.sacrificeFromList(ability, payment, this, list, c)); } return false; @@ -129,4 +134,128 @@ public class CostSacrifice extends CostPartWithList { } return true; } + + // Inputs + + /** + *

sacrificeAllType.

+ * + * @param sa a {@link forge.card.spellability.SpellAbility} object. + * @param payment a {@link forge.card.cost.Cost_Payment} object. + * @param part TODO + * @param typeList TODO + */ + public static void sacrificeAll(final SpellAbility sa, final Cost_Payment payment, CostPart part, CardList typeList) { + // TODO Ask First + for (Card card : typeList) { + payment.getAbility().addCostToHashList(card, "Sacrificed"); + AllZone.getGameAction().sacrifice(card); + } + + payment.setPaidManaPart(part, true); + } + + /** + *

sacrificeFromList.

+ * @param sa a {@link forge.card.spellability.SpellAbility} object. + * @param payment a {@link forge.card.cost.Cost_Payment} object. + * @param part TODO + * @param typeList TODO + * @param num TODO + * + * @return a {@link forge.gui.input.Input} object. + */ + public static Input sacrificeFromList(final SpellAbility sa, final Cost_Payment payment, final CostSacrifice part, final CardList typeList, final int nNeeded) { + Input target = new Input() { + private static final long serialVersionUID = 2685832214519141903L; + private int nSacrifices = 0; + + @Override + public void showMessage() { + StringBuilder msg = new StringBuilder("Sacrifice "); + int nLeft = nNeeded - nSacrifices; + msg.append(nLeft).append(" "); + msg.append(part.getDescriptiveType()); + if (nLeft > 1) { + msg.append("s"); + } + + AllZone.getDisplay().showMessage(msg.toString()); + ButtonUtil.enableOnlyCancel(); + } + + @Override + public void selectButtonCancel() { + cancel(); + } + + @Override + public void selectCard(Card card, PlayerZone zone) { + if (typeList.contains(card)) { + nSacrifices++; + payment.getAbility().addCostToHashList(card, "Sacrificed"); + AllZone.getGameAction().sacrifice(card); + typeList.remove(card); + //in case nothing else to sacrifice + if (nSacrifices == nNeeded) + done(); + else if (typeList.size() == 0) // this really shouldn't happen + cancel(); + else + showMessage(); + } + } + + public void done() { + stop(); + payment.paidCost(part); + } + + public void cancel() { + stop(); + payment.cancelCost(); + } + }; + + return target; + }//sacrificeType() + + /** + *

sacrificeThis.

+ * + * @param sa a {@link forge.card.spellability.SpellAbility} object. + * @param payment a {@link forge.card.cost.Cost_Payment} object. + * @param part TODO + * @return a {@link forge.gui.input.Input} object. + */ + public static Input sacrificeThis(final SpellAbility sa, final Cost_Payment payment, final CostPart part) { + Input target = new Input() { + private static final long serialVersionUID = 2685832214519141903L; + + @Override + public void showMessage() { + Card card = sa.getSourceCard(); + if (card.getController().isHuman() && AllZoneUtil.isCardInPlay(card)) { + 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", + JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, + null, possibleValues, possibleValues[0]); + if (choice.equals(0)) { + payment.getAbility().addCostToHashList(card, "Sacrificed"); + AllZone.getGameAction().sacrifice(card); + stop(); + payment.paidCost(part); + } else { + stop(); + payment.cancelCost(); + } + } + } + }; + + return target; + }//input_sacrifice() } diff --git a/src/main/java/forge/card/cost/CostTapType.java b/src/main/java/forge/card/cost/CostTapType.java index e528538814a..db9d0eaf012 100644 --- a/src/main/java/forge/card/cost/CostTapType.java +++ b/src/main/java/forge/card/cost/CostTapType.java @@ -1,12 +1,17 @@ package forge.card.cost; +import forge.AllZone; import forge.AllZoneUtil; +import forge.ButtonUtil; import forge.Card; import forge.CardList; import forge.ComputerUtil; +import forge.Constant; import forge.Player; +import forge.PlayerZone; import forge.card.abilityFactory.AbilityFactory; import forge.card.spellability.SpellAbility; +import forge.gui.input.Input; public class CostTapType extends CostPartWithList { public CostTapType(String amount, String type, String description){ @@ -89,7 +94,7 @@ public class CostTapType extends CostPartWithList { } } - CostUtil.setInput(Cost_Input.input_tapXCost(this, typeList, ability, payment, c)); + CostUtil.setInput(CostTapType.input_tapXCost(this, typeList, ability, payment, c)); return false; } @@ -110,4 +115,69 @@ public class CostTapType extends CostPartWithList { return true; } + + // Inputs + + /** + *

input_tapXCost.

+ * + * @param nCards a int. + * @param cardType a {@link java.lang.String} object. + * @param cardList a {@link forge.CardList} object. + * @param sa a {@link forge.card.spellability.SpellAbility} object. + * @param payment a {@link forge.card.cost.Cost_Payment} object. + * @return a {@link forge.gui.input.Input} object. + */ + public static Input input_tapXCost(final CostTapType tapType, final CardList cardList, SpellAbility sa, final Cost_Payment payment, final int nCards) { + Input target = new Input() { + + private static final long serialVersionUID = 6438988130447851042L; + int nTapped = 0; + + @Override + public void showMessage() { + if (cardList.size() == 0) stop(); + + int left = nCards - nTapped; + AllZone.getDisplay().showMessage("Select a " + tapType.getDescription() + " to tap (" + left + " left)"); + ButtonUtil.enableOnlyCancel(); + } + + @Override + public void selectButtonCancel() { + cancel(); + } + + @Override + public void selectCard(Card card, PlayerZone zone) { + if (zone.is(Constant.Zone.Battlefield) && cardList.contains(card) && card.isUntapped()) { + // send in CardList for Typing + card.tap(); + tapType.addToList(card); + cardList.remove(card); + payment.getAbility().addCostToHashList(card, "Tapped"); + nTapped++; + + if (nTapped == nCards) + done(); + else if (cardList.size() == 0) // this really shouldn't happen + cancel(); + else + showMessage(); + } + } + + public void cancel() { + stop(); + payment.cancelCost(); + } + + public void done() { + stop(); + payment.paidCost(tapType); + } + }; + + return target; + }//input_tapXCost() } diff --git a/src/main/java/forge/card/cost/Cost_Input.java b/src/main/java/forge/card/cost/Cost_Input.java deleted file mode 100644 index 91a3b011e20..00000000000 --- a/src/main/java/forge/card/cost/Cost_Input.java +++ /dev/null @@ -1,760 +0,0 @@ -package forge.card.cost; - -import java.util.Iterator; - -import javax.swing.JOptionPane; - -import forge.AllZone; -import forge.AllZoneUtil; -import forge.ButtonUtil; -import forge.Card; -import forge.CardList; -import forge.Constant; -import forge.GameActionUtil; -import forge.Phase; -import forge.Player; -import forge.PlayerZone; -import forge.card.mana.ManaCost; -import forge.card.spellability.SpellAbility; -import forge.gui.GuiUtils; -import forge.gui.input.Input; -import forge.gui.input.Input_PayManaCostUtil; - -public class Cost_Input { - // ****************************************************************************** - // *********** Inputs used by Cost_Payment below here *************************** - // ****************************************************************************** - - /** - *

input_payMana.

- * - * @param sa a {@link forge.card.spellability.SpellAbility} object. - * @param payment a {@link forge.card.cost.Cost_Payment} object. - * @param manaToAdd 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, final int manaToAdd) { - final ManaCost manaCost; - - if (Phase.getGameBegins() == 1) { - if (sa.getSourceCard().isCopiedSpell() && sa.isSpell()) { - manaCost = new ManaCost("0"); - } else { - String mana = costMana.getMana(); - manaCost = new ManaCost(mana); - manaCost.increaseColorlessMana(manaToAdd); - } - } else { - System.out.println("Is input_payMana ever called when the Game isn't in progress?"); - manaCost = new ManaCost(sa.getManaCost()); - } - - Input payMana = new Input() { - private ManaCost mana = manaCost; - private static final long serialVersionUID = 3467312982164195091L; - - private final String originalManaCost = costMana.getMana(); - - private int phyLifeToLose = 0; - - private void resetManaCost() { - mana = new ManaCost(originalManaCost); - phyLifeToLose = 0; - } - - @Override - public void selectCard(Card card, PlayerZone zone) { - // prevent cards from tapping themselves if ability is a tapability, although it should already be tapped - if (sa.getSourceCard().equals(card) && sa.isTapAbility()) { - return; - } - - mana = Input_PayManaCostUtil.activateManaAbility(sa, card, mana); - - if (mana.isPaid()) - done(); - else if (AllZone.getInputControl().getInput() == this) - showMessage(); - } - - @Override - public void selectPlayer(Player player) { - if (player.isHuman()) { - if (manaCost.payPhyrexian()) { - phyLifeToLose += 2; - } - - showMessage(); - } - } - - private void done() { - Card source = sa.getSourceCard(); - if (phyLifeToLose > 0) - AllZone.getHumanPlayer().payLife(phyLifeToLose, source); - source.setColorsPaid(mana.getColorsPaid()); - source.setSunburstValue(mana.getSunburst()); - resetManaCost(); - stop(); - - if (costMana.hasNoXManaCost() || manaToAdd > 0){ - payment.paidCost(costMana); - } - else{ - source.setXManaCostPaid(0); - CostUtil.setInput(input_payXMana(sa, payment, costMana, costMana.getXMana())); - } - - } - - @Override - public void selectButtonCancel() { - stop(); - resetManaCost(); - payment.cancelCost(); - AllZone.getHumanBattlefield().updateObservers(); - } - - @Override - public void showMessage() { - ButtonUtil.enableOnlyCancel(); - String displayMana = mana.toString().replace("X", "").trim(); - AllZone.getDisplay().showMessage("Pay Mana Cost: " + displayMana); - - StringBuilder msg = new StringBuilder("Pay Mana Cost: " + displayMana); - if (phyLifeToLose > 0) { - msg.append(" ("); - msg.append(phyLifeToLose); - msg.append(" life paid for phyrexian mana)"); - } - - if (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(); - } - }; - return payMana; - } - - /** - *

input_payXMana.

- * @param sa a {@link forge.card.spellability.SpellAbility} object. - * @param payment a {@link forge.card.cost.Cost_Payment} object. - * @param costMana TODO - * @param numX a int. - * - * @return a {@link forge.gui.input.Input} object. - */ - public static Input input_payXMana(final SpellAbility sa, final Cost_Payment payment, final CostMana costMana, final int numX) { - Input payX = new Input() { - private static final long serialVersionUID = -6900234444347364050L; - int xPaid = 0; - ManaCost manaCost = new ManaCost(Integer.toString(numX)); - - @Override - public void showMessage() { - if (manaCost.toString().equals(Integer.toString(numX))) // Can only 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."); - } - - // selectCard - @Override - public void selectCard(Card card, PlayerZone zone) { - if (sa.getSourceCard().equals(card) && sa.isTapAbility()) { - // this really shouldn't happen but just in case - return; - } - - manaCost = Input_PayManaCostUtil.activateManaAbility(sa, card, manaCost); - if (manaCost.isPaid()) { - manaCost = new ManaCost(Integer.toString(numX)); - xPaid++; - } - - if (AllZone.getInputControl().getInput() == this) - showMessage(); - } - - @Override - public void selectButtonCancel() { - stop(); - payment.cancelCost(); - AllZone.getHumanBattlefield().updateObservers(); - } - - @Override - public void selectButtonOK() { - stop(); - payment.getCard().setXManaCostPaid(xPaid); - payment.paidCost(costMana); - } - - }; - - return payX; - } - - /** - *

input_discardCost.

- * @param discType a {@link java.lang.String} object. - * @param handList a {@link forge.CardList} object. - * @param sa a {@link forge.card.spellability.SpellAbility} object. - * @param payment a {@link forge.card.cost.Cost_Payment} object. - * @param part TODO - * @param nNeeded a int. - * - * @return a {@link forge.gui.input.Input} object. - */ - public static Input input_discardCost(final String discType, final CardList handList, SpellAbility sa, final Cost_Payment payment, final CostPart part, final int nNeeded) { - final SpellAbility sp = sa; - Input target = new Input() { - private static final long serialVersionUID = -329993322080934435L; - - int nDiscard = 0; - - @Override - public void showMessage() { - boolean any = discType.equals("Any") ? true : false; - if (AllZone.getHumanHand().size() == 0) stop(); - StringBuilder type = new StringBuilder(""); - if (any || !discType.equals("Card")) { - type.append(" ").append(discType); - } - StringBuilder sb = new StringBuilder(); - sb.append("Select "); - if (any) { - sb.append("any "); - } else { - sb.append("a ").append(type.toString()).append(" "); - } - sb.append("card to discard."); - if (nNeeded > 1) { - sb.append(" You have "); - sb.append(nNeeded - nDiscard); - sb.append(" remaining."); - } - AllZone.getDisplay().showMessage(sb.toString()); - ButtonUtil.enableOnlyCancel(); - } - - @Override - public void selectButtonCancel() { - cancel(); - } - - @Override - public void selectCard(Card card, PlayerZone zone) { - if (zone.is(Constant.Zone.Hand) && handList.contains(card)) { - // send in CardList for Typing - card.getController().discard(card, sp); - handList.remove(card); - nDiscard++; - - //in case no more cards in hand - if (nDiscard == nNeeded) - done(); - else if (AllZone.getHumanHand().size() == 0) // this really shouldn't happen - cancel(); - else - showMessage(); - } - } - - public void cancel() { - stop(); - payment.cancelCost(); - } - - public void done() { - stop(); - payment.paidCost(part); - } - }; - - return target; - }//input_discard() - - /** - *

sacrificeThis.

- * - * @param sa a {@link forge.card.spellability.SpellAbility} object. - * @param payment a {@link forge.card.cost.Cost_Payment} object. - * @param part TODO - * @return a {@link forge.gui.input.Input} object. - */ - public static Input sacrificeThis(final SpellAbility sa, final Cost_Payment payment, final CostPart part) { - Input target = new Input() { - private static final long serialVersionUID = 2685832214519141903L; - - @Override - public void showMessage() { - Card card = sa.getSourceCard(); - if (card.getController().isHuman() && AllZoneUtil.isCardInPlay(card)) { - 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", - JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, - null, possibleValues, possibleValues[0]); - if (choice.equals(0)) { - payment.getAbility().addCostToHashList(card, "Sacrificed"); - AllZone.getGameAction().sacrifice(card); - stop(); - payment.paidCost(part); - } else { - stop(); - payment.cancelCost(); - } - } - } - }; - - return target; - }//input_sacrifice() - - /** - *

sacrificeType.

- * @param sa a {@link forge.card.spellability.SpellAbility} object. - * @param payment a {@link forge.card.cost.Cost_Payment} object. - * @param part TODO - * @param typeList TODO - * @param num TODO - * - * @return a {@link forge.gui.input.Input} object. - */ - public static Input sacrificeFromList(final SpellAbility sa, final Cost_Payment payment, final CostSacrifice part, final CardList typeList, final int nNeeded) { - Input target = new Input() { - private static final long serialVersionUID = 2685832214519141903L; - private int nSacrifices = 0; - - @Override - public void showMessage() { - StringBuilder msg = new StringBuilder("Sacrifice "); - int nLeft = nNeeded - nSacrifices; - msg.append(nLeft).append(" "); - msg.append(part.getDescriptiveType()); - if (nLeft > 1) { - msg.append("s"); - } - - AllZone.getDisplay().showMessage(msg.toString()); - ButtonUtil.enableOnlyCancel(); - } - - @Override - public void selectButtonCancel() { - cancel(); - } - - @Override - public void selectCard(Card card, PlayerZone zone) { - if (typeList.contains(card)) { - nSacrifices++; - payment.getAbility().addCostToHashList(card, "Sacrificed"); - AllZone.getGameAction().sacrifice(card); - typeList.remove(card); - //in case nothing else to sacrifice - if (nSacrifices == nNeeded) - done(); - else if (typeList.size() == 0) // this really shouldn't happen - cancel(); - else - showMessage(); - } - } - - public void done() { - stop(); - payment.paidCost(part); - } - - public void cancel() { - stop(); - payment.cancelCost(); - } - }; - - return target; - }//sacrificeType() - - /** - *

sacrificeAllType.

- * - * @param sa a {@link forge.card.spellability.SpellAbility} object. - * @param payment a {@link forge.card.cost.Cost_Payment} object. - * @param part TODO - * @param typeList TODO - */ - public static void sacrificeAll(final SpellAbility sa, final Cost_Payment payment, CostPart part, CardList typeList) { - // TODO Ask First - for (Card card : typeList) { - payment.getAbility().addCostToHashList(card, "Sacrificed"); - AllZone.getGameAction().sacrifice(card); - } - - payment.setPaidManaPart(part, true); - } - - /** - *

exileThis.

- * - * @param sa a {@link forge.card.spellability.SpellAbility} object. - * @param payment a {@link forge.card.cost.Cost_Payment} object. - * @param costExile TODO - * @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() { - private static final long serialVersionUID = 678668673002725001L; - - @Override - public void showMessage() { - Card card = sa.getSourceCard(); - if (sa.getActivatingPlayer().isHuman() && AllZoneUtil.isCardInZone(AllZone.getZone(part.getFrom(), sa.getActivatingPlayer()), card)) { - 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", - JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, - null, possibleValues, possibleValues[0]); - if (choice.equals(0)) { - payment.getAbility().addCostToHashList(card, "Exiled"); - AllZone.getGameAction().exile(card); - stop(); - payment.paidCost(part); - } else { - stop(); - payment.cancelCost(); - } - } - } - }; - - return target; - }//input_exile() - - - /** - *

exileType.

- * - * @param sa a {@link forge.card.spellability.SpellAbility} object. - * @param costExile TODO - * @param type a {@link java.lang.String} object. - * @param payment a {@link forge.card.cost.Cost_Payment} object. - * @return a {@link forge.gui.input.Input} object. - */ - public static Input exileType(final SpellAbility sa, final CostExile part, final String type, final Cost_Payment payment, final int nNeeded) { - Input target = new Input() { - private static final long serialVersionUID = 1403915758082824694L; - - private CardList typeList; - private int nExiles = 0; - - @Override - public void showMessage() { - StringBuilder msg = new StringBuilder("Exile "); - int nLeft = nNeeded - nExiles; - msg.append(nLeft).append(" "); - msg.append(type); - if (nLeft > 1) { - msg.append("s"); - } - - if (part.getFrom().equals(Constant.Zone.Hand)){ - msg.append(" from your Hand"); - } - typeList = AllZoneUtil.getCardsInZone(part.getFrom(), sa.getActivatingPlayer()); - typeList = typeList.getValidCards(type.split(";"), sa.getActivatingPlayer(), sa.getSourceCard()); - AllZone.getDisplay().showMessage(msg.toString()); - ButtonUtil.enableOnlyCancel(); - } - - @Override - public void selectButtonCancel() { - cancel(); - } - - @Override - public void selectCard(Card card, PlayerZone zone) { - if (typeList.contains(card)) { - nExiles++; - payment.getAbility().addCostToHashList(card, "Exiled"); - AllZone.getGameAction().exile(card); - typeList.remove(card); - //in case nothing else to exile - if (nExiles == nNeeded) - done(); - else if (typeList.size() == 0) // this really shouldn't happen - cancel(); - else - showMessage(); - } - } - - public void done() { - stop(); - payment.paidCost(part); - } - - public void cancel() { - stop(); - payment.cancelCost(); - } - }; - - return target; - }//exileType() - - public static Input exileFrom(final SpellAbility sa, final CostExile part, final String type, final Cost_Payment payment, final int nNeeded) { - Input target = new Input() { - private static final long serialVersionUID = 734256837615635021L; - CardList typeList; - - @Override - public void showMessage() { - typeList = AllZoneUtil.getCardsInZone(part.getFrom(), sa.getActivatingPlayer()); - typeList = typeList.getValidCards(type.split(";"), sa.getActivatingPlayer(), sa.getSourceCard()); - - for (int i = 0; i < nNeeded; i++) { - if (typeList.size() == 0) - cancel(); - - Object o = GuiUtils.getChoiceOptional("Exile from "+part.getFrom(), typeList.toArray()); - - if (o != null) { - Card c = (Card) o; - typeList.remove(c); - payment.getAbility().addCostToHashList(c, "Exiled"); - AllZone.getGameAction().exile(c); - if (i == nNeeded - 1) done(); - } - else{ - cancel(); - break; - } - } - } - - @Override - public void selectButtonCancel() { - cancel(); - } - - public void done() { - stop(); - payment.paidCost(part); - } - - public void cancel() { - stop(); - payment.cancelCost(); - } - }; - return target; - }//exileFrom() - - - public static void exileFromTop(final SpellAbility sa, final CostExile part, final Cost_Payment payment, final int nNeeded){ - StringBuilder sb = new StringBuilder(); - sb.append("Exile ").append(nNeeded).append(" cards from the top of your library?"); - CardList list = AllZoneUtil.getPlayerCardsInLibrary(sa.getActivatingPlayer(), nNeeded); - - if (list.size() > nNeeded){ - // I don't believe this is possible - payment.cancelCost(); - return; - } - - boolean doExile = GameActionUtil.showYesNoDialog(sa.getSourceCard(), sb.toString()); - if (doExile){ - Iterator itr = list.iterator(); - while(itr.hasNext()){ - Card c = (Card)itr.next(); - payment.getAbility().addCostToHashList(c, "Exiled"); - AllZone.getGameAction().exile(c); - } - payment.paidCost(part); - } - else{ - payment.cancelCost(); - } - } - - /** - *

input_tapXCost.

- * - * @param nCards a int. - * @param cardType a {@link java.lang.String} object. - * @param cardList a {@link forge.CardList} object. - * @param sa a {@link forge.card.spellability.SpellAbility} object. - * @param payment a {@link forge.card.cost.Cost_Payment} object. - * @return a {@link forge.gui.input.Input} object. - */ - public static Input input_tapXCost(final CostTapType tapType, final CardList cardList, SpellAbility sa, final Cost_Payment payment, final int nCards) { - Input target = new Input() { - - private static final long serialVersionUID = 6438988130447851042L; - int nTapped = 0; - - @Override - public void showMessage() { - if (cardList.size() == 0) stop(); - - int left = nCards - nTapped; - AllZone.getDisplay().showMessage("Select a " + tapType.getDescription() + " to tap (" + left + " left)"); - ButtonUtil.enableOnlyCancel(); - } - - @Override - public void selectButtonCancel() { - cancel(); - } - - @Override - public void selectCard(Card card, PlayerZone zone) { - if (zone.is(Constant.Zone.Battlefield) && cardList.contains(card) && card.isUntapped()) { - // send in CardList for Typing - card.tap(); - tapType.addToList(card); - cardList.remove(card); - payment.getAbility().addCostToHashList(card, "Tapped"); - nTapped++; - - if (nTapped == nCards) - done(); - else if (cardList.size() == 0) // this really shouldn't happen - cancel(); - else - showMessage(); - } - } - - public void cancel() { - stop(); - payment.cancelCost(); - } - - public void done() { - stop(); - payment.paidCost(tapType); - } - }; - - return target; - }//input_tapXCost() - - /** - *

returnThis.

- * - * @param sa a {@link forge.card.spellability.SpellAbility} object. - * @param payment a {@link forge.card.cost.Cost_Payment} object. - * @param part TODO - * @return a {@link forge.gui.input.Input} object. - */ - public static Input returnThis(final SpellAbility sa, final Cost_Payment payment, final CostPart part) { - Input target = new Input() { - private static final long serialVersionUID = 2685832214519141903L; - - @Override - public void showMessage() { - Card card = sa.getSourceCard(); - if (card.getController().isHuman() && AllZoneUtil.isCardInPlay(card)) { - 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", - JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, - null, possibleValues, possibleValues[0]); - if (choice.equals(0)) { - AllZone.getGameAction().moveToHand(card); - stop(); - payment.paidCost(part); - } else { - stop(); - payment.cancelCost(); - } - } - } - }; - - return target; - }//input_sacrifice() - - - /** - *

returnType.

- * - * @param sa a {@link forge.card.spellability.SpellAbility} object. - * @param type a {@link java.lang.String} object. - * @param payment a {@link forge.card.cost.Cost_Payment} object. - * @param part TODO - * @return a {@link forge.gui.input.Input} object. - */ - public static Input returnType(final SpellAbility sa, final String type, final Cost_Payment payment, final CostPart part, final int nNeeded) { - Input target = new Input() { - private static final long serialVersionUID = 2685832214519141903L; - private CardList typeList; - private int nReturns = 0; - - @Override - public void showMessage() { - StringBuilder msg = new StringBuilder("Return "); - int nLeft = nNeeded - nReturns; - msg.append(nLeft).append(" "); - msg.append(type); - if (nLeft > 1) { - msg.append("s"); - } - - typeList = AllZoneUtil.getPlayerCardsInPlay(sa.getSourceCard().getController()); - typeList = typeList.getValidCards(type.split(";"), sa.getActivatingPlayer(), sa.getSourceCard()); - AllZone.getDisplay().showMessage(msg.toString()); - ButtonUtil.enableOnlyCancel(); - } - - @Override - public void selectButtonCancel() { - cancel(); - } - - @Override - public void selectCard(Card card, PlayerZone zone) { - if (typeList.contains(card)) { - nReturns++; - AllZone.getGameAction().moveToHand(card); - typeList.remove(card); - //in case nothing else to return - if (nReturns == nNeeded) - done(); - else if (typeList.size() == 0) // this really shouldn't happen - cancel(); - else - showMessage(); - } - } - - public void done() { - stop(); - payment.paidCost(part); - } - - public void cancel() { - stop(); - payment.cancelCost(); - } - }; - - return target; - }//returnType() -}