use of mage.filter.FilterPermanent in project mage by magefree.
the class StripBareEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
boolean applied = false;
FilterPermanent filter = new FilterPermanent();
filter.add(Predicates.or(SubType.EQUIPMENT.getPredicate(), SubType.AURA.getPredicate()));
Permanent targetCreature = game.getPermanent(source.getFirstTarget());
if (targetCreature != null && !targetCreature.getAttachments().isEmpty()) {
for (Permanent attachment : game.getBattlefield().getAllActivePermanents(filter, game)) {
if (attachment != null && targetCreature.getAttachments().contains(attachment.getId())) {
applied = attachment.destroy(source, game, false);
}
}
}
return applied;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class DestroyAllNamedPermanentsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (targetPermanent == null) {
return false;
}
FilterPermanent filter = new FilterPermanent();
if (CardUtil.haveEmptyName(targetPermanent)) {
// if no name (face down creature) only the creature itself is selected
filter.add(new PermanentIdPredicate(targetPermanent.getId()));
} else {
filter.add(new NamePredicate(targetPermanent.getName()));
}
for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
perm.destroy(source, game, false);
}
return true;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class ConsumeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player player = game.getPlayer(source.getFirstTarget());
if (player == null || controller == null) {
return false;
}
int greatestPower = 0;
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(player.getId())) {
if (permanent != null && permanent.isCreature(game)) {
greatestPower = Math.max(permanent.getPower().getValue(), greatestPower);
}
}
FilterPermanent filter = new FilterCreaturePermanent("creature with power " + greatestPower);
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, greatestPower));
new SacrificeEffect(filter, 1, "").apply(game, source);
controller.gainLife(greatestPower, game, source);
return true;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class FavorOfTheMightyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int maxCMC = Integer.MIN_VALUE;
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game)) {
if (permanent != null && permanent.getManaValue() > maxCMC) {
maxCMC = permanent.getManaValue();
}
}
FilterPermanent filterMaxCMC = new FilterCreaturePermanent();
filterMaxCMC.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, maxCMC));
for (Permanent permanent : game.getBattlefield().getActivePermanents(filterMaxCMC, source.getControllerId(), game)) {
if (permanent != null) {
permanent.addAbility(new ProtectionAbility(filter), source.getSourceId(), game);
}
}
return true;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class HighcliffFelidarEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Set<UUID> toDestroy = new HashSet();
game.getOpponents(source.getControllerId()).stream().map(game::getPlayer).filter(Objects::nonNull).forEachOrdered(opponent -> {
int maxPower = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, opponent.getId(), game).stream().map(Permanent::getPower).mapToInt(MageInt::getValue).max().orElse(Integer.MIN_VALUE);
if (maxPower > Integer.MIN_VALUE) {
FilterPermanent filter = new FilterCreaturePermanent("creature with the greatest power controlled by " + opponent.getName());
filter.add(new ControllerIdPredicate(opponent.getId()));
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, maxPower));
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
if (controller.choose(outcome, target, source.getSourceId(), game)) {
toDestroy.add(target.getFirstTarget());
}
}
});
toDestroy.stream().map(game::getPermanent).filter(Objects::nonNull).forEachOrdered(permanent -> permanent.destroy(source, game, false));
return true;
}
Aggregations