Search in sources :

Example 11 with ProtectionAbility

use of mage.abilities.keyword.ProtectionAbility in project mage by magefree.

the class RazorBarrierEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    if (player.chooseUse(outcome, "Give the targeted permanent protection from artifacts?", null, "Yes", "No (choose a color instead)", source, game)) {
        game.addEffect(new GainAbilityTargetEffect(new ProtectionAbility(filter), Duration.EndOfTurn), source);
        return true;
    }
    game.addEffect(new GainProtectionFromColorTargetEffect(Duration.EndOfTurn), source);
    return true;
}
Also used : Player(mage.players.Player) GainProtectionFromColorTargetEffect(mage.abilities.effects.common.continuous.GainProtectionFromColorTargetEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ProtectionAbility(mage.abilities.keyword.ProtectionAbility)

Example 12 with ProtectionAbility

use of mage.abilities.keyword.ProtectionAbility in project mage by magefree.

the class MirrorGolemEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourceObject = game.getPermanent(source.getSourceId());
    ExileZone exileZone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source.getSourceId()));
    if (sourceObject == null || sourceObject.getImprinted() == null) {
        return false;
    }
    for (UUID imprinted : sourceObject.getImprinted()) {
        if (imprinted != null && exileZone.contains(imprinted)) {
            Card card = game.getCard(imprinted);
            if (card != null) {
                for (CardType cardType : card.getCardType(game)) {
                    FilterCard filterCard;
                    if (cardType.equals(CardType.SORCERY)) {
                        filterCard = new FilterCard("sorceries");
                    } else if (cardType.equals(CardType.TRIBAL)) {
                        filterCard = new FilterCard("tribal");
                    } else {
                        filterCard = new FilterCard(cardType.toString() + "s");
                    }
                    filterCard.add(cardType.getPredicate());
                    sourceObject.addAbility(new ProtectionAbility(filterCard), source.getSourceId(), game);
                }
            }
        }
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Permanent(mage.game.permanent.Permanent) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) ExileZone(mage.game.ExileZone) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 13 with ProtectionAbility

use of mage.abilities.keyword.ProtectionAbility 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 14 with ProtectionAbility

use of mage.abilities.keyword.ProtectionAbility in project mage by magefree.

the class EarnestFellowshipEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
        if (permanent.getColor(game).hasColor()) {
            List<ColorPredicate> colorPredicates = new ArrayList<>();
            for (ObjectColor color : permanent.getColor(game).getColors()) {
                colorPredicates.add(new ColorPredicate(color));
            }
            FilterCard filterColors = new FilterCard("its colors");
            filterColors.add(Predicates.or(colorPredicates));
            Ability ability = new ProtectionAbility(filterColors);
            permanent.addAbility(ability, source.getSourceId(), game);
        }
    }
    return true;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) FilterCard(mage.filter.FilterCard) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ArrayList(java.util.ArrayList) ObjectColor(mage.ObjectColor) ProtectionAbility(mage.abilities.keyword.ProtectionAbility)

Example 15 with ProtectionAbility

use of mage.abilities.keyword.ProtectionAbility in project mage by magefree.

the class EonFrolickerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getFirstTarget());
    if (player == null) {
        return false;
    }
    game.getState().getTurnMods().add(new TurnMod(player.getId(), false));
    FilterPlayer filter = new FilterPlayer(player.getName());
    filter.add(new PlayerIdPredicate(player.getId()));
    Ability ability = new ProtectionAbility(filter);
    game.addEffect(new GainAbilityControlledEffect(ability, Duration.UntilYourNextTurn, StaticFilters.FILTER_PERMANENT_PLANESWALKER), source);
    game.addEffect(new GainAbilityControllerEffect(ability, Duration.UntilYourNextTurn), source);
    return true;
}
Also used : EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) ConditionalInterveningIfTriggeredAbility(mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility) FlyingAbility(mage.abilities.keyword.FlyingAbility) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) FilterPlayer(mage.filter.FilterPlayer) GainAbilityControlledEffect(mage.abilities.effects.common.continuous.GainAbilityControlledEffect) FilterPlayer(mage.filter.FilterPlayer) PlayerIdPredicate(mage.filter.predicate.other.PlayerIdPredicate) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) TurnMod(mage.game.turn.TurnMod) GainAbilityControllerEffect(mage.abilities.effects.common.continuous.GainAbilityControllerEffect)

Aggregations

ProtectionAbility (mage.abilities.keyword.ProtectionAbility)24 ColorPredicate (mage.filter.predicate.mageobject.ColorPredicate)14 Permanent (mage.game.permanent.Permanent)13 FilterCard (mage.filter.FilterCard)12 Player (mage.players.Player)10 ObjectColor (mage.ObjectColor)7 Ability (mage.abilities.Ability)7 GainAbilityControllerEffect (mage.abilities.effects.common.continuous.GainAbilityControllerEffect)4 FilterObject (mage.filter.FilterObject)4 ContinuousEffect (mage.abilities.effects.ContinuousEffect)3 GainAbilityControlledEffect (mage.abilities.effects.common.continuous.GainAbilityControlledEffect)3 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)3 GainProtectionFromColorTargetEffect (mage.abilities.effects.common.continuous.GainProtectionFromColorTargetEffect)3 FlyingAbility (mage.abilities.keyword.FlyingAbility)3 ChoiceColor (mage.choices.ChoiceColor)3 FilterPermanent (mage.filter.FilterPermanent)3 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)3 ArrayList (java.util.ArrayList)2 MageObject (mage.MageObject)2 EntersBattlefieldTriggeredAbility (mage.abilities.common.EntersBattlefieldTriggeredAbility)2