Search in sources :

Example 6 with ProtectionAbility

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

the class ProtectionChosenColorTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (permanent != null) {
        ObjectColor color = (ObjectColor) game.getState().getValue(permanent.getId() + "_color");
        if (color != null && (protectionAbility == null || !color.equals(chosenColor))) {
            chosenColor = color;
            FilterObject protectionFilter = new FilterObject(chosenColor.getDescription());
            protectionFilter.add(new ColorPredicate(chosenColor));
            protectionAbility = new ProtectionAbility(protectionFilter);
        }
        if (protectionAbility != null) {
            permanent.addAbility(protectionAbility, source.getSourceId(), game);
            return true;
        }
    }
    return false;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterObject(mage.filter.FilterObject) ObjectColor(mage.ObjectColor) ProtectionAbility(mage.abilities.keyword.ProtectionAbility)

Example 7 with ProtectionAbility

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

the class ProtectionChosenColorSourceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent != null) {
        ObjectColor color = (ObjectColor) game.getState().getValue(permanent.getId() + "_color");
        if (color != null && (protectionAbility == null || !color.equals(chosenColor))) {
            chosenColor = color;
            FilterObject protectionFilter = new FilterObject(chosenColor.getDescription());
            protectionFilter.add(new ColorPredicate(chosenColor));
            protectionAbility = new ProtectionAbility(protectionFilter);
        }
        if (protectionAbility != null) {
            permanent.addAbility(protectionAbility, source.getSourceId(), game);
            return true;
        }
    }
    return false;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Permanent(mage.game.permanent.Permanent) FilterObject(mage.filter.FilterObject) ObjectColor(mage.ObjectColor) ProtectionAbility(mage.abilities.keyword.ProtectionAbility)

Example 8 with ProtectionAbility

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

the class ProtectionChosenColorAttachedEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent attachement = game.getPermanent(source.getSourceId());
    if (attachement != null && attachement.getAttachedTo() != null) {
        ObjectColor color = (ObjectColor) game.getState().getValue(attachement.getId() + "_color");
        if (color != null && (protectionAbility == null || !color.equals(chosenColor))) {
            chosenColor = color;
            FilterObject protectionFilter = new FilterObject(chosenColor.getDescription());
            protectionFilter.add(new ColorPredicate(chosenColor));
            protectionAbility = new ProtectionAbility(protectionFilter);
            if (notRemoveItself) {
                protectionAbility.setAuraIdNotToBeRemoved(source.getSourceId());
            }
            if (notRemoveControlled) {
                protectionAbility.setDoesntRemoveControlled(true);
                protectionAbility.setRemoveEquipment(false);
                protectionAbility.setRemovesAuras(false);
            }
        }
        if (protectionAbility != null) {
            Permanent attachedTo = game.getPermanent(attachement.getAttachedTo());
            if (attachedTo != null) {
                attachedTo.addAbility(protectionAbility, source.getSourceId(), game);
            }
            return true;
        }
    }
    return false;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Permanent(mage.game.permanent.Permanent) FilterObject(mage.filter.FilterObject) ObjectColor(mage.ObjectColor) ProtectionAbility(mage.abilities.keyword.ProtectionAbility)

Example 9 with ProtectionAbility

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

the class SamiteElderEffect method apply.

public boolean apply(Game game, Ability source) {
    Permanent target = game.getPermanent(source.getFirstTarget());
    if (target != null) {
        for (ObjectColor color : target.getColor(game).getColors()) {
            FilterCard filter = new FilterCard(color.getDescription());
            filter.add(new ColorPredicate(color));
            game.addEffect(new GainAbilityControlledEffect(new ProtectionAbility(filter), Duration.EndOfTurn, new FilterControlledCreaturePermanent()), source);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) GainAbilityControlledEffect(mage.abilities.effects.common.continuous.GainAbilityControlledEffect) ObjectColor(mage.ObjectColor) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Example 10 with ProtectionAbility

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

the class FavorOfTheMightyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int maxCMC = Integer.MIN_VALUE;
    for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game)) {
        if (permanent != null && permanent.getManaValue() > maxCMC) {
            maxCMC = permanent.getManaValue();
        }
    }
    FilterPermanent filterMaxCMC = new FilterCreaturePermanent();
    filterMaxCMC.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, maxCMC));
    for (Permanent permanent : game.getBattlefield().getActivePermanents(filterMaxCMC, source.getControllerId(), game)) {
        if (permanent != null) {
            permanent.addAbility(new ProtectionAbility(filter), source.getSourceId(), game);
        }
    }
    return true;
}
Also used : ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ProtectionAbility(mage.abilities.keyword.ProtectionAbility)

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