Search in sources :

Example 1 with PlayerList

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;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterPermanentCard(mage.filter.common.FilterPermanentCard) PlayerList(mage.players.PlayerList) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterPermanentCard(mage.filter.common.FilterPermanentCard) Card(mage.cards.Card)

Example 2 with PlayerList

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;
}
Also used : Player(mage.players.Player) PlayerList(mage.players.PlayerList)

Example 3 with PlayerList

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;
}
Also used : Target(mage.target.Target) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetNonlandPermanent(mage.target.common.TargetNonlandPermanent) TargetNonlandPermanent(mage.target.common.TargetNonlandPermanent) PlayerList(mage.players.PlayerList)

Example 4 with PlayerList

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;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) PlayerList(mage.players.PlayerList) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 5 with PlayerList

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;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) PlayerList(mage.players.PlayerList) TargetCardInExile(mage.target.common.TargetCardInExile) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Aggregations

PlayerList (mage.players.PlayerList)33 Player (mage.players.Player)30 UUID (java.util.UUID)13 Permanent (mage.game.permanent.Permanent)13 Target (mage.target.Target)9 Card (mage.cards.Card)6 FilterCard (mage.filter.FilterCard)5 FilterPermanent (mage.filter.FilterPermanent)5 ContinuousEffect (mage.abilities.effects.ContinuousEffect)4 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)4 TargetCard (mage.target.TargetCard)4 ArrayList (java.util.ArrayList)3 MageObject (mage.MageObject)3 Effect (mage.abilities.effects.Effect)3 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)3 Choice (mage.choices.Choice)3 TargetPermanent (mage.target.TargetPermanent)3 FixedTarget (mage.target.targetpointer.FixedTarget)3 Serializable (java.io.Serializable)2 java.util (java.util)2