Fixed to get the correct player list

Refactor to reveal first, then take action
This commit is contained in:
davidmfritz 2018-11-01 10:13:57 +01:00
parent 336732eba2
commit 1dc421a545

View file

@ -14,7 +14,6 @@ import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.players.Library; import mage.players.Library;
import mage.players.Player; import mage.players.Player;
import mage.players.Players;
/** /**
* *
@ -59,30 +58,27 @@ class ClearTheLandEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
int numOfCardsToReveal = 5;
boolean tapped = true; boolean tapped = true;
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
Players allPlayers = game.getPlayers(); for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
for (Player player : allPlayers.values()) { Player player = game.getPlayer(playerId);
if (player != null) { if (player != null) {
Library library = player.getLibrary(); Library library = player.getLibrary();
Cards cardsToReveal = new CardsImpl(); Cards cardsToReveal = new CardsImpl();
for (int i = 0; i < numOfCardsToReveal; i++) { cardsToReveal.addAll(library.getTopCards(game, 5));
if (!library.hasCards()) { if (!cardsToReveal.isEmpty()) {
break; player.revealCards(source, "Revealed cards for " + player.getName(), cardsToReveal, game);
} for (Card card : cardsToReveal.getCards(game)) {
Card card = library.getFromTop(game);
cardsToReveal.add(card);
if (card.isLand()) { if (card.isLand()) {
player.moveCards(card, Zone.BATTLEFIELD, source, game, tapped, false, true, null); player.moveCards(card, Zone.BATTLEFIELD, source, game, tapped, false, true, null);
} else { } else {
player.moveCards(card, Zone.EXILED, source, game); player.moveCards(card, Zone.EXILED, source, game);
} }
} }
player.revealCards(source, "Revealed cards for " + player.getName(), cardsToReveal, game); }
} }
} }
return true; return true;