Input discard N or 1 of type X - made synchronous

This commit is contained in:
Maxmtg
2013-03-29 08:00:23 +00:00
parent 6293da1247
commit 188096fcbc
3 changed files with 21 additions and 51 deletions

View File

@@ -93,6 +93,7 @@ public class DiscardEffect extends RevealEffectBase {
for (final Player p : getTargetPlayers(sa)) { for (final Player p : getTargetPlayers(sa)) {
if ((tgt == null) || p.canBeTargetedBy(sa)) { if ((tgt == null) || p.canBeTargetedBy(sa)) {
final int numCardsInHand = p.getCardsIn(ZoneType.Hand).size();
if (mode.equals("Defined")) { if (mode.equals("Defined")) {
final List<Card> toDiscard = AbilityUtils.getDefinedCards(source, sa.getParam("DefinedCards"), sa); final List<Card> toDiscard = AbilityUtils.getDefinedCards(source, sa.getParam("DefinedCards"), sa);
for (final Card c : toDiscard) { for (final Card c : toDiscard) {
@@ -155,7 +156,8 @@ public class DiscardEffect extends RevealEffectBase {
} }
} }
} else if (mode.equals("TgtChoose") && sa.hasParam("UnlessType")) { } else if (mode.equals("TgtChoose") && sa.hasParam("UnlessType")) {
p.discardUnless(numCards, sa.getParam("UnlessType"), sa); if( numCardsInHand > 0 )
p.discardUnless(Math.min(numCards, numCardsInHand), sa.getParam("UnlessType"), sa);
} else if (mode.equals("RevealDiscardAll")) { } else if (mode.equals("RevealDiscardAll")) {
// Reveal // Reveal
final List<Card> dPHand = p.getCardsIn(ZoneType.Hand); final List<Card> dPHand = p.getCardsIn(ZoneType.Hand);

View File

@@ -219,8 +219,7 @@ public class CardFactoryCreatures {
target.addDamage(c.getNetAttack(), c); target.addDamage(c.getNetAttack(), c);
} }
if (target.getController().isHuman()) { // Human choose if (target.getController().isHuman()) { // Human choose spread damage
// spread damage
for (int x = 0; x < target.getNetAttack(); x++) { for (int x = 0; x < target.getNetAttack(); x++) {
Singletons.getModel().getMatch().getInput().setInput( Singletons.getModel().getMatch().getInput().setInput(
CardFactoryUtil.masterOfTheWildHuntInputTargetCreature(this, wolves, new Command() { CardFactoryUtil.masterOfTheWildHuntInputTargetCreature(this, wolves, new Command() {

View File

@@ -17,16 +17,15 @@
*/ */
package forge.game.player; package forge.game.player;
import java.util.List;
import forge.Card; import forge.Card;
import forge.Singletons; import forge.FThreads;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.control.input.Input; import forge.control.input.InputSelectCards;
import forge.control.input.InputBase; import forge.control.input.InputSelectCardsFromList;
import forge.game.GameState; import forge.game.GameState;
import forge.game.zone.Zone;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.gui.match.CMatchUI;
import forge.view.ButtonUtil;
public class HumanPlayer extends Player { public class HumanPlayer extends Player {
private PlayerControllerHuman controller; private PlayerControllerHuman controller;
@@ -39,54 +38,24 @@ public class HumanPlayer extends Player {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public final void discardUnless(final int num, final String uType, final SpellAbility sa) { public final void discardUnless(final int num, final String uType, final SpellAbility sa) {
if (this.getCardsIn(ZoneType.Hand).size() > 0) {
Singletons.getModel().getMatch().getInput().setInput(inputDiscardNumUnless(num, uType, sa));
}
}
private static Input inputDiscardNumUnless(final int nCards, final String uType, final SpellAbility sa) {
final SpellAbility sp = sa; final SpellAbility sp = sa;
final Input target = new InputBase() { final List<Card> hand = getCardsIn(ZoneType.Hand);
private static final long serialVersionUID = 8822292413831640944L; final InputSelectCards target = new InputSelectCardsFromList(num, num, hand) {
private static final long serialVersionUID = -5774108410928795591L;
private int n = 0;
@Override @Override
public void showMessage() { protected boolean hasAllTargets() {
if (Singletons.getControl().getPlayer().getZone(ZoneType.Hand).size() == 0) { for(Card c : selected) {
this.stop(); if (c.isType(uType))
} return true;
CMatchUI.SINGLETON_INSTANCE.showMessage(
"Select " + (nCards - this.n) + " cards to discard, unless you discard a " + uType + ".");
ButtonUtil.disableAll();
}
@Override
public void selectButtonCancel() {
this.stop();
}
@Override
public void selectCard(final Card card) {
Zone zone = Singletons.getModel().getGame().getZoneOf(card);
if (zone.is(ZoneType.Hand)) {
card.getController().discard(card, sp);
this.n++;
if (card.isType(uType.toString())) {
this.stop();
} else {
if ((this.n == nCards) || (Singletons.getControl().getPlayer().getZone(ZoneType.Hand).size() == 0)) {
this.stop();
} else {
this.showMessage();
}
}
} }
return super.hasAllTargets();
} }
}; };
target.setMessage("Select %d cards to discard, unless you discard a " + uType + ".");
return target; FThreads.setInputAndWait(target);
for(Card c : target.getSelected())
c.getController().discard(c, sp);
} // input_discardNumUnless } // input_discardNumUnless