mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
discardUnless moved to player controllers
This commit is contained in:
@@ -8,6 +8,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import forge.control.input.InputQueue;
|
||||
import forge.control.input.InputSynchronized;
|
||||
|
||||
/**
|
||||
@@ -104,14 +105,15 @@ public class FThreads {
|
||||
|
||||
public static void invokeInNewThread(final Runnable proc, boolean lockUI) {
|
||||
Runnable toRun = proc;
|
||||
final InputQueue iq = Singletons.getControl().getMatch().getInput();
|
||||
if( lockUI ) {
|
||||
// checkEDT("FThreads.invokeInNewthread", true)
|
||||
Singletons.getControl().getMatch().getInput().lock();
|
||||
iq.lock();
|
||||
toRun = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
proc.run();
|
||||
Singletons.getControl().getMatch().getInput().unlock();
|
||||
iq.unlock();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -157,8 +157,12 @@ public class DiscardEffect extends RevealEffectBase {
|
||||
}
|
||||
}
|
||||
} else if (mode.equals("TgtChoose") && sa.hasParam("UnlessType")) {
|
||||
if( numCardsInHand > 0 )
|
||||
p.discardUnless(Math.min(numCards, numCardsInHand), sa.getParam("UnlessType"), sa);
|
||||
if( numCardsInHand > 0 ) {
|
||||
final List<Card> hand = p.getCardsIn(ZoneType.Hand);
|
||||
List<Card> toDiscard = p.getController().chooseCardsToDiscardUnlessType(Math.min(numCards, numCardsInHand), hand, sa.getParam("UnlessType"), sa);
|
||||
for(Card c : toDiscard)
|
||||
c.getController().discard(c, sa);
|
||||
}
|
||||
} else if (mode.equals("RevealDiscardAll")) {
|
||||
// Reveal
|
||||
final List<Card> dPHand = p.getCardsIn(ZoneType.Hand);
|
||||
|
||||
@@ -9,7 +9,6 @@ import java.util.Map;
|
||||
import forge.Card;
|
||||
import forge.CardLists;
|
||||
import forge.CardPredicates;
|
||||
import forge.Singletons;
|
||||
import forge.card.ability.SpellAbilityEffect;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.game.GameNew;
|
||||
|
||||
@@ -64,10 +64,6 @@ public abstract class InputBase implements java.io.Serializable, Input {
|
||||
afterStop(); // sync inputs will release their latch there
|
||||
}
|
||||
|
||||
protected final boolean isActive() {
|
||||
return Singletons.getControl().getMatch().getInput().getInput() == this;
|
||||
}
|
||||
|
||||
protected void afterStop() { }
|
||||
|
||||
|
||||
|
||||
@@ -17,16 +17,8 @@
|
||||
*/
|
||||
package forge.game.player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import forge.Card;
|
||||
import forge.CardLists;
|
||||
import forge.CardPredicates;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.game.GameState;
|
||||
import forge.game.ai.AiController;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.Aggregates;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -62,31 +54,6 @@ public class AIPlayer extends Player {
|
||||
|
||||
|
||||
|
||||
// //////////////////////////////
|
||||
// /
|
||||
// / replaces Singletons.getModel().getGameAction().discard* methods
|
||||
// /
|
||||
// //////////////////////////////
|
||||
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final void discardUnless(final int num, final String uType, final SpellAbility sa) {
|
||||
final List<Card> hand = this.getCardsIn(ZoneType.Hand);
|
||||
final List<Card> tHand = CardLists.getType(hand, uType);
|
||||
|
||||
if (tHand.size() > 0) {
|
||||
Card toDiscard = Aggregates.itemWithMin(tHand, CardPredicates.Accessors.fnGetCmc);
|
||||
discard(toDiscard, sa); // this got changed to doDiscard basically
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Card> toDiscard = getAi().getCardsToDiscard(num, (String[])null, sa);
|
||||
for (int i = 0; i < toDiscard.size(); i++) {
|
||||
discard(toDiscard.get(i), sa);
|
||||
}
|
||||
}
|
||||
|
||||
// /////////////////////////
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
@@ -35,11 +35,8 @@ import forge.card.spellability.SpellAbility;
|
||||
import forge.card.spellability.Target;
|
||||
import forge.control.input.InputPayManaBase;
|
||||
import forge.control.input.InputPayManaSimple;
|
||||
import forge.control.input.InputSelectCards;
|
||||
import forge.control.input.InputSelectCardsFromList;
|
||||
import forge.game.GameActionUtil;
|
||||
import forge.game.GameState;
|
||||
import forge.game.zone.ZoneType;
|
||||
|
||||
public class HumanPlayer extends Player {
|
||||
private final PlayerControllerHuman controller;
|
||||
@@ -51,28 +48,6 @@ public class HumanPlayer extends Player {
|
||||
controller = new PlayerControllerHuman(game, this);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final void discardUnless(final int num, final String uType, final SpellAbility sa) {
|
||||
final List<Card> hand = getCardsIn(ZoneType.Hand);
|
||||
final InputSelectCards target = new InputSelectCardsFromList(num, num, hand) {
|
||||
private static final long serialVersionUID = -5774108410928795591L;
|
||||
|
||||
@Override
|
||||
protected boolean hasAllTargets() {
|
||||
for(Card c : selected) {
|
||||
if (c.isType(uType))
|
||||
return true;
|
||||
}
|
||||
return super.hasAllTargets();
|
||||
}
|
||||
};
|
||||
target.setMessage("Select %d cards to discard, unless you discard a " + uType + ".");
|
||||
FThreads.setInputAndWait(target);
|
||||
for(Card c : target.getSelected())
|
||||
c.getController().discard(c, sa);
|
||||
} // input_discardNumUnless
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
* @param card
|
||||
|
||||
@@ -1672,19 +1672,6 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
|
||||
public final void resetNumDiscardedThisTurn() {
|
||||
this.numDiscardedThisTurn = 0;
|
||||
}
|
||||
/**
|
||||
* <p>
|
||||
* discardUnless.
|
||||
* </p>
|
||||
*
|
||||
* @param num
|
||||
* a int.
|
||||
* @param uType
|
||||
* a {@link java.lang.String} object.
|
||||
* @param sa
|
||||
* a {@link forge.card.spellability.SpellAbility} object.
|
||||
*/
|
||||
public abstract void discardUnless(int num, String uType, SpellAbility sa);
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
||||
@@ -125,4 +125,5 @@ public abstract class PlayerController {
|
||||
public abstract void playMiracle(SpellAbility miracle, Card card);
|
||||
public abstract void playMadness(SpellAbility madness);
|
||||
public abstract List<Card> chooseCardsToDelve(int colorLessAmount, List<Card> grave);
|
||||
public abstract List<Card> chooseCardsToDiscardUnlessType(int min, List<Card> hand, String param, SpellAbility sa);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,11 @@ import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.Card;
|
||||
import forge.CardLists;
|
||||
import forge.CardPredicates;
|
||||
import forge.GameEntity;
|
||||
import forge.card.spellability.Spell;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
@@ -26,6 +30,7 @@ import forge.game.ai.ComputerUtilBlock;
|
||||
import forge.game.ai.ComputerUtilCombat;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.gui.GuiChoose;
|
||||
import forge.util.Aggregates;
|
||||
|
||||
|
||||
/**
|
||||
@@ -299,4 +304,18 @@ public class PlayerControllerAi extends PlayerController {
|
||||
public void setShouldAlwaysAskTrigger(Integer trigger) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.game.player.PlayerController#chooseCardsToDiscardUnlessType(int, java.util.List, java.lang.String, forge.card.spellability.SpellAbility)
|
||||
*/
|
||||
@Override
|
||||
public List<Card> chooseCardsToDiscardUnlessType(int num, List<Card> hand, String uType, SpellAbility sa) {
|
||||
final List<Card> cardsOfType = CardLists.getType(hand, uType);
|
||||
if (!cardsOfType.isEmpty()) {
|
||||
Card toDiscard = Aggregates.itemWithMin(cardsOfType, CardPredicates.Accessors.fnGetCmc);
|
||||
return Lists.newArrayList(toDiscard);
|
||||
}
|
||||
return getAi().getCardsToDiscard(num, (String[])null, sa);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -475,4 +475,26 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
triggersAlwaysDecline.remove((Object)trigger);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.game.player.PlayerController#chooseCardsToDiscardUnlessType(int, java.lang.String, forge.card.spellability.SpellAbility)
|
||||
*/
|
||||
@Override
|
||||
public List<Card> chooseCardsToDiscardUnlessType(int num, List<Card> hand, final String uType, SpellAbility sa) {
|
||||
final InputSelectCards target = new InputSelectCardsFromList(num, num, hand) {
|
||||
private static final long serialVersionUID = -5774108410928795591L;
|
||||
|
||||
@Override
|
||||
protected boolean hasAllTargets() {
|
||||
for(Card c : selected) {
|
||||
if (c.isType(uType))
|
||||
return true;
|
||||
}
|
||||
return super.hasAllTargets();
|
||||
}
|
||||
};
|
||||
target.setMessage("Select %d cards to discard, unless you discard a " + uType + ".");
|
||||
FThreads.setInputAndWait(target);
|
||||
return target.getSelected();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user