Search in sources :

Example 51 with FilterPermanent

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;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent)

Example 52 with FilterPermanent

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;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent)

Example 53 with FilterPermanent

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;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) SacrificeEffect(mage.abilities.effects.common.SacrificeEffect)

Example 54 with FilterPermanent

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;
}
Also used : ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ProtectionAbility(mage.abilities.keyword.ProtectionAbility)

Example 55 with FilterPermanent

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;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) MageInt(mage.MageInt) HashSet(java.util.HashSet)

Aggregations

FilterPermanent (mage.filter.FilterPermanent)155 Permanent (mage.game.permanent.Permanent)99 Player (mage.players.Player)99 TargetPermanent (mage.target.TargetPermanent)62 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)49 UUID (java.util.UUID)41 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)30 Target (mage.target.Target)24 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)18 ColorPredicate (mage.filter.predicate.mageobject.ColorPredicate)17 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)16 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)14 OneShotEffect (mage.abilities.effects.OneShotEffect)13 Card (mage.cards.Card)13 FixedTarget (mage.target.targetpointer.FixedTarget)13 FilterCard (mage.filter.FilterCard)11 FilterNonlandPermanent (mage.filter.common.FilterNonlandPermanent)11 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)11 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)11 CardsImpl (mage.cards.CardsImpl)10