use of mage.filter.common.FilterNonlandPermanent 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;
}
use of mage.filter.common.FilterNonlandPermanent 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.filter.common.FilterNonlandPermanent in project mage by magefree.
the class SarulfRealmEaterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (player == null || permanent == null) {
return false;
}
int counterCount = permanent.getCounters(game).getCount(CounterType.P1P1);
permanent.removeCounters(CounterType.P1P1.createInstance(counterCount), source, game);
FilterPermanent filter = new FilterNonlandPermanent();
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, counterCount + 1));
filter.add(AnotherPredicate.instance);
Cards cards = new CardsImpl();
game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game).stream().filter(Objects::nonNull).map(MageItem::getId).forEach(cards::add);
return player.moveCards(cards, Zone.EXILED, source, game);
}
use of mage.filter.common.FilterNonlandPermanent in project mage by magefree.
the class DeputyOfDetentionExileEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
Permanent targeted = game.getPermanent(source.getFirstTarget());
if (permanent == null || controller == null || targeted == null) {
return false;
}
FilterPermanent filter = new FilterNonlandPermanent();
filter.add(new ControllerIdPredicate(targeted.getControllerId()));
filter.add(new NamePredicate(targeted.getName()));
Set<Card> toExile = new LinkedHashSet<>();
for (Permanent creature : game.getBattlefield().getActivePermanents(filter, controller.getId(), game)) {
toExile.add(creature);
}
if (!toExile.isEmpty()) {
controller.moveCardsToExile(toExile, source, game, true, CardUtil.getCardExileZoneId(game, source), permanent.getIdName());
new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility()).apply(game, source);
}
return true;
}
use of mage.filter.common.FilterNonlandPermanent in project mage by magefree.
the class AminatouUltimateEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Choice choice = new ChoiceLeftOrRight();
if (!controller.choose(Outcome.Neutral, choice, game)) {
return false;
}
boolean left = choice.getChoice().equals("Left");
PlayerList playerList = game.getState().getPlayerList().copy();
// set playerlist to controller
while (!playerList.get().equals(source.getControllerId())) {
playerList.getNext();
}
UUID currentPlayer = playerList.get();
UUID nextPlayer;
UUID firstNextPlayer = null;
while (!getNextPlayerInDirection(left, playerList, game).equals(firstNextPlayer)) {
nextPlayer = playerList.get();
if (nextPlayer == null) {
return false;
}
// skip players out of range
if (!game.getState().getPlayersInRange(controller.getId(), game).contains(nextPlayer)) {
continue;
}
// save first next player to check for iteration stop
if (firstNextPlayer == null) {
firstNextPlayer = nextPlayer;
}
FilterNonlandPermanent nextPlayerNonlandPermanentsFilter = new FilterNonlandPermanent();
nextPlayerNonlandPermanentsFilter.add(new ControllerIdPredicate(nextPlayer));
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(nextPlayerNonlandPermanentsFilter, game)) {
if (permanent.getId().equals(source.getSourceId())) {
continue;
}
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, currentPlayer);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
currentPlayer = nextPlayer;
}
return true;
}
return false;
}
Aggregations