Search in sources :

Example 6 with FilterObject

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

the class RunedHaloSetProtectionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
    if (controller != null && cardName != null && !cardName.isEmpty()) {
        FilterObject filter = new FilterObject("the card name [" + cardName + ']');
        filter.add(new NamePredicate(cardName));
        ContinuousEffect effect = new GainAbilityControllerEffect(new ProtectionAbility(filter), Duration.Custom);
        game.addEffect(effect, source);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterObject(mage.filter.FilterObject) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainAbilityControllerEffect(mage.abilities.effects.common.continuous.GainAbilityControllerEffect)

Example 7 with FilterObject

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

the class EmptyShrineKannushiProtectionAbility method canTarget.

@Override
public boolean canTarget(MageObject source, Game game) {
    ObjectColor color = new ObjectColor();
    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(controllerId)) {
        ObjectColor permanentColor = permanent.getColor(game);
        if (permanentColor.isColorless()) {
            continue;
        }
        if (permanentColor.isBlack()) {
            color.setBlack(true);
        }
        if (permanentColor.isBlue()) {
            color.setBlue(true);
        }
        if (permanentColor.isGreen()) {
            color.setGreen(true);
        }
        if (permanentColor.isRed()) {
            color.setRed(true);
        }
        if (permanentColor.isWhite()) {
            color.setWhite(true);
        }
    }
    List<Predicate<MageObject>> colorPredicates = new ArrayList<>();
    if (color.isBlack()) {
        colorPredicates.add(new ColorPredicate(ObjectColor.BLACK));
    }
    if (color.isBlue()) {
        colorPredicates.add(new ColorPredicate(ObjectColor.BLUE));
    }
    if (color.isGreen()) {
        colorPredicates.add(new ColorPredicate(ObjectColor.GREEN));
    }
    if (color.isRed()) {
        colorPredicates.add(new ColorPredicate(ObjectColor.RED));
    }
    if (color.isWhite()) {
        colorPredicates.add(new ColorPredicate(ObjectColor.WHITE));
    }
    Filter protectionFilter = new FilterObject("the colors of permanents you control");
    protectionFilter.add(Predicates.or(colorPredicates));
    this.filter = protectionFilter;
    return super.canTarget(source, game);
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Permanent(mage.game.permanent.Permanent) Filter(mage.filter.Filter) FilterObject(mage.filter.FilterObject) ObjectColor(mage.ObjectColor) ArrayList(java.util.ArrayList) Predicate(mage.filter.predicate.Predicate) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate)

Example 8 with FilterObject

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

the class MournersShieldEffect method init.

@Override
public void init(Ability source, Game game) {
    ObjectColor colorsAmongImprinted = new ObjectColor();
    Permanent sourceObject = game.getPermanent(source.getSourceId());
    ExileZone exileZone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source.getSourceId()));
    if (sourceObject == null || sourceObject.getImprinted() == null) {
        noneExiled = true;
        return;
    }
    for (UUID imprinted : sourceObject.getImprinted()) {
        if (imprinted != null && exileZone.contains(imprinted)) {
            Card card = game.getCard(imprinted);
            if (card != null) {
                colorsAmongImprinted = colorsAmongImprinted.union(card.getColor(game));
            }
        }
    }
    FilterObject filterObject = new FilterObject("a source of your choice that shares a color with the exiled card");
    filterObject.add(new SharesColorPredicate(colorsAmongImprinted));
    this.target = new TargetSource(filterObject);
    this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game);
    if (target.getFirstTarget() != null) {
        mageObjectReference = new MageObjectReference(target.getFirstTarget(), game);
    } else {
        mageObjectReference = null;
    }
}
Also used : TargetSource(mage.target.TargetSource) Permanent(mage.game.permanent.Permanent) SharesColorPredicate(mage.filter.predicate.mageobject.SharesColorPredicate) FilterObject(mage.filter.FilterObject) ObjectColor(mage.ObjectColor) ExileZone(mage.game.ExileZone) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card)

Aggregations

FilterObject (mage.filter.FilterObject)8 ObjectColor (mage.ObjectColor)7 ColorPredicate (mage.filter.predicate.mageobject.ColorPredicate)6 Permanent (mage.game.permanent.Permanent)5 ProtectionAbility (mage.abilities.keyword.ProtectionAbility)4 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 MageObjectReference (mage.MageObjectReference)1 ContinuousEffect (mage.abilities.effects.ContinuousEffect)1 GainAbilityControllerEffect (mage.abilities.effects.common.continuous.GainAbilityControllerEffect)1 Card (mage.cards.Card)1 Filter (mage.filter.Filter)1 Predicate (mage.filter.predicate.Predicate)1 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)1 SharesColorPredicate (mage.filter.predicate.mageobject.SharesColorPredicate)1 ExileZone (mage.game.ExileZone)1 Player (mage.players.Player)1 TargetSource (mage.target.TargetSource)1 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)1