Search in sources :

Example 16 with PlayerList

use of mage.players.PlayerList in project mage by magefree.

the class PlagueOfVerminEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Map<UUID, Integer> payLife = new HashMap<>();
    int currentLifePaid;
    int totalPaidLife;
    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;
        while (controller.canRespond()) {
            if (firstInactivePlayer == null) {
                firstInactivePlayer = currentPlayer.getId();
            }
            if (currentPlayer != null && currentPlayer.canRespond() && game.getState().getPlayersInRange(controller.getId(), game).contains(currentPlayer.getId())) {
                currentLifePaid = 0;
                totalPaidLife = 0;
                if (currentPlayer.chooseUse(Outcome.AIDontUseIt, "Pay life?", source, game)) {
                    totalPaidLife = currentPlayer.getAmount(0, controller.getLife(), "Pay how many life?", game);
                    if (totalPaidLife > 0) {
                        currentPlayer.loseLife(totalPaidLife, game, source, false);
                        if (payLife.get(currentPlayer.getId()) == null) {
                            payLife.put(currentPlayer.getId(), totalPaidLife);
                        } else {
                            currentLifePaid = payLife.get(currentPlayer.getId());
                            payLife.put(currentPlayer.getId(), currentLifePaid + totalPaidLife);
                        }
                    }
                    Card sourceCard = game.getCard(source.getSourceId());
                    game.informPlayers((sourceCard != null ? sourceCard.getName() : "") + ": " + currentPlayer.getLogName() + " pays " + payLife.get(currentPlayer.getId()) + " life");
                    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;
            }
        }
        // create tokens according to life spent by each player
        RatToken token = new RatToken();
        for (Map.Entry<UUID, Integer> entry : payLife.entrySet()) {
            Player player = game.getPlayer(entry.getKey());
            if (player != null) {
                token.putOntoBattlefield(entry.getValue(), game, source, player.getId());
            }
        }
    }
    return true;
}
Also used : Player(mage.players.Player) HashMap(java.util.HashMap) PlayerList(mage.players.PlayerList) RatToken(mage.game.permanent.token.RatToken) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) Card(mage.cards.Card)

Example 17 with PlayerList

use of mage.players.PlayerList in project mage by magefree.

the class InniazTheGaleForceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    PlayerList playerList = game.getState().getPlayersInRange(source.getControllerId(), game);
    List<PlayerPair> playerPairList = new ArrayList<>();
    for (int i = 0; i < playerList.size() - 1; i++) {
        playerPairList.add(new PlayerPair(game.getPlayer(playerList.get(i)), game.getPlayer(playerList.get(i + 1))));
    }
    playerPairList.add(new PlayerPair(game.getPlayer(playerList.get(playerList.size() - 1)), game.getPlayer(playerList.get(0))));
    for (PlayerPair playerPair : playerPairList) {
        playerPair.chooseTargets(controller, game, source);
    }
    for (PlayerPair playerPair : playerPairList) {
        playerPair.createEffect(game, source);
    }
    return true;
}
Also used : Player(mage.players.Player) PlayerList(mage.players.PlayerList) ArrayList(java.util.ArrayList)

Example 18 with PlayerList

use of mage.players.PlayerList in project mage by magefree.

the class KindleCardsInAllGraveyardsCount method calculate.

@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
    int amount = 0;
    PlayerList playerList = game.getPlayerList().copy();
    for (UUID playerUUID : playerList) {
        Player player = game.getPlayer(playerUUID);
        if (player != null) {
            amount += player.getGraveyard().count(filter, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game);
        }
    }
    return amount + 2;
}
Also used : Player(mage.players.Player) PlayerList(mage.players.PlayerList) UUID(java.util.UUID)

Example 19 with PlayerList

use of mage.players.PlayerList in project mage by magefree.

the class PainsRewardEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        PlayerList playerList = game.getPlayerList().copy();
        playerList.setCurrent(controller.getId());
        Player winner = game.getPlayer(controller.getId());
        // -1 for start with 0 min big
        int highBid = chooseLifeAmountToBid(controller, -1, game);
        game.informPlayers(winner.getLogName() + " has bet " + highBid + " lifes");
        Player currentPlayer = playerList.getNextInRange(controller, game);
        while (currentPlayer != null && !Objects.equals(currentPlayer, winner)) {
            String text = winner.getLogName() + " has bet " + highBid + " life" + (highBid > 1 ? "s" : "") + ". Top the bid?";
            // AI hint
            int safeLifeToLost = Math.min(6, currentPlayer.getLife() / 2);
            Outcome aiOutcome = (highBid + 1 <= safeLifeToLost) ? Outcome.Benefit : Outcome.Detriment;
            if (currentPlayer.chooseUse(aiOutcome, text, source, game)) {
                int newBid = chooseLifeAmountToBid(currentPlayer, highBid, game);
                if (newBid > highBid) {
                    highBid = newBid;
                    winner = currentPlayer;
                    game.informPlayers(currentPlayer.getLogName() + " bet " + newBid + " life" + (newBid > 1 ? "s" : ""));
                }
            }
            currentPlayer = playerList.getNextInRange(controller, game);
        }
        game.informPlayers(winner.getLogName() + " won the auction with a bid of " + highBid + " life" + (highBid > 1 ? "s" : ""));
        winner.loseLife(highBid, game, source, false);
        winner.drawCards(4, source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) PlayerList(mage.players.PlayerList) Outcome(mage.constants.Outcome)

Example 20 with PlayerList

use of mage.players.PlayerList in project mage by magefree.

the class ScrambleverseEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    PlayerList players = game.getState().getPlayersInRange(source.getControllerId(), game);
    int count = players.size();
    for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterNonlandPermanent(), source.getControllerId(), source.getSourceId(), game)) {
        ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, players.get(RandomUtil.nextInt(count)));
        effect.setTargetPointer(new FixedTarget(permanent, game));
        game.addEffect(effect, source);
        permanent.untap(game);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) Permanent(mage.game.permanent.Permanent) PlayerList(mage.players.PlayerList) ContinuousEffect(mage.abilities.effects.ContinuousEffect) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

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