Search in sources :

Example 21 with ProtectionAbility

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

the class GainAbilityAttachedEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent;
    if (affectedObjectsSet) {
        permanent = game.getPermanent(targetPointer.getFirst(game, source));
        if (permanent == null) {
            discard();
            return true;
        }
    } else {
        Permanent equipment = game.getPermanent(source.getSourceId());
        if (equipment != null && equipment.getAttachedTo() != null) {
            permanent = game.getPermanentOrLKIBattlefield(equipment.getAttachedTo());
        } else {
            permanent = null;
        }
    }
    if (permanent != null) {
        if (doesntRemoveItself && ability instanceof ProtectionAbility) {
            ((ProtectionAbility) ability).setAuraIdNotToBeRemoved(source.getSourceId());
        }
        permanent.addAbility(ability, source.getSourceId(), game);
        afterGain(game, source, permanent, ability);
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) ProtectionAbility(mage.abilities.keyword.ProtectionAbility)

Example 22 with ProtectionAbility

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

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

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

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