mirror of
https://github.com/correl/mage.git
synced 2025-01-12 19:25:44 +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()) {
|
if (!cardsToLibrary.isEmpty()) {
|
||||||
Cards cards = new CardsImpl(cardsToLibrary); // prevent possible ConcurrentModificationException
|
Cards cards = new CardsImpl(cardsToLibrary); // prevent possible ConcurrentModificationException
|
||||||
if (!anyOrder) {
|
if (!anyOrder) {
|
||||||
while (!cards.isEmpty()) {
|
// random order
|
||||||
Card card = cards.getRandom(game);
|
List<UUID> ids = new ArrayList<>(cards);
|
||||||
if (card != null) {
|
Collections.shuffle(ids);
|
||||||
cards.remove(card);
|
for (UUID id : ids) {
|
||||||
moveObjectToLibrary(card.getId(), source == null ? null : source.getSourceId(), game, false, false);
|
moveObjectToLibrary(id, source == null ? null : source.getSourceId(), game, false, false);
|
||||||
} else {
|
|
||||||
return false;// probably cards were removed because player left the game
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} 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)"));
|
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);
|
target.setRequired(true);
|
||||||
while (cards.size() > 1) {
|
while (cards.size() > 1 && this.canRespond() && this.choose(Outcome.Neutral, cards, target, game)) {
|
||||||
this.choose(Outcome.Neutral, cards, target, game);
|
|
||||||
if (!canRespond()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
UUID targetObjectId = target.getFirstTarget();
|
UUID targetObjectId = target.getFirstTarget();
|
||||||
|
if (targetObjectId == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
cards.remove(targetObjectId);
|
cards.remove(targetObjectId);
|
||||||
moveObjectToLibrary(targetObjectId, source == null ? null : source.getSourceId(), game, false, false);
|
moveObjectToLibrary(targetObjectId, source == null ? null : source.getSourceId(), game, false, false);
|
||||||
target.clearChosen();
|
target.clearChosen();
|
||||||
}
|
}
|
||||||
if (cards.size() == 1) {
|
for (UUID c : cards) {
|
||||||
moveObjectToLibrary(cards.iterator().next(), source == null ? null : source.getSourceId(), game, false, false);
|
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
|
Cards cards = new CardsImpl(cardsToLibrary); // prevent possible ConcurrentModificationException
|
||||||
UUID sourceId = (source == null ? null : source.getSourceId());
|
UUID sourceId = (source == null ? null : source.getSourceId());
|
||||||
if (!anyOrder) {
|
if (!anyOrder) {
|
||||||
while (!cards.isEmpty()) {
|
// random order
|
||||||
Card card = cards.getRandom(game);
|
List<UUID> ids = new ArrayList<>(cards);
|
||||||
if (card != null) {
|
Collections.shuffle(ids);
|
||||||
cards.remove(card.getId());
|
for (UUID id : ids) {
|
||||||
moveObjectToLibrary(card.getId(), source == null ? null : source.getSourceId(), game, true, false);
|
moveObjectToLibrary(id, source == null ? null : source.getSourceId(), game, true, false);
|
||||||
} else {
|
|
||||||
return false; // probably cards were removed because player left the game
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} 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);
|
target.setRequired(true);
|
||||||
while (cards.size() > 1) {
|
while (cards.size() > 1 && this.canRespond() && this.choose(Outcome.Neutral, cards, target, game)) {
|
||||||
this.choose(Outcome.Neutral, cards, target, game);
|
|
||||||
if (!canRespond()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
UUID targetObjectId = target.getFirstTarget();
|
UUID targetObjectId = target.getFirstTarget();
|
||||||
|
if (targetObjectId == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
cards.remove(targetObjectId);
|
cards.remove(targetObjectId);
|
||||||
moveObjectToLibrary(targetObjectId, sourceId, game, true, false);
|
moveObjectToLibrary(targetObjectId, source == null ? null : source.getSourceId(), game, true, false);
|
||||||
target.clearChosen();
|
target.clearChosen();
|
||||||
}
|
}
|
||||||
if (cards.size() == 1) {
|
for (UUID c : cards) {
|
||||||
moveObjectToLibrary(cards.iterator().next(), sourceId, game, true, false);
|
moveObjectToLibrary(c, source == null ? null : source.getSourceId(), game, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue