Special input for discard cost during resolve also removed

This commit is contained in:
Maxmtg
2013-03-25 10:15:23 +00:00
parent 70ee826a52
commit 948ea6803c
4 changed files with 43 additions and 242 deletions

View File

@@ -25,14 +25,14 @@ import forge.FThreads;
import forge.Singletons;
import forge.card.ability.AbilityUtils;
import forge.card.spellability.SpellAbility;
import forge.control.input.InputSelectCards;
import forge.control.input.InputSelectCardsFromList;
import forge.game.GameState;
import forge.game.ai.ComputerUtil;
import forge.game.player.AIPlayer;
import forge.game.player.Player;
import forge.game.zone.ZoneType;
import forge.gui.GuiDialog;
import forge.gui.match.CMatchUI;
import forge.view.ButtonUtil;
/**
* The Class CostReturn.
@@ -40,76 +40,6 @@ import forge.view.ButtonUtil;
public class CostReturn extends CostPartWithList {
// Return<Num/Type{/TypeDescription}>
/**
* TODO: Write javadoc for this type.
*
*/
public static final class InputPayReturnType extends InputPayCostBase {
private final SpellAbility sa;
private final CostReturn part;
private final int nNeeded;
private final String type;
private static final long serialVersionUID = 2685832214519141903L;
private List<Card> typeList;
private int nReturns = 0;
/**
* TODO: Write javadoc for Constructor.
* @param sa
* @param part
* @param nNeeded
* @param cdl
* @param type
* @param payment
*/
public InputPayReturnType( SpellAbility sa, CostReturn part, int nNeeded, String type, CostPayment payment) {
super(payment);
this.sa = sa;
this.part = part;
this.nNeeded = nNeeded;
this.type = type;
}
@Override
public void showMessage() {
if (nNeeded == 0) {
this.done();
}
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");
}
this.typeList = new ArrayList<Card>(sa.getActivatingPlayer().getCardsIn(ZoneType.Battlefield));
this.typeList = CardLists.getValidCards(this.typeList, type.split(";"), sa.getActivatingPlayer(), sa.getSourceCard());
CMatchUI.SINGLETON_INSTANCE.showMessage(msg.toString());
ButtonUtil.enableOnlyCancel();
}
@Override
public void selectCard(final Card card) {
if (this.typeList.contains(card)) {
this.nReturns++;
part.addToList(card);
Singletons.getModel().getGame().getAction().moveToHand(card);
this.typeList.remove(card);
// in case nothing else to return
if (this.nReturns == nNeeded) {
this.done();
} else if (this.typeList.size() == 0) {
// happen
this.cancel();
} else {
this.showMessage();
}
}
}
}
/**
* Instantiates a new cost return.
*
@@ -223,13 +153,22 @@ public class CostReturn extends CostPartWithList {
boolean confirm = GuiDialog.confirm(card, card.getName() + " - Return to Hand?");
if (confirm) {
addToList(card);
Singletons.getModel().getGame().getAction().moveToHand(card);
game.getAction().moveToHand(card);
} else {
payment.cancelCost();
}
}
} else {
FThreads.setInputAndWait(new InputPayReturnType(ability, this, c, this.getType(), payment));
List<Card> validCards = CardLists.getValidCards(ability.getActivatingPlayer().getCardsIn(ZoneType.Battlefield), this.getType().split(";"), ability.getActivatingPlayer(), ability.getSourceCard());
InputSelectCards inp = new InputSelectCardsFromList(c, c, validCards);
inp.setMessage("Return %d " + this.getType() + " card(s) to hand");
FThreads.setInputAndWait(inp);
if (inp.hasCancelled())
payment.setCancel(true);
else
for(Card crd : inp.getSelected())
game.getAction().moveToHand(crd);
}
if (!payment.isCanceled())

View File

@@ -1,146 +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 <http://www.gnu.org/licenses/>.
*/
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.CostDiscard;
import forge.card.spellability.SpellAbility;
import forge.game.player.Player;
import forge.game.zone.ZoneType;
import forge.gui.match.CMatchUI;
import forge.view.ButtonUtil;
//if cost is paid, Command.execute() is called
/**
* <p>
* Input_PayManaCost_Ability class.
* </p>
*
* @author Forge
* @version $Id: InputPayManaCostAbility.java 15673 2012-05-23 14:01:35Z ArsenalNut $
*/
public class InputPayDiscardCostWithCommands extends InputSyncronizedBase implements InputPayment {
/**
* Constant <code>serialVersionUID=2685832214529141991L</code>.
*/
private static final long serialVersionUID = 5634078561074764401L;
private int numChosen = 0;
private int numRequired = 0;
private List<Card> choiceList;
private CostDiscard discardCost;
private SpellAbility ability;
private boolean bPaid;
public final boolean isPaid() { return bPaid; }
/**
* <p>
* Constructor for Input_PayManaCost_Ability.
* </p>
*
* @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 InputPayDiscardCostWithCommands(final CostDiscard cost, final SpellAbility sa) {
final Card source = sa.getSourceCard();
final Player human = Singletons.getControl().getPlayer();
this.ability = sa;
this.discardCost = cost;
this.choiceList = CardLists.getValidCards(human.getCardsIn(ZoneType.Hand), cost.getType().split(";"), human, 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("Discard ");
final int nLeft = this.numRequired - this.numChosen;
msg.append(nLeft).append(" ");
msg.append(this.discardCost.getDescriptiveType());
if (nLeft > 1) {
msg.append("s");
}
if (!this.discardCost.getList().isEmpty()) {
msg.append("\r\nSelected:\r\n");
for (Card selected : this.discardCost.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() {
for (Card selected : this.discardCost.getList()) {
selected.setUsedToPay(false);
}
this.bPaid = false;
this.stop();
}
/** {@inheritDoc} */
@Override
public void selectButtonOK() {
for (Card selected : this.discardCost.getList()) {
selected.setUsedToPay(false);
Singletons.getControl().getPlayer().discard(selected, this.ability);
}
this.discardCost.addListToHash(this.ability, "Discarded");
this.bPaid = true;
this.stop();
}
/** {@inheritDoc} */
@Override
public void selectCard(final Card card) {
if (this.discardCost.getList().contains(card)) {
this.numChosen--;
card.setUsedToPay(false);
this.discardCost.getList().remove(card);
this.choiceList.add(card);
}
else if (this.choiceList.contains(card) && this.numChosen < numRequired) {
this.numChosen++;
this.discardCost.addToList(card);
card.setUsedToPay(true);
this.choiceList.remove(card);
}
this.showMessage();
}
}

