prefer cheaper CardCollectionView. Thread-safe card exiles. Moved early-exit conditions up. Added javadoc comment.

This commit is contained in:
icy
2023-04-18 16:00:02 -04:00
parent 6b9a1642a7
commit 3082186cd5

View File

@@ -102,32 +102,34 @@ public class InputConfirmMulligan extends InputSyncronizedBase {
volatile boolean cardSelectLocked = false; volatile boolean cardSelectLocked = false;
/**
* When a card selected at the time of mulligan (currently affects just Serum Powder).
*/
@Override @Override
protected boolean onCardSelected(final Card c0, final List<Card> otherCardsToSelect, final ITriggerEvent triggerEvent) { // the only place that would cause troubles - input is supposed only to confirm, not to fire abilities protected boolean onCardSelected(final Card c0, final List<Card> otherCardsToSelect, final ITriggerEvent triggerEvent) { // the only place that would cause troubles - input is supposed only to confirm, not to fire abilities
if (cardSelectLocked) { return false; }
final boolean fromHand = player.getZone(ZoneType.Hand).contains(c0); final boolean fromHand = player.getZone(ZoneType.Hand).contains(c0);
final boolean isSerumPowder = c0.getName().equals("Serum Powder"); final boolean isSerumPowder = c0.getName().equals("Serum Powder");
final boolean isLegalChoice = fromHand && (isSerumPowder); if (!isSerumPowder || !fromHand) {
if (!isLegalChoice || cardSelectLocked) {
return false; return false;
} }
final CardView cView = c0.getView(); final CardView cView = c0.getView();
//pfps leave this as is for now - it is confirming during another confirm so it might need the popup //pfps leave this as is for now - it is confirming during another confirm so it might need the popup
if (isSerumPowder && getController().getGui().confirm(cView, "Use " + cView + "'s ability?")) { if (getController().getGui().confirm(cView, "Use " + cView + "'s ability?")) {
cardSelectLocked = true; cardSelectLocked = true;
ThreadUtil.invokeInGameThread(new Runnable() { ThreadUtil.invokeInGameThread(new Runnable() {
@Override public void run() { @Override public void run() {
final CardCollection hand = new CardCollection(c0.getController().getCardsIn(ZoneType.Hand)); final CardCollectionView hand = c0.getController().getCardsIn(ZoneType.Hand);
for (final Card c : hand) { final int handSize = hand.size();
for (final Card c : hand.threadSafeIterable()) {
player.getGame().getAction().exile(c, null); player.getGame().getAction().exile(c, null);
} }
c0.getController().drawCards(hand.size()); c0.getController().drawCards(handSize);
cardSelectLocked = false; cardSelectLocked = false;
} }
}); });
return true;
} }
return true; return true;
} }