use of mage.target.common.TargetNonlandPermanent 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;
}
use of mage.target.common.TargetNonlandPermanent in project mage by magefree.
the class FortunateFewEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Map<Permanent, Integer> chosenCards = new HashMap<>(2);
int maxCount = 0;
// Players each choose a legal permanent
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
FilterNonlandPermanent filter = new FilterNonlandPermanent("a nonland permanent you don't control");
filter.add(Predicates.not(new ControllerIdPredicate(player.getId())));
for (Permanent chosenPerm : chosenCards.keySet()) {
filter.add(Predicates.not(new PermanentIdPredicate(chosenPerm.getId())));
}
Target target = new TargetNonlandPermanent(filter);
target.setNotTarget(true);
if (player.choose(Outcome.Exile, target, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
chosenCards.put(permanent, 1);
game.informPlayers(player.getLogName() + " has chosen: " + permanent.getName());
}
}
}
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterNonlandPermanent(), source.getControllerId(), source.getSourceId(), game)) {
if (!chosenCards.containsKey(permanent)) {
permanent.destroy(source, game, false);
}
}
return true;
}
return false;
}
use of mage.target.common.TargetNonlandPermanent in project mage by magefree.
the class ConsumingTideEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
HashSet<UUID> chosenPermanents = new HashSet<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
TargetNonlandPermanent target = new TargetNonlandPermanent();
target.setNotTarget(true);
player.choose(Outcome.Benefit, target, source.getSourceId(), game);
UUID permId = target.getFirstTarget();
if (permId != null) {
chosenPermanents.add(permId);
}
}
}
HashSet<Card> permanentsToHand = new HashSet<>();
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_NON_LAND, controller.getId(), source.getSourceId(), game)) {
if (!chosenPermanents.contains(permanent.getId())) {
permanentsToHand.add(permanent);
}
}
controller.moveCards(permanentsToHand, Zone.HAND, source, game);
int controllerHandSize = controller.getHand().size();
int cardsToDraw = 0;
for (UUID opponentId : game.getOpponents(controller.getId())) {
Player opponent = game.getPlayer(opponentId);
if (opponent != null && opponent.getHand().size() > controllerHandSize) {
cardsToDraw++;
}
}
controller.drawCards(cardsToDraw, source, game);
return true;
}
Aggregations