Search in sources :

Example 6 with PowerPredicate

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

the class ShowOfDominanceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int highestPower = Integer.MIN_VALUE;
        Permanent selectedCreature = null;
        for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game)) {
            if (highestPower < permanent.getPower().getValue()) {
                highestPower = permanent.getPower().getValue();
                selectedCreature = permanent;
            } else if (highestPower == permanent.getPower().getValue()) {
                highestPower = permanent.getPower().getValue();
                selectedCreature = null;
            }
        }
        if (highestPower != Integer.MIN_VALUE) {
            if (selectedCreature == null) {
                FilterPermanent filter = new FilterCreaturePermanent("creature with power " + highestPower);
                filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, highestPower));
                Target target = new TargetPermanent(1, 1, filter, true);
                if (controller.chooseTarget(outcome, target, source, game)) {
                    selectedCreature = game.getPermanent(target.getFirstTarget());
                }
            }
            if (selectedCreature != null) {
                FixedTarget target = new FixedTarget(selectedCreature.getId(), game);
                Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(4));
                effect.setTargetPointer(target);
                effect.apply(game, source);
                ContinuousEffect continuousEffect = new GainAbilityTargetEffect(TrampleAbility.getInstance(), Duration.EndOfTurn);
                continuousEffect.setTargetPointer(target);
                game.addEffect(continuousEffect, source);
                return true;
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) TargetPermanent(mage.target.TargetPermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

Example 7 with PowerPredicate

use of mage.filter.predicate.mageobject.PowerPredicate 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 8 with PowerPredicate

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

the class DropOfHoneyStateTriggeredAbility 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(StaticFilters.FILTER_PERMANENT_CREATURES, 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 9 with PowerPredicate

use of mage.filter.predicate.mageobject.PowerPredicate 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)

Example 10 with PowerPredicate

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

the class MobRuleControlAllEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean applied = false;
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(new PowerPredicate(type, power));
    List<Permanent> creatures = game.getBattlefield().getAllActivePermanents(filter, game);
    for (Permanent creature : creatures) {
        ContinuousEffect effect = new MobRuleControlAllEffect(source.getControllerId());
        effect.setTargetPointer(new FixedTarget(creature.getId(), game));
        game.addEffect(effect, source);
        applied = true;
    }
    for (Permanent creature : creatures) {
        creature.untap(game);
        applied = true;
    }
    for (Permanent creature : creatures) {
        ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
        effect.setTargetPointer(new FixedTarget(creature.getId(), game));
        game.addEffect(effect, source);
        applied = true;
    }
    return applied;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

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