Search in sources :

Example 56 with FilterCreaturePermanent

use of mage.filter.common.FilterCreaturePermanent 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 57 with FilterCreaturePermanent

use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.

the class DoOrDieEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (player != null && targetPlayer != null) {
        int count = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURES, targetPlayer.getId(), game);
        TargetCreaturePermanent creatures = new TargetCreaturePermanent(0, count, new FilterCreaturePermanent("creatures to put in the first pile"), true);
        List<Permanent> pile1 = new ArrayList<>();
        creatures.setRequired(false);
        if (player.choose(Outcome.Neutral, creatures, source.getSourceId(), game)) {
            List<UUID> targets = creatures.getTargets();
            for (UUID targetId : targets) {
                Permanent p = game.getPermanent(targetId);
                if (p != null) {
                    pile1.add(p);
                }
            }
        }
        List<Permanent> pile2 = new ArrayList<>();
        for (Permanent p : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, targetPlayer.getId(), game)) {
            if (!pile1.contains(p)) {
                pile2.add(p);
            }
        }
        boolean choice = targetPlayer.choosePile(Outcome.DestroyPermanent, "Choose a pile to destroy.", pile1, pile2, game);
        if (choice) {
            destroyPermanents(pile1, game, source);
        } else {
            destroyPermanents(pile2, game, source);
        }
        return true;
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 58 with FilterCreaturePermanent

use of mage.filter.common.FilterCreaturePermanent 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 59 with FilterCreaturePermanent

use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.

the class DromarTheBanisherEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        ChoiceColor choice = new ChoiceColor();
        if (player.choose(outcome, choice, game)) {
            game.informPlayers(player.getLogName() + " chooses " + choice.getChoice());
            FilterCreaturePermanent filter = new FilterCreaturePermanent();
            filter.add(new ColorPredicate(choice.getColor()));
            new ReturnToHandFromBattlefieldAllEffect(filter).apply(game, source);
            return true;
        }
    }
    return false;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ReturnToHandFromBattlefieldAllEffect(mage.abilities.effects.common.ReturnToHandFromBattlefieldAllEffect) ChoiceColor(mage.choices.ChoiceColor)

Example 60 with FilterCreaturePermanent

use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.

the class DroningBureaucratsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int xValue = source.getManaCostsToPay().getX();
    FilterCreaturePermanent filter = new FilterCreaturePermanent("creature with mana value X");
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, xValue));
    game.addEffect(new CantAttackBlockAllEffect(Duration.EndOfTurn, filter), source);
    return true;
}
Also used : ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) CantAttackBlockAllEffect(mage.abilities.effects.common.combat.CantAttackBlockAllEffect)

Aggregations

FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)187 Player (mage.players.Player)125 Permanent (mage.game.permanent.Permanent)108 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)83 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)67 UUID (java.util.UUID)55 TargetPermanent (mage.target.TargetPermanent)32 Target (mage.target.Target)31 FilterPermanent (mage.filter.FilterPermanent)27 FixedTarget (mage.target.targetpointer.FixedTarget)25 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)23 ContinuousEffect (mage.abilities.effects.ContinuousEffect)22 MageObject (mage.MageObject)16 PowerPredicate (mage.filter.predicate.mageobject.PowerPredicate)16 OneShotEffect (mage.abilities.effects.OneShotEffect)14 Effect (mage.abilities.effects.Effect)13 Choice (mage.choices.Choice)13 TargetPlayer (mage.target.TargetPlayer)13 Card (mage.cards.Card)12 ChoiceCreatureType (mage.choices.ChoiceCreatureType)12