Search in sources :

Example 51 with ColorPredicate

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

the class ApostlesBlessingEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        ChoiceColorOrArtifact choice = new ChoiceColorOrArtifact();
        if (controller.choose(outcome, choice, game)) {
            FilterCard protectionFilter = new FilterCard();
            if (choice.isArtifactSelected()) {
                protectionFilter.add(CardType.ARTIFACT.getPredicate());
            } else {
                protectionFilter.add(new ColorPredicate(choice.getColor()));
            }
            protectionFilter.setMessage(choice.getChoice());
            ProtectionAbility protectionAbility = new ProtectionAbility(protectionFilter);
            ContinuousEffect effect = new GainAbilityTargetEffect(protectionAbility, Duration.EndOfTurn);
            effect.setTargetPointer(getTargetPointer());
            game.addEffect(effect, source);
            return true;
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) ChoiceColorOrArtifact(mage.choices.ChoiceColorOrArtifact) Player(mage.players.Player) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Example 52 with ColorPredicate

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

the class CephalidSnitchEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent targetCreature = game.getPermanent(targetPointer.getFirst(game, source));
    if (targetCreature != null) {
        List<Ability> toRemove = new ArrayList<>();
        // Go through protection abilities and sort out any containing black
        for (ProtectionAbility a : targetCreature.getAbilities().getProtectionAbilities()) {
            ObjectColor colors = a.getFromColor();
            if (colors.isBlack()) {
                List<ObjectColor> nonBlackColors = colors.intersection(NONBLACK).getColors();
                if (!nonBlackColors.isEmpty()) {
                    // If the ability is protection from multiple colors, construct a new filter excluding black
                    FilterCard filter = new FilterCard(filterNameAssembler(nonBlackColors));
                    if (nonBlackColors.size() == 1)
                        filter.add(new ColorPredicate(nonBlackColors.get(0)));
                    else if (nonBlackColors.size() == 2)
                        filter.add(Predicates.or(new ColorPredicate(nonBlackColors.get(0)), new ColorPredicate(nonBlackColors.get(1))));
                    else if (nonBlackColors.size() == 3)
                        filter.add(Predicates.or(new ColorPredicate(nonBlackColors.get(0)), new ColorPredicate(nonBlackColors.get(1)), new ColorPredicate(nonBlackColors.get(2))));
                    else if (nonBlackColors.size() == 4)
                        filter.add(Predicates.or(new ColorPredicate(nonBlackColors.get(0)), new ColorPredicate(nonBlackColors.get(1)), new ColorPredicate(nonBlackColors.get(2)), new ColorPredicate(nonBlackColors.get(3))));
                    a.setFilter(filter);
                } else {
                    // if the ability is just protection from black, remove it from the creature
                    toRemove.add(a);
                }
            }
        }
        targetCreature.removeAbilities(toRemove, source.getSourceId(), game);
        return true;
    }
    return false;
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) Ability(mage.abilities.Ability) FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) ObjectColor(mage.ObjectColor)

Example 53 with ColorPredicate

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

the class DarigaazTheIgniterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    ChoiceColor choice = new ChoiceColor(true);
    if (controller != null && controller.choose(outcome, choice, game)) {
        game.informPlayers(controller.getLogName() + " chooses " + choice.getColor());
        Player damagedPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
        if (damagedPlayer != null) {
            damagedPlayer.revealCards("hand of " + damagedPlayer.getName(), damagedPlayer.getHand(), game);
            FilterCard filter = new FilterCard();
            filter.add(new ColorPredicate(choice.getColor()));
            int damage = damagedPlayer.getHand().count(filter, source.getSourceId(), source.getControllerId(), game);
            if (damage > 0) {
                damagedPlayer.damage(damage, source.getSourceId(), source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) ChoiceColor(mage.choices.ChoiceColor)

Example 54 with ColorPredicate

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

the class DarkTemperEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
    if (permanent == null) {
        return false;
    }
    FilterPermanent filter = new FilterPermanent("black permanent");
    filter.add(new ColorPredicate(ObjectColor.BLACK));
    if (game.getBattlefield().countAll(filter, source.getControllerId(), game) == 0) {
        permanent.damage(2, source.getSourceId(), source, game, false, true);
    } else {
        permanent.destroy(source, game, false);
    }
    return true;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent)

Aggregations

ColorPredicate (mage.filter.predicate.mageobject.ColorPredicate)54 Player (mage.players.Player)28 FilterCard (mage.filter.FilterCard)20 ObjectColor (mage.ObjectColor)18 FilterPermanent (mage.filter.FilterPermanent)16 Permanent (mage.game.permanent.Permanent)16 ProtectionAbility (mage.abilities.keyword.ProtectionAbility)14 ChoiceColor (mage.choices.ChoiceColor)14 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)10 Ability (mage.abilities.Ability)6 UUID (java.util.UUID)5 MageObject (mage.MageObject)5 Card (mage.cards.Card)5 FilterObject (mage.filter.FilterObject)5 CardsImpl (mage.cards.CardsImpl)4 ArrayList (java.util.ArrayList)3 ContinuousEffect (mage.abilities.effects.ContinuousEffect)3 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)3 TargetPlayer (mage.target.TargetPlayer)3 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)3