diff --git a/Mage.Sets/src/mage/cards/j/JacesArchivist.java b/Mage.Sets/src/mage/cards/j/JacesArchivist.java index 4d5d557d45..a6934dd862 100644 --- a/Mage.Sets/src/mage/cards/j/JacesArchivist.java +++ b/Mage.Sets/src/mage/cards/j/JacesArchivist.java @@ -10,6 +10,7 @@ import mage.abilities.costs.mana.ColoredManaCost; import mage.abilities.effects.OneShotEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; +import mage.cards.Cards; import mage.constants.CardType; import mage.constants.SubType; import mage.constants.ColoredManaSymbol; @@ -66,13 +67,13 @@ class JacesArchivistEffect extends OneShotEffect { for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); if (player != null) { - int discarded = player.getHand().size(); - player.discard(discarded, false, source, game); - if (discarded > maxDiscarded) { - maxDiscarded = discarded; + Cards discardedCards = player.discard(player.getHand().size(), false, source, game); + if (discardedCards.size() > maxDiscarded) { + maxDiscarded = discardedCards.size(); } } } + for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); if (player != null) { diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 27191a9765..b36a18d108 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -70,6 +70,7 @@ import java.io.Serializable; import java.text.SimpleDateFormat; import java.util.*; import java.util.Map.Entry; +import java.util.stream.Collectors; public abstract class PlayerImpl implements Player, Serializable { @@ -714,19 +715,23 @@ public abstract class PlayerImpl implements Player, Serializable { if (amount <= 0) { return discardedCards; } + + // all without dialogs if (this.getHand().size() == 1 || this.getHand().size() == amount) { - discardedCards.addAll(this.getHand()); - while (!this.getHand().isEmpty()) { - discard(this.getHand().get(this.getHand().iterator().next(), game), source, game); + List cardsToDiscard = new ArrayList<>(this.getHand()); + for (UUID id : cardsToDiscard) { + if (discard(this.getHand().get(id, game), source, game)) { + discardedCards.add(id); + } } return discardedCards; } + if (random) { for (int i = 0; i < amount; i++) { Card card = this.getHand().getRandom(game); - if (card != null) { + if (discard(card, source, game)) { discardedCards.add(card); - discard(card, source, game); } } } else { @@ -734,11 +739,9 @@ public abstract class PlayerImpl implements Player, Serializable { TargetDiscard target = new TargetDiscard(possibleAmount, possibleAmount, new FilterCard(CardUtil.numberToText(possibleAmount, "a") + " card" + (possibleAmount > 1 ? "s" : "")), playerId); choose(Outcome.Discard, target, source == null ? null : source.getSourceId(), game); for (UUID cardId : target.getTargets()) { - Card card = this.getHand().get(cardId, game); - if (card != null) { // can happen if user is removed (session expires) - discardedCards.add(card); - discard(card, source, game); - } + if(discard(this.getHand().get(cardId, game), source, game)) { + discardedCards.add(cardId); + } } } return discardedCards;