From 59e6d17461c6f45a26712ad629746a1dbb20007f Mon Sep 17 00:00:00 2001 From: Maxmtg Date: Mon, 25 Mar 2013 09:37:32 +0000 Subject: [PATCH] InputPayReturnCost.java removed for there's already input to select cards, and the very discard can be done from outside of input. --- .gitattributes | 1 - .../control/input/InputPayReturnCost.java | 185 ------------------ src/main/java/forge/game/GameActionUtil.java | 57 +++--- 3 files changed, 34 insertions(+), 209 deletions(-) delete mode 100644 src/main/java/forge/control/input/InputPayReturnCost.java diff --git a/.gitattributes b/.gitattributes index 9df6a326203..772c8acae9c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -13813,7 +13813,6 @@ src/main/java/forge/control/input/InputPayManaExecuteCommands.java svneol=native src/main/java/forge/control/input/InputPayManaOfCostPayment.java -text src/main/java/forge/control/input/InputPayManaSimple.java svneol=native#text/plain src/main/java/forge/control/input/InputPayManaX.java -text -src/main/java/forge/control/input/InputPayReturnCost.java -text src/main/java/forge/control/input/InputPayment.java -text src/main/java/forge/control/input/InputSelectCards.java -text src/main/java/forge/control/input/InputSelectCardsFromList.java -text diff --git a/src/main/java/forge/control/input/InputPayReturnCost.java b/src/main/java/forge/control/input/InputPayReturnCost.java deleted file mode 100644 index 391ddde909f..00000000000 --- a/src/main/java/forge/control/input/InputPayReturnCost.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.control.input; - -import java.util.List; -import forge.Card; -import forge.CardLists; -import forge.Singletons; -import forge.card.cardfactory.CardFactoryUtil; -import forge.card.cost.CostReturn; -import forge.card.spellability.SpellAbility; -import forge.game.zone.PlayerZone; -import forge.game.zone.ZoneType; -import forge.gui.match.CMatchUI; -import forge.view.ButtonUtil; - -//if cost is paid, Command.execute() is called - -/** - *

- * Input_PayManaCost_Ability class. - *

