Search in sources :

Example 16 with PowerPredicate

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

the class PorphyryNodesStateTriggeredAbility method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && sourcePermanent != null) {
        int leastPower = Integer.MAX_VALUE;
        boolean multipleExist = false;
        Permanent permanentToDestroy = null;
        for (Permanent permanent : game.getBattlefield().getActivePermanents(PorphyryNodes.filter, source.getControllerId(), game)) {
            if (permanent.getPower().getValue() < leastPower) {
                permanentToDestroy = permanent;
                leastPower = permanent.getPower().getValue();
                multipleExist = false;
            } else {
                if (permanent.getPower().getValue() == leastPower) {
                    multipleExist = true;
                }
            }
        }
        if (multipleExist) {
            FilterCreaturePermanent filter = new FilterCreaturePermanent("one of the creatures with the least power");
            filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, leastPower));
            Target target = new TargetPermanent(filter);
            target.setNotTarget(true);
            if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
                if (controller.choose(outcome, target, source.getSourceId(), game)) {
                    permanentToDestroy = game.getPermanent(target.getFirstTarget());
                }
            }
        }
        if (permanentToDestroy != null) {
            game.informPlayers(sourcePermanent.getName() + " chosen creature: " + permanentToDestroy.getName());
            return permanentToDestroy.destroy(source, game, true);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) TargetPermanent(mage.target.TargetPermanent)

Example 17 with PowerPredicate

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

the class ShadowgrangeArchfiendEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    List<Permanent> toSacrifice = new ArrayList<>();
    // Iterate through each opponent
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        if (!controller.hasOpponent(playerId, game)) {
            continue;
        }
        Player opponent = game.getPlayer(playerId);
        if (opponent == null) {
            continue;
        }
        int greatestPower = Integer.MIN_VALUE;
        int numberOfCreatures = 0;
        Permanent creatureToSacrifice = null;
        // Iterature through each creature
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)) {
            if (permanent.getPower().getValue() > greatestPower) {
                greatestPower = permanent.getPower().getValue();
                numberOfCreatures = 1;
                creatureToSacrifice = permanent;
            } else if (permanent.getPower().getValue() == greatestPower) {
                numberOfCreatures++;
            }
        }
        // If multiple creatures are tied for having the greatest power
        if (numberOfCreatures > 1) {
            FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature to sacrifice with power equal to " + greatestPower);
            filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, greatestPower));
            Target target = new TargetControlledCreaturePermanent(filter);
            if (opponent.choose(outcome, target, playerId, game)) {
                creatureToSacrifice = game.getPermanent(target.getFirstTarget());
            }
        }
        if (creatureToSacrifice != null) {
            toSacrifice.add(creatureToSacrifice);
        }
    }
    int greatestPowerAmongAllCreaturesSacked = Integer.MIN_VALUE;
    int powerOfCurrentCreature;
    // Sack the creatures and save the greaterest power amoung those which were sacked
    for (Permanent permanent : toSacrifice) {
        powerOfCurrentCreature = permanent.getPower().getValue();
        // Try to sack it
        if (permanent.sacrifice(source, game)) {
            if (powerOfCurrentCreature > greatestPowerAmongAllCreaturesSacked) {
                greatestPowerAmongAllCreaturesSacked = powerOfCurrentCreature;
            }
        }
    }
    // Gain life equal to the power of greatest creature sacked, if it is positive
    if (greatestPowerAmongAllCreaturesSacked > 0) {
        new GainLifeEffect(greatestPowerAmongAllCreaturesSacked).apply(game, source);
    }
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ArrayList(java.util.ArrayList) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) GainLifeEffect(mage.abilities.effects.common.GainLifeEffect)

Example 18 with PowerPredicate

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

the class LenaSelflessChampionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (permanent == null) {
        return false;
    }
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(new PowerPredicate(ComparisonType.FEWER_THAN, permanent.getPower().getValue()));
    game.addEffect(new GainAbilityControlledEffect(IndestructibleAbility.getInstance(), Duration.EndOfTurn, filter), source);
    return true;
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) GainAbilityControlledEffect(mage.abilities.effects.common.continuous.GainAbilityControlledEffect) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate)

Example 19 with PowerPredicate

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

the class PuppetsVerdictEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        if (controller.flipCoin(source, game, true)) {
            FilterCreaturePermanent filterPower2OrLess = new FilterCreaturePermanent("all creatures power 2 or less");
            filterPower2OrLess.add(new PowerPredicate(ComparisonType.FEWER_THAN, 3));
            for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filterPower2OrLess, game)) {
                permanent.destroy(source, game, false);
            }
            return true;
        } else {
            FilterCreaturePermanent filterPower3OrGreater = new FilterCreaturePermanent("all creatures power 3 or greater");
            filterPower3OrGreater.add(new PowerPredicate(ComparisonType.MORE_THAN, 2));
            for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filterPower3OrGreater, game)) {
                permanent.destroy(source, game, false);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate)

Example 20 with PowerPredicate

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

the class RhonasTheIndomitableRestrictionEffect method applies.

@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
    FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
    filter.add(new PowerPredicate(ComparisonType.MORE_THAN, 3));
    filter.add(AnotherPredicate.instance);
    if (permanent.getId().equals(source.getSourceId())) {
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null) {
            int permanentsOnBattlefield = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
            // is this correct?
            return permanentsOnBattlefield < 1;
        }
        return true;
    }
    // do not apply to other creatures.
    return false;
}
Also used : Player(mage.players.Player) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate)

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