use of mage.players.PlayerList in project mage by magefree.
the class EurekaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
PlayerList playerList = game.getState().getPlayerList().copy();
while (!playerList.get().equals(source.getControllerId()) && controller.canRespond()) {
playerList.getNext();
}
Player currentPlayer = game.getPlayer(playerList.get());
UUID firstInactivePlayer = null;
Target target = new TargetCardInHand(new FilterPermanentCard());
while (controller.canRespond()) {
if (firstInactivePlayer == null) {
firstInactivePlayer = currentPlayer.getId();
}
if (currentPlayer != null && currentPlayer.canRespond() && game.getState().getPlayersInRange(controller.getId(), game).contains(currentPlayer.getId())) {
target.clearChosen();
if (target.canChoose(source.getSourceId(), currentPlayer.getId(), game) && currentPlayer.chooseUse(outcome, "Put permanent from your hand to play?", source, game)) {
if (target.chooseTarget(outcome, currentPlayer.getId(), source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
currentPlayer.moveCards(card, Zone.BATTLEFIELD, source, game);
firstInactivePlayer = null;
}
}
}
}
// get next player
playerList.getNext();
currentPlayer = game.getPlayer(playerList.get());
// if all player since this player didn't put permanent in play finish the process
if (currentPlayer != null && currentPlayer.getId().equals(firstInactivePlayer)) {
break;
}
}
return true;
}
return false;
}
use of mage.players.PlayerList in project mage by magefree.
the class TariffEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
PlayerList playerList = game.getPlayerList().copy();
playerList.setCurrent(game.getActivePlayerId());
Player player = game.getPlayer(game.getActivePlayerId());
do {
processPlayer(game, source, player);
player = playerList.getNext(game, false);
} while (player != null && !player.getId().equals(game.getActivePlayerId()));
return true;
}
use of mage.players.PlayerList in project mage by magefree.
the class EyeOfDoomEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Map<UUID, Permanent> permanents = new HashMap<>();
Target target = new TargetNonlandPermanent();
target.setNotTarget(true);
PlayerList playerList = game.getPlayerList().copy();
playerList.setCurrent(game.getActivePlayerId());
Player player = game.getPlayer(game.getActivePlayerId());
do {
target.clearChosen();
if (player != null && player.chooseTarget(outcome, target, source, game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanents.put(player.getId(), permanent);
game.informPlayers(player.getLogName() + " chooses " + permanent.getName());
}
}
player = playerList.getNext(game, false);
} while (player != null && !player.getId().equals(game.getActivePlayerId()));
for (Map.Entry<UUID, Permanent> entry : permanents.entrySet()) {
entry.getValue().addCounters(CounterType.DOOM.createInstance(), entry.getKey(), source, game);
}
return true;
}
use of mage.players.PlayerList in project mage by magefree.
the class HypergenesisEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
PlayerList playerList = game.getState().getPlayerList().copy();
while (!playerList.get().equals(source.getControllerId()) && controller.canRespond()) {
playerList.getNext();
}
Player currentPlayer = game.getPlayer(playerList.get());
UUID firstInactivePlayer = null;
Target target = new TargetCardInHand(filter);
while (controller.canRespond()) {
if (currentPlayer != null && currentPlayer.canRespond() && game.getState().getPlayersInRange(controller.getId(), game).contains(currentPlayer.getId())) {
if (firstInactivePlayer == null) {
firstInactivePlayer = currentPlayer.getId();
}
target.clearChosen();
if (target.canChoose(source.getSourceId(), currentPlayer.getId(), game) && currentPlayer.chooseUse(outcome, "Put card from your hand to play?", source, game)) {
if (target.chooseTarget(outcome, currentPlayer.getId(), source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
currentPlayer.moveCards(card, Zone.BATTLEFIELD, source, game);
firstInactivePlayer = null;
}
}
}
}
// get next player
playerList.getNext();
currentPlayer = game.getPlayer(playerList.get());
// if all player since this player didn't put permanent in play finish the process
if (currentPlayer.getId().equals(firstInactivePlayer)) {
break;
}
}
return true;
}
return false;
}
use of mage.players.PlayerList in project mage by magefree.
the class ThievesAuctionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
// Exile all nontoken permanents.
Cards exiledCards = new CardsImpl();
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
exiledCards.add(permanent);
controller.moveCardsToExile(permanent, source, game, true, CardUtil.getCardExileZoneId(game, source.getSourceId()), "Thieves' Auction");
}
// Starting with you, each player
PlayerList playerList = game.getState().getPlayersInRange(controller.getId(), game);
Player player = playerList.getCurrent(game);
while (player != null && !exiledCards.isEmpty() && !game.hasEnded()) {
if (player.canRespond()) {
// chooses one of the exiled cards
TargetCard target = new TargetCardInExile(new FilterCard());
if (player.choose(Outcome.PutCardInPlay, exiledCards, target, game)) {
// and puts it onto the battlefield tapped under their control.
Card chosenCard = exiledCards.get(target.getFirstTarget(), game);
if (chosenCard != null) {
player.moveCards(chosenCard, Zone.BATTLEFIELD, source, game, true, false, false, null);
}
exiledCards.remove(chosenCard);
} else {
break;
}
}
// Repeat this process until all cards exiled this way have been chosen.
player = playerList.getNext(game, false);
}
return true;
}
return false;
}
Aggregations