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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations