Search in sources :

Example 11 with PowerPredicate

use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.

the class TargetCreatureWithLessPowerPermanent method canChoose.

@Override
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
    // get the most powerful controlled creature that can be targeted
    int maxPower = Integer.MIN_VALUE;
    Card sourceCard = game.getCard(sourceId);
    if (sourceCard == null) {
        return false;
    }
    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, sourceControllerId, game)) {
        if (permanent.getPower().getValue() > maxPower && permanent.canBeTargetedBy(sourceCard, sourceControllerId, game)) {
            maxPower = permanent.getPower().getValue();
        }
    }
    // now check, if another creature has less power and can be targeted
    FilterCreaturePermanent checkFilter = new FilterCreaturePermanent();
    checkFilter.add(new PowerPredicate(ComparisonType.FEWER_THAN, maxPower));
    for (Permanent permanent : game.getBattlefield().getActivePermanents(checkFilter, sourceControllerId, sourceId, game)) {
        if (permanent.canBeTargetedBy(sourceCard, sourceControllerId, game)) {
            return true;
        }
    }
    return false;
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) Card(mage.cards.Card)

Example 12 with PowerPredicate

use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.

the class NightmareUnmakingEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    FilterPermanent filter = new FilterCreaturePermanent();
    filter.add(new PowerPredicate(comparisonType, player.getHand().size()));
    return new ExileAllEffect(filter).apply(game, source);
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ExileAllEffect(mage.abilities.effects.common.ExileAllEffect) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate)

Example 13 with PowerPredicate

use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.

the class RumblingRuinEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int counter = 1;
    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(source.getControllerId())) {
        if (permanent == null || !permanent.isCreature(game)) {
            continue;
        }
        counter += permanent.getCounters(game).getCount(CounterType.P1P1);
    }
    FilterCreaturePermanent filter = new FilterOpponentsCreaturePermanent();
    filter.add(new PowerPredicate(ComparisonType.FEWER_THAN, counter));
    game.addEffect(new CantBlockAllEffect(filter, Duration.EndOfTurn), source);
    return true;
}
Also used : FilterOpponentsCreaturePermanent(mage.filter.common.FilterOpponentsCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterOpponentsCreaturePermanent(mage.filter.common.FilterOpponentsCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) CantBlockAllEffect(mage.abilities.effects.common.combat.CantBlockAllEffect) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate)

Example 14 with PowerPredicate

use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.

the class FallOfTheImpostorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(source.getFirstTarget());
    if (controller != null && opponent != null) {
        List<Permanent> permanents = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, opponent.getId(), game);
        Integer maxPower = null;
        for (Permanent permanent : permanents) {
            if (permanent != null) {
                int power = permanent.getPower().getValue();
                if (maxPower == null || power > maxPower) {
                    maxPower = power;
                }
            }
        }
        if (maxPower != null) {
            FilterCreaturePermanent filter = new FilterCreaturePermanent();
            filter.add(new ControllerIdPredicate(opponent.getId()));
            filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, maxPower));
            TargetCreaturePermanent target = new TargetCreaturePermanent(1, 1, filter, true);
            controller.chooseTarget(outcome, target, source, game);
            Permanent permanent = game.getPermanent(target.getFirstTarget());
            if (permanent != null) {
                controller.moveCardsToExile(permanent, source, game, true, null, null);
                return true;
            }
        }
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate)

Example 15 with PowerPredicate

use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.

the class TargetCreatureWithLessPowerPermanent method possibleTargets.

@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
    Spell spell = game.getStack().getSpell(sourceId);
    if (spell != null) {
        Permanent firstTarget = getPermanentFromFirstTarget(spell.getSpellAbility(), game);
        if (firstTarget != null) {
            int power = firstTarget.getPower().getValue();
            // overwrite the filter with the power predicate
            filter = new FilterCreaturePermanent("creature with power less than " + power);
            filter.add(new PowerPredicate(ComparisonType.FEWER_THAN, power));
        }
    }
    return super.possibleTargets(sourceId, sourceControllerId, game);
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) Spell(mage.game.stack.Spell)

Aggregations

PowerPredicate (mage.filter.predicate.mageobject.PowerPredicate)20 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)16 Permanent (mage.game.permanent.Permanent)16 Player (mage.players.Player)15 TargetPermanent (mage.target.TargetPermanent)8 Target (mage.target.Target)6 FilterPermanent (mage.filter.FilterPermanent)5 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)5 UUID (java.util.UUID)4 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)4 OneShotEffect (mage.abilities.effects.OneShotEffect)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ContinuousEffect (mage.abilities.effects.ContinuousEffect)2 Effect (mage.abilities.effects.Effect)2 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)2 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)2 FixedTarget (mage.target.targetpointer.FixedTarget)2 java.util (java.util)1 Collectors (java.util.stream.Collectors)1