* Fixed some problems with getting cards at random from collection that could cause loops.

This commit is contained in:
LevelX2 2018-02-04 12:27:08 +01:00
parent 5fa20278b0
commit 4dd196f373
20 changed files with 134 additions and 160 deletions

View file

@ -177,18 +177,7 @@ public class LookLibraryControllerEffect extends OneShotEffect {
switch (targetZoneLookedCards) {
case LIBRARY:
if (putOnTop) {
player.putCardsOnTopOfLibrary(cards, game, source, true);
} else {
if (backInRandomOrder) {
Cards newOrder = new CardsImpl();
while (!cards.isEmpty()) {
Card card = cards.getRandom(game);
newOrder.add(card);
cards.remove(card);
}
cards = newOrder;
}
player.putCardsOnBottomOfLibrary(cards, game, source, true);
player.putCardsOnBottomOfLibrary(cards, game, source, !backInRandomOrder);
}
break;
case GRAVEYARD:

View file

@ -31,7 +31,6 @@ import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.Outcome;
import mage.constants.Zone;
@ -129,15 +128,7 @@ class CascadeEffect extends OneShotEffect {
}
}
// Move the remaining cards to the buttom of the library in a random order
Cards cardsFromExile = new CardsImpl();
Cards cardsToLibrary = new CardsImpl();
cardsFromExile.addAll(exile);
while (!cardsFromExile.isEmpty()) {
card = cardsFromExile.getRandom(game);
cardsFromExile.remove(card.getId());
cardsToLibrary.add(card);
}
return controller.putCardsOnBottomOfLibrary(cardsToLibrary, game, source, false);
return controller.putCardsOnBottomOfLibrary(new CardsImpl(exile), game, source, false);
}
@Override

View file

@ -861,6 +861,8 @@ public abstract class PlayerImpl implements Player, Serializable {
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
}
}
} else {
@ -900,9 +902,13 @@ public abstract class PlayerImpl implements Player, Serializable {
UUID sourceId = (source == null ? null : source.getSourceId());
if (!anyOrder) {
while (!cards.isEmpty()) {
UUID cardId = cards.getRandom(game).getId();
cards.remove(cardId);
moveObjectToLibrary(cardId, source == null ? null : source.getSourceId(), game, true, false);
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
}
}
} else {
TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put on the top of your library (last one chosen will be topmost)"));
@ -1360,7 +1366,7 @@ public abstract class PlayerImpl implements Player, Serializable {
@Override
public LinkedHashMap<UUID, ActivatedAbility> getUseableActivatedAbilities(MageObject object, Zone zone, Game game) {
LinkedHashMap<UUID, ActivatedAbility> useable = new LinkedHashMap<>();
if (object instanceof StackAbility) { // It may not be possible to activate abilities of stack actilities
if (object instanceof StackAbility) { // It may not be possible to activate abilities of stack actilities
return useable;
}
if (object instanceof SplitCard) {