Search in sources :

Example 1 with RatToken

use of mage.game.permanent.token.RatToken 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)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Card (mage.cards.Card)1 RatToken (mage.game.permanent.token.RatToken)1 Player (mage.players.Player)1 PlayerList (mage.players.PlayerList)1