Search in sources :

Example 26 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class ParasiticStrixTriggeredAbility method checkInterveningIfClause.

@Override
public boolean checkInterveningIfClause(Game game) {
    FilterPermanent filter = new FilterPermanent();
    filter.add(new ColorPredicate(ObjectColor.BLACK));
    if (game.getBattlefield().countAll(filter, this.controllerId, game) >= 1) {
        return true;
    }
    return false;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) FilterPermanent(mage.filter.FilterPermanent)

Example 27 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class RidersOfGavonyGainAbilityControlledEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    if (protectionFilter == null) {
        Permanent permanent = game.getPermanent(source.getSourceId());
        if (permanent != null) {
            SubType subType = ChooseCreatureTypeEffect.getChosenCreatureType(permanent.getId(), game);
            if (subType != null) {
                protectionFilter = new FilterPermanent(subType.getDescription() + 's');
                protectionFilter.add(subType.getPredicate());
            } else {
                discard();
            }
        }
    }
    if (protectionFilter != null) {
        for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
            perm.addAbility(new ProtectionAbility(protectionFilter), source.getSourceId(), game);
        }
        return true;
    }
    return false;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ProtectionAbility(mage.abilities.keyword.ProtectionAbility)

Example 28 with FilterPermanent

use of mage.filter.FilterPermanent 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 29 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class SoullessOneDynamicCount method calculate.

@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
    FilterPermanent zombiesBattlefield = new FilterPermanent("Zombies on the battlefield");
    FilterCard zombiesInGraveyard = new FilterCard("Zombie cards in all graveyards");
    zombiesBattlefield.add(SubType.ZOMBIE.getPredicate());
    zombiesInGraveyard.add(SubType.ZOMBIE.getPredicate());
    int count = game.getBattlefield().count(zombiesBattlefield, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game);
    for (UUID playerId : game.getState().getPlayersInRange(sourceAbility.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            count += player.getGraveyard().count(zombiesInGraveyard, game);
        }
    }
    return count;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) UUID(java.util.UUID)

Example 30 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class TrevaTheRenewerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    ChoiceColor choice = new ChoiceColor();
    if (controller.choose(outcome, choice, game)) {
        game.informPlayers(controller.getLogName() + " chooses " + choice.getColor());
        FilterPermanent filter = new FilterPermanent();
        filter.add(new ColorPredicate(choice.getColor()));
        int cardsWithColor = game.getBattlefield().count(filter, source.getSourceId(), controller.getId(), game);
        if (cardsWithColor > 0) {
            new GainLifeEffect(cardsWithColor).apply(game, source);
        }
        return true;
    }
    return false;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) ChoiceColor(mage.choices.ChoiceColor) GainLifeEffect(mage.abilities.effects.common.GainLifeEffect)

Aggregations

FilterPermanent (mage.filter.FilterPermanent)155 Permanent (mage.game.permanent.Permanent)99 Player (mage.players.Player)99 TargetPermanent (mage.target.TargetPermanent)62 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)49 UUID (java.util.UUID)41 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)30 Target (mage.target.Target)24 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)18 ColorPredicate (mage.filter.predicate.mageobject.ColorPredicate)17 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)16 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)14 OneShotEffect (mage.abilities.effects.OneShotEffect)13 Card (mage.cards.Card)13 FixedTarget (mage.target.targetpointer.FixedTarget)13 FilterCard (mage.filter.FilterCard)11 FilterNonlandPermanent (mage.filter.common.FilterNonlandPermanent)11 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)11 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)11 CardsImpl (mage.cards.CardsImpl)10