@Override public boolean apply(Game game, Ability source) { int maxDiscarded = 0; Player sourcePlayer = game.getPlayer(source.getControllerId()); if (sourcePlayer == null) { return false; } for (UUID playerId : sourcePlayer.getInRange()) { Player player = game.getPlayer(playerId); if (player != null) { int discarded = 0; for (Card c : player.getHand().getCards(game)) { if (player.discard(c, source, game)) { discarded++; } } if (discarded > maxDiscarded) { maxDiscarded = discarded; } } } for (UUID playerId : sourcePlayer.getInRange()) { Player player = game.getPlayer(playerId); if (player != null) { player.drawCards(maxDiscarded, game); } } return true; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId()); if (controller == null || sourcePermanent == null) { return false; } for (UUID playerId : controller.getInRange()) { Player player = game.getPlayer(playerId); String playerName = new StringBuilder(player.getLogName()).append("'s").toString(); if (source.getControllerId().equals(player.getId())) { playerName = "your"; } TargetCardInLibrary target = new TargetCardInLibrary( new FilterNonlandCard( new StringBuilder("nonland card from ") .append(playerName) .append(" library") .toString())); if (controller.searchLibrary(target, game, playerId)) { UUID targetId = target.getFirstTarget(); Card card = player.getLibrary().remove(targetId, game); if (card != null) { controller.moveCardToExileWithInfo( card, CardUtil.getCardExileZoneId(game, source), sourcePermanent.getIdName(), source.getSourceId(), game, Zone.LIBRARY, true); } } player.shuffleLibrary(game); } ExileZone jaceExileZone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source)); if (jaceExileZone == null) { return true; } FilterCard filter = new FilterCard("card to cast without mana costs"); TargetCardInExile target = new TargetCardInExile(filter, source.getSourceId()); while (jaceExileZone.count(filter, game) > 0 && controller.choose(Outcome.PlayForFree, jaceExileZone, target, game)) { Card card = game.getCard(target.getFirstTarget()); if (card != null) { if (controller.cast(card.getSpellAbility(), game, true)) { game.getExile().removeCard(card, game); } } target.clearChosen(); } return true; }
@Override public boolean apply(Game game, Ability source) { Player sourcePlayer = game.getPlayer(source.getControllerId()); for (UUID playerId : sourcePlayer.getInRange()) { Player player = game.getPlayer(playerId); if (player != null) { player.getLibrary().addAll(player.getHand().getCards(game), game); player.getLibrary().addAll(player.getGraveyard().getCards(game), game); player.shuffleLibrary(game); player.getHand().clear(); player.getGraveyard().clear(); player.drawCards(7, game); } } return true; }
@Override public boolean apply(Game game, Ability source) { Player sourcePlayer = game.getPlayer(source.getControllerId()); Permanent permanent = game.getPermanent(source.getSourceId()); if (permanent != null) { int amount = permanent.getCounters().getCount(CounterType.CHARGE); if (amount > 0) { for (UUID playerId : sourcePlayer.getInRange()) { Player player = game.getPlayer(playerId); if (player != null) { player.drawCards(amount, game); } } } } return true; }
@Override public void adjustTargets(Ability ability, Game game) { Target target = ability.getTargets().get(0); if (target instanceof DynamicTargetCreaturePermanent) { Player controller = game.getPlayer(ability.getControllerId()); int amount = 0; if (controller != null) { for (UUID playerId : controller.getInRange()) { Player player = game.getPlayer(playerId); if (player != null) { amount += player.getGraveyard().getCards(filter, game).size(); } } } ((DynamicTargetCreaturePermanent) target).setMaxNumberOfTargets(amount + 1); } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller == null) { return false; } for (UUID playerId : controller.getInRange()) { Player player = game.getPlayer(playerId); if (player != null) { TargetCardInHand target = new TargetCardInHand(filter); if (player.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) { Card card = game.getCard(target.getFirstTarget()); if (card != null) { card.putOntoBattlefield(game, Zone.HAND, source.getId(), player.getId()); } } } } return true; }
@Override public boolean apply(Game game, Ability source) { Permanent permanent = game.getPermanent(source.getSourceId()); if (permanent != null) { permanent.addCounters(CounterType.DESPAIR.createInstance(), game); int count = permanent.getCounters().getCount(CounterType.DESPAIR); if (count > 0) { Player controller = game.getPlayer(permanent.getControllerId()); if (controller != null) { for (UUID playerId : controller.getInRange()) { Player player = game.getPlayer(playerId); if (player != null) { exileCards(player, count, source, game); } } } } } return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { boolean costPaid = false; for (UUID playerId : controller.getInRange()) { Cost cost = new SacrificeTargetCost( new TargetControlledPermanent(new FilterControlledLandPermanent())); Player player = game.getPlayer(playerId); if (player != null && cost.canPay(source, source.getSourceId(), playerId, game) && player.chooseUse(Outcome.Sacrifice, "Sacrifice a land?", game) && cost.pay(source, game, source.getSourceId(), playerId, true)) { costPaid = true; } } if (costPaid) { super.apply(game, source); } return true; } return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { // Each player loses a third of his or her life, for (UUID playerId : controller.getInRange()) { Player player = game.getPlayer(playerId); if (player != null) { int lifeToLose = (int) Math.ceil(player.getLife() / 3.0); player.loseLife(lifeToLose, game); } } // then discards a third of the cards in his or her hand, for (UUID playerId : controller.getInRange()) { Player player = game.getPlayer(playerId); if (player != null) { int cardsToDiscard = (int) Math.ceil(player.getHand().size() / 3.0); if (cardsToDiscard > 0) { player.discard(cardsToDiscard, false, source, game); } } } // then sacrifices a third of the creatures he or she controls, for (UUID playerId : controller.getInRange()) { Player player = game.getPlayer(playerId); if (player != null) { FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent(); int creaturesToSacrifice = (int) Math.ceil( game.getBattlefield() .count(filter, source.getSourceId(), player.getId(), game) / 3.0); if (creaturesToSacrifice > 0) { Target target = new TargetControlledCreaturePermanent( creaturesToSacrifice, creaturesToSacrifice, filter, true); target.chooseTarget(Outcome.Sacrifice, playerId, source, game); for (UUID permanentId : target.getTargets()) { Permanent permanent = game.getPermanent(permanentId); if (permanent != null) { permanent.sacrifice(source.getSourceId(), game); } } } } } // then sacrifices a third of the lands he or she controls. for (UUID playerId : controller.getInRange()) { Player player = game.getPlayer(playerId); if (player != null) { FilterControlledLandPermanent filter = new FilterControlledLandPermanent(); int landsToSacrifice = (int) Math.ceil( game.getBattlefield() .count(filter, source.getSourceId(), player.getId(), game) / 3.0); if (landsToSacrifice > 0) { Target target = new TargetControlledPermanent(landsToSacrifice, landsToSacrifice, filter, true); target.chooseTarget(Outcome.Sacrifice, playerId, source, game); for (UUID permanentId : target.getTargets()) { Permanent permanent = game.getPermanent(permanentId); if (permanent != null) { permanent.sacrifice(source.getSourceId(), game); } } } } } return true; } return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Card sourceCard = game.getCard(source.getSourceId()); 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.isInGame()) { playerList.getNext(); } Player currentPlayer = game.getPlayer(playerList.get()); UUID firstInactivePlayer = null; while (controller.isInGame()) { if (firstInactivePlayer == null) { firstInactivePlayer = currentPlayer.getId(); } if (currentPlayer != null && currentPlayer.isInGame() && controller.getInRange().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); if (payLife.get(currentPlayer.getId()) == null) { payLife.put(currentPlayer.getId(), totalPaidLife); } else { currentLifePaid = payLife.get(currentPlayer.getId()); payLife.put(currentPlayer.getId(), currentLifePaid + totalPaidLife); } } game.informPlayers( new StringBuilder(sourceCard.getName()) .append(": ") .append(currentPlayer.getLogName()) .append(" pays ") .append(payLife.get(currentPlayer.getId())) .append(" life") .toString()); 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.getSourceId(), player.getId()); } } } return true; }