From 88f3db03c4ac3e575e51c3f3be8654bd78edf4c9 Mon Sep 17 00:00:00 2001 From: Tyler Moore Date: Wed, 3 Oct 2018 17:38:30 -0700 Subject: [PATCH] Both players' decks show up at the same time, but hangs if you don't select in the correct order --- .../mage/cards/j/JaceArchitectOfThought.java | 68 +++++++++++++++---- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/Mage.Sets/src/mage/cards/j/JaceArchitectOfThought.java b/Mage.Sets/src/mage/cards/j/JaceArchitectOfThought.java index 09ebb7644e..1caa13f393 100644 --- a/Mage.Sets/src/mage/cards/j/JaceArchitectOfThought.java +++ b/Mage.Sets/src/mage/cards/j/JaceArchitectOfThought.java @@ -1,6 +1,8 @@ package mage.cards.j; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.Set; import java.util.UUID; @@ -34,10 +36,13 @@ import mage.players.Player; import mage.target.TargetCard; import mage.target.common.TargetCardInExile; import mage.target.common.TargetCardInLibrary; +import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetOpponent; import mage.target.targetpointer.FixedTarget; import mage.util.CardUtil; +import javax.swing.*; + /** * * @@ -239,23 +244,21 @@ class JaceArchitectOfThoughtEffect3 extends OneShotEffect { if (controller == null || sourcePermanent == null) { return false; } + ArrayList threads = new ArrayList<>(); for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { - Player player = game.getPlayer(playerId); - String playerName = new StringBuilder(player.getLogName()).append("'s").toString(); - if (source.isControlledBy(player.getId())) { - playerName = "your"; - } - TargetCardInLibrary target = new TargetCardInLibrary(new FilterNonlandCard(new StringBuilder("nonland card from ").append(playerName).append(" library").toString())); - if (controller.searchLibrary(target, game, playerId)) { - UUID targetId = target.getFirstTarget(); - Card card = player.getLibrary().remove(targetId, game); - if (card != null) { - controller.moveCardToExileWithInfo(card, CardUtil.getCardExileZoneId(game, source), sourcePermanent.getIdName(), source.getSourceId(), game, Zone.LIBRARY, true); + JaceArchitectOfThoughtEffect3Helper thread = new JaceArchitectOfThoughtEffect3Helper(playerId, game, source, sourcePermanent, controller); + thread.execute(); + thread.addPropertyChangeListener(new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + if("state".equals(evt.getPropertyName()) && SwingWorker.StateValue.DONE.equals(evt.getNewValue())){ + threads.remove(evt.getSource()); + } } - } - player.shuffleLibrary(source, game); + }); + threads.add(thread); } - + while(threads.size() > 0) {} ExileZone jaceExileZone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source)); if (jaceExileZone == null) { return true; @@ -274,3 +277,40 @@ class JaceArchitectOfThoughtEffect3 extends OneShotEffect { return true; } } + +class JaceArchitectOfThoughtEffect3Helper extends SwingWorker { + + UUID playerId; + Game game; + Ability source; + Permanent sourcePermanent; + Player controller; + + public JaceArchitectOfThoughtEffect3Helper (UUID playerId, Game game, Ability source, Permanent sourcePermanent, Player controller) { + this.playerId = playerId; + this.game = game; + this.source = source; + this.sourcePermanent = sourcePermanent; + this.controller = controller; + } + + @Override + protected Boolean doInBackground() throws Exception { + Player player = this.game.getPlayer(this.playerId); + String playerName = new StringBuilder(player.getLogName()).append("'s").toString(); + if (this.source.isControlledBy(player.getId())) { + playerName = "your"; + } + TargetCardInLibrary target = new TargetCardInLibrary(new FilterNonlandCard(new StringBuilder("nonland card from ").append(playerName).append(" library").toString())); + if (this.controller.searchLibrary(target, this.game, this.playerId)) { + UUID targetId = target.getFirstTarget(); + Card card = player.getLibrary().remove(targetId, this.game); + if (card != null) { + this.controller.moveCardToExileWithInfo(card, CardUtil.getCardExileZoneId(this.game, this.source), this.sourcePermanent.getIdName(), this.source.getSourceId(), this.game, Zone.LIBRARY, true); + } + player.shuffleLibrary(this.source, this.game); + } + return true; + } + +}