* Jace's Archivist - fixed AI freeze the game (#5023);

This commit is contained in:
Oleg Agafonov 2019-04-01 21:52:11 +04:00
parent 97712971fa
commit ef4c223bcf
2 changed files with 18 additions and 14 deletions

View file

@ -10,6 +10,7 @@ import mage.abilities.costs.mana.ColoredManaCost;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.cards.Cards;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.SubType; import mage.constants.SubType;
import mage.constants.ColoredManaSymbol; import mage.constants.ColoredManaSymbol;
@ -66,13 +67,13 @@ class JacesArchivistEffect extends OneShotEffect {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId); Player player = game.getPlayer(playerId);
if (player != null) { if (player != null) {
int discarded = player.getHand().size(); Cards discardedCards = player.discard(player.getHand().size(), false, source, game);
player.discard(discarded, false, source, game); if (discardedCards.size() > maxDiscarded) {
if (discarded > maxDiscarded) { maxDiscarded = discardedCards.size();
maxDiscarded = discarded;
} }
} }
} }
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId); Player player = game.getPlayer(playerId);
if (player != null) { if (player != null) {

View file

@ -70,6 +70,7 @@ import java.io.Serializable;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.stream.Collectors;
public abstract class PlayerImpl implements Player, Serializable { public abstract class PlayerImpl implements Player, Serializable {
@ -714,19 +715,23 @@ public abstract class PlayerImpl implements Player, Serializable {
if (amount <= 0) { if (amount <= 0) {
return discardedCards; return discardedCards;
} }
// all without dialogs
if (this.getHand().size() == 1 || this.getHand().size() == amount) { if (this.getHand().size() == 1 || this.getHand().size() == amount) {
discardedCards.addAll(this.getHand()); List<UUID> cardsToDiscard = new ArrayList<>(this.getHand());
while (!this.getHand().isEmpty()) { for (UUID id : cardsToDiscard) {
discard(this.getHand().get(this.getHand().iterator().next(), game), source, game); if (discard(this.getHand().get(id, game), source, game)) {
discardedCards.add(id);
}
} }
return discardedCards; return discardedCards;
} }
if (random) { if (random) {
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
Card card = this.getHand().getRandom(game); Card card = this.getHand().getRandom(game);
if (card != null) { if (discard(card, source, game)) {
discardedCards.add(card); discardedCards.add(card);
discard(card, source, game);
} }
} }
} else { } else {
@ -734,10 +739,8 @@ public abstract class PlayerImpl implements Player, Serializable {
TargetDiscard target = new TargetDiscard(possibleAmount, possibleAmount, new FilterCard(CardUtil.numberToText(possibleAmount, "a") + " card" + (possibleAmount > 1 ? "s" : "")), playerId); 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); choose(Outcome.Discard, target, source == null ? null : source.getSourceId(), game);
for (UUID cardId : target.getTargets()) { for (UUID cardId : target.getTargets()) {
Card card = this.getHand().get(cardId, game); if(discard(this.getHand().get(cardId, game), source, game)) {
if (card != null) { // can happen if user is removed (session expires) discardedCards.add(cardId);
discardedCards.add(card);
discard(card, source, game);
} }
} }
} }