Search in sources :

Example 1 with ToughnessPredicate

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

the class PurgingScytheEffect 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 leastToughness = Integer.MAX_VALUE;
        boolean multipleExist = false;
        Permanent permanentToDamage = null;
        for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), game)) {
            if (permanent.getToughness().getValue() < leastToughness) {
                permanentToDamage = permanent;
                leastToughness = permanent.getToughness().getValue();
                multipleExist = false;
            } else {
                if (permanent.getToughness().getValue() == leastToughness) {
                    multipleExist = true;
                }
            }
        }
        if (multipleExist) {
            FilterCreaturePermanent filter = new FilterCreaturePermanent("one of the creatures with the least toughness");
            filter.add(new ToughnessPredicate(ComparisonType.EQUAL_TO, leastToughness));
            Target target = new TargetPermanent(filter);
            target.setNotTarget(true);
            if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
                if (controller.choose(outcome, target, source.getSourceId(), game)) {
                    permanentToDamage = game.getPermanent(target.getFirstTarget());
                }
            }
        }
        if (permanentToDamage != null) {
            game.informPlayers(sourcePermanent.getName() + " chosen creature: " + permanentToDamage.getName());
            return permanentToDamage.damage(2, source.getSourceId(), source, game, false, true) > 0;
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ToughnessPredicate(mage.filter.predicate.mageobject.ToughnessPredicate) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

Example 2 with ToughnessPredicate

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

the class SkymarkRocAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getSourceId().equals(this.getSourceId())) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls with toughness 2 or less");
        UUID defenderId = game.getCombat().getDefendingPlayerId(sourceId, game);
        filter.add(new ControllerIdPredicate(defenderId));
        filter.add(new ToughnessPredicate(ComparisonType.FEWER_THAN, 3));
        this.getTargets().clear();
        TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
        this.addTarget(target);
        return true;
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ToughnessPredicate(mage.filter.predicate.mageobject.ToughnessPredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID)

Example 3 with ToughnessPredicate

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

the class ColfenorTheLastYewTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!super.checkTrigger(event, game)) {
        return false;
    }
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    Permanent permanent = zEvent.getTarget();
    if (permanent == null) {
        return false;
    }
    FilterCard filterCard = new FilterCreatureCard("creature card with toughness less than " + permanent.getToughness().getValue());
    filterCard.add(new ToughnessPredicate(ComparisonType.FEWER_THAN, permanent.getToughness().getValue()));
    filterCard.add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(permanent, game))));
    this.getTargets().clear();
    this.addTarget(new TargetCardInYourGraveyard(0, 1, filterCard));
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ToughnessPredicate(mage.filter.predicate.mageobject.ToughnessPredicate) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) MageObjectReference(mage.MageObjectReference)

Example 4 with ToughnessPredicate

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

the class EngulfTheShoreEffect 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(new ToughnessPredicate(ComparisonType.FEWER_THAN, islands + 1));
        Set<Card> cardsToHand = new HashSet<>();
        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) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 5 with ToughnessPredicate

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

the class ProfanerOfTheDeadReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent exploitedCreature = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
    if (controller != null && exploitedCreature != null) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent();
        filter.add(TargetController.OPPONENT.getControllerPredicate());
        filter.add(new ToughnessPredicate(ComparisonType.FEWER_THAN, exploitedCreature.getToughness().getValue()));
        Cards cardsToHand = new CardsImpl();
        for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, 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) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

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