- * - * @author Forge - * @version $Id: InputPayManaCostAbility.java 15673 2012-05-23 14:01:35Z ArsenalNut $ - */ -public class InputPayReturnCost extends InputSyncronizedBase implements InputPayment { - /** - * Constant serialVersionUID=2685832214529141991L. - */ - private static final long serialVersionUID = 8701146064257627671L; - - private int numChosen = 0; - private int numRequired = 0; - private List choiceList; - private CostReturn returnCost; - private SpellAbility ability; - - private boolean bPaid; - public boolean isPaid() { return bPaid; } - - /** - *

- * Constructor for InputPayReturnCost. - *

- * - * @param cost - * a {@link forge.card.cost.CostSacrifice} object. - * @param sa - * a {@link forge.card.spellability.SpellAbility} object. - * @param paidCommand - * a {@link forge.Command} object. - * @param unpaidCommand - * a {@link forge.Command} object. - */ - public InputPayReturnCost(final CostReturn cost, final SpellAbility sa) { - final Card source = sa.getSourceCard(); - - - this.ability = sa; - this.returnCost = cost; - this.choiceList = CardLists.getValidCards(Singletons.getControl().getPlayer().getCardsIn(ZoneType.Battlefield), cost.getType().split(";"), Singletons.getControl().getPlayer(), source); - String amountString = cost.getAmount(); - this.numRequired = amountString.matches("[0-9][0-9]?") ? Integer.parseInt(amountString) - : CardFactoryUtil.xCount(source, source.getSVar(amountString)); - } - - /** {@inheritDoc} */ - @Override - public void showMessage() { - final StringBuilder msg = new StringBuilder("Return "); - final int nLeft = this.numRequired - this.numChosen; - msg.append(nLeft).append(" "); - msg.append(this.returnCost.getDescriptiveType()); - if (nLeft > 1) { - msg.append("s"); - } - msg.append(" to your hand"); - if (!this.returnCost.getList().isEmpty()) { - msg.append("\r\nSelected:\r\n"); - for (Card selected : this.returnCost.getList()) { - msg.append(selected + "\r\n"); - } - } - - CMatchUI.SINGLETON_INSTANCE.showMessage(msg.toString()); - if (nLeft > 0) { - ButtonUtil.enableOnlyCancel(); - } - else { - ButtonUtil.enableAllFocusOk(); - } - } - - /** {@inheritDoc} */ - @Override - public void selectButtonCancel() { - this.cancel(); - } - - /** {@inheritDoc} */ - @Override - public void selectButtonOK() { - this.done(); - } - - /** {@inheritDoc} */ - @Override - public void selectCard(final Card card) { - if (this.choiceList.contains(card) && this.numChosen < numRequired) { - this.numChosen++; - this.returnCost.addToList(card); - card.setUsedToPay(true); - this.choiceList.remove(card); - this.showMessage(); - } - } - - /** - *

- * unselectCard. - *

- * - * @param card - * a {@link forge.Card} object. - * @param zone - * a {@link forge.game.zone.PlayerZone} object. - */ - public void unselectCard(final Card card, final PlayerZone zone) { - if (this.returnCost.getList().contains(card)) { - this.numChosen--; - card.setUsedToPay(false); - this.returnCost.getList().remove(card); - this.choiceList.add(card); - this.showMessage(); - } - } - - /** - *

- * executes paid commmand. - *

- * - */ - public void done() { - - // actually sacrifice the cards - for (Card selected : this.returnCost.getList()) { - selected.setUsedToPay(false); - Singletons.getModel().getGame().getAction().moveTo(ZoneType.Hand, selected); - } - this.returnCost.addListToHash(ability, "Returned"); - bPaid = true; - this.stop(); - } - - /** - *

- * executes unpaid commmand. - *

- * - */ - public void cancel() { - for (Card selected : this.returnCost.getList()) { - selected.setUsedToPay(false); - } - bPaid = false; - this.stop(); - } -} diff --git a/src/main/java/forge/game/GameActionUtil.java b/src/main/java/forge/game/GameActionUtil.java index f05ebc003ec..0efa659666b 100644 --- a/src/main/java/forge/game/GameActionUtil.java +++ b/src/main/java/forge/game/GameActionUtil.java @@ -59,8 +59,9 @@ import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbilityRestriction; import forge.control.input.InputPayDiscardCostWithCommands; import forge.control.input.InputPayManaExecuteCommands; -import forge.control.input.InputPayReturnCost; import forge.control.input.InputPayment; +import forge.control.input.InputSelectCards; +import forge.control.input.InputSelectCardsFromList; import forge.game.event.CardDamagedEvent; import forge.game.event.LifeLossEvent; import forge.game.player.AIPlayer; @@ -529,20 +530,34 @@ public final class GameActionUtil { hasPaid = false; break; } - - for (int i = 0; i < amount; i++) { - if (list.isEmpty()) { - hasPaid = false; - break; - } - Object o = GuiChoose.one("Select a card to sacrifice", list); - if (o != null) { - final Card c = (Card) o; - - Singletons.getModel().getGame().getAction().sacrifice(c, ability); - - list.remove(c); - } + + List toSac = p.getController().choosePermanentsToSacrifice(list, amount, ability, false, false); + if ( toSac.size() != amount ) { + hasPaid = false; + break; + } + for(Card c : toSac) { + Singletons.getModel().getGame().getAction().sacrifice(c, ability); + } + remainingParts.remove(part); + } + + else if (part instanceof CostReturn) { + List choiceList = CardLists.getValidCards(p.getCardsIn(ZoneType.Battlefield), part.getType().split(";"), p, source); + String amountString = part.getAmount(); + int amount = amountString.matches("[0-9][0-9]?") ? Integer.parseInt(amountString) : CardFactoryUtil.xCount(source, source.getSVar(amountString)); + + InputSelectCards inp = new InputSelectCardsFromList(amount, amount, choiceList); + inp.setMessage("Select cards to return to hand"); + inp.setCancelWithSelectedAllowed(true); + + FThreads.setInputAndWait(inp); + if( inp.hasCancelled() || inp.getSelected().size() != amount) { + hasPaid = false; + break; + } + for(Card c : inp.getSelected()) { + p.getGame().getAction().moveTo(ZoneType.Hand, c); } remainingParts.remove(part); } @@ -574,19 +589,14 @@ public final class GameActionUtil { //the following costs need inputs and can't be combined at the moment - InputPayment toSet = null; - if (costPart instanceof CostReturn) { - toSet = new InputPayReturnCost((CostReturn) costPart, ability); - } - else if (costPart instanceof CostDiscard) { + InputPayment toSet = null;; + if (costPart instanceof CostDiscard) { toSet = new InputPayDiscardCostWithCommands((CostDiscard) costPart, ability); } else if (costPart instanceof CostPartMana) { toSet = new InputPayManaExecuteCommands(game, source + "\r\n", ability.getManaCost().toString()); } - - if (toSet != null) { - + if (null != toSet) { FThreads.setInputAndWait(toSet); if (toSet.isPaid() ) { paid.execute(); @@ -594,6 +604,7 @@ public final class GameActionUtil { unpaid.execute(); } } + } // not restricted to combat damage, not restricted to dealing damage to