Search in sources :

Example 6 with ToughnessPredicate

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

the class ScourgeOfFleetsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int islands = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
        FilterPermanent creatureFilter = new FilterCreaturePermanent();
        creatureFilter.add(TargetController.OPPONENT.getControllerPredicate());
        creatureFilter.add(new ToughnessPredicate(ComparisonType.FEWER_THAN, islands + 1));
        Cards cardsToHand = new CardsImpl();
        for (Permanent permanent : game.getBattlefield().getActivePermanents(creatureFilter, source.getControllerId(), source.getSourceId(), game)) {
            cardsToHand.add(permanent);
        }
        controller.moveCards(cardsToHand, Zone.HAND, source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ToughnessPredicate(mage.filter.predicate.mageobject.ToughnessPredicate) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 7 with ToughnessPredicate

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

the class BolsterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        if (amount.calculate(game, source, this) <= 0) {
            return true;
        }
        int leastToughness = Integer.MAX_VALUE;
        Permanent selectedCreature = null;
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game)) {
            if (leastToughness > permanent.getToughness().getValue()) {
                leastToughness = permanent.getToughness().getValue();
                selectedCreature = permanent;
            } else if (leastToughness == permanent.getToughness().getValue()) {
                leastToughness = permanent.getToughness().getValue();
                selectedCreature = null;
            }
        }
        if (leastToughness != Integer.MAX_VALUE) {
            if (selectedCreature == null) {
                FilterPermanent filter = new FilterControlledCreaturePermanent("creature you control with toughness " + leastToughness);
                filter.add(new ToughnessPredicate(ComparisonType.EQUAL_TO, leastToughness));
                Target target = new TargetPermanent(1, 1, filter, true);
                if (controller.chooseTarget(outcome, target, source, game)) {
                    selectedCreature = game.getPermanent(target.getFirstTarget());
                }
            }
            if (selectedCreature != null) {
                Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(amount.calculate(game, source, this)));
                effect.setTargetPointer(new FixedTarget(selectedCreature, game));
                return effect.apply(game, source);
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) ToughnessPredicate(mage.filter.predicate.mageobject.ToughnessPredicate) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) TargetPermanent(mage.target.TargetPermanent) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

Aggregations

ToughnessPredicate (mage.filter.predicate.mageobject.ToughnessPredicate)7 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)6 Permanent (mage.game.permanent.Permanent)6 Player (mage.players.Player)5 FilterPermanent (mage.filter.FilterPermanent)3 Cards (mage.cards.Cards)2 CardsImpl (mage.cards.CardsImpl)2 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)2 Target (mage.target.Target)2 TargetPermanent (mage.target.TargetPermanent)2 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 MageObjectReference (mage.MageObjectReference)1 Effect (mage.abilities.effects.Effect)1 OneShotEffect (mage.abilities.effects.OneShotEffect)1 AddCountersTargetEffect (mage.abilities.effects.common.counter.AddCountersTargetEffect)1 Card (mage.cards.Card)1 FilterCard (mage.filter.FilterCard)1 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)1 FilterCreatureCard (mage.filter.common.FilterCreatureCard)1