* 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.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) {

View file

@ -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<UUID> 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;