permanentsOwned.put(permanent.getOwnerId(), list);
}
// shuffle permanents into owner's library
Map<UUID, Integer> permanentsCount = new HashMap<>();
PlayerList playerList = game.getPlayerList();
playerList.setCurrent(game.getActivePlayerId());
Player player = game.getPlayer(game.getActivePlayerId());
do {
List<Permanent> list = permanentsOwned.remove(player.getId());
Integer count = 0;
if (list != null) {
count = list.size();
for (Permanent permanent : list) {
permanent.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
}
}
if (count > 0) {
player.shuffleLibrary(game);
}
permanentsCount.put(player.getId(), count);
player = playerList.getNext(game);
} while (!player.getId().equals(game.getActivePlayerId()));
Map<UUID, CardsImpl> cardsRevealed = new HashMap<>();
// draw cards and reveal them
playerList.setCurrent(game.getActivePlayerId());
player = game.getPlayer(game.getActivePlayerId());
do {
Integer count = Math.min(permanentsCount.get(player.getId()), player.getLibrary().size());
CardsImpl cards = new CardsImpl();
for (int i = 0; i < count; i++) {
Card card = player.getLibrary().removeFromTop(game);
if (card != null) {
cards.add(card);
}
}
player.revealCards("Warp World " + player.getName(), cards, game);
cardsRevealed.put(player.getId(), cards);
player = playerList.getNext(game);
} while (!player.getId().equals(game.getActivePlayerId()));
// put artifacts, creaturs and lands onto the battlefield
playerList.setCurrent(game.getActivePlayerId());
player = game.getPlayer(game.getActivePlayerId());
do {
CardsImpl cards = cardsRevealed.get(player.getId());
for (Card card : cards.getCards(game)) {
if (card != null && (card.getCardType().contains(CardType.ARTIFACT)
|| card.getCardType().contains(CardType.CREATURE)
|| card.getCardType().contains(CardType.LAND))) {
card.putOntoBattlefield(game, Zone.HAND, source.getSourceId(), player.getId());
cards.remove(card);
}
}
player = playerList.getNext(game);
} while (!player.getId().equals(game.getActivePlayerId()));
// put enchantments onto the battlefield
playerList.setCurrent(game.getActivePlayerId());
player = game.getPlayer(game.getActivePlayerId());
do {
CardsImpl cards = cardsRevealed.get(player.getId());
for (Card card : cards.getCards(game)) {
if (card != null && card.getCardType().contains(CardType.ENCHANTMENT)) {
card.putOntoBattlefield(game, Zone.HAND, source.getSourceId(), player.getId());
cards.remove(card);
}
}
player = playerList.getNext(game);
} while (!player.getId().equals(game.getActivePlayerId()));
// put the rest of the cards into the graveyard
playerList.setCurrent(game.getActivePlayerId());
player = game.getPlayer(game.getActivePlayerId());
do {
CardsImpl cards = cardsRevealed.get(player.getId());
for (Card card : cards.getCards(game)) {
if (card != null) {
card.moveToZone(Zone.GRAVEYARD, source.getSourceId(), game, false);
}
}
player = playerList.getNext(game);
} while (!player.getId().equals(game.getActivePlayerId()));
return true;
}