From 3082186cd55d82b27c278d7718a19af1d768d817 Mon Sep 17 00:00:00 2001 From: icy Date: Tue, 18 Apr 2023 16:00:02 -0400 Subject: [PATCH] prefer cheaper CardCollectionView. Thread-safe card exiles. Moved early-exit conditions up. Added javadoc comment. --- .../match/input/InputConfirmMulligan.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/forge-gui/src/main/java/forge/gamemodes/match/input/InputConfirmMulligan.java b/forge-gui/src/main/java/forge/gamemodes/match/input/InputConfirmMulligan.java index 449114d7762..73ae6f82d38 100644 --- a/forge-gui/src/main/java/forge/gamemodes/match/input/InputConfirmMulligan.java +++ b/forge-gui/src/main/java/forge/gamemodes/match/input/InputConfirmMulligan.java @@ -102,32 +102,34 @@ public class InputConfirmMulligan extends InputSyncronizedBase { volatile boolean cardSelectLocked = false; + /** + * When a card selected at the time of mulligan (currently affects just Serum Powder). + */ @Override protected boolean onCardSelected(final Card c0, final List 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 isSerumPowder = c0.getName().equals("Serum Powder"); - final boolean isLegalChoice = fromHand && (isSerumPowder); - if (!isLegalChoice || cardSelectLocked) { + if (!isSerumPowder || !fromHand) { return false; } final CardView cView = c0.getView(); //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; ThreadUtil.invokeInGameThread(new Runnable() { @Override public void run() { - final CardCollection hand = new CardCollection(c0.getController().getCardsIn(ZoneType.Hand)); - for (final Card c : hand) { + final CardCollectionView hand = c0.getController().getCardsIn(ZoneType.Hand); + final int handSize = hand.size(); + for (final Card c : hand.threadSafeIterable()) { player.getGame().getAction().exile(c, null); } - c0.getController().drawCards(hand.size()); + c0.getController().drawCards(handSize); cardSelectLocked = false; } }); - return true; } - return true; }