Search in sources :

Example 46 with ColorPredicate

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

the class SelfInflictedWoundEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetOpponent = game.getPlayer(source.getTargets().getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (targetOpponent == null || controller == null) {
        return false;
    }
    FilterControlledPermanent filter = new FilterControlledPermanent("a green or white creature");
    filter.add(CardType.CREATURE.getPredicate());
    filter.add(TargetController.YOU.getControllerPredicate());
    filter.add(Predicates.or(new ColorPredicate(ObjectColor.GREEN), new ColorPredicate(ObjectColor.WHITE)));
    TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
    if (target.canChoose(source.getSourceId(), targetOpponent.getId(), game)) {
        targetOpponent.chooseTarget(Outcome.Sacrifice, target, source, game);
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
            if (permanent.sacrifice(source, game)) {
                targetOpponent.loseLife(2, game, source, false);
            }
        }
    }
    return true;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 47 with ColorPredicate

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

the class GainProtectionFromColorSourceEffect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        ChoiceColor colorChoice = new ChoiceColor(true);
        colorChoice.setMessage("Choose color for protection ability");
        if (controller.choose(outcome, colorChoice, game)) {
            game.informPlayers("Choosen color: " + colorChoice.getColor());
            protectionFilter.add(new ColorPredicate(colorChoice.getColor()));
            protectionFilter.setMessage(colorChoice.getChoice());
            ((ProtectionAbility) ability).setFilter(protectionFilter);
            return;
        }
    }
    discard();
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) ChoiceColor(mage.choices.ChoiceColor)

Example 48 with ColorPredicate

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

the class ProtectionAbility method from.

public static ProtectionAbility from(ObjectColor color) {
    FilterObject filter = new FilterObject(getFilterText(color));
    filter.add(new ColorPredicate(color));
    ProtectionAbility ability = new ProtectionAbility(filter);
    ability.getFromColor().addColor(color);
    return ability;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate)

Example 49 with ColorPredicate

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

the class TargetControlledCreatureEachColor method makeFilter.

private static final FilterControlledPermanent makeFilter(String colors) {
    List<ObjectColor> objectColors = Arrays.stream(colors.split("")).map(ObjectColor::new).collect(Collectors.toList());
    FilterControlledPermanent filter = new FilterControlledCreaturePermanent(CardUtil.concatWithAnd(objectColors.stream().map(ObjectColor::getDescription).map(s -> CardUtil.addArticle(s) + " creature").collect(Collectors.toList())));
    filter.add(Predicates.or(objectColors.stream().map(ColorPredicate::new).collect(Collectors.toList())));
    return filter;
}
Also used : Arrays(java.util.Arrays) Cards(mage.cards.Cards) Predicates(mage.filter.predicate.Predicates) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Collectors(java.util.stream.Collectors) ColorAssignment(mage.abilities.dynamicvalue.common.ColorAssignment) Game(mage.game.Game) List(java.util.List) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) ObjectColor(mage.ObjectColor) Ability(mage.abilities.Ability) ObjectColor(mage.ObjectColor) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 50 with ColorPredicate

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

the class AddleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    ChoiceColor choice = new ChoiceColor();
    if (controller != null && controller.choose(outcome, choice, game)) {
        ObjectColor color = choice.getColor();
        game.informPlayers(controller.getLogName() + " chooses " + color + '.');
        FilterCard filter = new FilterCard();
        filter.add(new ColorPredicate(color));
        Effect effect = new DiscardCardYouChooseTargetEffect(filter);
        return effect.apply(game, source);
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) ObjectColor(mage.ObjectColor) DiscardCardYouChooseTargetEffect(mage.abilities.effects.common.discard.DiscardCardYouChooseTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) DiscardCardYouChooseTargetEffect(mage.abilities.effects.common.discard.DiscardCardYouChooseTargetEffect) ChoiceColor(mage.choices.ChoiceColor)

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