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)) {
if ((tgt == null) || p.canBeTargetedBy(sa)) {
final int numCardsInHand = p.getCardsIn(ZoneType.Hand).size();
if (mode.equals("Defined")) {
final List<Card> toDiscard = AbilityUtils.getDefinedCards(source, sa.getParam("DefinedCards"), sa);
for (final Card c : toDiscard) {
@@ -155,7 +156,8 @@ public class DiscardEffect extends RevealEffectBase {
}
}
} 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")) {
// Reveal
final List<Card> dPHand = p.getCardsIn(ZoneType.Hand);

View File

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

View File

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