use of mage.filter.common.FilterNonlandPermanent in project mage by magefree.
the class DispersalEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Set<PermanentIdPredicate> permsToReturn = new HashSet<>();
for (UUID opponentId : game.getOpponents(player.getId())) {
Player opponent = game.getPlayer(opponentId);
if (opponent == null) {
continue;
}
int highestCMC = 0;
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(opponentId)) {
if (permanent != null) {
highestCMC = Math.max(highestCMC, permanent.getManaValue());
}
}
FilterPermanent filter = new FilterNonlandPermanent("permanent you control with mana value " + highestCMC);
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, highestCMC));
filter.add(new ControllerIdPredicate(opponentId));
Target target = new TargetPermanent(1, 1, filter, true);
if (opponent.choose(outcome, target, source.getSourceId(), game)) {
if (target.getFirstTarget() == null) {
continue;
}
permsToReturn.add(new PermanentIdPredicate(target.getFirstTarget()));
}
}
FilterPermanent filter = new FilterPermanent();
filter.add(Predicates.or(permsToReturn));
new ReturnToHandFromBattlefieldAllEffect(filter).apply(game, source);
new DiscardEachPlayerEffect(StaticValue.get(1), false, TargetController.OPPONENT).apply(game, source);
return true;
}
use of mage.filter.common.FilterNonlandPermanent in project mage by magefree.
the class ZzzyxassAbyssEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
List<String> permanentNames = new ArrayList<>();
FilterPermanent filter = new FilterNonlandPermanent();
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, controller.getId(), game)) {
permanentNames.add(permanent.getName());
}
if (permanentNames.isEmpty()) {
return true;
}
Collections.sort(permanentNames);
filter.add(new NamePredicate(permanentNames.get(0)));
return new DestroyAllEffect(filter).apply(game, source);
}
return false;
}
use of mage.filter.common.FilterNonlandPermanent in project mage by magefree.
the class OKagachiVengefulKamiWatcher method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Player player = game.getPlayer(event.getTargetId());
if (player == null || !((DamagedPlayerEvent) event).isCombatDamage() || !event.getSourceId().equals(getSourceId())) {
return false;
}
this.getEffects().setValue("damagedPlayer", event.getTargetId());
FilterPermanent filter = new FilterNonlandPermanent("nonland permanent controlled by " + player.getName());
filter.add(new ControllerIdPredicate(event.getTargetId()));
this.getTargets().clear();
this.addTarget(new TargetPermanent(filter));
return true;
}
use of mage.filter.common.FilterNonlandPermanent in project mage by magefree.
the class MythosOfSnapdaxEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
boolean conditionMet = condition.apply(game, source);
List<Player> playerList = game.getState().getPlayersInRange(source.getControllerId(), game).stream().map(game::getPlayer).filter(Objects::nonNull).collect(Collectors.toList());
Set<UUID> toKeep = new HashSet();
for (Player player : playerList) {
for (CardType cardType : cardTypes) {
String message = cardType.toString().equals("Artifact") ? "an " : "a ";
message += cardType.toString().toLowerCase(Locale.ENGLISH);
message += (conditionMet && player != controller) ? " controlled by " + player.getName() : " you control";
FilterPermanent filter = new FilterNonlandPermanent(message);
filter.add(cardType.getPredicate());
filter.add(new ControllerIdPredicate(player.getId()));
if (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) == 0) {
continue;
}
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
if (conditionMet) {
controller.choose(outcome, target, source.getSourceId(), game);
} else {
player.choose(outcome, target, source.getSourceId(), game);
}
toKeep.add(target.getFirstTarget());
}
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_NON_LAND, source.getControllerId(), game)) {
if (permanent == null || toKeep.contains(permanent.getId())) {
continue;
}
permanent.sacrifice(source, game);
}
return true;
}
use of mage.filter.common.FilterNonlandPermanent in project mage by magefree.
the class BlastZoneEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
int xValue = permanent.getCounters(game).getCount(CounterType.CHARGE);
FilterPermanent filter = new FilterNonlandPermanent();
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, xValue));
return new DestroyAllEffect(filter).apply(game, source);
}
Aggregations