View File

@@ -57,7 +57,6 @@ import forge.card.spellability.AbilityManaPart;
import forge.card.spellability.AbilitySub;
import forge.card.spellability.SpellAbility;
import forge.card.spellability.SpellAbilityRestriction;
import forge.control.input.InputPayDiscardCostWithCommands;
import forge.control.input.InputPayManaExecuteCommands;
import forge.control.input.InputPayment;
import forge.control.input.InputSelectCards;
@@ -545,10 +544,10 @@ public final class GameActionUtil {
else if (part instanceof CostReturn) {
List<Card> 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));
int amount = StringUtils.isNumeric(amountString) ? 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.setMessage("Select %d card(s) to return to hand");
inp.setCancelWithSelectedAllowed(true);
FThreads.setInputAndWait(inp);
@@ -556,12 +555,34 @@ public final class GameActionUtil {
hasPaid = false;
break;
}
((CostReturn)part).addListToHash(ability, "Returned");
for(Card c : inp.getSelected()) {
p.getGame().getAction().moveTo(ZoneType.Hand, c);
}
remainingParts.remove(part);
}
else if (part instanceof CostDiscard) {
List<Card> choiceList = CardLists.getValidCards(p.getCardsIn(ZoneType.Hand), part.getType().split(";"), p, source);
String amountString = part.getAmount();
int amount = StringUtils.isNumeric(amountString) ? Integer.parseInt(amountString) : CardFactoryUtil.xCount(source, source.getSVar(amountString));
InputSelectCards inp = new InputSelectCardsFromList(amount, amount, choiceList);
inp.setMessage("Select %d card(s) to discard");
inp.setCancelWithSelectedAllowed(true);
FThreads.setInputAndWait(inp);
if( inp.hasCancelled() || inp.getSelected().size() != amount) {
hasPaid = false;
break;
}
((CostDiscard)part).addListToHash(ability, "Discarded");
for(Card c : inp.getSelected()) {
p.discard(c, ability);
}
remainingParts.remove(part);
}
else if (part instanceof CostPartMana && ((CostPartMana) part).getManaToPay().equals("0")) {
remainingParts.remove(part);
}
@@ -586,25 +607,13 @@ public final class GameActionUtil {
// at some point in time, it's possible to restore the InputPaySacCost-based input
// interface for sacrifice costs (instead of the menu-based one above).
//the following costs need inputs and can't be combined at the moment
InputPayment toSet = null;;
if (costPart instanceof CostDiscard) {
toSet = new InputPayDiscardCostWithCommands((CostDiscard) costPart, ability);
InputPayment toSet = new InputPayManaExecuteCommands(game, source + "\r\n", ability.getManaCost().toString());
FThreads.setInputAndWait(toSet);
if (toSet.isPaid() ) {
paid.execute();
} else {
unpaid.execute();
}
else if (costPart instanceof CostPartMana) {
toSet = new InputPayManaExecuteCommands(game, source + "\r\n", ability.getManaCost().toString());
}
if (null != toSet) {
FThreads.setInputAndWait(toSet);
if (toSet.isPaid() ) {
paid.execute();
} else {
unpaid.execute();
}
}
}
// not restricted to combat damage, not restricted to dealing damage to