mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
* Fixed AI game freeze on put cards to library (#5023);
This commit is contained in:
parent
13cb3a443a
commit
184af3f681
1 changed files with 26 additions and 32 deletions
|
@ -880,30 +880,27 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
if (!cardsToLibrary.isEmpty()) {
|
||||
Cards cards = new CardsImpl(cardsToLibrary); // prevent possible ConcurrentModificationException
|
||||
if (!anyOrder) {
|
||||
while (!cards.isEmpty()) {
|
||||
Card card = cards.getRandom(game);
|
||||
if (card != null) {
|
||||
cards.remove(card);
|
||||
moveObjectToLibrary(card.getId(), source == null ? null : source.getSourceId(), game, false, false);
|
||||
} else {
|
||||
return false;// probably cards were removed because player left the game
|
||||
}
|
||||
// random order
|
||||
List<UUID> ids = new ArrayList<>(cards);
|
||||
Collections.shuffle(ids);
|
||||
for (UUID id : ids) {
|
||||
moveObjectToLibrary(id, source == null ? null : source.getSourceId(), game, false, false);
|
||||
}
|
||||
} else {
|
||||
// user defined order
|
||||
TargetCard target = new TargetCard(Zone.ALL, new FilterCard("card ORDER to put on the BOTTOM of your library (last one chosen will be bottommost)"));
|
||||
target.setRequired(true);
|
||||
while (cards.size() > 1) {
|
||||
this.choose(Outcome.Neutral, cards, target, game);
|
||||
if (!canRespond()) {
|
||||
return false;
|
||||
}
|
||||
while (cards.size() > 1 && this.canRespond() && this.choose(Outcome.Neutral, cards, target, game)) {
|
||||
UUID targetObjectId = target.getFirstTarget();
|
||||
if (targetObjectId == null) {
|
||||
break;
|
||||
}
|
||||
cards.remove(targetObjectId);
|
||||
moveObjectToLibrary(targetObjectId, source == null ? null : source.getSourceId(), game, false, false);
|
||||
target.clearChosen();
|
||||
}
|
||||
if (cards.size() == 1) {
|
||||
moveObjectToLibrary(cards.iterator().next(), source == null ? null : source.getSourceId(), game, false, false);
|
||||
for (UUID c : cards) {
|
||||
moveObjectToLibrary(c, source == null ? null : source.getSourceId(), game, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -945,30 +942,27 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
Cards cards = new CardsImpl(cardsToLibrary); // prevent possible ConcurrentModificationException
|
||||
UUID sourceId = (source == null ? null : source.getSourceId());
|
||||
if (!anyOrder) {
|
||||
while (!cards.isEmpty()) {
|
||||
Card card = cards.getRandom(game);
|
||||
if (card != null) {
|
||||
cards.remove(card.getId());
|
||||
moveObjectToLibrary(card.getId(), source == null ? null : source.getSourceId(), game, true, false);
|
||||
} else {
|
||||
return false; // probably cards were removed because player left the game
|
||||
}
|
||||
// random order
|
||||
List<UUID> ids = new ArrayList<>(cards);
|
||||
Collections.shuffle(ids);
|
||||
for (UUID id : ids) {
|
||||
moveObjectToLibrary(id, source == null ? null : source.getSourceId(), game, true, false);
|
||||
}
|
||||
} else {
|
||||
TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card ORDER to put on the TOP of your library (last one chosen will be topmost)"));
|
||||
// user defined order
|
||||
TargetCard target = new TargetCard(Zone.ALL, new FilterCard("card ORDER to put on the TOP of your library (last one chosen will be topmost)"));
|
||||
target.setRequired(true);
|
||||
while (cards.size() > 1) {
|
||||
this.choose(Outcome.Neutral, cards, target, game);
|
||||
if (!canRespond()) {
|
||||
return false;
|
||||
}
|
||||
while (cards.size() > 1 && this.canRespond() && this.choose(Outcome.Neutral, cards, target, game)) {
|
||||
UUID targetObjectId = target.getFirstTarget();
|
||||
if (targetObjectId == null) {
|
||||
break;
|
||||
}
|
||||
cards.remove(targetObjectId);
|
||||
moveObjectToLibrary(targetObjectId, sourceId, game, true, false);
|
||||
moveObjectToLibrary(targetObjectId, source == null ? null : source.getSourceId(), game, true, false);
|
||||
target.clearChosen();
|
||||
}
|
||||
if (cards.size() == 1) {
|
||||
moveObjectToLibrary(cards.iterator().next(), sourceId, game, true, false);
|
||||
for (UUID c : cards) {
|
||||
moveObjectToLibrary(c, source == null ? null : source.getSourceId(), game, true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue